romo 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +9 -1
- data/README.md +1 -1
- data/assets/css/romo/_mixins.scss +486 -0
- data/assets/css/romo/_vars.scss +159 -0
- data/assets/css/romo/base.scss +454 -0
- data/assets/css/romo/buttons.scss +211 -0
- data/assets/css/romo/datepicker.scss +73 -0
- data/assets/css/romo/dropdown.scss +33 -0
- data/assets/css/romo/forms.scss +193 -0
- data/assets/css/romo/grid.scss +271 -0
- data/assets/css/romo/grid_table.scss +129 -0
- data/assets/css/romo/labels.scss +41 -0
- data/assets/css/romo/lists.scss +37 -0
- data/assets/css/romo/modal.scss +32 -0
- data/assets/css/romo/normalize.scss +425 -0
- data/assets/css/romo/select.scss +89 -0
- data/assets/css/romo/sortable.scss +14 -0
- data/assets/css/romo/table.scss +99 -0
- data/assets/css/romo/tabs.scss +71 -0
- data/assets/css/romo/tooltip.scss +89 -0
- data/assets/css/romo/z_index.scss +26 -0
- data/assets/js/romo/base.js +177 -0
- data/assets/js/romo/datepicker.js +541 -0
- data/assets/js/romo/dropdown.js +309 -0
- data/assets/js/romo/dropdown_form.js +92 -0
- data/assets/js/romo/form.js +182 -0
- data/assets/js/romo/indicator.js +88 -0
- data/assets/js/romo/inline.js +77 -0
- data/assets/js/romo/inline_form.js +86 -0
- data/assets/js/romo/invoke.js +87 -0
- data/assets/js/romo/modal.js +311 -0
- data/assets/js/romo/modal_form.js +101 -0
- data/assets/js/romo/select.js +139 -0
- data/assets/js/romo/select_dropdown.js +325 -0
- data/assets/js/romo/sortable.js +201 -0
- data/assets/js/romo/tooltip.js +258 -0
- data/lib/romo/dassets.rb +64 -0
- data/lib/romo/version.rb +1 -1
- data/lib/romo.rb +9 -0
- data/romo.gemspec +4 -2
- data/test/support/.gitkeep +0 -0
- data/test/system/.gitkeep +0 -0
- data/test/unit/dassets_tests.rb +67 -0
- data/test/unit/romo_tests.rb +21 -0
- metadata +53 -10
@@ -0,0 +1,541 @@
|
|
1
|
+
$.fn.romoDatepicker = function() {
|
2
|
+
return $.map(this, function(element) {
|
3
|
+
return new RomoDatepicker(element);
|
4
|
+
});
|
5
|
+
}
|
6
|
+
|
7
|
+
var RomoDatepicker = function(element) {
|
8
|
+
this.elem = $(element);
|
9
|
+
this.defaultFormat = 'yyyy-mm-dd'
|
10
|
+
this.monthNames = [
|
11
|
+
"January", "February", "March", "April", "May", "June",
|
12
|
+
"July", "August", "September", "October", "November", "December"
|
13
|
+
]
|
14
|
+
this.defaultPrevClass = undefined;
|
15
|
+
this.defaultNextClass = undefined;
|
16
|
+
this.defaultIndicatorClass = undefined;
|
17
|
+
this.itemSelector = 'TD.romo-datepicker-day:not(.disabled)';
|
18
|
+
this.calTable = $();
|
19
|
+
this.date = undefined;
|
20
|
+
this.today = new Date;
|
21
|
+
|
22
|
+
this.doInit();
|
23
|
+
this.doBindElem();
|
24
|
+
this.doSetFormat();
|
25
|
+
this.doSetDate(this.elem.val());
|
26
|
+
this.doBindDropdown();
|
27
|
+
this.doBuildUI();
|
28
|
+
|
29
|
+
this.elem.trigger('datepicker:ready', [this]);
|
30
|
+
}
|
31
|
+
|
32
|
+
RomoDatepicker.prototype.doInit = function() {
|
33
|
+
// override as needed
|
34
|
+
}
|
35
|
+
|
36
|
+
RomoDatepicker.prototype.doBindElem = function() {
|
37
|
+
var elemWrapper = $('<div class="romo-datepicker-wrapper"></div>');
|
38
|
+
elemWrapper.css({'display': (this.elem.data('romo-datepicker-elem-display') || 'inline-block')});
|
39
|
+
if (this.elem.data('romo-datepicker-btn-group') === true) {
|
40
|
+
elemWrapper.addClass('romo-btn-group');
|
41
|
+
}
|
42
|
+
|
43
|
+
this.elem.before(elemWrapper);
|
44
|
+
elemWrapper.append(this.elem);
|
45
|
+
|
46
|
+
this.elem.attr('autocomplete', 'off');
|
47
|
+
|
48
|
+
this.indicatorElem = $();
|
49
|
+
var indicatorClass = this.elem.data('romo-datepicker-indicator') || this.defaultIndicatorClass;
|
50
|
+
if (indicatorClass !== undefined && indicatorClass !== 'none') {
|
51
|
+
this.indicatorElem = $('<i class="romo-datepicker-indicator '+indicatorClass+'"></i>');
|
52
|
+
this.indicatorElem.css({'line-height': this.elem.css('height')});
|
53
|
+
if (this.elem.prop('disabled') === true) {
|
54
|
+
this.indicatorElem.addClass('disabled');
|
55
|
+
}
|
56
|
+
this.indicatorElem.on('click', $.proxy(this.onIndicatorClick, this));
|
57
|
+
this.elem.css({'padding-right': '22px'});
|
58
|
+
this.elem.after(this.indicatorElem);
|
59
|
+
}
|
60
|
+
|
61
|
+
this.elem.on('datepicker:triggerEnable', $.proxy(function(e) {
|
62
|
+
this.doEnable();
|
63
|
+
}, this));
|
64
|
+
this.elem.on('datepicker:triggerDisable', $.proxy(function(e) {
|
65
|
+
this.doDisable();
|
66
|
+
}, this));
|
67
|
+
}
|
68
|
+
|
69
|
+
RomoDatepicker.prototype.doSetFormat = function() {
|
70
|
+
var format = this.elem.data('romo-datepicker-format') || this.defaultFormat;
|
71
|
+
this.formatValues = this._parseFormatValues(format);
|
72
|
+
}
|
73
|
+
|
74
|
+
RomoDatepicker.prototype.doSetDate = function(value) {
|
75
|
+
this.date = this._parseDate(value);
|
76
|
+
if (this.date !== undefined) {
|
77
|
+
this.elem.val(this._formatDate(this.date));
|
78
|
+
} else {
|
79
|
+
this.elem.val(value);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
RomoDatepicker.prototype.doEnable = function() {
|
84
|
+
this.elem.prop('disabled', false);
|
85
|
+
this.elem.removeClass('disabled');
|
86
|
+
this.indicatorElem.removeClass('disabled');
|
87
|
+
}
|
88
|
+
|
89
|
+
RomoDatepicker.prototype.doDisable = function() {
|
90
|
+
this.elem.prop('disabled', true);
|
91
|
+
this.elem.addClass('disabled');
|
92
|
+
this.indicatorElem.addClass('disabled');
|
93
|
+
}
|
94
|
+
|
95
|
+
RomoDatepicker.prototype.doBindDropdown = function() {
|
96
|
+
this.elem.attr('data-romo-dropdown-disable-toggle', 'true');
|
97
|
+
if (this.elem.data('romo-dropdown-width') === undefined) {
|
98
|
+
this.elem.attr('data-romo-dropdown-width', 'elem');
|
99
|
+
}
|
100
|
+
if (this.elem.width() < 175) {
|
101
|
+
this.elem.attr('data-romo-dropdown-width', '175px');
|
102
|
+
}
|
103
|
+
this.romoDropdown = this.elem.romoDropdown()[0];
|
104
|
+
|
105
|
+
this.romoDropdown.doSetPopupZIndex(this.elem);
|
106
|
+
this.romoDropdown.bodyElem.addClass('romo-datepicker-calendar');
|
107
|
+
this.romoDropdown.elem.on('dropdown:popupOpen', $.proxy(this.onPopupOpen, this));
|
108
|
+
this.romoDropdown.elem.on('dropdown:popupClose', $.proxy(this.onPopupClose, this));
|
109
|
+
this.romoDropdown.elem.on('blur', $.proxy(function(e) {
|
110
|
+
this.blurTimeoutId = setTimeout($.proxy(function() {
|
111
|
+
if (this.popupMouseDown !== true) {
|
112
|
+
this.romoDropdown.elem.trigger('dropdown:triggerPopupClose', []);
|
113
|
+
}
|
114
|
+
}, this), 10);
|
115
|
+
}, this));
|
116
|
+
this.romoDropdown.elem.on('keydown', $.proxy(this.onElemKeyDown, this));
|
117
|
+
|
118
|
+
this.romoDropdown.elem.on('dropdown:toggle', $.proxy(function(e, dropdown) {
|
119
|
+
this.elem.trigger('datepicker:dropdown:toggle', [dropdown, this]);
|
120
|
+
}, this));
|
121
|
+
this.romoDropdown.elem.on('dropdown:popupOpen', $.proxy(function(e, dropdown) {
|
122
|
+
this.elem.trigger('datepicker:dropdown:popupOpen', [dropdown, this]);
|
123
|
+
}, this));
|
124
|
+
this.romoDropdown.elem.on('dropdown:popupClose', $.proxy(function(e, dropdown) {
|
125
|
+
this.elem.trigger('datepicker:dropdown:popupClose', [dropdown, this]);
|
126
|
+
}, this));
|
127
|
+
|
128
|
+
this.elem.on('datepicker:triggerToggle', $.proxy(function(e) {
|
129
|
+
this.romoDropdown.elem.trigger('dropdown:triggerToggle', []);
|
130
|
+
}, this));
|
131
|
+
this.elem.on('datepicker:triggerPopupOpen', $.proxy(function(e) {
|
132
|
+
this.romoDropdown.elem.trigger('dropdown:triggerPopupOpen', []);
|
133
|
+
}, this));
|
134
|
+
this.elem.on('datepicker:triggerPopupClose', $.proxy(function(e) {
|
135
|
+
this.romoDropdown.elem.trigger('dropdown:triggerPopupClose', []);
|
136
|
+
}, this));
|
137
|
+
}
|
138
|
+
|
139
|
+
RomoDatepicker.prototype.doBuildUI = function() {
|
140
|
+
this.calTable = this._buildCalendar();
|
141
|
+
this.romoDropdown.bodyElem.html('');
|
142
|
+
this.romoDropdown.bodyElem.append(this.calTable);
|
143
|
+
|
144
|
+
this.calTable.find('.romo-datepicker-prev').on('click', $.proxy(this.onPrevClick, this));
|
145
|
+
this.calTable.find('.romo-datepicker-next').on('click', $.proxy(this.onNextClick, this));
|
146
|
+
}
|
147
|
+
|
148
|
+
RomoDatepicker.prototype.doRefreshUI = function(date) {
|
149
|
+
var rDate = date || this.date || (new Date);
|
150
|
+
this._refreshCalendar(rDate);
|
151
|
+
this.elem.trigger('datepicker:refresh', [rDate, this]);
|
152
|
+
|
153
|
+
this.calTable.find(this.itemSelector).on('hover', $.proxy(this.onItemHover, this));
|
154
|
+
this.calTable.find(this.itemSelector).on('click', $.proxy(this.onItemClick, this));
|
155
|
+
|
156
|
+
this.romoDropdown.popupElem.on('mousedown', $.proxy(this.onPopupMouseDown, this));
|
157
|
+
this.romoDropdown.popupElem.on('mouseup', $.proxy(this.onPopupMouseUp, this));
|
158
|
+
}
|
159
|
+
|
160
|
+
RomoDatepicker.prototype.doRefreshToPrevMonth = function() {
|
161
|
+
var date = this.refreshDate || this.date || (new Date);
|
162
|
+
var year = date.getUTCFullYear();
|
163
|
+
var month = date.getUTCMonth() - 1;
|
164
|
+
if (month < 0) {
|
165
|
+
year -= 1;
|
166
|
+
month = 11;
|
167
|
+
}
|
168
|
+
|
169
|
+
var pDate = this._UTCDate(year, month, 1);
|
170
|
+
this.doRefreshUI(pDate);
|
171
|
+
this.elem.trigger('datepicker:prevRefresh', [pDate, this]);
|
172
|
+
}
|
173
|
+
|
174
|
+
RomoDatepicker.prototype.doRefreshToNextMonth = function() {
|
175
|
+
var date = this.refreshDate || this.date || (new Date);
|
176
|
+
var year = date.getUTCFullYear();
|
177
|
+
var month = date.getUTCMonth() + 1;
|
178
|
+
if (month > 11) {
|
179
|
+
year += 1;
|
180
|
+
month = 0;
|
181
|
+
}
|
182
|
+
|
183
|
+
var nDate = this._UTCDate(year, month, 1);
|
184
|
+
this.doRefreshUI(nDate);
|
185
|
+
this.elem.trigger('datepicker:nextRefresh', [nDate, this]);
|
186
|
+
}
|
187
|
+
|
188
|
+
RomoDatepicker.prototype.doSelectHighlightedItem = function() {
|
189
|
+
var prevValue = this.elem.val();
|
190
|
+
var newValue = this.calTable.find('TD.romo-datepicker-highlight').data('romo-datepicker-value');
|
191
|
+
|
192
|
+
this.romoDropdown.doPopupClose();
|
193
|
+
this.doSetDate(newValue);
|
194
|
+
this.elem.focus();
|
195
|
+
this.elem.trigger('datepicker:itemSelected', [newValue, prevValue, this]);
|
196
|
+
|
197
|
+
if (newValue !== prevValue) {
|
198
|
+
this.elem.trigger('change');
|
199
|
+
this.elem.trigger('datepicker:change', [newValue, prevValue, this]);
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
RomoDatepicker.prototype.onElemKeyDown = function(e) {
|
204
|
+
if (this.elem.hasClass('disabled') === false) {
|
205
|
+
if (this.romoDropdown.popupElem.hasClass('romo-dropdown-open')) {
|
206
|
+
return true;
|
207
|
+
} else {
|
208
|
+
if(e.keyCode === 40 /* Down */ ) {
|
209
|
+
this.romoDropdown.doPopupOpen();
|
210
|
+
this.romoDropdown.popupElem.focus();
|
211
|
+
return false;
|
212
|
+
} else {
|
213
|
+
return true;
|
214
|
+
}
|
215
|
+
}
|
216
|
+
}
|
217
|
+
return true;
|
218
|
+
}
|
219
|
+
|
220
|
+
RomoDatepicker.prototype.onPopupOpen = function(e) {
|
221
|
+
if (this.elem.hasClass('disabled') === false) {
|
222
|
+
this.doSetDate(this.elem.val());
|
223
|
+
this.doRefreshUI();
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
RomoDatepicker.prototype.onPopupClose = function(e) {
|
228
|
+
this._highlightItem($());
|
229
|
+
}
|
230
|
+
|
231
|
+
RomoDatepicker.prototype.onItemHover = function(e) {
|
232
|
+
if (e !== undefined) {
|
233
|
+
e.preventDefault();
|
234
|
+
e.stopPropagation();
|
235
|
+
}
|
236
|
+
this._highlightItem($(e.target));
|
237
|
+
}
|
238
|
+
|
239
|
+
RomoDatepicker.prototype.onIndicatorClick = function(e) {
|
240
|
+
this._clearBlurTimeout();
|
241
|
+
if (e !== undefined) {
|
242
|
+
e.preventDefault();
|
243
|
+
e.stopPropagation();
|
244
|
+
}
|
245
|
+
if (this.elem.prop('disabled') === false) {
|
246
|
+
this.elem.focus();
|
247
|
+
this.elem.trigger('datepicker:triggerPopupOpen');
|
248
|
+
}
|
249
|
+
}
|
250
|
+
|
251
|
+
RomoDatepicker.prototype.onItemClick = function(e) {
|
252
|
+
this._clearBlurTimeout();
|
253
|
+
if (e !== undefined) {
|
254
|
+
e.preventDefault();
|
255
|
+
e.stopPropagation();
|
256
|
+
}
|
257
|
+
this.doSelectHighlightedItem();
|
258
|
+
}
|
259
|
+
|
260
|
+
RomoDatepicker.prototype.onPrevClick = function(e) {
|
261
|
+
this._clearBlurTimeout();
|
262
|
+
if (e !== undefined) {
|
263
|
+
e.preventDefault();
|
264
|
+
e.stopPropagation();
|
265
|
+
}
|
266
|
+
this.doRefreshToPrevMonth();
|
267
|
+
}
|
268
|
+
|
269
|
+
RomoDatepicker.prototype.onNextClick = function(e) {
|
270
|
+
this._clearBlurTimeout();
|
271
|
+
if (e !== undefined) {
|
272
|
+
e.preventDefault();
|
273
|
+
e.stopPropagation();
|
274
|
+
}
|
275
|
+
this.doRefreshToNextMonth();
|
276
|
+
}
|
277
|
+
|
278
|
+
RomoDatepicker.prototype.onPopupMouseDown = function(e) {
|
279
|
+
this.popupMouseDown = true;
|
280
|
+
}
|
281
|
+
|
282
|
+
RomoDatepicker.prototype.onPopupMouseUp = function(e) {
|
283
|
+
this.popupMouseDown = false;
|
284
|
+
}
|
285
|
+
|
286
|
+
RomoDatepicker.prototype._clearBlurTimeout = function() {
|
287
|
+
if (this.blurTimeoutId !== undefined) {
|
288
|
+
clearTimeout(this.blurTimeoutId);
|
289
|
+
this.blurTimeoutId = undefined;
|
290
|
+
}
|
291
|
+
}
|
292
|
+
|
293
|
+
RomoDatepicker.prototype._refreshCalendar = function(date) {
|
294
|
+
this.calTable.find('.romo-datepicker-title').html(this._buildCalendarTitle(date));
|
295
|
+
this.calTable.find('tbody').empty().append(this._buildCalendarBody(date));
|
296
|
+
this.refreshDate = date;
|
297
|
+
}
|
298
|
+
|
299
|
+
RomoDatepicker.prototype._buildCalendar = function() {
|
300
|
+
var table = $('<table></table>');
|
301
|
+
table.append(this._buildCalendarHeader());
|
302
|
+
table.append($('<tbody></tbody>'));
|
303
|
+
return table;
|
304
|
+
}
|
305
|
+
|
306
|
+
RomoDatepicker.prototype._buildCalendarHeader = function() {
|
307
|
+
var prevClass = this.elem.data('romo-datepicker-prev') || this.defaultPrevClass;
|
308
|
+
var nextClass = this.elem.data('romo-datepicker-next') || this.defaultNextClass;
|
309
|
+
var header = $('<thead></thead');
|
310
|
+
|
311
|
+
var row = $('<tr></tr>');
|
312
|
+
var th = $('<th class="romo-datepicker-prev" title="Previous Month"></th>');
|
313
|
+
if (prevClass) {
|
314
|
+
th.append('<i class="'+prevClass+'"></i>');
|
315
|
+
} else {
|
316
|
+
th.text('<<');
|
317
|
+
}
|
318
|
+
row.append(th);
|
319
|
+
row.append($('<th class="romo-datepicker-title" colspan="5"></th>'));
|
320
|
+
var th = $('<th class="romo-datepicker-next" title="Next Month"></th>');
|
321
|
+
if (nextClass) {
|
322
|
+
th.append('<i class="'+nextClass+'"></i>');
|
323
|
+
} else {
|
324
|
+
th.text('>>');
|
325
|
+
}
|
326
|
+
row.append(th);
|
327
|
+
header.append(row);
|
328
|
+
|
329
|
+
row = $('<tr></tr>');
|
330
|
+
row.append($('<th class="romo-datepicker-day">Su</th>'));
|
331
|
+
row.append($('<th class="romo-datepicker-day">M</th>'));
|
332
|
+
row.append($('<th class="romo-datepicker-day">T</th>'));
|
333
|
+
row.append($('<th class="romo-datepicker-day">W</th>'));
|
334
|
+
row.append($('<th class="romo-datepicker-day">Th</th>'));
|
335
|
+
row.append($('<th class="romo-datepicker-day">F</th>'));
|
336
|
+
row.append($('<th class="romo-datepicker-day">S</th>'));
|
337
|
+
header.append(row);
|
338
|
+
|
339
|
+
return header;
|
340
|
+
}
|
341
|
+
|
342
|
+
RomoDatepicker.prototype._buildCalendarTitle = function(date) {
|
343
|
+
return this.monthNames[date.getUTCMonth()] + ' ' + date.getUTCFullYear().toString();
|
344
|
+
}
|
345
|
+
|
346
|
+
RomoDatepicker.prototype._buildCalendarBody = function(date) {
|
347
|
+
var ty = this.today.getUTCFullYear();
|
348
|
+
var tm = this.today.getUTCMonth();
|
349
|
+
var td = this.today.getUTCDate();
|
350
|
+
var year = date.getUTCFullYear();
|
351
|
+
var month = date.getUTCMonth();
|
352
|
+
var day = date.getUTCDate();
|
353
|
+
var fomdow = this._UTCDate(year, month, 1).getUTCDay(); // first-of-the-month day-of-the-week
|
354
|
+
if (fomdow == 0) {
|
355
|
+
fomdow = 7; // don't start calendar on the first-of-the-month, show last week of prev month
|
356
|
+
}
|
357
|
+
var iDate = this._UTCDate(year, month, 1 - fomdow);
|
358
|
+
var iWeek = 0;
|
359
|
+
var html = [];
|
360
|
+
|
361
|
+
while (iWeek < 6) { // render 6 weeks in the calendar
|
362
|
+
var y = iDate.getUTCFullYear();
|
363
|
+
var m = iDate.getUTCMonth();
|
364
|
+
var d = iDate.getUTCDate();
|
365
|
+
var dow = iDate.getUTCDay();
|
366
|
+
var cls = [];
|
367
|
+
|
368
|
+
if (dow === 0) {
|
369
|
+
html.push('<tr>');
|
370
|
+
}
|
371
|
+
|
372
|
+
cls.push('romo-datepicker-day');
|
373
|
+
if (dow === 0 || dow === 6) {
|
374
|
+
cls.push('romo-datepicker-day-weekend');
|
375
|
+
}
|
376
|
+
if (y !== year || m !== month) {
|
377
|
+
cls.push('romo-datepicker-day-other');
|
378
|
+
}
|
379
|
+
if (y === ty && m === tm && d === td) {
|
380
|
+
cls.push('romo-datepicker-day-today');
|
381
|
+
}
|
382
|
+
if (this.date &&
|
383
|
+
y === this.date.getUTCFullYear() &&
|
384
|
+
m === this.date.getUTCMonth() &&
|
385
|
+
d === this.date.getUTCDate()) {
|
386
|
+
cls.push('selected');
|
387
|
+
}
|
388
|
+
|
389
|
+
html.push('<td');
|
390
|
+
html.push(' class="'+cls.join(' ')+'"');
|
391
|
+
var dt = this._formatDate(iDate);
|
392
|
+
html.push(' title="'+dt+'"');
|
393
|
+
html.push(' data-romo-datepicker-value="'+dt+'"');
|
394
|
+
html.push('>');
|
395
|
+
html.push(d.toString());
|
396
|
+
html.push('</td>');
|
397
|
+
|
398
|
+
if (dow === 6) {
|
399
|
+
html.push('</tr>');
|
400
|
+
iWeek += 1;
|
401
|
+
}
|
402
|
+
iDate.setUTCDate(iDate.getUTCDate()+1);
|
403
|
+
}
|
404
|
+
|
405
|
+
return $(html.join(''));
|
406
|
+
}
|
407
|
+
|
408
|
+
RomoDatepicker.prototype._highlightItem = function(item) {
|
409
|
+
this.calTable.find('TD.romo-datepicker-highlight').removeClass('romo-datepicker-highlight');
|
410
|
+
item.addClass('romo-datepicker-highlight');
|
411
|
+
}
|
412
|
+
|
413
|
+
RomoDatepicker.prototype._formatDate = function(date) {
|
414
|
+
var year = date.getUTCFullYear();
|
415
|
+
var month = date.getUTCMonth() + 1;
|
416
|
+
var day = date.getUTCDate();
|
417
|
+
|
418
|
+
return this.formatValues.reduce(function(prev, curr) {
|
419
|
+
switch (curr) {
|
420
|
+
case "yyyy":
|
421
|
+
case "yyy":
|
422
|
+
prev += year.toString();
|
423
|
+
break;
|
424
|
+
case "yy":
|
425
|
+
case "y":
|
426
|
+
prev += year.toString().slice(-2);
|
427
|
+
break;
|
428
|
+
case "mm":
|
429
|
+
prev += ("00"+ month.toString()).slice(-2); // pad 2 with "0"s
|
430
|
+
break;
|
431
|
+
case "m":
|
432
|
+
prev += month.toString();
|
433
|
+
break;
|
434
|
+
case "dd":
|
435
|
+
prev += ("00"+ day.toString()).slice(-2); // pad 2 with "0"s
|
436
|
+
break;
|
437
|
+
case "d":
|
438
|
+
prev += day.toString();
|
439
|
+
break;
|
440
|
+
default:
|
441
|
+
prev += curr; // delimeter, pass-thru
|
442
|
+
}
|
443
|
+
return prev;
|
444
|
+
}, '');
|
445
|
+
}
|
446
|
+
|
447
|
+
RomoDatepicker.prototype._parseFormatValues = function(value) {
|
448
|
+
var regex, matches;
|
449
|
+
|
450
|
+
regex = /^([m]{1,2})([^md]+)([d]{1,2})([^dy]+)([y]{2,4})$/; // mm dd yyyy or mm dd yy
|
451
|
+
matches = this._regexMatches(value, regex);
|
452
|
+
if (matches.length === 5) {
|
453
|
+
return matches;
|
454
|
+
}
|
455
|
+
|
456
|
+
regex = /^([y]{3,4})([^ym]+)([m]{1,2})([^md]+)([d]{1,2})$/; // yyyy mm dd
|
457
|
+
matches = this._regexMatches(value, regex);
|
458
|
+
if (matches.length === 5) {
|
459
|
+
return matches;
|
460
|
+
}
|
461
|
+
|
462
|
+
return ['yyyy', '-', 'mm', '-', 'dd'];
|
463
|
+
}
|
464
|
+
|
465
|
+
RomoDatepicker.prototype._parseDate = function(value) {
|
466
|
+
if (value.trim() === '') {
|
467
|
+
return undefined;
|
468
|
+
}
|
469
|
+
|
470
|
+
var dateValues = this._parseDateValues(value.trim());
|
471
|
+
if (dateValues.length === 0) {
|
472
|
+
return undefined;
|
473
|
+
}
|
474
|
+
|
475
|
+
var year = parseInt(dateValues[0]);
|
476
|
+
if (year < 0) {
|
477
|
+
return undefined;
|
478
|
+
}
|
479
|
+
if (dateValues[0].length > 2 && year < 100) {
|
480
|
+
return undefined;
|
481
|
+
}
|
482
|
+
if (dateValues[0].length === 2 && year < 100) {
|
483
|
+
year = this._currentYear() - (this._currentYear() % 1000) + year;
|
484
|
+
}
|
485
|
+
|
486
|
+
var month = parseInt(dateValues[1]) - 1;
|
487
|
+
if (month < 0 || month > 11) {
|
488
|
+
return undefined;
|
489
|
+
}
|
490
|
+
|
491
|
+
var day = parseInt(dateValues[2]);
|
492
|
+
var date = this._UTCDate(year, month, day);
|
493
|
+
if (date.getUTCMonth() !== month) {
|
494
|
+
return undefined;
|
495
|
+
}
|
496
|
+
|
497
|
+
return date;
|
498
|
+
}
|
499
|
+
|
500
|
+
RomoDatepicker.prototype._parseDateValues = function(value) {
|
501
|
+
var regex, matches;
|
502
|
+
|
503
|
+
regex = /^([0-9]{1,2})[^0-9]+([0-9]{1,2})[^0-9]+([0-9]{2,4})$/; // mm dd yyyy or mm dd yy
|
504
|
+
matches = this._regexMatches(value, regex);
|
505
|
+
if (matches.length === 3) {
|
506
|
+
return [matches[2], matches[0], matches[1]];
|
507
|
+
}
|
508
|
+
|
509
|
+
regex = /^([0-9]{3,4})[^0-9]+([0-9]{1,2})[^0-9]+([0-9]{1,2})$/; // yyyy mm dd
|
510
|
+
matches = this._regexMatches(value, regex);
|
511
|
+
if (matches.length === 3) {
|
512
|
+
return matches;
|
513
|
+
}
|
514
|
+
|
515
|
+
regex = /^([0-9]{1,2})[^0-9]+([0-9]{1,2})$/; // mm dd
|
516
|
+
matches = this._regexMatches(value, regex);
|
517
|
+
if (matches.length === 2) {
|
518
|
+
return [this._currentYear(), matches[0], matches[1]];
|
519
|
+
}
|
520
|
+
|
521
|
+
return [];
|
522
|
+
}
|
523
|
+
|
524
|
+
RomoDatepicker.prototype._regexMatches = function(value, regex) {
|
525
|
+
if (regex.test(value) === true) {
|
526
|
+
return regex.exec(value).slice(1);
|
527
|
+
}
|
528
|
+
return [];
|
529
|
+
}
|
530
|
+
|
531
|
+
RomoDatepicker.prototype._currentYear = function() {
|
532
|
+
return (new Date).getUTCFullYear();
|
533
|
+
}
|
534
|
+
|
535
|
+
RomoDatepicker.prototype._UTCDate = function(year, month, day) {
|
536
|
+
return new Date(Date.UTC.apply(Date, [year, month, day]));
|
537
|
+
}
|
538
|
+
|
539
|
+
Romo.onInitUI(function(e) {
|
540
|
+
Romo.initUIElems(e, '[data-romo-datepicker-auto="true"]').romoDatepicker();
|
541
|
+
});
|