This repository was archived by the owner on Oct 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjQuery.simpleSlider.js
100 lines (78 loc) · 1.96 KB
/
jQuery.simpleSlider.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
97
98
99
100
/*!
* jQuery SimpleSlide Plugin
*
* Copyright(c) 2012 Alex Sancho <[email protected]>
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($) {
"use strict";
$.fn.simpleSlider = function(options) {
return this.each(function() {
new $.simpleSlider(this, options);
});
};
$.simpleSlider = function(element, options) {
this.options = $.extend({}, $.simpleSlider.defaults, options || {});
this.element = $(element);
this.init();
};
$.simpleSlider.prototype = {
init: function() {
var $this = jQuery(this.element),
navi = jQuery('<ul class="navigator" />'),
figures = jQuery('figure', $this);
$this.addClass('simpleSlider slider');
figures.each(function(index, value) {
var idx = index+1,
trigger = jQuery('<li><a href="#">'+idx+'</a></li>');
if (idx === 1) {
trigger.addClass('selected');
} else {
jQuery(value).hide();
}
trigger.bind('click', function(event) {
event.preventDefault();
jQuery(this)
.siblings()
.removeClass('selected');
jQuery(this)
.addClass('selected');
jQuery(value)
.siblings('figure')
.hide();
jQuery(value).show();
});
navi.append(trigger);
});
if (jQuery('li', navi).length > 1) {
var prev = jQuery('<li class="control"><a href="#"><</></li>'),
next = jQuery('<li class="control"><a href="#">></></li>');
prev.bind('click', function(event) {
event.preventDefault();
jQuery(this)
.siblings('.selected')
.prev()
.not('.control')
.click();
});
next.bind('click', function(event) {
event.preventDefault();
jQuery(this)
.siblings('.selected')
.next()
.not('.control')
.click();
});
navi
.prepend(prev)
.append(next);
$this.append(navi);
}
}
};
$.simpleSlider.defaults = {
};
}(jQuery));