Repository navigation
Expand file tree
/
Copy pathfeatherlight.gallery.js
More file actions
101 lines (89 loc) · 3.44 KB
/
Copy pathfeatherlight.gallery.js
File metadata and controls
101 lines (89 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* Featherlight Gallery – an extension for the ultra slim jQuery lightbox
* Version 0.4.10 - http://noelboss.github.io/featherlight/
*
* Copyright 2014, Noël Raoul Bossart (http://www.noelboss.com)
* MIT Licensed.
**/
(function($) {
"use strict";
if('undefined' === typeof $) {
if('console' in window){ window.console.info('Too much lightness, Featherlight needs jQuery.');
if(!('featherlight' in $)){ window.console.info('Load the featherlight plugin before the gallery plugin'); }
}
return;
}
var isTouchAware = 'ontouchstart' in document.documentElement,
jQueryConstructor = $.event && $.event.special.swipeleft && $,
hammerConstructor = ('Hammer' in window) && function($el){ new window.Hammer(el[0]); },
swipeAwareConstructor = isTouchAware && (jQueryConstructor || hammerConstructor);
/* extend jQuery with selector featherlight method $(elm).featherlight(config, elm); */
$.fn.featherlightGallery = function(config) {
var $gallery = $(this),
flg = {
gallery: {
previous: '◀', /* Code that is used as previous icon */
next: '▶', /* Code that is used as next icon */
fadeIn: 100, /* fadeIn speed when image is loaded */
fadeOut: 300 /* fadeOut speed before image is loaded */
},
type: {
image: true
}
},
customAfterOpen = config && config.afterOpen,
customAfterClose = config && config.afterClose,
overrideCallbacks = { /* provide an afterOpen function */
afterClose: function(event){
var fl = this;
fl.$instance.off('next.'+fl.config.namespace+' previous.'+fl.config.namespace);
if (swipeAwareConstructor) {
fl.$instance.off('swipeleft');
fl.$instance.off('swiperight');
}
if('function' === typeof customAfterClose) {
customAfterClose.call(this, event);
}
},
afterOpen: function(event){
var fl = this,
$img = fl.$instance.find('img');
fl.$currentTarget = $(event.currentTarget);
$img.load(function(){
$img.stop().fadeTo(fl.config.gallery.fadeIn,1);
});
fl.$instance.on('next.'+fl.config.namespace+' previous.'+fl.config.namespace, function(event){
var offset = event.type === 'next' ? +1 : -1;
var $nx = $gallery.eq(($gallery.index(fl.$currentTarget)+offset) % $gallery.length);
$img.fadeTo(fl.config.gallery.fadeOut,0.2);
fl.$currentTarget = $nx;
$img[0].src = $nx.attr('href');
});
if (swipeAwareConstructor) {
swipeAwareConstructor(fl.$instance)
.on('swipeleft', function() { fl.$instance.trigger('next'); })
.on('swiperight', function() { fl.$instance.trigger('previous'); });
} else {
var createNav = function(target){
return $('<span title="'+target+'" class="'+fl.config.namespace+'-'+target+'"><span>'+fl.config.gallery[target]+'</span></span>').click(function(){
$(this).trigger(target+'.'+fl.config.namespace);
});
};
$img.after(createNav('previous'))
.after(createNav('next'));
}
if('function' === typeof customAfterOpen) {
customAfterOpen.call(this, event);
}
}
};
$gallery.featherlight($.extend(true, {}, flg, config, overrideCallbacks));
};
/* extend jQuery with standalone featherlight method $.featherlight(elm, config); */
$.featherlightGallery = function($targets, config) {
if('object' !== typeof $targets){
$targets = $($targets);
}
$targets.featherlightGallery(config);
};
}(jQuery));