jquery-radiantscroller-rails 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffce4f5a48353afbbfdab1ca1bef4aecf3d6dcb6
|
4
|
+
data.tar.gz: 870598a436c4c9e3bd6d17fa2604c0711f16f1eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 514f254964e76dee7a8c3ea770a2ef277ba0361a8baf86732419cba44ef4f91ef8b0906c846bc6ad15f267bfd0b37c686ffc1addc33bb2e8d39dae32b062a6aa
|
7
|
+
data.tar.gz: 569ba7661c06423b6e81c1207f7fa2f3c3c7138d8df01ac9963b0612112b2bff7428fc6f155ed4c1809a5af3fce3fd8d5eefbbd8d29c9ef0a21f5765d69614c2
|
@@ -1,183 +1,189 @@
|
|
1
1
|
/*!
|
2
2
|
* jQuery RadiantScroller
|
3
|
-
* Version: 0.0.
|
3
|
+
* Version: 0.0.5 (28/07/2014)
|
4
4
|
* Copyright (c) 2014 Ilya Bodrov (http://www.radiant-wind.com/plugins/radiant_scroller)
|
5
5
|
*
|
6
6
|
* Requires: jQuery 1.7.0+
|
7
7
|
*/
|
8
8
|
|
9
9
|
(function($) {
|
10
|
-
|
11
|
-
|
10
|
+
$.radiantScroller = function(el, options) {
|
11
|
+
var scroller = $(el);
|
12
12
|
|
13
|
-
|
13
|
+
scroller.vars = $.extend({}, $.radiantScroller.defaults, options);
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
// Store reference to scroller in data of the object
|
16
|
+
scroller.data("radiantscroller", scroller);
|
17
|
+
// Set to true when scrolling
|
18
|
+
scroller.animating = false;
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
var elements = scroller.find('.scroller-el'),
|
21
|
+
el_count = elements.size(),
|
22
|
+
el_width = scroller.vars.elementWidth + scroller.vars.elementMargin,
|
23
|
+
per_row = Math.ceil(el_count / scroller.vars.rows);
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
// Calculating scroller's width with regard to items per row
|
26
|
+
scroller.width( (el_width * per_row) - scroller.vars.elementMargin );
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
28
|
+
// Grouping elements by rows
|
29
|
+
do $(elements.slice(0, per_row)).wrapAll('<div class="radiant_scroller_row" />');
|
30
|
+
while((elements = elements.slice(per_row)).length > 0);
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
// Wrapper with hidden scrollbars
|
33
|
+
scroller.wrap('<div class="radiant_scroller"></div>').wrap('<div class="radiant_scroller_wrapper" />');
|
34
|
+
var wrapper = scroller.parent('.radiant_scroller_wrapper'),
|
35
|
+
outer_wrapper = wrapper.parent('.radiant_scroller'),
|
36
|
+
max_wrapper_width = (scroller.vars.cols * el_width - scroller.vars.elementMargin) + 'px';
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
outer_wrapper.css('max-width', max_wrapper_width);
|
38
|
+
wrapper.css('max-width', max_wrapper_width);
|
39
|
+
outer_wrapper.css('max-width', max_wrapper_width);
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
// Next/previous buttons
|
42
|
+
var nav = $('<div class="radiant-navigation" />').insertAfter(wrapper),
|
43
|
+
prev = nav.append($('<div class="radiant-prev">' + scroller.vars.prevButtonText + '</div>')),
|
44
|
+
next = nav.append($('<div class="radiant-next">' + scroller.vars.nextButtonText + '</div>'));
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
46
|
+
// Scroller methods
|
47
|
+
scroller.calculateVisibleElements = function() {
|
48
|
+
scroller.visible_els = (wrapper.width() + scroller.vars.elementMargin) / el_width;
|
49
|
+
};
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
var new_current_page = scroller.current_page + scrollBy;
|
57
|
-
// The requested page should be between 0 and total number of pages and should not be the same page
|
58
|
-
// as the current, otherwise do nothing
|
59
|
-
if (new_current_page >= 0 && new_current_page < scroller.total_pages &&
|
60
|
-
new_current_page !== scroller.current_page) {
|
61
|
-
scroller.animating = true;
|
62
|
-
|
63
|
-
wrapper.animate(
|
64
|
-
{ scrollLeft: wrapper.scrollLeft() + scroller.visible_els * el_width * scrollBy },
|
65
|
-
scroller.vars.animateDuration, scroller.vars.easingType,
|
66
|
-
function() { scroller.animating = false; }
|
67
|
-
);
|
68
|
-
|
69
|
-
scroller.current_page = new_current_page;
|
70
|
-
|
71
|
-
if (scroller.vars.addPagination)
|
72
|
-
scroller.assignActivePage(true);
|
73
|
-
}
|
74
|
-
}
|
75
|
-
};
|
51
|
+
scroller.moveElements = function(scrollBy, instant) {
|
52
|
+
if (!scroller.animating) {
|
53
|
+
if (typeof scrollBy === 'undefined')
|
54
|
+
scrollBy = 1;
|
76
55
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
scroller.old_visible_els = scroller.visible_els;
|
81
|
-
scroller.total_pages = Math.ceil(per_row / scroller.visible_els);
|
82
|
-
|
83
|
-
if (typeof scroller.current_page === 'undefined') {
|
84
|
-
// If current page was not set previously, we set it now
|
85
|
-
scroller.current_page = 0;
|
86
|
-
} else {
|
87
|
-
scroller.current_page = Math.ceil(wrapper.scrollLeft() / (scroller.visible_els * el_width));
|
88
|
-
}
|
89
|
-
|
90
|
-
if (scroller.vars.addPagination)
|
91
|
-
scroller.drawPagination();
|
92
|
-
}
|
93
|
-
};
|
56
|
+
var duration = scroller.vars.animateDuration;
|
57
|
+
if (typeof instant !== 'undefined' && instant)
|
58
|
+
duration = 0;
|
94
59
|
|
95
|
-
scroller.
|
96
|
-
|
97
|
-
|
60
|
+
var new_current_page = scroller.current_page + scrollBy;
|
61
|
+
// The requested page should be between 0 and total number of pages and should not be the same page
|
62
|
+
// as the current, otherwise do nothing
|
63
|
+
if (new_current_page >= 0 && new_current_page < scroller.total_pages &&
|
64
|
+
new_current_page !== scroller.current_page) {
|
65
|
+
scroller.animating = true;
|
98
66
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
};
|
67
|
+
wrapper.animate(
|
68
|
+
{ scrollLeft: wrapper.scrollLeft() + scroller.visible_els * el_width * scrollBy },
|
69
|
+
duration, scroller.vars.easingType,
|
70
|
+
function() { scroller.animating = false; }
|
71
|
+
);
|
105
72
|
|
106
|
-
|
107
|
-
if (remove_old_active === true)
|
108
|
-
outer_wrapper.find('.current-page').removeClass('current-page');
|
109
|
-
$(outer_wrapper.find('.radiant-page').get(scroller.current_page)).addClass('current-page');
|
110
|
-
};
|
73
|
+
scroller.current_page = new_current_page;
|
111
74
|
|
112
|
-
|
113
|
-
|
114
|
-
scroller.calculateVisibleElements();
|
115
|
-
scroller.initializePagination();
|
116
|
-
}, 500, true);
|
117
|
-
|
118
|
-
nav.on('click', '.radiant-next', function() {
|
119
|
-
scroller.moveElements(1);
|
120
|
-
});
|
121
|
-
|
122
|
-
nav.on('click', '.radiant-prev', function() {
|
123
|
-
scroller.moveElements(-1);
|
124
|
-
});
|
125
|
-
|
126
|
-
if (scroller.vars.useMouseWheel) {
|
127
|
-
wrapper.on('mousewheel', function(event) {
|
128
|
-
event.preventDefault();
|
129
|
-
scroller.moveElements(event.deltaY);
|
130
|
-
});
|
75
|
+
if (scroller.vars.addPagination)
|
76
|
+
scroller.assignActivePage(true);
|
131
77
|
}
|
132
|
-
|
133
|
-
outer_wrapper.on('click', '.radiant-page', function() {
|
134
|
-
var this_page = $(this).data('page');
|
135
|
-
// If not clicking on the same page
|
136
|
-
if (scroller.current_page !== this_page) {
|
137
|
-
var current_page_number = scroller.current_page;
|
138
|
-
scroller.moveElements(this_page - current_page_number);
|
139
|
-
}
|
140
|
-
});
|
141
|
-
|
142
|
-
// Init scroller
|
143
|
-
scroller.calculateVisibleElements();
|
144
|
-
scroller.initializePagination();
|
145
|
-
};
|
146
|
-
|
147
|
-
$.radiantScroller.defaults = {
|
148
|
-
cols: 2,
|
149
|
-
elementWidth: 200,
|
150
|
-
elementMargin: 10,
|
151
|
-
easingType: 'swing',
|
152
|
-
animateDuration: 700,
|
153
|
-
rows: 2,
|
154
|
-
useMouseWheel: false,
|
155
|
-
addPagination: false,
|
156
|
-
nextButtonText: '',
|
157
|
-
prevButtonText: ''
|
78
|
+
}
|
158
79
|
};
|
159
80
|
|
160
|
-
|
161
|
-
|
81
|
+
scroller.initializePagination = function() {
|
82
|
+
// If there is the same number of visible elements we don't have to change anything
|
83
|
+
if (typeof scroller.old_visible_els === 'undefined' || scroller.old_visible_els !== scroller.visible_els) {
|
84
|
+
scroller.old_visible_els = scroller.visible_els;
|
85
|
+
scroller.total_pages = Math.ceil(per_row / scroller.visible_els);
|
162
86
|
|
163
|
-
if (typeof
|
164
|
-
|
87
|
+
if (typeof scroller.current_page === 'undefined') {
|
88
|
+
// If current page was not set previously, we set it now
|
89
|
+
scroller.current_page = 0;
|
165
90
|
} else {
|
166
|
-
|
167
|
-
switch (options) {
|
168
|
-
case "next": $scroller.moveElements(1); break;
|
169
|
-
case "prev": $scroller.moveElements(-1); break;
|
170
|
-
// radiantScroller('by', 2) - scroll by 2 pages, not to the 2nd page
|
171
|
-
//TODO: check number
|
172
|
-
case "by": if (typeof options2 === "number") $scroller.moveElements(options2); break;
|
173
|
-
// Default behaviour: radiantScroller(3) means go to 3 page and page numeration starts from 1
|
174
|
-
// (whereas plugin has numeration starting from 0, so have to substract 1!!!)
|
175
|
-
default: if (typeof options === "number") $scroller.moveElements(options - 1 - $scroller.current_page);
|
176
|
-
}
|
91
|
+
scroller.current_page = Math.ceil(wrapper.scrollLeft() / (scroller.visible_els * el_width));
|
177
92
|
}
|
178
93
|
|
179
|
-
|
94
|
+
if (scroller.vars.addPagination)
|
95
|
+
scroller.drawPagination();
|
96
|
+
}
|
180
97
|
};
|
98
|
+
|
99
|
+
scroller.drawPagination = function() {
|
100
|
+
if (outer_wrapper.find('.radiant-pagination').size() > 0)
|
101
|
+
outer_wrapper.find('.radiant-pagination').remove();
|
102
|
+
|
103
|
+
var pagination = $('<div class="radiant-pagination" />').insertAfter(wrapper);
|
104
|
+
for (var i = 0; i < scroller.total_pages; i++) {
|
105
|
+
pagination.append('<div class="radiant-page" data-page="' + i + '" />');
|
106
|
+
}
|
107
|
+
scroller.assignActivePage();
|
108
|
+
};
|
109
|
+
|
110
|
+
scroller.assignActivePage = function(remove_old_active) {
|
111
|
+
if (remove_old_active === true)
|
112
|
+
outer_wrapper.find('.current-page').removeClass('current-page');
|
113
|
+
$(outer_wrapper.find('.radiant-page').get(scroller.current_page)).addClass('current-page');
|
114
|
+
};
|
115
|
+
|
116
|
+
// Binding events
|
117
|
+
$(window).bindWithDelay('resize', function() {
|
118
|
+
scroller.calculateVisibleElements();
|
119
|
+
scroller.initializePagination();
|
120
|
+
var temp_page = scroller.current_page;
|
121
|
+
scroller.moveElements(-temp_page, true);
|
122
|
+
scroller.moveElements(temp_page, true);
|
123
|
+
}, scroller.vars.delayDuration, true);
|
124
|
+
|
125
|
+
nav.on('click', '.radiant-next', function() {
|
126
|
+
scroller.moveElements(1);
|
127
|
+
});
|
128
|
+
|
129
|
+
nav.on('click', '.radiant-prev', function() {
|
130
|
+
scroller.moveElements(-1);
|
131
|
+
});
|
132
|
+
|
133
|
+
if (scroller.vars.useMouseWheel) {
|
134
|
+
wrapper.on('mousewheel', function(event) {
|
135
|
+
event.preventDefault();
|
136
|
+
scroller.moveElements(event.deltaY);
|
137
|
+
});
|
138
|
+
}
|
139
|
+
|
140
|
+
outer_wrapper.on('click', '.radiant-page', function() {
|
141
|
+
var this_page = $(this).data('page');
|
142
|
+
// If not clicking on the same page
|
143
|
+
if (scroller.current_page !== this_page) {
|
144
|
+
scroller.moveElements(this_page - scroller.current_page);
|
145
|
+
}
|
146
|
+
});
|
147
|
+
|
148
|
+
// Init scroller
|
149
|
+
scroller.calculateVisibleElements();
|
150
|
+
scroller.initializePagination();
|
151
|
+
};
|
152
|
+
|
153
|
+
$.radiantScroller.defaults = {
|
154
|
+
addPagination: false,
|
155
|
+
animateDuration: 700,
|
156
|
+
cols: 2,
|
157
|
+
delayDuration: 500,
|
158
|
+
easingType: 'swing',
|
159
|
+
elementMargin: 10,
|
160
|
+
elementWidth: 200,
|
161
|
+
nextButtonText: '',
|
162
|
+
prevButtonText: '',
|
163
|
+
rows: 2,
|
164
|
+
useMouseWheel: false
|
165
|
+
};
|
166
|
+
|
167
|
+
$.fn.radiantScroller = function(options, options2) {
|
168
|
+
if (options === undefined) options = {};
|
169
|
+
|
170
|
+
if (typeof options === "object") {
|
171
|
+
new $.radiantScroller(this, options);
|
172
|
+
} else {
|
173
|
+
var $scroller = $(this).data('radiantscroller');
|
174
|
+
switch (options) {
|
175
|
+
case "next": $scroller.moveElements(1); break;
|
176
|
+
case "prev": $scroller.moveElements(-1); break;
|
177
|
+
// radiantScroller('by', 2) - scroll by 2 pages, not to the 2nd page
|
178
|
+
case "by": if (typeof options2 === "number") $scroller.moveElements(options2); break;
|
179
|
+
// Default behaviour: radiantScroller(3) means go to 3 page and page numeration starts from 1
|
180
|
+
// (whereas plugin has numeration starting from 0, so have to substract 1!!!)
|
181
|
+
default: if (typeof options === "number") $scroller.moveElements(options - 1 - $scroller.current_page);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
return this;
|
186
|
+
};
|
181
187
|
})(jQuery);
|
182
188
|
|
183
189
|
/*
|
@@ -200,39 +206,39 @@
|
|
200
206
|
|
201
207
|
(function($) {
|
202
208
|
|
203
|
-
|
209
|
+
$.fn.bindWithDelay = function( type, data, fn, timeout, throttle ) {
|
204
210
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
+
if ( $.isFunction( data ) ) {
|
212
|
+
throttle = timeout;
|
213
|
+
timeout = fn;
|
214
|
+
fn = data;
|
215
|
+
data = undefined;
|
216
|
+
}
|
211
217
|
|
212
|
-
|
213
|
-
|
218
|
+
// Allow delayed function to be removed with fn in unbind function
|
219
|
+
fn.guid = fn.guid || ($.guid && $.guid++);
|
214
220
|
|
215
|
-
|
216
|
-
|
221
|
+
// Bind each separately so that each element has its own delay
|
222
|
+
return this.each(function() {
|
217
223
|
|
218
|
-
|
224
|
+
var wait = null;
|
219
225
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
226
|
+
function cb() {
|
227
|
+
var e = $.extend(true, { }, arguments[0]);
|
228
|
+
var ctx = this;
|
229
|
+
var throttler = function() {
|
230
|
+
wait = null;
|
231
|
+
fn.apply(ctx, [e]);
|
232
|
+
};
|
227
233
|
|
228
|
-
|
229
|
-
|
230
|
-
|
234
|
+
if (!throttle) { clearTimeout(wait); wait = null; }
|
235
|
+
if (!wait) { wait = setTimeout(throttler, timeout); }
|
236
|
+
}
|
231
237
|
|
232
|
-
|
238
|
+
cb.guid = fn.guid;
|
233
239
|
|
234
|
-
|
235
|
-
|
236
|
-
|
240
|
+
$(this).bind(type, data, cb);
|
241
|
+
});
|
242
|
+
};
|
237
243
|
|
238
244
|
})(jQuery);
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jquery-radiantscroller-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilya Bodrov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|