mobiscroll-rails 2.3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README.md +43 -0
- data/lib/mobiscroll-rails.rb +9 -0
- data/lib/mobiscroll-rails/version.rb +5 -0
- data/vendor/assets/javascripts/mobiscroll.android-ics.js +16 -0
- data/vendor/assets/javascripts/mobiscroll.android.js +12 -0
- data/vendor/assets/javascripts/mobiscroll.core.js +966 -0
- data/vendor/assets/javascripts/mobiscroll.datetime.js +656 -0
- data/vendor/assets/javascripts/mobiscroll.ios.js +14 -0
- data/vendor/assets/javascripts/mobiscroll.jqm.js +30 -0
- data/vendor/assets/javascripts/mobiscroll.js +18 -0
- data/vendor/assets/javascripts/mobiscroll.list.js +377 -0
- data/vendor/assets/javascripts/mobiscroll.select.js +257 -0
- data/vendor/assets/javascripts/mobiscroll.wp.js +30 -0
- data/vendor/assets/javascripts/mobiscroll.zepto.js +72 -0
- data/vendor/assets/stylesheets/mobiscroll.android-ics.css +173 -0
- data/vendor/assets/stylesheets/mobiscroll.android.css +90 -0
- data/vendor/assets/stylesheets/mobiscroll.core.css +349 -0
- data/vendor/assets/stylesheets/mobiscroll.css +13 -0
- data/vendor/assets/stylesheets/mobiscroll.ios.css +215 -0
- data/vendor/assets/stylesheets/mobiscroll.jqm.css +249 -0
- data/vendor/assets/stylesheets/mobiscroll.sense-ui.css +62 -0
- data/vendor/assets/stylesheets/mobiscroll.wp.css +249 -0
- data/vendor/assets/stylesheets/wp_icons.png +0 -0
- data/vendor/assets/stylesheets/wp_icons_light.png +0 -0
- metadata +82 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Massimiliano Marzo
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# mobiscroll-rails
|
2
|
+
|
3
|
+
mobiscroll-rails wraps the [Mobiscroll Jquery Plugin](http://mobiscroll.com/) library in a rails engine for simple
|
4
|
+
use with the asset pipeline provided by rails 3.1. The gem includes the development (non-minified)
|
5
|
+
source for ease of exploration. The asset pipeline will minify in production.
|
6
|
+
|
7
|
+
Mobiscroll allow you to create awesome experiences with technologies you know and love, and build hybrid and webapps
|
8
|
+
with mobiscroll UI scroller components, HTML, CSS and Javascript. Please see the
|
9
|
+
[documentation](http://docs.mobiscroll.com/) for details.
|
10
|
+
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
Add the following to your gemfile:
|
15
|
+
|
16
|
+
gem 'mobiscroll-rails'
|
17
|
+
|
18
|
+
Add the following directive to your Javascript manifest file (application.js):
|
19
|
+
|
20
|
+
//= require mobiscroll
|
21
|
+
|
22
|
+
If you want to include a localization file, also add the following directive:
|
23
|
+
|
24
|
+
//= require mobiscroll/<locale>.js
|
25
|
+
|
26
|
+
|
27
|
+
## Versioning
|
28
|
+
|
29
|
+
mobiscroll-rails 3.2.1 == Mobiscroll.js 3.2.1
|
30
|
+
|
31
|
+
Every attempt is made to mirror the currently shipping Mobiscroll.js version number wherever possible.
|
32
|
+
The major, minor, and patch version numbers will always represent the Mobiscroll.js version. Should a gem
|
33
|
+
bug be discovered, a 4th version identifier will be added and incremented.
|
34
|
+
|
35
|
+
|
36
|
+
## Credits
|
37
|
+
|
38
|
+
[Mobiscroll](http://mobiscroll.com/) - For developping the js components.
|
39
|
+
|
40
|
+
|
41
|
+
## Copyright
|
42
|
+
|
43
|
+
Copyright (c) 2012 ( massimiliano dot marzo at gmail dot com ), released under the MIT license.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
(function ($) {
|
2
|
+
var theme = {
|
3
|
+
defaults: {
|
4
|
+
dateOrder: 'Mddyy',
|
5
|
+
mode: 'mixed',
|
6
|
+
rows: 5,
|
7
|
+
width: 70,
|
8
|
+
height: 36,
|
9
|
+
showLabel: false
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
$.mobiscroll.themes['android-ics'] = theme;
|
14
|
+
$.mobiscroll.themes['android-ics light'] = theme;
|
15
|
+
|
16
|
+
})(jQuery);
|
@@ -0,0 +1,966 @@
|
|
1
|
+
/*jslint eqeq: true, plusplus: true, undef: true, sloppy: true, vars: true, forin: true */
|
2
|
+
/*!
|
3
|
+
* jQuery MobiScroll v2.3
|
4
|
+
* http://mobiscroll.com
|
5
|
+
*
|
6
|
+
* Copyright 2010-2011, Acid Media
|
7
|
+
* Licensed under the MIT license.
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
(function ($) {
|
11
|
+
|
12
|
+
function Scroller(elem, settings) {
|
13
|
+
var that = this,
|
14
|
+
ms = $.mobiscroll,
|
15
|
+
e = elem,
|
16
|
+
elm = $(e),
|
17
|
+
theme,
|
18
|
+
lang,
|
19
|
+
s = extend({}, defaults),
|
20
|
+
pres = {},
|
21
|
+
m,
|
22
|
+
hi,
|
23
|
+
v,
|
24
|
+
dw,
|
25
|
+
warr = [],
|
26
|
+
iv = {},
|
27
|
+
input = elm.is('input'),
|
28
|
+
visible = false;
|
29
|
+
|
30
|
+
// Private functions
|
31
|
+
|
32
|
+
function isReadOnly(wh) {
|
33
|
+
if ($.isArray(s.readonly)) {
|
34
|
+
var i = $('.dwwl', dw).index(wh);
|
35
|
+
return s.readonly[i];
|
36
|
+
}
|
37
|
+
return s.readonly;
|
38
|
+
}
|
39
|
+
|
40
|
+
function generateWheelItems(wIndex) {
|
41
|
+
var html = '',
|
42
|
+
j;
|
43
|
+
|
44
|
+
for (j in warr[wIndex]) {
|
45
|
+
html += '<li class="dw-v" data-val="' + j + '" style="height:' + hi + 'px;line-height:' + hi + 'px;"><div class="dw-i">' + warr[wIndex][j] + '</div></li>';
|
46
|
+
}
|
47
|
+
return html;
|
48
|
+
}
|
49
|
+
|
50
|
+
function getDocHeight() {
|
51
|
+
var body = document.body,
|
52
|
+
html = document.documentElement;
|
53
|
+
return Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
|
54
|
+
}
|
55
|
+
|
56
|
+
function setGlobals(t) {
|
57
|
+
min = $('li.dw-v', t).eq(0).index();
|
58
|
+
max = $('li.dw-v', t).eq(-1).index();
|
59
|
+
index = $('ul', dw).index(t);
|
60
|
+
h = hi;
|
61
|
+
inst = that;
|
62
|
+
}
|
63
|
+
|
64
|
+
function formatHeader(v) {
|
65
|
+
var t = s.headerText;
|
66
|
+
return t ? (typeof (t) == 'function' ? t.call(e, v) : t.replace(/\{value\}/i, v)) : '';
|
67
|
+
}
|
68
|
+
|
69
|
+
function read() {
|
70
|
+
that.temp = ((input && (that.val !== null && that.val != elm.val() || !elm.val().length)) || that.values === null) ? s.parseValue(elm.val() || '', that) : that.values.slice(0);
|
71
|
+
that.setValue(true);
|
72
|
+
}
|
73
|
+
|
74
|
+
function scrollToPos(time, index, manual, dir) {
|
75
|
+
// Call validation event
|
76
|
+
event('validate', [dw, index]);
|
77
|
+
|
78
|
+
// Set scrollers to position
|
79
|
+
$('.dww ul', dw).each(function (i) {
|
80
|
+
var t = $(this),
|
81
|
+
cell = $('li[data-val="' + that.temp[i] + '"]', t),
|
82
|
+
v = cell.index(),
|
83
|
+
sc = i == index || index === undefined;
|
84
|
+
|
85
|
+
// Scroll to a valid cell
|
86
|
+
if (!cell.hasClass('dw-v')) {
|
87
|
+
var cell1 = cell,
|
88
|
+
cell2 = cell,
|
89
|
+
dist1 = 0,
|
90
|
+
dist2 = 0;
|
91
|
+
while (cell1.prev().length && !cell1.hasClass('dw-v')) {
|
92
|
+
cell1 = cell1.prev();
|
93
|
+
dist1++;
|
94
|
+
}
|
95
|
+
while (cell2.next().length && !cell2.hasClass('dw-v')) {
|
96
|
+
cell2 = cell2.next();
|
97
|
+
dist2++;
|
98
|
+
}
|
99
|
+
// If we have direction (+/- or mouse wheel), the distance does not count
|
100
|
+
if (((dist2 < dist1 && dist2 && dir !== 2) || !dist1 || !(cell1.hasClass('dw-v')) || dir == 1) && cell2.hasClass('dw-v')) {
|
101
|
+
cell = cell2;
|
102
|
+
v = v + dist2;
|
103
|
+
} else {
|
104
|
+
cell = cell1;
|
105
|
+
v = v - dist1;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
if (!(cell.hasClass('dw-sel')) || sc) {
|
110
|
+
// Set valid value
|
111
|
+
that.temp[i] = cell.attr('data-val');
|
112
|
+
|
113
|
+
// Add selected class to cell
|
114
|
+
$('.dw-sel', t).removeClass('dw-sel');
|
115
|
+
cell.addClass('dw-sel');
|
116
|
+
|
117
|
+
// Scroll to position
|
118
|
+
that.scroll(t, i, v, time);
|
119
|
+
}
|
120
|
+
});
|
121
|
+
|
122
|
+
// Reformat value if validation changed something
|
123
|
+
that.change(manual);
|
124
|
+
}
|
125
|
+
|
126
|
+
function position() {
|
127
|
+
|
128
|
+
if (s.display == 'inline') {
|
129
|
+
return;
|
130
|
+
}
|
131
|
+
|
132
|
+
function countWidth() {
|
133
|
+
$('.dwc', dw).each(function () {
|
134
|
+
//if ($(this).css('display') != 'none') {
|
135
|
+
w = $(this).outerWidth(true);
|
136
|
+
totalw += w;
|
137
|
+
minw = (w > minw) ? w : minw;
|
138
|
+
//}
|
139
|
+
});
|
140
|
+
w = totalw > ww ? minw : totalw;
|
141
|
+
w = $('.dwwr', dw).width(w + 1).outerWidth();
|
142
|
+
h = d.outerHeight();
|
143
|
+
}
|
144
|
+
|
145
|
+
var totalw = 0,
|
146
|
+
minw = 0,
|
147
|
+
ww = $(window).width(),
|
148
|
+
wh = window.innerHeight,
|
149
|
+
st = $(window).scrollTop(),
|
150
|
+
d = $('.dw', dw),
|
151
|
+
w,
|
152
|
+
t,
|
153
|
+
l,
|
154
|
+
h,
|
155
|
+
ew,
|
156
|
+
css = {},
|
157
|
+
needScroll,
|
158
|
+
elma = s.anchor === undefined ? elm : s.anchor;
|
159
|
+
|
160
|
+
wh = wh || $(window).height();
|
161
|
+
|
162
|
+
if (s.display == 'modal') {
|
163
|
+
countWidth();
|
164
|
+
l = (ww - w) / 2;
|
165
|
+
t = st + (wh - h) / 2;
|
166
|
+
} else if (s.display == 'bubble') {
|
167
|
+
countWidth();
|
168
|
+
var p = elma.offset(),
|
169
|
+
poc = $('.dw-arr', dw),
|
170
|
+
pocw = $('.dw-arrw-i', dw),
|
171
|
+
wd = d.outerWidth();
|
172
|
+
|
173
|
+
// horizontal positioning
|
174
|
+
ew = elma.outerWidth();
|
175
|
+
l = p.left - (d.outerWidth(true) - ew) / 2;
|
176
|
+
l = l > (ww - wd) ? (ww - (wd + 20)) : l;
|
177
|
+
l = l >= 0 ? l : 20;
|
178
|
+
|
179
|
+
// vertical positioning
|
180
|
+
t = p.top - (d.outerHeight() + 3); // above the input
|
181
|
+
if ((t < st) || (p.top > st + wh)) { // if doesn't fit above or the input is out of the screen
|
182
|
+
d.removeClass('dw-bubble-top').addClass('dw-bubble-bottom');
|
183
|
+
t = p.top + elma.outerHeight() + 3; // below the input
|
184
|
+
needScroll = ((t + d.outerHeight(true) > st + wh) || (p.top > st + wh));
|
185
|
+
} else {
|
186
|
+
d.removeClass('dw-bubble-bottom').addClass('dw-bubble-top');
|
187
|
+
}
|
188
|
+
|
189
|
+
t = t >= st ? t : st;
|
190
|
+
|
191
|
+
// Calculate Arrow position
|
192
|
+
var pl = p.left + ew / 2 - (l + (wd - pocw.outerWidth()) / 2);
|
193
|
+
|
194
|
+
// Limit Arrow position to [0, pocw.width] intervall
|
195
|
+
if (pl > pocw.outerWidth()) {
|
196
|
+
pl = pocw.outerWidth();
|
197
|
+
}
|
198
|
+
|
199
|
+
poc.css({ left: pl });
|
200
|
+
} else {
|
201
|
+
css.width = '100%';
|
202
|
+
if (s.display == 'top') {
|
203
|
+
t = st;
|
204
|
+
} else if (s.display == 'bottom') {
|
205
|
+
t = st + wh - d.outerHeight();
|
206
|
+
t = t >= 0 ? t : 0;
|
207
|
+
}
|
208
|
+
}
|
209
|
+
css.top = t;
|
210
|
+
css.left = l;
|
211
|
+
d.css(css);
|
212
|
+
|
213
|
+
$('.dwo, .dw-persp', dw).height(0).height(getDocHeight());
|
214
|
+
|
215
|
+
if (needScroll) {
|
216
|
+
$(window).scrollTop(t + d.outerHeight(true) - wh);
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
function event(name, args) {
|
221
|
+
var ret;
|
222
|
+
args.push(that);
|
223
|
+
$.each([pres, settings], function (i, v) {
|
224
|
+
if (v[name]) { // Call preset event
|
225
|
+
ret = v[name].apply(e, args)
|
226
|
+
}
|
227
|
+
});
|
228
|
+
return ret;
|
229
|
+
}
|
230
|
+
|
231
|
+
function plus(t) {
|
232
|
+
var p = +t.data('pos'),
|
233
|
+
val = p + 1;
|
234
|
+
calc(t, val > max ? min : val, 1);
|
235
|
+
}
|
236
|
+
|
237
|
+
function minus(t) {
|
238
|
+
var p = +t.data('pos'),
|
239
|
+
val = p - 1;
|
240
|
+
calc(t, val < min ? max : val, 2);
|
241
|
+
}
|
242
|
+
|
243
|
+
// Public functions
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Enables the scroller and the associated input.
|
247
|
+
*/
|
248
|
+
that.enable = function () {
|
249
|
+
s.disabled = false;
|
250
|
+
if (input) {
|
251
|
+
elm.prop('disabled', false);
|
252
|
+
}
|
253
|
+
};
|
254
|
+
|
255
|
+
/**
|
256
|
+
* Disables the scroller and the associated input.
|
257
|
+
*/
|
258
|
+
that.disable = function () {
|
259
|
+
s.disabled = true;
|
260
|
+
if (input) {
|
261
|
+
elm.prop('disabled', true);
|
262
|
+
}
|
263
|
+
};
|
264
|
+
|
265
|
+
/**
|
266
|
+
* Scrolls target to the specified position
|
267
|
+
* @param {Object} t - Target wheel jQuery object.
|
268
|
+
* @param {Number} index - Index of the changed wheel.
|
269
|
+
* @param {Number} val - Value.
|
270
|
+
* @param {Number} time - Duration of the animation, optional.
|
271
|
+
* @param {Number} orig - Original value.
|
272
|
+
*/
|
273
|
+
that.scroll = function (t, index, val, time, orig, callback) {
|
274
|
+
|
275
|
+
function getVal(t, b, c, d) {
|
276
|
+
return c * Math.sin(t / d * (Math.PI / 2)) + b;
|
277
|
+
}
|
278
|
+
|
279
|
+
function ready() {
|
280
|
+
clearInterval(iv[index]);
|
281
|
+
iv[index] = undefined;
|
282
|
+
t.data('pos', val).closest('.dwwl').removeClass('dwa');
|
283
|
+
}
|
284
|
+
|
285
|
+
var px = (m - val) * hi,
|
286
|
+
i;
|
287
|
+
|
288
|
+
callback = callback || empty;
|
289
|
+
|
290
|
+
t.attr('style', (time ? (prefix + '-transition:all ' + time.toFixed(1) + 's ease-out;') : '') + (has3d ? (prefix + '-transform:translate3d(0,' + px + 'px,0);') : ('top:' + px + 'px;')));
|
291
|
+
|
292
|
+
if (iv[index]) {
|
293
|
+
ready();
|
294
|
+
}
|
295
|
+
|
296
|
+
if (time && orig !== undefined) {
|
297
|
+
i = 0;
|
298
|
+
t.closest('.dwwl').addClass('dwa');
|
299
|
+
iv[index] = setInterval(function () {
|
300
|
+
i += 0.1;
|
301
|
+
t.data('pos', Math.round(getVal(i, orig, val - orig, time)));
|
302
|
+
if (i >= time) {
|
303
|
+
ready();
|
304
|
+
callback();
|
305
|
+
}
|
306
|
+
}, 100);
|
307
|
+
// Trigger animation start event
|
308
|
+
event('onAnimStart', [index, time]);
|
309
|
+
} else {
|
310
|
+
t.data('pos', val);
|
311
|
+
callback();
|
312
|
+
}
|
313
|
+
};
|
314
|
+
|
315
|
+
/**
|
316
|
+
* Gets the selected wheel values, formats it, and set the value of the scroller instance.
|
317
|
+
* If input parameter is true, populates the associated input element.
|
318
|
+
* @param {Boolean} sc - Scroll the wheel in position.
|
319
|
+
* @param {Boolean} fill - Also set the value of the associated input element. Default is true.
|
320
|
+
* @param {Number} time - Animation time
|
321
|
+
* @param {Boolean} temp - If true, then only set the temporary value.(only scroll there but not set the value)
|
322
|
+
*/
|
323
|
+
that.setValue = function (sc, fill, time, temp) {
|
324
|
+
if (!temp) {
|
325
|
+
that.values = that.temp.slice(0);
|
326
|
+
}
|
327
|
+
|
328
|
+
if (visible && sc) {
|
329
|
+
scrollToPos(time);
|
330
|
+
}
|
331
|
+
|
332
|
+
if (fill) {
|
333
|
+
v = s.formatResult(that.temp);
|
334
|
+
that.val = v;
|
335
|
+
if (input) {
|
336
|
+
elm.val(v).trigger('change');
|
337
|
+
}
|
338
|
+
}
|
339
|
+
};
|
340
|
+
|
341
|
+
/**
|
342
|
+
* Checks if the current selected values are valid together.
|
343
|
+
* In case of date presets it checks the number of days in a month.
|
344
|
+
* @param {Number} time - Animation time
|
345
|
+
* @param {Number} orig - Original value
|
346
|
+
* @param {Number} i - Currently changed wheel index, -1 if initial validation.
|
347
|
+
* @param {Number} dir - Scroll direction
|
348
|
+
*/
|
349
|
+
that.validate = function (i, dir) {
|
350
|
+
scrollToPos(0.2, i, true, dir);
|
351
|
+
};
|
352
|
+
|
353
|
+
/**
|
354
|
+
*
|
355
|
+
*/
|
356
|
+
that.change = function (manual) {
|
357
|
+
v = s.formatResult(that.temp);
|
358
|
+
if (s.display == 'inline') {
|
359
|
+
that.setValue(false, manual);
|
360
|
+
} else {
|
361
|
+
$('.dwv', dw).html(formatHeader(v));
|
362
|
+
}
|
363
|
+
|
364
|
+
if (manual) {
|
365
|
+
event('onChange', [v]);
|
366
|
+
}
|
367
|
+
};
|
368
|
+
|
369
|
+
/**
|
370
|
+
* Hides the scroller instance.
|
371
|
+
*/
|
372
|
+
that.hide = function (prevAnim) {
|
373
|
+
// If onClose handler returns false, prevent hide
|
374
|
+
if (event('onClose', [v]) === false) {
|
375
|
+
return false;
|
376
|
+
}
|
377
|
+
|
378
|
+
// Re-enable temporary disabled fields
|
379
|
+
$('.dwtd').prop('disabled', false).removeClass('dwtd');
|
380
|
+
elm.blur();
|
381
|
+
|
382
|
+
// Hide wheels and overlay
|
383
|
+
if (dw) {
|
384
|
+
if (s.display != 'inline' && s.animate && !prevAnim) {
|
385
|
+
$('.dw', dw).addClass('dw-' + s.animate + ' dw-out');
|
386
|
+
setTimeout(function () {
|
387
|
+
dw.remove();
|
388
|
+
dw = null;
|
389
|
+
}, 350);
|
390
|
+
} else {
|
391
|
+
dw.remove();
|
392
|
+
dw = null;
|
393
|
+
}
|
394
|
+
visible = false;
|
395
|
+
// Stop positioning on window resize
|
396
|
+
$(window).unbind('.dw');
|
397
|
+
}
|
398
|
+
};
|
399
|
+
|
400
|
+
/**
|
401
|
+
* Changes the values of a wheel, and scrolls to the correct position
|
402
|
+
*/
|
403
|
+
that.changeWheel = function (idx, time) {
|
404
|
+
if (dw) {
|
405
|
+
var i = 0,
|
406
|
+
j,
|
407
|
+
k,
|
408
|
+
nr = idx.length;
|
409
|
+
|
410
|
+
for (j in s.wheels) {
|
411
|
+
for (k in s.wheels[j]) {
|
412
|
+
if ($.inArray(i, idx) > -1) {
|
413
|
+
warr[i] = s.wheels[j][k];
|
414
|
+
$('ul', dw).eq(i).html(generateWheelItems(i));
|
415
|
+
nr--;
|
416
|
+
if (!nr) {
|
417
|
+
position();
|
418
|
+
scrollToPos(time);
|
419
|
+
return;
|
420
|
+
}
|
421
|
+
}
|
422
|
+
i++;
|
423
|
+
}
|
424
|
+
}
|
425
|
+
}
|
426
|
+
};
|
427
|
+
|
428
|
+
/**
|
429
|
+
* Shows the scroller instance.
|
430
|
+
* @param {Boolean} prevAnim - Prevent animation if true
|
431
|
+
*/
|
432
|
+
that.show = function (prevAnim) {
|
433
|
+
if (s.disabled || visible) {
|
434
|
+
return false;
|
435
|
+
}
|
436
|
+
|
437
|
+
if (s.display == 'top') {
|
438
|
+
s.animate = 'slidedown';
|
439
|
+
}
|
440
|
+
|
441
|
+
if (s.display == 'bottom') {
|
442
|
+
s.animate = 'slideup';
|
443
|
+
}
|
444
|
+
|
445
|
+
// Parse value from input
|
446
|
+
read();
|
447
|
+
|
448
|
+
event('onBeforeShow', [dw]);
|
449
|
+
|
450
|
+
// Create wheels
|
451
|
+
var l = 0,
|
452
|
+
i,
|
453
|
+
label,
|
454
|
+
mAnim = '',
|
455
|
+
persPS = '',
|
456
|
+
persPE = '';
|
457
|
+
|
458
|
+
if (s.animate && !prevAnim) {
|
459
|
+
persPS = '<div class="dw-persp">';
|
460
|
+
persPE = '</div>';
|
461
|
+
mAnim = 'dw-' + s.animate + ' dw-in';
|
462
|
+
}
|
463
|
+
// Create wheels containers
|
464
|
+
var html = '<div class="' + s.theme + ' dw-' + s.display + '">' + (s.display == 'inline' ? '<div class="dw dwbg dwi"><div class="dwwr">' : persPS + '<div class="dwo"></div><div class="dw dwbg ' + mAnim + '"><div class="dw-arrw"><div class="dw-arrw-i"><div class="dw-arr"></div></div></div><div class="dwwr">' + (s.headerText ? '<div class="dwv"></div>' : ''));
|
465
|
+
|
466
|
+
for (i = 0; i < s.wheels.length; i++) {
|
467
|
+
html += '<div class="dwc' + (s.mode != 'scroller' ? ' dwpm' : ' dwsc') + (s.showLabel ? '' : ' dwhl') + '"><div class="dwwc dwrc"><table cellpadding="0" cellspacing="0"><tr>';
|
468
|
+
// Create wheels
|
469
|
+
for (label in s.wheels[i]) {
|
470
|
+
warr[l] = s.wheels[i][label];
|
471
|
+
html += '<td><div class="dwwl dwrc dwwl' + l + '">' + (s.mode != 'scroller' ? '<div class="dwwb dwwbp" style="height:' + hi + 'px;line-height:' + hi + 'px;"><span>+</span></div><div class="dwwb dwwbm" style="height:' + hi + 'px;line-height:' + hi + 'px;"><span>–</span></div>' : '') + '<div class="dwl">' + label + '</div><div class="dww dwrc" style="height:' + (s.rows * hi) + 'px;min-width:' + s.width + 'px;"><ul>';
|
472
|
+
// Create wheel values
|
473
|
+
html += generateWheelItems(l);
|
474
|
+
html += '</ul><div class="dwwo"></div></div><div class="dwwol"></div></div></td>';
|
475
|
+
l++;
|
476
|
+
}
|
477
|
+
html += '</tr></table></div></div>';
|
478
|
+
}
|
479
|
+
html += (s.display != 'inline' ? '<div class="dwbc' + (s.button3 ? ' dwbc-p' : '') + '"><span class="dwbw dwb-s"><span class="dwb">' + s.setText + '</span></span>' + (s.button3 ? '<span class="dwbw dwb-n"><span class="dwb">' + s.button3Text + '</span></span>' : '') + '<span class="dwbw dwb-c"><span class="dwb">' + s.cancelText + '</span></span></div>' + persPE : '<div class="dwcc"></div>') + '</div></div></div>';
|
480
|
+
dw = $(html);
|
481
|
+
|
482
|
+
scrollToPos();
|
483
|
+
|
484
|
+
// Show
|
485
|
+
if (s.display != 'inline') {
|
486
|
+
dw.appendTo('body');
|
487
|
+
} else if (elm.is('div')) {
|
488
|
+
elm.html(dw);
|
489
|
+
} else {
|
490
|
+
dw.insertAfter(elm);
|
491
|
+
}
|
492
|
+
visible = true;
|
493
|
+
|
494
|
+
if (s.display != 'inline') {
|
495
|
+
// Init buttons
|
496
|
+
$('.dwb-s span', dw).click(function () {
|
497
|
+
if (that.hide() !== false) {
|
498
|
+
that.setValue(false, true);
|
499
|
+
event('onSelect', [that.val]);
|
500
|
+
}
|
501
|
+
return false;
|
502
|
+
});
|
503
|
+
|
504
|
+
$('.dwb-c span', dw).click(function () {
|
505
|
+
if (that.hide() !== false) {
|
506
|
+
event('onCancel', [that.val]);
|
507
|
+
}
|
508
|
+
return false;
|
509
|
+
});
|
510
|
+
|
511
|
+
if (s.button3) {
|
512
|
+
$('.dwb-n span', dw).click(s.button3);
|
513
|
+
}
|
514
|
+
|
515
|
+
// prevent scrolling if not specified otherwise
|
516
|
+
if (s.scrollLock) {
|
517
|
+
dw.bind('touchmove', function (e) {
|
518
|
+
e.preventDefault();
|
519
|
+
});
|
520
|
+
}
|
521
|
+
|
522
|
+
// Disable inputs to prevent bleed through (Android bug)
|
523
|
+
$('input,select').each(function () {
|
524
|
+
if (!$(this).prop('disabled')) {
|
525
|
+
$(this).addClass('dwtd');
|
526
|
+
}
|
527
|
+
});
|
528
|
+
$('input,select').prop('disabled', true);
|
529
|
+
|
530
|
+
// Set position
|
531
|
+
position();
|
532
|
+
$(window).bind('resize.dw', position);
|
533
|
+
|
534
|
+
}
|
535
|
+
|
536
|
+
// Events
|
537
|
+
dw.delegate('.dwwl', 'DOMMouseScroll mousewheel', function (e) {
|
538
|
+
if (!isReadOnly(this)) {
|
539
|
+
e.preventDefault();
|
540
|
+
e = e.originalEvent;
|
541
|
+
var delta = e.wheelDelta ? (e.wheelDelta / 120) : (e.detail ? (-e.detail / 3) : 0),
|
542
|
+
t = $('ul', this),
|
543
|
+
p = +t.data('pos'),
|
544
|
+
val = Math.round(p - delta);
|
545
|
+
setGlobals(t);
|
546
|
+
calc(t, val, delta < 0 ? 1 : 2);
|
547
|
+
}
|
548
|
+
}).delegate('.dwb, .dwwb', START_EVENT, function (e) {
|
549
|
+
// Active button
|
550
|
+
$(this).addClass('dwb-a');
|
551
|
+
}).delegate('.dwwb', START_EVENT, function (e) {
|
552
|
+
var w = $(this).closest('.dwwl');
|
553
|
+
if (!isReadOnly(w) && !w.hasClass('dwa')) {
|
554
|
+
// + Button
|
555
|
+
e.preventDefault();
|
556
|
+
e.stopPropagation();
|
557
|
+
var t = w.find('ul'),
|
558
|
+
func = $(this).hasClass('dwwbp') ? plus : minus;
|
559
|
+
click = true;
|
560
|
+
setGlobals(t);
|
561
|
+
clearInterval(timer);
|
562
|
+
timer = setInterval(function () { func(t); }, s.delay);
|
563
|
+
func(t);
|
564
|
+
}
|
565
|
+
}).delegate('.dwwl', START_EVENT, function (e) {
|
566
|
+
// Prevent scroll
|
567
|
+
e.preventDefault();
|
568
|
+
// Scroll start
|
569
|
+
if (!move && !isReadOnly(this) && !click && s.mode != 'clickpick') {
|
570
|
+
move = true;
|
571
|
+
target = $('ul', this);
|
572
|
+
target.closest('.dwwl').addClass('dwa');
|
573
|
+
pos = +target.data('pos');
|
574
|
+
setGlobals(target);
|
575
|
+
moved = iv[index] !== undefined; // Don't allow tap, if still moving
|
576
|
+
start = getY(e);
|
577
|
+
startTime = new Date();
|
578
|
+
stop = start;
|
579
|
+
that.scroll(target, index, pos);
|
580
|
+
}
|
581
|
+
});
|
582
|
+
|
583
|
+
event('onShow', [dw, v]);
|
584
|
+
|
585
|
+
// Theme init
|
586
|
+
theme.init(dw, that);
|
587
|
+
};
|
588
|
+
|
589
|
+
/**
|
590
|
+
* Scroller initialization.
|
591
|
+
*/
|
592
|
+
that.init = function (ss) {
|
593
|
+
// Get theme defaults
|
594
|
+
theme = extend({ defaults: {}, init: empty }, ms.themes[ss.theme || s.theme]);
|
595
|
+
|
596
|
+
// Get language defaults
|
597
|
+
lang = ms.i18n[ss.lang || s.lang];
|
598
|
+
|
599
|
+
extend(settings, ss); // Update original user settings
|
600
|
+
extend(s, theme.defaults, lang, settings);
|
601
|
+
|
602
|
+
that.settings = s;
|
603
|
+
|
604
|
+
// Unbind all events (if re-init)
|
605
|
+
elm.unbind('.dw');
|
606
|
+
|
607
|
+
var preset = ms.presets[s.preset];
|
608
|
+
|
609
|
+
if (preset) {
|
610
|
+
pres = preset.call(e, that);
|
611
|
+
extend(s, pres, settings); // Load preset settings
|
612
|
+
extend(methods, pres.methods); // Extend core methods
|
613
|
+
}
|
614
|
+
|
615
|
+
// Set private members
|
616
|
+
m = Math.floor(s.rows / 2);
|
617
|
+
hi = s.height;
|
618
|
+
|
619
|
+
if (elm.data('dwro') !== undefined) {
|
620
|
+
e.readOnly = bool(elm.data('dwro'));
|
621
|
+
}
|
622
|
+
|
623
|
+
if (visible) {
|
624
|
+
that.hide();
|
625
|
+
}
|
626
|
+
|
627
|
+
if (s.display == 'inline') {
|
628
|
+
that.show();
|
629
|
+
} else {
|
630
|
+
read();
|
631
|
+
if (input && s.showOnFocus) {
|
632
|
+
// Set element readonly, save original state
|
633
|
+
elm.data('dwro', e.readOnly);
|
634
|
+
e.readOnly = true;
|
635
|
+
// Init show datewheel
|
636
|
+
elm.bind('focus.dw', function () { that.show(); });
|
637
|
+
}
|
638
|
+
}
|
639
|
+
};
|
640
|
+
|
641
|
+
that.values = null;
|
642
|
+
that.val = null;
|
643
|
+
that.temp = null;
|
644
|
+
|
645
|
+
that.init(settings);
|
646
|
+
}
|
647
|
+
|
648
|
+
function testProps(props) {
|
649
|
+
var i;
|
650
|
+
for (i in props) {
|
651
|
+
if (mod[props[i]] !== undefined) {
|
652
|
+
return true;
|
653
|
+
}
|
654
|
+
}
|
655
|
+
return false;
|
656
|
+
}
|
657
|
+
|
658
|
+
function testPrefix() {
|
659
|
+
var prefixes = ['Webkit', 'Moz', 'O', 'ms'],
|
660
|
+
p;
|
661
|
+
|
662
|
+
for (p in prefixes) {
|
663
|
+
if (testProps([prefixes[p] + 'Transform'])) {
|
664
|
+
return '-' + prefixes[p].toLowerCase();
|
665
|
+
}
|
666
|
+
}
|
667
|
+
return '';
|
668
|
+
}
|
669
|
+
|
670
|
+
function getInst(e) {
|
671
|
+
return scrollers[e.id];
|
672
|
+
}
|
673
|
+
|
674
|
+
function getY(e) {
|
675
|
+
var org = e.originalEvent,
|
676
|
+
ct = e.changedTouches;
|
677
|
+
return ct || (org && org.changedTouches) ? (org ? org.changedTouches[0].pageY : ct[0].pageY) : e.pageY;
|
678
|
+
|
679
|
+
}
|
680
|
+
|
681
|
+
function bool(v) {
|
682
|
+
return (v === true || v == 'true');
|
683
|
+
}
|
684
|
+
|
685
|
+
function constrain(val, min, max) {
|
686
|
+
val = val > max ? max : val;
|
687
|
+
val = val < min ? min : val;
|
688
|
+
return val;
|
689
|
+
}
|
690
|
+
|
691
|
+
function calc(t, val, dir, anim, orig) {
|
692
|
+
val = constrain(val, min, max);
|
693
|
+
|
694
|
+
var cell = $('li', t).eq(val),
|
695
|
+
idx = index,
|
696
|
+
time = anim ? (val == orig ? 0.1 : Math.abs((val - orig) * 0.1)) : 0;
|
697
|
+
|
698
|
+
inst.scroll(t, idx, val, time, orig, function() {
|
699
|
+
// Set selected scroller value
|
700
|
+
inst.temp[idx] = cell.attr('data-val');
|
701
|
+
// Validate on animation end
|
702
|
+
inst.validate(idx, dir);
|
703
|
+
});
|
704
|
+
}
|
705
|
+
|
706
|
+
function init(that, method, args) {
|
707
|
+
if (methods[method]) {
|
708
|
+
return methods[method].apply(that, Array.prototype.slice.call(args, 1));
|
709
|
+
}
|
710
|
+
if (typeof method === 'object') {
|
711
|
+
return methods.init.call(that, method);
|
712
|
+
}
|
713
|
+
return that;
|
714
|
+
}
|
715
|
+
|
716
|
+
var scrollers = {},
|
717
|
+
timer,
|
718
|
+
empty = function () { },
|
719
|
+
h,
|
720
|
+
min,
|
721
|
+
max,
|
722
|
+
inst, // Current instance
|
723
|
+
date = new Date(),
|
724
|
+
uuid = date.getTime(),
|
725
|
+
move,
|
726
|
+
click,
|
727
|
+
target,
|
728
|
+
index,
|
729
|
+
start,
|
730
|
+
stop,
|
731
|
+
startTime,
|
732
|
+
pos,
|
733
|
+
moved,
|
734
|
+
mod = document.createElement('modernizr').style,
|
735
|
+
has3d = testProps(['perspectiveProperty', 'WebkitPerspective', 'MozPerspective', 'OPerspective', 'msPerspective']),
|
736
|
+
prefix = testPrefix(),
|
737
|
+
extend = $.extend,
|
738
|
+
START_EVENT = 'touchstart mousedown',
|
739
|
+
MOVE_EVENT = 'touchmove mousemove',
|
740
|
+
END_EVENT = 'touchend mouseup',
|
741
|
+
defaults = {
|
742
|
+
// Options
|
743
|
+
width: 70,
|
744
|
+
height: 40,
|
745
|
+
rows: 3,
|
746
|
+
delay: 300,
|
747
|
+
disabled: false,
|
748
|
+
readonly: false,
|
749
|
+
showOnFocus: true,
|
750
|
+
showLabel: true,
|
751
|
+
wheels: [],
|
752
|
+
theme: '',
|
753
|
+
headerText: '{value}',
|
754
|
+
display: 'modal',
|
755
|
+
mode: 'scroller',
|
756
|
+
preset: '',
|
757
|
+
lang: 'en-US',
|
758
|
+
setText: 'Set',
|
759
|
+
cancelText: 'Cancel',
|
760
|
+
scrollLock: true,
|
761
|
+
formatResult: function (d) {
|
762
|
+
return d.join(' ');
|
763
|
+
},
|
764
|
+
parseValue: function (value, inst) {
|
765
|
+
var w = inst.settings.wheels,
|
766
|
+
val = value.split(' '),
|
767
|
+
ret = [],
|
768
|
+
j = 0,
|
769
|
+
i,
|
770
|
+
l,
|
771
|
+
v;
|
772
|
+
|
773
|
+
for (i = 0; i < w.length; i++) {
|
774
|
+
for (l in w[i]) {
|
775
|
+
if (w[i][l][val[j]] !== undefined) {
|
776
|
+
ret.push(val[j]);
|
777
|
+
} else {
|
778
|
+
for (v in w[i][l]) { // Select first value from wheel
|
779
|
+
ret.push(v);
|
780
|
+
break;
|
781
|
+
}
|
782
|
+
}
|
783
|
+
j++;
|
784
|
+
}
|
785
|
+
}
|
786
|
+
return ret;
|
787
|
+
}
|
788
|
+
},
|
789
|
+
|
790
|
+
methods = {
|
791
|
+
init: function (options) {
|
792
|
+
if (options === undefined) {
|
793
|
+
options = {};
|
794
|
+
}
|
795
|
+
|
796
|
+
return this.each(function () {
|
797
|
+
if (!this.id) {
|
798
|
+
uuid += 1;
|
799
|
+
this.id = 'scoller' + uuid;
|
800
|
+
}
|
801
|
+
scrollers[this.id] = new Scroller(this, options);
|
802
|
+
});
|
803
|
+
},
|
804
|
+
enable: function () {
|
805
|
+
return this.each(function () {
|
806
|
+
var inst = getInst(this);
|
807
|
+
if (inst) {
|
808
|
+
inst.enable();
|
809
|
+
}
|
810
|
+
});
|
811
|
+
},
|
812
|
+
disable: function () {
|
813
|
+
return this.each(function () {
|
814
|
+
var inst = getInst(this);
|
815
|
+
if (inst) {
|
816
|
+
inst.disable();
|
817
|
+
}
|
818
|
+
});
|
819
|
+
},
|
820
|
+
isDisabled: function () {
|
821
|
+
var inst = getInst(this[0]);
|
822
|
+
if (inst) {
|
823
|
+
return inst.settings.disabled;
|
824
|
+
}
|
825
|
+
},
|
826
|
+
option: function (option, value) {
|
827
|
+
return this.each(function () {
|
828
|
+
var inst = getInst(this);
|
829
|
+
if (inst) {
|
830
|
+
var obj = {};
|
831
|
+
if (typeof option === 'object') {
|
832
|
+
obj = option;
|
833
|
+
} else {
|
834
|
+
obj[option] = value;
|
835
|
+
}
|
836
|
+
inst.init(obj);
|
837
|
+
}
|
838
|
+
});
|
839
|
+
},
|
840
|
+
setValue: function (d, fill, time, temp) {
|
841
|
+
return this.each(function () {
|
842
|
+
var inst = getInst(this);
|
843
|
+
if (inst) {
|
844
|
+
inst.temp = d;
|
845
|
+
inst.setValue(true, fill, time, temp);
|
846
|
+
}
|
847
|
+
});
|
848
|
+
},
|
849
|
+
getInst: function () {
|
850
|
+
return getInst(this[0]);
|
851
|
+
},
|
852
|
+
getValue: function () {
|
853
|
+
var inst = getInst(this[0]);
|
854
|
+
if (inst) {
|
855
|
+
return inst.values;
|
856
|
+
}
|
857
|
+
},
|
858
|
+
show: function () {
|
859
|
+
var inst = getInst(this[0]);
|
860
|
+
if (inst) {
|
861
|
+
return inst.show();
|
862
|
+
}
|
863
|
+
},
|
864
|
+
hide: function () {
|
865
|
+
return this.each(function () {
|
866
|
+
var inst = getInst(this);
|
867
|
+
if (inst) {
|
868
|
+
inst.hide();
|
869
|
+
}
|
870
|
+
});
|
871
|
+
},
|
872
|
+
destroy: function () {
|
873
|
+
return this.each(function () {
|
874
|
+
var inst = getInst(this);
|
875
|
+
if (inst) {
|
876
|
+
inst.hide();
|
877
|
+
$(this).unbind('.dw');
|
878
|
+
delete scrollers[this.id];
|
879
|
+
if ($(this).is('input')) {
|
880
|
+
this.readOnly = bool($(this).data('dwro'));
|
881
|
+
}
|
882
|
+
}
|
883
|
+
});
|
884
|
+
}
|
885
|
+
};
|
886
|
+
|
887
|
+
$(document).bind(MOVE_EVENT, function (e) {
|
888
|
+
if (move) {
|
889
|
+
e.preventDefault();
|
890
|
+
stop = getY(e);
|
891
|
+
inst.scroll(target, index, constrain(pos + (start - stop) / h, min - 1, max + 1));
|
892
|
+
moved = true;
|
893
|
+
}
|
894
|
+
});
|
895
|
+
|
896
|
+
$(document).bind(END_EVENT, function (e) {
|
897
|
+
if (move) {
|
898
|
+
e.preventDefault();
|
899
|
+
|
900
|
+
var time = new Date() - startTime,
|
901
|
+
val = constrain(pos + (start - stop) / h, min - 1, max + 1),
|
902
|
+
speed,
|
903
|
+
dist,
|
904
|
+
tindex,
|
905
|
+
ttop = target.offset().top;
|
906
|
+
|
907
|
+
if (time < 300) {
|
908
|
+
speed = (stop - start) / time;
|
909
|
+
dist = (speed * speed) / (2 * 0.0006);
|
910
|
+
if (stop - start < 0) {
|
911
|
+
dist = -dist;
|
912
|
+
}
|
913
|
+
} else {
|
914
|
+
dist = stop - start;
|
915
|
+
}
|
916
|
+
|
917
|
+
if (!dist && !moved) { // this is a "tap"
|
918
|
+
tindex = Math.floor((stop - ttop) / h);
|
919
|
+
var li = $('li', target).eq(tindex)
|
920
|
+
li.addClass('dw-hl'); // Highlight
|
921
|
+
setTimeout(function() {
|
922
|
+
li.removeClass('dw-hl');
|
923
|
+
}, 200);
|
924
|
+
} else {
|
925
|
+
tindex = Math.round(pos - dist / h);
|
926
|
+
}
|
927
|
+
|
928
|
+
calc(target, tindex, 0, true, Math.round(val));
|
929
|
+
move = false;
|
930
|
+
target = null;
|
931
|
+
}
|
932
|
+
if (click) {
|
933
|
+
clearInterval(timer);
|
934
|
+
click = false;
|
935
|
+
}
|
936
|
+
$('.dwb-a').removeClass('dwb-a');
|
937
|
+
});
|
938
|
+
|
939
|
+
$.fn.mobiscroll = function (method) {
|
940
|
+
extend(this, $.mobiscroll.shorts);
|
941
|
+
return init(this, method, arguments);
|
942
|
+
};
|
943
|
+
|
944
|
+
$.mobiscroll = $.mobiscroll || {
|
945
|
+
/**
|
946
|
+
* Set settings for all instances.
|
947
|
+
* @param {Object} o - New default settings.
|
948
|
+
*/
|
949
|
+
setDefaults: function (o) {
|
950
|
+
extend(defaults, o);
|
951
|
+
},
|
952
|
+
presetShort: function(name) {
|
953
|
+
this.shorts[name] = function(method) {
|
954
|
+
return init(this, extend(method, { preset: name }), arguments);
|
955
|
+
};
|
956
|
+
},
|
957
|
+
shorts: {},
|
958
|
+
presets: {},
|
959
|
+
themes: {},
|
960
|
+
i18n: {}
|
961
|
+
};
|
962
|
+
|
963
|
+
$.scroller = $.scroller || $.mobiscroll;
|
964
|
+
$.fn.scroller = $.fn.scroller || $.fn.mobiscroll;
|
965
|
+
|
966
|
+
})(jQuery);
|