Repository navigation
Expand file tree
/
Copy pathfeatherlight.gallery.js
More file actions
141 lines (125 loc) · 4.67 KB
/
Copy pathfeatherlight.gallery.js
File metadata and controls
141 lines (125 loc) · 4.67 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Featherlight Gallery – an extension for the ultra slim jQuery lightbox
* Version 0.4.9 - 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),
callbackChain = {
afterClose: function(_super, event) {
var self = this;
self.$instance.off('next.'+self.namespace+' previous.'+self.namespace);
if (swipeAwareConstructor) {
swipeAwareConstructor(self.$instance).off('swipeleft', self._swipeleft); /* See http://stackoverflow.com/questions/17367198/hammer-js-cant-remove-event-listener */
swipeAwareConstructor(self.$instance).off('swiperight', self._swiperight);
}
return _super(event);
},
beforeOpen: function(_super, event){
var self = this;
self.$instance.on('next.'+self.namespace+' previous.'+self.namespace, function(event){
var offset = event.type === 'next' ? +1 : -1;
self.navigateTo(self.currentNavigation() + offset);
});
if (swipeAwareConstructor) {
swipeAwareConstructor(self.$instance)
.on('swipeleft', self._swipeleft = function() { self.$instance.trigger('next'); })
.on('swiperight', self._swiperight = function() { self.$instance.trigger('previous'); });
} else {
self.$instance.find('.'+self.namespace+'-content')
.append(self.createNavigation('previous'))
.append(self.createNavigation('next'));
}
},
afterOpen: function(_super, event){
_super(event);
this.afterSlide(event);
},
onKeyDown: function(_super, event){
var dir = {
37: 'previous', /* Left arrow */
39: 'next' /* Rigth arrow */
}[event.keyCode];
if(dir) {
this.$instance.trigger(dir);
event.preventDefault();
} else {
return _super(event);
}
}
};
function FeatherlightGallery($source, config) {
if(this instanceof FeatherlightGallery) { /* called with new */
$.featherlight.apply(this, arguments);
this.chainCallbacks(callbackChain);
} else {
var flg = new FeatherlightGallery($.extend({$source: $source, $currentTarget: $source.first()}, config));
flg.open();
return flg;
}
}
$.featherlight.extend(FeatherlightGallery);
$.extend(FeatherlightGallery.prototype, {
/** Additional settings for Gallery **/
beforeSlide: $.noop, /* Callback before an image is changed */
afterSlide: $.noop, /* Callback after an image is presented */
previousIcon: '◀', /* Code that is used as previous icon */
nextIcon: '▶', /* Code that is used as next icon */
galleryFadeIn: 100, /* fadeIn speed when image is loaded */
galleryFadeOut: 300, /* fadeOut speed before image is loaded */
images: function() {
if (this.filter) {
return this.$source.find(this.filter);
}
return this.$source;
},
currentNavigation: function() {
return this.images().index(this.$currentTarget);
},
navigateTo: function(index) {
var self = this,
source = self.images(),
len = source.length,
$inner = self.$instance.find('.' + self.namespace + '-inner');
index = ((index % len) + len) % len; /* pin index to [0, len[ */
self.$currentTarget = source.eq(index);
self.beforeSlide(event);
self.beforeContent();
return $.when(
self.getContent(),
$inner.fadeTo(self.galleryFadeOut,0.2)
).done(function($newContent) {
self.setContent($newContent);
self.afterContent();
self.afterSlide(event);
$newContent.fadeTo(self.galleryFadeIn,1);
});
},
createNavigation: function(target) {
var self = this;
return $('<span title="'+target+'" class="'+this.namespace+'-'+target+'"><span>'+this[target+'Icon']+'</span></span>').click(function(){
$(this).trigger(target+'.'+self.namespace);
});
}
});
FeatherlightGallery.functionAttributes = FeatherlightGallery.functionAttributes.concat([
'beforeSlide', 'afterSlide'
]);
$.featherlightGallery = FeatherlightGallery;
/* extend jQuery with selector featherlight method $(elm).featherlight(config, elm); */
$.fn.featherlightGallery = function(config) {
return FeatherlightGallery.attach(this, config);
};
}(jQuery));