-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.wixel.content_slider.js
149 lines (109 loc) · 3.6 KB
/
jquery.wixel.content_slider.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
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
142
143
144
145
146
147
148
149
/**
* Wixel Content Slider
* http://wixelhq.com
*
* Copyright 2012, WixelHQ
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* Author: Sean Nieuwoudt (http://twitter.com/SeanNieuwoudt)
*/
(function( $ ) {
var methods = {
init : function( options )
{
var settings = $.extend({
'debug': false,
'speed': 500
}, options);
if(settings.debug)
{
jQuery.data(document.body, 'wx_scroll_debug', true);
}
if(settings.speed)
{
jQuery.data(document.body, 'wx_scroll_speed', settings.speed);
}
return this.each(function() {
var i = 1;
var $this = $(this);
$this.data('debug' , settings.debug);
$this.data('duration' , settings.duration);
$this.data('auto_scroll', settings.auto_scroll);
methods.log(settings);
methods.log('Creating the .wx-slide-rail container');
$this.wrapInner('<div class="wx-slide-rail">');
$(this).find('.wx-slide-rail').css({
'position': 'absolute',
'top' : '0',
'left' : '0'
});
$this.find('.slide-item').first().addClass('active-slide');
$this.find('.slide-item').each(function(e){
$(this).attr('position', i);
methods.log('Setting slide position attribute: '+i);
i++;
});
var slide_width = $this.width();
var total_slides = $this.find('.slide-item').length;
var slide_rail_width = slide_width * total_slides;
$this.data('slide_width', slide_width);
$this.find('.wx-slide-rail').css({'width': slide_rail_width});
});
},
next : function()
{
return this.each(function(){
var $this = $(this);
var active_slide = $this.find('.slide-item.active-slide').next();
if (active_slide.length == 0)
{
active_slide = $this.find('.slide-item').first();
}
$this.find('.slide-item').removeClass('active-slide');
active_slide.addClass('active-slide');
methods.log('Sliding to: '+ active_slide.attr('position'));
var count = active_slide.attr('position') - 1;
var slide_width = $(this).data('slide_width');
$this.find('.wx-slide-rail').animate({'left': -(count * slide_width)}, jQuery.data(document.body, 'wx_scroll_speed'));
});
},
previous : function( )
{
return this.each(function(){
var $this = $(this);
var active_slide = $this.find('.slide-item.active-slide').prev();
if (active_slide.length == 0)
{
active_slide = $this.find('.slide-item').last();
}
$this.find('.slide-item').removeClass('active-slide');
active_slide.addClass('active-slide');
methods.log('Sliding to: '+ active_slide.attr('position'));
var count = active_slide.attr('position') - 1;
var slide_width = $(this).data('slide_width');
$this.find('.wx-slide-rail').animate({'left': -(count * slide_width)}, jQuery.data(document.body, 'wx_scroll_speed'));
});
},
log: function(msg)
{
if(jQuery.data(document.body, 'wx_scroll_debug') && console)
{
console.log(msg);
}
}
};
$.fn.wxContentSlider = function(method) {
if(methods[method])
{
return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
}
else if ( typeof method === 'object' || ! method )
{
return methods.init.apply( this, arguments );
}
else
{
$.error( 'Method ' + method + ' does not exist on jQuery.wxContentSlider' );
}
};
})( jQuery );