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.
@@ -0,0 +1,14 @@
1
+ (function ($) {
2
+
3
+ $.mobiscroll.themes.ios = {
4
+ defaults: {
5
+ dateOrder: 'MMdyy',
6
+ rows: 5,
7
+ height: 30,
8
+ width: 55,
9
+ headerText: false,
10
+ showLabel: false
11
+ }
12
+ }
13
+
14
+ })(jQuery);
@@ -0,0 +1,30 @@
1
+ (function ($) {
2
+
3
+ $.mobiscroll.themes.jqm = {
4
+ defaults: {
5
+ jqmBody: 'c',
6
+ jqmHeader:'b',
7
+ jqmWheel: 'd',
8
+ jqmClickPick: 'c',
9
+ jqmSet: 'b',
10
+ jqmCancel: 'c'
11
+ },
12
+ init: function(elm, inst) {
13
+ var s = inst.settings;
14
+ $('.dw', elm).removeClass('dwbg').addClass('ui-overlay-shadow ui-corner-all ui-body-a');
15
+ $('.dwb-s span', elm).attr('data-role', 'button').attr('data-theme', s.jqmSet);
16
+ $('.dwb-n span', elm).attr('data-role', 'button').attr('data-theme', s.jqmCancel);
17
+ $('.dwb-c span', elm).attr('data-role', 'button').attr('data-theme', s.jqmCancel);
18
+ $('.dwwb', elm).attr('data-role', 'button').attr('data-theme', s.jqmClickPick);
19
+ $('.dwv', elm).addClass('ui-header ui-bar-' + s.jqmHeader);
20
+ $('.dwwr', elm).addClass('ui-body-' + s.jqmBody);
21
+ $('.dwpm .dww', elm).addClass('ui-body-' + s.jqmWheel);
22
+ if (s.display != 'inline')
23
+ $('.dw', elm).addClass('pop in');
24
+ elm.trigger('create');
25
+ // Hide on overlay click
26
+ $('.dwo', elm).click(function() { inst.hide(); });
27
+ }
28
+ }
29
+
30
+ })(jQuery);
@@ -0,0 +1,18 @@
1
+ // Core javascript required to use Mobiscroll
2
+ //= require mobiscroll.core
3
+
4
+ // Add datetime support
5
+ //= require mobiscroll.datetime
6
+
7
+ // Add select support
8
+ //= require mobiscroll.select
9
+
10
+ // Add list support
11
+ //= require mobiscroll.list
12
+
13
+ // Additional themes
14
+ //= require mobiscroll.android-ics
15
+ //= require mobiscroll.android
16
+ //= require mobiscroll.ios
17
+ //= require mobiscroll.jqm
18
+ //= require mobiscroll.wp
@@ -0,0 +1,377 @@
1
+ /*jslint eqeq: true, plusplus: true, undef: true, sloppy: true, vars: true, forin: true */
2
+ (function ($) {
3
+ var ms = $.mobiscroll,
4
+ defaults = {
5
+ invalid: [],
6
+ showInput: true,
7
+ inputClass: ''
8
+ },
9
+ preset = function (inst) {
10
+ var s = $.extend({}, defaults, inst.settings),
11
+ elm = $(this),
12
+ input,
13
+ id = this.id + '_dummy',
14
+ lvl = 0,
15
+ ilvl = 0,
16
+ wa = s.wheelArray || createWheelArray(elm),
17
+ labels = generateLabels(lvl),
18
+ currWheelVector = [],
19
+ fwv = firstWheelVector(wa),
20
+ w = generateWheelsFromVector(fwv, lvl);
21
+
22
+ /**
23
+ * Disables the invalid items on the wheels
24
+ * @param {Object} dw - the jQuery mobiscroll object
25
+ * @param {Number} nrWheels - the number of the current wheels
26
+ * @param {Array} whArray - The wheel array objects containing the wheel tree
27
+ * @param {Array} whVector - the wheel vector containing the current keys
28
+ */
29
+ function setDisabled(dw, nrWheels, whArray, whVector) {
30
+ var i = 0;
31
+ while (i < nrWheels) {
32
+ var currWh = $('.dwwl' + i, dw),
33
+ inv = getInvalidKeys(whVector, i, whArray);
34
+ $.each(inv, function (i, v) {
35
+ $('li[data-val="' + v + '"]', currWh).removeClass('dw-v');
36
+ });
37
+ i++;
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Returns the invalid keys of one wheel as an array
43
+ * @param {Array} whVector - the wheel vector used to search for the wheel in the wheel array
44
+ * @param {Number} index - index of the wheel in the wheel vector, that we are interested in
45
+ * @param {Array} whArray - the wheel array we are searching in
46
+ * @return {Array} - list of invalid keys
47
+ */
48
+ function getInvalidKeys(whVector, index, whArray) {
49
+ var i = 0,
50
+ whObjA = whArray,
51
+ invalids = [];
52
+
53
+ while (i < index) {
54
+ var ii = whVector[i];
55
+ //whObjA = whObjA[ii].children;
56
+ for (var n in whObjA) {
57
+ if (whObjA[n].key == ii) {
58
+ whObjA = whObjA[n].children;
59
+ break;
60
+ }
61
+ }
62
+ i++;
63
+ }
64
+ i = 0;
65
+ while (i < whObjA.length) {
66
+ if (whObjA[i].invalid) {
67
+ invalids.push(whObjA[i].key);
68
+ }
69
+ i++;
70
+ }
71
+ return invalids;
72
+ }
73
+
74
+ /**
75
+ * Creates a Boolean vector with true values (except one) that can be used as the readonly vector
76
+ * n - the length of the vector
77
+ * i - the index of the value that's going to be false
78
+ */
79
+ function createROVector(n, i) {
80
+ var a = [];
81
+ while (n) {
82
+ a[--n] = true;
83
+ }
84
+ a[i] = false;
85
+ return a;
86
+ }
87
+
88
+ /**
89
+ * Creates a labels vector, from values if they are defined, otherwise from numbers
90
+ * l - the length of the vector
91
+ */
92
+ function generateLabels(l) {
93
+ var a = [],
94
+ i;
95
+ for (i = 0; i < l; i++) {
96
+ a[i] = s.labels && s.labels[i] ? s.labels[i] : i;
97
+ }
98
+ return a;
99
+ }
100
+
101
+ /**
102
+ * Creates the wheel array from the vector provided
103
+ * wv - wheel vector containing the values that should be selected on the wheels
104
+ * l - the length of the wheel array
105
+ */
106
+ function generateWheelsFromVector(wv, l, index) {
107
+ var i = 0, j, obj, chInd,
108
+ w = [{}],
109
+ wtObjA = wa;
110
+
111
+ if (l) { // if length is defined we need to generate that many wheels (even if they are empty)
112
+ for (j = 0; j < l; j++) {
113
+ w[j] = {};
114
+ w[j][labels[j]] = {}; // each wheel will have a label generated by the generateLabels method
115
+ }
116
+ }
117
+ while (i < wv.length) { // we generate the wheels until the length of the wheel vector
118
+ w[i] = {};
119
+ w[i][labels[i]] = getWheelFromObjA(wtObjA);
120
+
121
+ j = 0;
122
+ chInd = undefined;
123
+
124
+ while (j < wtObjA.length && chInd === undefined) {
125
+ if (wtObjA[j].key == wv[i] && ((index !== undefined && i <= index) || index === undefined)) {
126
+ chInd = j;
127
+ }
128
+ j++;
129
+ }
130
+
131
+ if (chInd !== undefined && wtObjA[chInd].children) {
132
+ i++;
133
+ wtObjA = wtObjA[chInd].children;
134
+ } else if ((obj = getFirstValidItemObjOrInd(wtObjA)) && obj.children) {
135
+ i++;
136
+ wtObjA = obj.children;
137
+ } else {
138
+ return w;
139
+ }
140
+ }
141
+ return w;
142
+ }
143
+
144
+ /**
145
+ * Returns the first valid Wheel Node Object or its index from a Wheel Node Object Array
146
+ * getInd - if it is true then the return value is going to be the index, otherwise the object itself
147
+ */
148
+ function getFirstValidItemObjOrInd(wtObjA, getInd) {
149
+ if (!wtObjA) {
150
+ return false;
151
+ }
152
+
153
+ var i = 0,
154
+ obj;
155
+
156
+ while (i < wtObjA.length) {
157
+ if (!(obj = wtObjA[i++]).invalid) {
158
+ return getInd ? i - 1 : obj;
159
+ }
160
+ }
161
+ return false;
162
+ }
163
+
164
+ function getWheelFromObjA(objA) {
165
+ var wheel = {},
166
+ j = 0;
167
+
168
+ while (j < objA.length) {
169
+ wheel[objA[j].key] = objA[j++].value;
170
+ }
171
+ return wheel;
172
+ }
173
+
174
+ /**
175
+ * Hides the last i number of wheels
176
+ * i - the last number of wheels that has to be hidden
177
+ */
178
+ function hideWheels(dw, i) {
179
+ $('.dwc', dw).css('display', '').slice(i).hide();
180
+ }
181
+
182
+ /**
183
+ * Generates the first wheel vector from the wheeltree
184
+ * wt - the wheel tree object
185
+ * uses the lvl global variable to determine the length of the vector
186
+ */
187
+ function firstWheelVector(wa) {
188
+ var t = [],
189
+ ndObjA = wa,
190
+ obj,
191
+ ok = true,
192
+ i = 0;
193
+
194
+ while (ok) {
195
+ obj = getFirstValidItemObjOrInd(ndObjA);
196
+ t[i++] = obj.key;
197
+ if (ok = obj.children) {
198
+ ndObjA = obj.children;
199
+ }
200
+ }
201
+ return t;
202
+ }
203
+
204
+ /**
205
+ * Calculates the level of a wheel vector and the new wheel vector, depending on current wheel vector and the index of the changed wheel
206
+ * wv - current wheel vector
207
+ * index - index of the changed wheel
208
+ */
209
+ function calcLevelOfVector2(wv, index) {
210
+ var t = [],
211
+ ndObjA = wa,
212
+ lvl = 0,
213
+ next = false,
214
+ i,
215
+ childName,
216
+ chInd;
217
+
218
+ if (wv[lvl] !== undefined && lvl <= index) {
219
+ i = 0;
220
+
221
+ childName = wv[lvl];
222
+ chInd = undefined;
223
+
224
+ while (i < ndObjA.length && chInd === undefined) {
225
+ if (ndObjA[i].key == wv[lvl] && !ndObjA[i].invalid) {
226
+ chInd = i;
227
+ }
228
+ i++;
229
+ }
230
+ } else {
231
+ chInd = getFirstValidItemObjOrInd(ndObjA, true);
232
+ childName = ndObjA[chInd].key;
233
+ }
234
+
235
+ next = chInd !== undefined ? ndObjA[chInd].children : false;
236
+
237
+ t[lvl] = childName;
238
+
239
+ while (next) {
240
+ ndObjA = ndObjA[chInd].children;
241
+ lvl++;
242
+ next = false;
243
+ chInd = undefined;
244
+
245
+ if (wv[lvl] !== undefined && lvl <= index) {
246
+ i = 0;
247
+
248
+ childName = wv[lvl];
249
+ chInd = undefined;
250
+
251
+ while (i < ndObjA.length && chInd === undefined) {
252
+ if (ndObjA[i].key == wv[lvl] && !ndObjA[i].invalid) {
253
+ chInd = i;
254
+ }
255
+ i++;
256
+ }
257
+ } else {
258
+ chInd = getFirstValidItemObjOrInd(ndObjA, true);
259
+ chInd = chInd === false ? undefined : chInd;
260
+ childName = ndObjA[chInd].key;
261
+ }
262
+ next = chInd !== undefined && getFirstValidItemObjOrInd(ndObjA[chInd].children) ? ndObjA[chInd].children : false;
263
+ t[lvl] = childName;
264
+ }
265
+ return {
266
+ lvl: lvl + 1,
267
+ nVector: t
268
+ }; // return the calculated level and the wheel vector as an object
269
+ }
270
+
271
+ function createWheelArray(ul) {
272
+ var wheelArray = [];
273
+
274
+ lvl = lvl > ilvl++ ? lvl : ilvl;
275
+
276
+ ul.children('li').each(function (index) {
277
+ var that = $(this),
278
+ c = that.clone();
279
+
280
+ c.children('ul,ol').remove();
281
+
282
+ var v = c.html().replace(/^\s\s*/, '').replace(/\s\s*$/, ''),
283
+ inv = that.data('invalid') ? true : false,
284
+ wheelObj = {
285
+ key: that.data('val') || index,
286
+ value: v,
287
+ invalid: inv,
288
+ children: null
289
+ },
290
+ nest = that.children('ul,ol');
291
+
292
+ if (nest.length) {
293
+ wheelObj.children = createWheelArray(nest);
294
+ }
295
+
296
+ wheelArray.push(wheelObj);
297
+ });
298
+
299
+ ilvl--;
300
+ return wheelArray;
301
+ }
302
+
303
+ $('#' + id).remove(); // Remove input if exists
304
+
305
+ if (s.showInput) {
306
+ input = $('<input type="text" id="' + id + '" value="" class="' + s.inputClass + '" readonly />').insertBefore(elm);
307
+ inst.settings.anchor = input; // give the core the input element for the bubble positioning
308
+
309
+ if (s.showOnFocus) {
310
+ input.focus(function () {
311
+ inst.show();
312
+ });
313
+ }
314
+ }
315
+
316
+ if (!s.wheelArray) {
317
+ elm.hide().closest('.ui-field-contain').trigger('create');
318
+ }
319
+
320
+ return {
321
+ width: 50,
322
+ wheels: w,
323
+ headerText: false,
324
+ onBeforeShow: function (dw) {
325
+ var t = inst.temp;
326
+ currWheelVector = inst.temp.slice(0);
327
+ inst.settings.wheels = generateWheelsFromVector(t, lvl, lvl);
328
+ },
329
+ onSelect: function (v, inst) {
330
+ if (input) {
331
+ input.val(v);
332
+ }
333
+ },
334
+ onChange: function (v, inst) {
335
+ if (input && s.display == 'inline') {
336
+ input.val(v);
337
+ }
338
+ },
339
+ onClose: function () {
340
+ if (input) {
341
+ input.blur();
342
+ }
343
+ },
344
+ onAnimStart: function(index) {
345
+ inst.settings.readonly = createROVector(lvl, index);
346
+ },
347
+ validate: function (dw, index) {
348
+ var t = inst.temp;
349
+ if (index !== undefined && currWheelVector[index] != t[index]) {
350
+ inst.settings.wheels = generateWheelsFromVector(t, null, index);
351
+ var args = [],
352
+ i = index,
353
+ o = calcLevelOfVector2(t, index);
354
+ inst.temp = o.nVector.slice(0);
355
+ while (i < o.lvl) {
356
+ args.push(i++);
357
+ }
358
+ hideWheels(dw, o.lvl);
359
+ inst.changeWheel(args);
360
+ currWheelVector = inst.temp.slice(0);
361
+ setDisabled(dw, o.lvl, wa, inst.temp);
362
+ } else {
363
+ var o = calcLevelOfVector2(t, t.length);
364
+ setDisabled(dw, o.lvl, wa, t);
365
+ hideWheels(dw, o.lvl);
366
+ }
367
+ inst.settings.readonly = false;
368
+ }
369
+ };
370
+ };
371
+
372
+ $.each(['list', 'image', 'treelist'], function(i, v) {
373
+ ms.presets[v] = preset;
374
+ ms.presetShort(v);
375
+ });
376
+
377
+ })(jQuery);
@@ -0,0 +1,257 @@
1
+ /*jslint eqeq: true, plusplus: true, undef: true, sloppy: true, vars: true, forin: true */
2
+ (function ($) {
3
+
4
+ var defaults = {
5
+ inputClass: '',
6
+ invalid: [],
7
+ rtl: false,
8
+ group: false,
9
+ groupLabel: 'Groups'
10
+ };
11
+
12
+ $.mobiscroll.presetShort('select');
13
+
14
+ $.mobiscroll.presets.select = function (inst) {
15
+ var stg = inst.settings,
16
+ s = $.extend({}, defaults, stg),
17
+ elm = $(this),
18
+ option = elm.val(),
19
+ group = elm.find('option[value="' + elm.val() + '"]').parent(),
20
+ prev = group.index() + '',
21
+ gr = prev,
22
+ prevent,
23
+ id = this.id + '_dummy',
24
+ l1 = $('label[for="' + this.id + '"]').attr('for', id),
25
+ l2 = $('label[for="' + id + '"]'),
26
+ label = s.label !== undefined ? s.label : (l2.length ? l2.text() : elm.attr('name')),
27
+ invalid = [],
28
+ main = {},
29
+ grIdx,
30
+ optIdx,
31
+ roPre = stg.readonly,
32
+ w;
33
+
34
+ function replace(str) {
35
+ if (str) {
36
+ return str.replace(/_/, '');
37
+ }
38
+ return '';
39
+ }
40
+
41
+ function genWheels() {
42
+ var cont,
43
+ wg = 0,
44
+ wheel = {},
45
+ w = [{}];
46
+
47
+ if (s.group) {
48
+ if (s.rtl) {
49
+ wg = 1;
50
+ }
51
+
52
+ $('optgroup', elm).each(function (index) {
53
+ wheel['_' + index] = $(this).attr('label');
54
+ });
55
+
56
+ w[wg] = {};
57
+ w[wg][s.groupLabel] = wheel;
58
+ cont = group;
59
+ wg += (s.rtl ? -1 : 1);
60
+
61
+ } else {
62
+ cont = elm;
63
+ }
64
+ w[wg] = {};
65
+ w[wg][label] = {};
66
+
67
+ $('option', cont).each(function () {
68
+ var v = $(this).attr('value');
69
+ w[wg][label]['_' + v] = $(this).text();
70
+ if ($(this).prop('disabled')) {
71
+ invalid.push(v);
72
+ }
73
+ });
74
+
75
+ return w;
76
+ }
77
+
78
+ // if groups is true and there are no groups fall back to no grouping
79
+ if (s.group && !$('optgroup', elm).length) {
80
+ s.group = false;
81
+ }
82
+
83
+ if (!s.invalid.length) {
84
+ s.invalid = invalid;
85
+ }
86
+
87
+ if (s.group) {
88
+ if (s.rtl) {
89
+ grIdx = 1;
90
+ optIdx = 0;
91
+ } else {
92
+ grIdx = 0;
93
+ optIdx = 1;
94
+ }
95
+ } else {
96
+ grIdx = -1;
97
+ optIdx = 0;
98
+ }
99
+
100
+ $('#' + id).remove();
101
+
102
+ $('option', elm).each(function () {
103
+ main[$(this).attr('value')] = $(this).text();
104
+ });
105
+
106
+ var input = $('<input type="text" id="' + id + '" value="' + main[elm.val()] + '" class="' + s.inputClass + '" readonly />').insertBefore(elm);
107
+
108
+ if (s.showOnFocus) {
109
+ input.focus(function () {
110
+ inst.show();
111
+ });
112
+ }
113
+
114
+ elm.bind('change', function () {
115
+ if (!prevent && option != elm.val()) {
116
+ inst.setSelectVal([elm.val()], true);
117
+ }
118
+ prevent = false;
119
+ }).hide().closest('.ui-field-contain').trigger('create');
120
+
121
+ inst.setSelectVal = function (d, fill, time) {
122
+ option = d[0];
123
+
124
+ if (s.group) {
125
+ group = elm.find('option[value="' + option + '"]').parent();
126
+ gr = group.index();
127
+ inst.temp = s.rtl ? ['_' + option, '_' + group.index()] : ['_' + group.index(), '_' + option];
128
+ if (gr !== prev) { // Need to regenerate wheels, if group changed
129
+ stg.wheels = genWheels();
130
+ inst.changeWheel([optIdx]);
131
+ prev = gr + '';
132
+ }
133
+ } else {
134
+ inst.temp = ['_' + option];
135
+ }
136
+
137
+ inst.setValue(true, fill, time);
138
+
139
+ // Set input/select values
140
+ if (fill) {
141
+ input.val(main[option]);
142
+ var changed = option !== elm.val();
143
+ elm.val(option);
144
+ // Trigger change on element
145
+ if (changed) {
146
+ elm.trigger('change');
147
+ }
148
+ }
149
+ };
150
+
151
+ inst.getSelectVal = function (temp) {
152
+ var val = temp ? inst.temp : inst.values;
153
+ return replace(val[optIdx]);
154
+ };
155
+
156
+ return {
157
+ width: 50,
158
+ wheels: w,
159
+ headerText: false,
160
+ anchor: input,
161
+ formatResult: function (d) {
162
+ return main[replace(d[optIdx])];
163
+ },
164
+ parseValue: function () {
165
+ option = elm.val();
166
+ group = elm.find('option[value="' + option + '"]').parent();
167
+ gr = group.index();
168
+ return s.group && s.rtl ? ['_' + option, '_' + gr] : s.group ? ['_' + gr, '_' + option] : ['_' + option];
169
+ },
170
+ validate: function (dw, i) {
171
+ if (i === grIdx) {
172
+ gr = replace(inst.temp[grIdx]);
173
+
174
+ if (gr !== prev) {
175
+ group = elm.find('optgroup').eq(gr);
176
+ gr = group.index();
177
+ option = group.find('option').eq(0).val();
178
+ option = option || elm.val();
179
+ stg.wheels = genWheels();
180
+ if (s.group) {
181
+ inst.temp = s.rtl ? ['_' + option, '_' + gr] : ['_' + gr, '_' + option];
182
+ inst.changeWheel([optIdx]);
183
+ prev = gr + '';
184
+ }
185
+ }
186
+ stg.readonly = roPre;
187
+ } else {
188
+ option = replace(inst.temp[optIdx]);
189
+ }
190
+
191
+ var t = $('ul', dw).eq(optIdx);
192
+ $.each(s.invalid, function (i, v) {
193
+ $('li[data-val="_' + v + '"]', t).removeClass('dw-v');
194
+ });
195
+ },
196
+ onAnimStart: function(i) {
197
+ if (i === grIdx) { // If group wheel is scroller, lock the options wheel
198
+ stg.readonly = [s.rtl, !s.rtl];
199
+ }
200
+ },
201
+ onBeforeShow: function () {
202
+ stg.wheels = genWheels();
203
+ if (s.group) {
204
+ inst.temp = s.rtl ? ['_' + option, '_' + group.index()] : ['_' + group.index(), '_' + option];
205
+ }
206
+ },
207
+ onSelect: function (v) {
208
+ input.val(v);
209
+ prevent = true;
210
+ elm.val(replace(inst.values[optIdx])).trigger('change');
211
+ if (s.group) {
212
+ inst.values = null;
213
+ }
214
+ },
215
+ onCancel: function () {
216
+ if (s.group) {
217
+ inst.values = null;
218
+ }
219
+ },
220
+ onChange: function (v) {
221
+ if (s.display == 'inline') {
222
+ input.val(v);
223
+ prevent = true;
224
+ elm.val(replace(inst.temp[optIdx])).trigger('change');
225
+ }
226
+ },
227
+ onClose: function () {
228
+ input.blur();
229
+ },
230
+ methods: {
231
+ setValue: function (d, fill, time) {
232
+ return this.each(function () {
233
+ var inst = $(this).mobiscroll('getInst');
234
+ if (inst) {
235
+ if (inst.setSelectVal) {
236
+ inst.setSelectVal(d, fill, time);
237
+ } else {
238
+ inst.temp = d;
239
+ inst.setValue(true, fill, time);
240
+ }
241
+ }
242
+ });
243
+ },
244
+ getValue: function (temp) {
245
+ var inst = $(this).mobiscroll('getInst');
246
+ if (inst) {
247
+ if (inst.getSelectVal) {
248
+ return inst.getSelectVal(temp);
249
+ }
250
+ return inst.values;
251
+ }
252
+ }
253
+ }
254
+ };
255
+ }
256
+
257
+ })(jQuery);