This repository has been archived by the owner on Feb 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.simple-gallery.js
66 lines (55 loc) · 1.82 KB
/
jquery.simple-gallery.js
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
/*!
* jQuery Simple Gallery Plugin v2.1
* https://github.com/straube/simple-gallery
*
* Copyright 2013, 2014 Gustavo Straube
*/
;(function ($) {
'use strict';
$.fn.gallery = function (options) {
return this.each(function () {
var settings = $.extend({}, $.fn.gallery.defaults, options);
var $gallery = $(this);
var $images = $gallery.find(settings.tag);
var loop;
// Local functions
var show = function ($image) {
$images.removeClass('current').fadeOut().promise().done(function () {
$image.addClass('current').fadeIn();
});
};
$images.hide().first().show().addClass('current');
$gallery.find('a').on('click', function (event) {
var id = this.href.replace(/^[^#]*(#.*)?$/i, '$1');
if (!id) {
return true;
}
event.preventDefault();
window.clearInterval(loop);
loop = null;
show($images.filter(id));
});
if (settings.loop) {
var interval = settings.interval * 1000;
loop = window.setInterval(function () {
var $next = $images.filter('.current').next(settings.tag);
if ($next.length === 0) {
$next = $images.first();
}
show($next);
}, interval);
}
});
};
$.fn.gallery.defaults = {
tag : 'figure',
loop : true,
interval : 5
};
$(function () {
var $simple = $('[data-gallery="simple"]');
if ($simple.length) {
$simple.gallery($simple.data());
}
});
})(jQuery);