-
Notifications
You must be signed in to change notification settings - Fork 83
/
jquery.wmuGallery.js
96 lines (86 loc) · 3.42 KB
/
jquery.wmuGallery.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
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
/*!
* jQuery wmuGallery v2.1
*
* Copyright (c) 2011 Brice Lechatellier
* http://brice.lechatellier.com/
*
* Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
*/
;(function($) {
$.fn.wmuGallery = function(options) {
/* Default Options
================================================== */
var defaults = {
position: 'before',
animationDuration: 600,
touch: false,
slide: 'article',
items: 5
};
var options = $.extend(defaults, options);
return this.each(function() {
/* Variables
================================================== */
var $this = $(this);
var slides = $this.find(options.slide);
var gallery;
var image;
var slider;
/* Slider
================================================== */
var loadImage = function(i) {
var imageURI = $(slides[i]).find('img').attr('data-src-full');
if (!image) {
image = $('<img src="' + imageURI + '" />');
gallery.append(image);
} else {
image.attr('src', imageURI);
}
};
/* Init
================================================== */
var init = function() {
gallery = $('<div class="wmuGalleryImage"></div>');
if (options.position == 'before') {
$this.prepend(gallery);
} else if (options.position == 'after') {
$this.append(gallery);
}
if (!$.isFunction($.fn.wmuSlider)) {
$.ajax({
url: 'jquery.wmuSlider.min.js',
async: false
});
}
if ($.isFunction($.fn.wmuSlider)) {
slider = $this.find('.wmuSlider');
slider.bind('hasLoaded', function(e) {
var prev = slider.find('.wmuSliderPrev');
var next = slider.find('.wmuSliderNext');
var pagination = slider.find('.wmuSliderPagination');
gallery.append(prev);
gallery.append(next);
gallery.append(pagination);
slides = $this.find(options.slide);
slides.each(function(i) {
var slide = $(this);
slide.click(function(e) {
e.preventDefault();
slider.trigger('loadSlide', parseInt(slide.attr('data-index')));
});
});
}).bind('slideLoaded', function(e, i) {
loadImage(i);
}).wmuSlider({
touch: options.touch,
animation: 'slide',
animationDuration: options.animationDuration,
slide: options.slide,
items: options.items
});
}
};
init();
});
}
})(jQuery);