flashoff 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +74 -0
  6. data/Rakefile +1 -0
  7. data/app/assets/fonts/gotham/gotham-bold.eot +0 -0
  8. data/app/assets/fonts/gotham/gotham-bold.svg +2066 -0
  9. data/app/assets/fonts/gotham/gotham-bold.ttf +0 -0
  10. data/app/assets/fonts/gotham/gotham-bold.woff +0 -0
  11. data/app/assets/fonts/gotham/gotham-book.eot +0 -0
  12. data/app/assets/fonts/gotham/gotham-book.svg +631 -0
  13. data/app/assets/fonts/gotham/gotham-book.ttf +0 -0
  14. data/app/assets/fonts/gotham/gotham-book.woff +0 -0
  15. data/app/assets/fonts/gotham/gotham-light.eot +0 -0
  16. data/app/assets/fonts/gotham/gotham-light.svg +635 -0
  17. data/app/assets/fonts/gotham/gotham-light.ttf +0 -0
  18. data/app/assets/fonts/gotham/gotham-light.woff +0 -0
  19. data/app/assets/fonts/gotham/gotham-medium.eot +0 -0
  20. data/app/assets/fonts/gotham/gotham-medium.svg +629 -0
  21. data/app/assets/fonts/gotham/gotham-medium.ttf +0 -0
  22. data/app/assets/fonts/gotham/gotham-medium.woff +0 -0
  23. data/app/assets/fonts/ionicons/ionicons.eot +0 -0
  24. data/app/assets/fonts/ionicons/ionicons.svg +1390 -0
  25. data/app/assets/fonts/ionicons/ionicons.ttf +0 -0
  26. data/app/assets/fonts/ionicons/ionicons.woff +0 -0
  27. data/flashoff.gemspec +23 -0
  28. data/lib/flashoff/version.rb +3 -0
  29. data/lib/flashoff.rb +5 -0
  30. data/vendor/assets/javascripts/alert.js +78 -0
  31. data/vendor/assets/javascripts/collapse.js +159 -0
  32. data/vendor/assets/javascripts/date_picker.js +1385 -0
  33. data/vendor/assets/javascripts/dropdown.js +134 -0
  34. data/vendor/assets/javascripts/file_input.js +88 -0
  35. data/vendor/assets/javascripts/map.js +2036 -0
  36. data/vendor/assets/javascripts/modal.js +226 -0
  37. data/vendor/assets/javascripts/popover.js +97 -0
  38. data/vendor/assets/javascripts/tab.js +115 -0
  39. data/vendor/assets/javascripts/time_picker.js +878 -0
  40. data/vendor/assets/javascripts/tooltip.js +365 -0
  41. data/vendor/assets/javascripts/transition.js +36 -0
  42. data/vendor/assets/stylesheets/ad.css.scss +72 -0
  43. data/vendor/assets/stylesheets/alert.css.scss +57 -0
  44. data/vendor/assets/stylesheets/breadcrumb.css.scss +26 -0
  45. data/vendor/assets/stylesheets/button.css.scss +183 -0
  46. data/vendor/assets/stylesheets/code.css.scss +49 -0
  47. data/vendor/assets/stylesheets/collapse.css.scss +15 -0
  48. data/vendor/assets/stylesheets/datepicker.css.scss +104 -0
  49. data/vendor/assets/stylesheets/dropdown.css.scss +84 -0
  50. data/vendor/assets/stylesheets/footer.css.scss +33 -0
  51. data/vendor/assets/stylesheets/form.css.scss +213 -0
  52. data/vendor/assets/stylesheets/grid.css.scss +291 -0
  53. data/vendor/assets/stylesheets/header.css.scss +134 -0
  54. data/vendor/assets/stylesheets/icon.css.scss +972 -0
  55. data/vendor/assets/stylesheets/image.css.scss +39 -0
  56. data/vendor/assets/stylesheets/label_and_badge.css.scss +53 -0
  57. data/vendor/assets/stylesheets/link.css.scss +19 -0
  58. data/vendor/assets/stylesheets/list.css.scss +38 -0
  59. data/vendor/assets/stylesheets/map.css.scss +13 -0
  60. data/vendor/assets/stylesheets/modal.css.scss +117 -0
  61. data/vendor/assets/stylesheets/pagination.css.scss +37 -0
  62. data/vendor/assets/stylesheets/placeholder.css.scss +11 -0
  63. data/vendor/assets/stylesheets/popover.css.scss +107 -0
  64. data/vendor/assets/stylesheets/progress.css.scss +25 -0
  65. data/vendor/assets/stylesheets/reset.css.scss +57 -0
  66. data/vendor/assets/stylesheets/tab.css.scss +165 -0
  67. data/vendor/assets/stylesheets/table.css.scss +70 -0
  68. data/vendor/assets/stylesheets/timepicker.css.scss +69 -0
  69. data/vendor/assets/stylesheets/tooltip.css.scss +81 -0
  70. data/vendor/assets/stylesheets/transition.css.scss +12 -0
  71. data/vendor/assets/stylesheets/trunk.css.scss +69 -0
  72. data/vendor/assets/stylesheets/typography.css.scss +147 -0
  73. metadata +144 -0
@@ -0,0 +1,1385 @@
1
+ (function($, undefined) {
2
+
3
+ var $window = $(window);
4
+
5
+ function UTCDate(){
6
+ return new Date(Date.UTC.apply(Date, arguments));
7
+ }
8
+ function UTCToday(){
9
+ var today = new Date();
10
+ return UTCDate(today.getFullYear(), today.getMonth(), today.getDate());
11
+ }
12
+
13
+
14
+ // Picker object
15
+
16
+ var Datepicker = function(element, options) {
17
+ this.date = undefined;
18
+ this.viewDate = UTCToday();
19
+
20
+ this._process_options(options);
21
+
22
+ this.element = $(element);
23
+ this.isInline = false;
24
+ this.isInput = this.element.is('input');
25
+ this.component = this.element.is('.date') ? this.element.find('.add-on, .input-group-addon, .btn') : false;
26
+ this.hasInput = this.component && this.element.find('input').length;
27
+ if(this.component && this.component.length === 0)
28
+ this.component = false;
29
+
30
+ this.picker = $(DPGlobal.template);
31
+ this._buildEvents();
32
+ this._attachEvents();
33
+
34
+ if(this.isInline) {
35
+ this.picker.addClass('datepicker-inline').appendTo(this.element);
36
+ } else {
37
+ this.picker.addClass('datepicker-dropdown dropdown-menu');
38
+ }
39
+
40
+ if (this.o.rtl){
41
+ this.picker.addClass('datepicker-rtl');
42
+ this.picker.find('.prev i, .next i')
43
+ .toggleClass('icon-arrow-left icon-arrow-right');
44
+ }
45
+
46
+ this.viewMode = this.o.startView;
47
+
48
+ if (this.o.calendarWeeks)
49
+ this.picker.find('tfoot th.today')
50
+ .attr('colspan', function(i, val){
51
+ return parseInt(val) + 1;
52
+ });
53
+
54
+ this._allow_update = false;
55
+
56
+ this.setStartDate(this._o.startDate);
57
+ this.setEndDate(this._o.endDate);
58
+ this.setDaysOfWeekDisabled(this.o.daysOfWeekDisabled);
59
+
60
+ this.fillDow();
61
+ this.fillMonths();
62
+
63
+ this._allow_update = true;
64
+
65
+ this.update();
66
+ this.showMode();
67
+
68
+ if(this.isInline) {
69
+ this.show();
70
+ }
71
+ };
72
+
73
+ Datepicker.prototype = {
74
+ constructor: Datepicker,
75
+
76
+ _process_options: function(opts){
77
+ // Store raw options for reference
78
+ this._o = $.extend({}, this._o, opts);
79
+ // Processed options
80
+ var o = this.o = $.extend({}, this._o);
81
+
82
+ // Check if "de-DE" style date is available, if not language should
83
+ // fallback to 2 letter code eg "de"
84
+ var lang = o.language;
85
+ if (!dates[lang]) {
86
+ lang = lang.split('-')[0];
87
+ if (!dates[lang])
88
+ lang = defaults.language;
89
+ }
90
+ o.language = lang;
91
+
92
+ switch(o.startView){
93
+ case 2:
94
+ case 'decade':
95
+ o.startView = 2;
96
+ break;
97
+ case 1:
98
+ case 'year':
99
+ o.startView = 1;
100
+ break;
101
+ default:
102
+ o.startView = 0;
103
+ }
104
+
105
+ switch (o.minViewMode) {
106
+ case 1:
107
+ case 'months':
108
+ o.minViewMode = 1;
109
+ break;
110
+ case 2:
111
+ case 'years':
112
+ o.minViewMode = 2;
113
+ break;
114
+ default:
115
+ o.minViewMode = 0;
116
+ }
117
+
118
+ o.startView = Math.max(o.startView, o.minViewMode);
119
+
120
+ o.weekStart %= 7;
121
+ o.weekEnd = ((o.weekStart + 6) % 7);
122
+
123
+ var format = DPGlobal.parseFormat(o.format);
124
+ if (o.startDate !== -Infinity) {
125
+ if (!!o.startDate) {
126
+ if (o.startDate instanceof Date)
127
+ o.startDate = this._local_to_utc(this._zero_time(o.startDate));
128
+ else
129
+ o.startDate = DPGlobal.parseDate(o.startDate, format, o.language);
130
+ } else {
131
+ o.startDate = -Infinity;
132
+ }
133
+ }
134
+ if (o.endDate !== Infinity) {
135
+ if (!!o.endDate) {
136
+ if (o.endDate instanceof Date)
137
+ o.endDate = this._local_to_utc(this._zero_time(o.endDate));
138
+ else
139
+ o.endDate = DPGlobal.parseDate(o.endDate, format, o.language);
140
+ } else {
141
+ o.endDate = Infinity;
142
+ }
143
+ }
144
+
145
+ o.daysOfWeekDisabled = o.daysOfWeekDisabled||[];
146
+ if (!$.isArray(o.daysOfWeekDisabled))
147
+ o.daysOfWeekDisabled = o.daysOfWeekDisabled.split(/[,\s]*/);
148
+ o.daysOfWeekDisabled = $.map(o.daysOfWeekDisabled, function (d) {
149
+ return parseInt(d, 10);
150
+ });
151
+
152
+ var plc = String(o.orientation).toLowerCase().split(/\s+/g),
153
+ _plc = o.orientation.toLowerCase();
154
+ plc = $.grep(plc, function(word){
155
+ return (/^auto|left|right|top|bottom$/).test(word);
156
+ });
157
+ o.orientation = {x: 'auto', y: 'auto'};
158
+ if (!_plc || _plc === 'auto')
159
+ ; // no action
160
+ else if (plc.length === 1){
161
+ switch(plc[0]){
162
+ case 'top':
163
+ case 'bottom':
164
+ o.orientation.y = plc[0];
165
+ break;
166
+ case 'left':
167
+ case 'right':
168
+ o.orientation.x = plc[0];
169
+ break;
170
+ }
171
+ }
172
+ else {
173
+ _plc = $.grep(plc, function(word){
174
+ return (/^left|right$/).test(word);
175
+ });
176
+ o.orientation.x = _plc[0] || 'auto';
177
+
178
+ _plc = $.grep(plc, function(word){
179
+ return (/^top|bottom$/).test(word);
180
+ });
181
+ o.orientation.y = _plc[0] || 'auto';
182
+ }
183
+ },
184
+ _events: [],
185
+ _secondaryEvents: [],
186
+ _applyEvents: function(evs){
187
+ for (var i=0, el, ev; i<evs.length; i++){
188
+ el = evs[i][0];
189
+ ev = evs[i][1];
190
+ el.on(ev);
191
+ }
192
+ },
193
+ _unapplyEvents: function(evs){
194
+ for (var i=0, el, ev; i<evs.length; i++){
195
+ el = evs[i][0];
196
+ ev = evs[i][1];
197
+ el.off(ev);
198
+ }
199
+ },
200
+ _buildEvents: function(){
201
+ if (this.isInput) { // single input
202
+ this._events = [
203
+ [this.element, {
204
+ focus: $.proxy(this.show, this),
205
+ keyup: $.proxy(function(){ this.update() }, this),
206
+ keydown: $.proxy(this.keydown, this)
207
+ }]
208
+ ];
209
+ }
210
+ else if (this.component && this.hasInput){ // component: input + button
211
+ this._events = [
212
+ // For components that are not readonly, allow keyboard nav
213
+ [this.element.find('input'), {
214
+ focus: $.proxy(this.show, this),
215
+ keyup: $.proxy(function(){ this.update() }, this),
216
+ keydown: $.proxy(this.keydown, this)
217
+ }],
218
+ [this.component, {
219
+ click: $.proxy(this.show, this)
220
+ }]
221
+ ];
222
+ }
223
+ else if (this.element.is('div')) { // inline datepicker
224
+ this.isInline = true;
225
+ }
226
+ else {
227
+ this._events = [
228
+ [this.element, {
229
+ click: $.proxy(this.show, this)
230
+ }]
231
+ ];
232
+ }
233
+
234
+ this._secondaryEvents = [
235
+ [this.picker, {
236
+ click: $.proxy(this.click, this)
237
+ }],
238
+ [$(window), {
239
+ resize: $.proxy(this.place, this)
240
+ }],
241
+ [$(document), {
242
+ 'mousedown touchstart': $.proxy(function (e) {
243
+ // Clicked outside the datepicker, hide it
244
+ if (!(
245
+ this.element.is(e.target) ||
246
+ this.element.find(e.target).length ||
247
+ this.picker.is(e.target) ||
248
+ this.picker.find(e.target).length
249
+ )) {
250
+ this.hide();
251
+ }
252
+ }, this)
253
+ }]
254
+ ];
255
+ },
256
+ _attachEvents: function(){
257
+ this._detachEvents();
258
+ this._applyEvents(this._events);
259
+ },
260
+ _detachEvents: function(){
261
+ this._unapplyEvents(this._events);
262
+ },
263
+ _attachSecondaryEvents: function(){
264
+ this._detachSecondaryEvents();
265
+ this._applyEvents(this._secondaryEvents);
266
+ },
267
+ _detachSecondaryEvents: function(){
268
+ this._unapplyEvents(this._secondaryEvents);
269
+ },
270
+ _trigger: function(event, altdate){
271
+ var date = altdate || this.date,
272
+ local_date = this._utc_to_local(date);
273
+
274
+ this.element.trigger({
275
+ type: event,
276
+ date: local_date,
277
+ format: $.proxy(function(altformat){
278
+ var format = altformat || this.o.format;
279
+ return DPGlobal.formatDate(date, format, this.o.language);
280
+ }, this)
281
+ });
282
+ },
283
+
284
+ show: function(e) {
285
+ if (!this.isInline)
286
+ this.picker.appendTo('body');
287
+ this.picker.show();
288
+ this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
289
+ this.place();
290
+ this._attachSecondaryEvents();
291
+ if (e) {
292
+ e.preventDefault();
293
+ }
294
+ this._trigger('show');
295
+ },
296
+
297
+ hide: function(){
298
+ if(this.isInline) return;
299
+ if (!this.picker.is(':visible')) return;
300
+ this.picker.hide().detach();
301
+ this._detachSecondaryEvents();
302
+ this.viewMode = this.o.startView;
303
+ this.showMode();
304
+
305
+ if (
306
+ this.o.forceParse &&
307
+ (
308
+ this.isInput && this.element.val() ||
309
+ this.hasInput && this.element.find('input').val()
310
+ )
311
+ )
312
+ this.setValue();
313
+ this._trigger('hide');
314
+ },
315
+
316
+ remove: function() {
317
+ this.hide();
318
+ this._detachEvents();
319
+ this._detachSecondaryEvents();
320
+ this.picker.remove();
321
+ delete this.element.data().datepicker;
322
+ if (!this.isInput) {
323
+ delete this.element.data().date;
324
+ }
325
+ },
326
+
327
+ _utc_to_local: function(utc){
328
+ return utc && new Date(utc.getTime() + (utc.getTimezoneOffset()*60000));
329
+ },
330
+ _local_to_utc: function(local){
331
+ return local && new Date(local.getTime() - (local.getTimezoneOffset()*60000));
332
+ },
333
+ _zero_time: function(local){
334
+ return local && new Date(local.getFullYear(), local.getMonth(), local.getDate());
335
+ },
336
+ _zero_utc_time: function(utc){
337
+ return utc && new Date(Date.UTC(utc.getUTCFullYear(), utc.getUTCMonth(), utc.getUTCDate()));
338
+ },
339
+
340
+ getDate: function() {
341
+ return this._utc_to_local(this.getUTCDate());
342
+ },
343
+
344
+ getUTCDate: function() {
345
+ return this.date;
346
+ },
347
+
348
+ setDate: function(d) {
349
+ this.setUTCDate(this._local_to_utc(d));
350
+ },
351
+
352
+ setUTCDate: function(d) {
353
+ this.date = d;
354
+ this.setValue();
355
+ },
356
+
357
+ setValue: function() {
358
+ var formatted = this.getFormattedDate();
359
+ if (!this.isInput) {
360
+ if (this.component){
361
+ this.element.find('input').val(formatted).change();
362
+ }
363
+ } else {
364
+ this.element.val(formatted).change();
365
+ }
366
+ },
367
+
368
+ getFormattedDate: function(format) {
369
+ if (format === undefined)
370
+ format = this.o.format;
371
+ return DPGlobal.formatDate(this.date, format, this.o.language);
372
+ },
373
+
374
+ setStartDate: function(startDate){
375
+ this._process_options({startDate: startDate});
376
+ this.update();
377
+ this.updateNavArrows();
378
+ },
379
+
380
+ setEndDate: function(endDate){
381
+ this._process_options({endDate: endDate});
382
+ this.update();
383
+ this.updateNavArrows();
384
+ },
385
+
386
+ setDaysOfWeekDisabled: function(daysOfWeekDisabled){
387
+ this._process_options({daysOfWeekDisabled: daysOfWeekDisabled});
388
+ this.update();
389
+ this.updateNavArrows();
390
+ },
391
+
392
+ place: function(){
393
+ if(this.isInline) return;
394
+ var calendarWidth = this.picker.outerWidth(),
395
+ calendarHeight = this.picker.outerHeight(),
396
+ visualPadding = 10,
397
+ windowWidth = $window.width(),
398
+ windowHeight = $window.height(),
399
+ scrollTop = $window.scrollTop();
400
+
401
+ var zIndex = parseInt(this.element.parents().filter(function() {
402
+ return $(this).css('z-index') != 'auto';
403
+ }).first().css('z-index'))+10;
404
+ var offset = this.component ? this.component.parent().offset() : this.element.offset();
405
+ var height = this.component ? this.component.outerHeight(true) : this.element.outerHeight(false);
406
+ var width = this.component ? this.component.outerWidth(true) : this.element.outerWidth(false);
407
+ var left = offset.left,
408
+ top = offset.top;
409
+
410
+ this.picker.removeClass(
411
+ 'datepicker-orient-top datepicker-orient-bottom '+
412
+ 'datepicker-orient-right datepicker-orient-left'
413
+ );
414
+
415
+ if (this.o.orientation.x !== 'auto') {
416
+ this.picker.addClass('datepicker-orient-' + this.o.orientation.x);
417
+ if (this.o.orientation.x === 'right')
418
+ left -= calendarWidth - width;
419
+ }
420
+ // auto x orientation is best-placement: if it crosses a window
421
+ // edge, fudge it sideways
422
+ else {
423
+ // Default to left
424
+ this.picker.addClass('datepicker-orient-left');
425
+ if (offset.left < 0)
426
+ left -= offset.left - visualPadding;
427
+ else if (offset.left + calendarWidth > windowWidth)
428
+ left = windowWidth - calendarWidth - visualPadding;
429
+ }
430
+
431
+ // auto y orientation is best-situation: top or bottom, no fudging,
432
+ // decision based on which shows more of the calendar
433
+ var yorient = this.o.orientation.y,
434
+ top_overflow, bottom_overflow;
435
+ if (yorient === 'auto') {
436
+ top_overflow = -scrollTop + offset.top - calendarHeight;
437
+ bottom_overflow = scrollTop + windowHeight - (offset.top + height + calendarHeight);
438
+ if (Math.max(top_overflow, bottom_overflow) === bottom_overflow)
439
+ yorient = 'top';
440
+ else
441
+ yorient = 'bottom';
442
+ }
443
+ this.picker.addClass('datepicker-orient-' + yorient);
444
+ if (yorient === 'top')
445
+ top += height;
446
+ else
447
+ top -= calendarHeight + parseInt(this.picker.css('padding-top'));
448
+
449
+ this.picker.css({
450
+ top: top,
451
+ left: left,
452
+ zIndex: zIndex
453
+ });
454
+ },
455
+
456
+ _allow_update: true,
457
+ update: function(){
458
+ if (!this._allow_update) return;
459
+
460
+ var oldDate = this.date && new Date(this.date),
461
+ date, fromArgs = false;
462
+ if(arguments.length) {
463
+ date = arguments[0];
464
+ if (date instanceof Date)
465
+ date = this._local_to_utc(date);
466
+ fromArgs = true;
467
+ } else {
468
+ date = this.isInput ? this.element.val() : this.element.data('date') || this.element.find('input').val();
469
+ delete this.element.data().date;
470
+ }
471
+
472
+ this.date = DPGlobal.parseDate(date, this.o.format, this.o.language);
473
+
474
+ if (this.date < this.o.startDate) {
475
+ this.viewDate = new Date(this.o.startDate);
476
+ this.date = new Date(this.o.startDate);
477
+ } else if (this.date > this.o.endDate) {
478
+ this.viewDate = new Date(this.o.endDate);
479
+ this.date = new Date(this.o.endDate);
480
+ } else if (this.date) {
481
+ this.viewDate = new Date(this.date);
482
+ this.date = new Date(this.date);
483
+ } else {
484
+ this.date = undefined;
485
+ }
486
+
487
+ if (fromArgs) {
488
+ // setting date by clicking
489
+ this.setValue();
490
+ } else if (date) {
491
+ // setting date by typing
492
+ if (oldDate && this.date && oldDate.getTime() !== this.date.getTime())
493
+ this._trigger('changeDate');
494
+ }
495
+ if (!this.date && oldDate)
496
+ this._trigger('clearDate');
497
+
498
+ this.fill();
499
+ },
500
+
501
+ fillDow: function(){
502
+ var dowCnt = this.o.weekStart,
503
+ html = '<tr>';
504
+ if(this.o.calendarWeeks){
505
+ var cell = '<th class="cw">&nbsp;</th>';
506
+ html += cell;
507
+ this.picker.find('.datepicker-days thead tr:first-child').prepend(cell);
508
+ }
509
+ while (dowCnt < this.o.weekStart + 7) {
510
+ html += '<th class="dow">'+dates[this.o.language].daysMin[(dowCnt++)%7]+'</th>';
511
+ }
512
+ html += '</tr>';
513
+ this.picker.find('.datepicker-days thead').append(html);
514
+ },
515
+
516
+ fillMonths: function(){
517
+ var html = '',
518
+ i = 0;
519
+ while (i < 12) {
520
+ html += '<span class="month">'+dates[this.o.language].monthsShort[i++]+'</span>';
521
+ }
522
+ this.picker.find('.datepicker-months td').html(html);
523
+ },
524
+
525
+ setRange: function(range){
526
+ if (!range || !range.length)
527
+ delete this.range;
528
+ else
529
+ this.range = $.map(range, function(d){ return d.valueOf(); });
530
+ this.fill();
531
+ },
532
+
533
+ getClassNames: function(date){
534
+ var cls = [],
535
+ year = this.viewDate.getUTCFullYear(),
536
+ month = this.viewDate.getUTCMonth(),
537
+ currentDate = this.date && this.date.valueOf(),
538
+ today = new Date();
539
+ if (date.getUTCFullYear() < year || (date.getUTCFullYear() == year && date.getUTCMonth() < month)) {
540
+ cls.push('old');
541
+ } else if (date.getUTCFullYear() > year || (date.getUTCFullYear() == year && date.getUTCMonth() > month)) {
542
+ cls.push('new');
543
+ }
544
+ // Compare internal UTC date with local today, not UTC today
545
+ if (this.o.todayHighlight &&
546
+ date.getUTCFullYear() == today.getFullYear() &&
547
+ date.getUTCMonth() == today.getMonth() &&
548
+ date.getUTCDate() == today.getDate()) {
549
+ cls.push('today');
550
+ }
551
+ if (date.valueOf() == currentDate) {
552
+ cls.push('active');
553
+ }
554
+ if (date.valueOf() < this.o.startDate || date.valueOf() > this.o.endDate ||
555
+ $.inArray(date.getUTCDay(), this.o.daysOfWeekDisabled) !== -1) {
556
+ cls.push('disabled');
557
+ }
558
+ if (this.range){
559
+ if (date > this.range[0] && date < this.range[this.range.length-1]){
560
+ cls.push('range');
561
+ }
562
+ if ($.inArray(date.valueOf(), this.range) != -1){
563
+ cls.push('selected');
564
+ }
565
+ }
566
+ return cls;
567
+ },
568
+
569
+ fill: function() {
570
+ var d = new Date(this.viewDate),
571
+ year = d.getUTCFullYear(),
572
+ month = d.getUTCMonth(),
573
+ startYear = this.o.startDate !== -Infinity ? this.o.startDate.getUTCFullYear() : -Infinity,
574
+ startMonth = this.o.startDate !== -Infinity ? this.o.startDate.getUTCMonth() : -Infinity,
575
+ endYear = this.o.endDate !== Infinity ? this.o.endDate.getUTCFullYear() : Infinity,
576
+ endMonth = this.o.endDate !== Infinity ? this.o.endDate.getUTCMonth() : Infinity,
577
+ tooltip;
578
+ this.picker.find('.datepicker-days thead th.datepicker-switch')
579
+ .text(dates[this.o.language].months[month]+' '+year);
580
+ this.picker.find('tfoot th.today')
581
+ .text(dates[this.o.language].today)
582
+ .toggle(this.o.todayBtn !== false);
583
+ this.picker.find('tfoot th.clear')
584
+ .text(dates[this.o.language].clear)
585
+ .toggle(this.o.clearBtn !== false);
586
+ this.updateNavArrows();
587
+ this.fillMonths();
588
+ var prevMonth = UTCDate(year, month-1, 28),
589
+ day = DPGlobal.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
590
+ prevMonth.setUTCDate(day);
591
+ prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.o.weekStart + 7)%7);
592
+ var nextMonth = new Date(prevMonth);
593
+ nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
594
+ nextMonth = nextMonth.valueOf();
595
+ var html = [];
596
+ var clsName;
597
+ while(prevMonth.valueOf() < nextMonth) {
598
+ if (prevMonth.getUTCDay() == this.o.weekStart) {
599
+ html.push('<tr>');
600
+ if(this.o.calendarWeeks){
601
+ // ISO 8601: First week contains first thursday.
602
+ // ISO also states week starts on Monday, but we can be more abstract here.
603
+ var
604
+ // Start of current week: based on weekstart/current date
605
+ ws = new Date(+prevMonth + (this.o.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
606
+ // Thursday of this week
607
+ th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
608
+ // First Thursday of year, year from thursday
609
+ yth = new Date(+(yth = UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
610
+ // Calendar week: ms between thursdays, div ms per day, div 7 days
611
+ calWeek = (th - yth) / 864e5 / 7 + 1;
612
+ html.push('<td class="cw">'+ calWeek +'</td>');
613
+
614
+ }
615
+ }
616
+ clsName = this.getClassNames(prevMonth);
617
+ clsName.push('day');
618
+
619
+ if (this.o.beforeShowDay !== $.noop){
620
+ var before = this.o.beforeShowDay(this._utc_to_local(prevMonth));
621
+ if (before === undefined)
622
+ before = {};
623
+ else if (typeof(before) === 'boolean')
624
+ before = {enabled: before};
625
+ else if (typeof(before) === 'string')
626
+ before = {classes: before};
627
+ if (before.enabled === false)
628
+ clsName.push('disabled');
629
+ if (before.classes)
630
+ clsName = clsName.concat(before.classes.split(/\s+/));
631
+ if (before.tooltip)
632
+ tooltip = before.tooltip;
633
+ }
634
+
635
+ clsName = $.unique(clsName);
636
+ html.push('<td class="'+clsName.join(' ')+'"' + (tooltip ? ' title="'+tooltip+'"' : '') + '>'+prevMonth.getUTCDate() + '</td>');
637
+ if (prevMonth.getUTCDay() == this.o.weekEnd) {
638
+ html.push('</tr>');
639
+ }
640
+ prevMonth.setUTCDate(prevMonth.getUTCDate()+1);
641
+ }
642
+ this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
643
+ var currentYear = this.date && this.date.getUTCFullYear();
644
+
645
+ var months = this.picker.find('.datepicker-months')
646
+ .find('th:eq(1)')
647
+ .text(year)
648
+ .end()
649
+ .find('span').removeClass('active');
650
+ if (currentYear && currentYear == year) {
651
+ months.eq(this.date && this.date.getUTCMonth()).addClass('active');
652
+ }
653
+ if (year < startYear || year > endYear) {
654
+ months.addClass('disabled');
655
+ }
656
+ if (year == startYear) {
657
+ months.slice(0, startMonth).addClass('disabled');
658
+ }
659
+ if (year == endYear) {
660
+ months.slice(endMonth+1).addClass('disabled');
661
+ }
662
+
663
+ html = '';
664
+ year = parseInt(year/10, 10) * 10;
665
+ var yearCont = this.picker.find('.datepicker-years')
666
+ .find('th:eq(1)')
667
+ .text(year + '-' + (year + 9))
668
+ .end()
669
+ .find('td');
670
+ year -= 1;
671
+ for (var i = -1; i < 11; i++) {
672
+ html += '<span class="year'+(i == -1 ? ' old' : i == 10 ? ' new' : '')+(currentYear == year ? ' active' : '')+(year < startYear || year > endYear ? ' disabled' : '')+'">'+year+'</span>';
673
+ year += 1;
674
+ }
675
+ yearCont.html(html);
676
+ },
677
+
678
+ updateNavArrows: function() {
679
+ if (!this._allow_update) return;
680
+
681
+ var d = new Date(this.viewDate),
682
+ year = d.getUTCFullYear(),
683
+ month = d.getUTCMonth();
684
+ switch (this.viewMode) {
685
+ case 0:
686
+ if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear() && month <= this.o.startDate.getUTCMonth()) {
687
+ this.picker.find('.prev').css({visibility: 'hidden'});
688
+ } else {
689
+ this.picker.find('.prev').css({visibility: 'visible'});
690
+ }
691
+ if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear() && month >= this.o.endDate.getUTCMonth()) {
692
+ this.picker.find('.next').css({visibility: 'hidden'});
693
+ } else {
694
+ this.picker.find('.next').css({visibility: 'visible'});
695
+ }
696
+ break;
697
+ case 1:
698
+ case 2:
699
+ if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear()) {
700
+ this.picker.find('.prev').css({visibility: 'hidden'});
701
+ } else {
702
+ this.picker.find('.prev').css({visibility: 'visible'});
703
+ }
704
+ if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear()) {
705
+ this.picker.find('.next').css({visibility: 'hidden'});
706
+ } else {
707
+ this.picker.find('.next').css({visibility: 'visible'});
708
+ }
709
+ break;
710
+ }
711
+ },
712
+
713
+ click: function(e) {
714
+ e.preventDefault();
715
+ var target = $(e.target).closest('span, td, th'),
716
+ year, month, day;
717
+ if (target.length == 1) {
718
+ switch(target[0].nodeName.toLowerCase()) {
719
+ case 'th':
720
+ switch(target[0].className) {
721
+ case 'datepicker-switch':
722
+ this.showMode(1);
723
+ break;
724
+ case 'prev':
725
+ case 'next':
726
+ var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1);
727
+ switch(this.viewMode){
728
+ case 0:
729
+ this.viewDate = this.moveMonth(this.viewDate, dir);
730
+ this._trigger('changeMonth', this.viewDate);
731
+ break;
732
+ case 1:
733
+ case 2:
734
+ this.viewDate = this.moveYear(this.viewDate, dir);
735
+ if (this.viewMode === 1)
736
+ this._trigger('changeYear', this.viewDate);
737
+ break;
738
+ }
739
+ this.fill();
740
+ break;
741
+ case 'today':
742
+ var date = new Date();
743
+ date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
744
+
745
+ this.showMode(-2);
746
+ var which = this.o.todayBtn == 'linked' ? null : 'view';
747
+ this._setDate(date, which);
748
+ break;
749
+ case 'clear':
750
+ var element;
751
+ if (this.isInput)
752
+ element = this.element;
753
+ else if (this.component)
754
+ element = this.element.find('input');
755
+ if (element)
756
+ element.val("").change();
757
+ this.update();
758
+ this._trigger('changeDate');
759
+ if (this.o.autoclose)
760
+ this.hide();
761
+ break;
762
+ }
763
+ break;
764
+ case 'span':
765
+ if (!target.is('.disabled')) {
766
+ this.viewDate.setUTCDate(1);
767
+ if (target.is('.month')) {
768
+ day = 1;
769
+ month = target.parent().find('span').index(target);
770
+ year = this.viewDate.getUTCFullYear();
771
+ this.viewDate.setUTCMonth(month);
772
+ this._trigger('changeMonth', this.viewDate);
773
+ if (this.o.minViewMode === 1) {
774
+ this._setDate(UTCDate(year, month, day));
775
+ }
776
+ } else {
777
+ day = 1;
778
+ month = 0;
779
+ year = parseInt(target.text(), 10)||0;
780
+ this.viewDate.setUTCFullYear(year);
781
+ this._trigger('changeYear', this.viewDate);
782
+ if (this.o.minViewMode === 2) {
783
+ this._setDate(UTCDate(year, month, day));
784
+ }
785
+ }
786
+ this.showMode(-1);
787
+ this.fill();
788
+ }
789
+ break;
790
+ case 'td':
791
+ if (target.is('.day') && !target.is('.disabled')){
792
+ day = parseInt(target.text(), 10)||1;
793
+ year = this.viewDate.getUTCFullYear();
794
+ month = this.viewDate.getUTCMonth();
795
+ if (target.is('.old')) {
796
+ if (month === 0) {
797
+ month = 11;
798
+ year -= 1;
799
+ } else {
800
+ month -= 1;
801
+ }
802
+ } else if (target.is('.new')) {
803
+ if (month == 11) {
804
+ month = 0;
805
+ year += 1;
806
+ } else {
807
+ month += 1;
808
+ }
809
+ }
810
+ this._setDate(UTCDate(year, month, day));
811
+ }
812
+ break;
813
+ }
814
+ }
815
+ },
816
+
817
+ _setDate: function(date, which){
818
+ if (!which || which == 'date')
819
+ this.date = date && new Date(date);
820
+ if (!which || which == 'view')
821
+ this.viewDate = date && new Date(date);
822
+ this.fill();
823
+ this.setValue();
824
+ this._trigger('changeDate');
825
+ var element;
826
+ if (this.isInput) {
827
+ element = this.element;
828
+ } else if (this.component){
829
+ element = this.element.find('input');
830
+ }
831
+ if (element) {
832
+ element.change();
833
+ }
834
+ if (this.o.autoclose && (!which || which == 'date')) {
835
+ this.hide();
836
+ }
837
+ },
838
+
839
+ moveMonth: function(date, dir){
840
+ if (!date) return undefined;
841
+ if (!dir) return date;
842
+ var new_date = new Date(date.valueOf()),
843
+ day = new_date.getUTCDate(),
844
+ month = new_date.getUTCMonth(),
845
+ mag = Math.abs(dir),
846
+ new_month, test;
847
+ dir = dir > 0 ? 1 : -1;
848
+ if (mag == 1){
849
+ test = dir == -1
850
+ // If going back one month, make sure month is not current month
851
+ // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
852
+ ? function(){ return new_date.getUTCMonth() == month; }
853
+ // If going forward one month, make sure month is as expected
854
+ // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
855
+ : function(){ return new_date.getUTCMonth() != new_month; };
856
+ new_month = month + dir;
857
+ new_date.setUTCMonth(new_month);
858
+ // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
859
+ if (new_month < 0 || new_month > 11)
860
+ new_month = (new_month + 12) % 12;
861
+ } else {
862
+ // For magnitudes >1, move one month at a time...
863
+ for (var i=0; i<mag; i++)
864
+ // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
865
+ new_date = this.moveMonth(new_date, dir);
866
+ // ...then reset the day, keeping it in the new month
867
+ new_month = new_date.getUTCMonth();
868
+ new_date.setUTCDate(day);
869
+ test = function(){ return new_month != new_date.getUTCMonth(); };
870
+ }
871
+ // Common date-resetting loop -- if date is beyond end of month, make it
872
+ // end of month
873
+ while (test()){
874
+ new_date.setUTCDate(--day);
875
+ new_date.setUTCMonth(new_month);
876
+ }
877
+ return new_date;
878
+ },
879
+
880
+ moveYear: function(date, dir){
881
+ return this.moveMonth(date, dir*12);
882
+ },
883
+
884
+ dateWithinRange: function(date){
885
+ return date >= this.o.startDate && date <= this.o.endDate;
886
+ },
887
+
888
+ keydown: function(e){
889
+ if (this.picker.is(':not(:visible)')){
890
+ if (e.keyCode == 27) // allow escape to hide and re-show picker
891
+ this.show();
892
+ return;
893
+ }
894
+ var dateChanged = false,
895
+ dir, newDate, newViewDate;
896
+ switch(e.keyCode){
897
+ case 27: // escape
898
+ this.hide();
899
+ e.preventDefault();
900
+ break;
901
+ case 37: // left
902
+ case 39: // right
903
+ if (!this.o.keyboardNavigation) break;
904
+ dir = e.keyCode == 37 ? -1 : 1;
905
+ if (e.ctrlKey){
906
+ newDate = this.moveYear(this.date || UTCToday(), dir);
907
+ newViewDate = this.moveYear(this.viewDate, dir);
908
+ this._trigger('changeYear', this.viewDate);
909
+ } else if (e.shiftKey){
910
+ newDate = this.moveMonth(this.date || UTCToday(), dir);
911
+ newViewDate = this.moveMonth(this.viewDate, dir);
912
+ this._trigger('changeMonth', this.viewDate);
913
+ } else {
914
+ newDate = new Date(this.date || UTCToday());
915
+ newDate.setUTCDate(newDate.getUTCDate() + dir);
916
+ newViewDate = new Date(this.viewDate);
917
+ newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
918
+ }
919
+ if (this.dateWithinRange(newDate)){
920
+ this.date = newDate;
921
+ this.viewDate = newViewDate;
922
+ this.setValue();
923
+ this.update();
924
+ e.preventDefault();
925
+ dateChanged = true;
926
+ }
927
+ break;
928
+ case 38: // up
929
+ case 40: // down
930
+ if (!this.o.keyboardNavigation) break;
931
+ dir = e.keyCode == 38 ? -1 : 1;
932
+ if (e.ctrlKey){
933
+ newDate = this.moveYear(this.date || UTCToday(), dir);
934
+ newViewDate = this.moveYear(this.viewDate, dir);
935
+ this._trigger('changeYear', this.viewDate);
936
+ } else if (e.shiftKey){
937
+ newDate = this.moveMonth(this.date || UTCToday(), dir);
938
+ newViewDate = this.moveMonth(this.viewDate, dir);
939
+ this._trigger('changeMonth', this.viewDate);
940
+ } else {
941
+ newDate = new Date(this.date || UTCToday());
942
+ newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
943
+ newViewDate = new Date(this.viewDate);
944
+ newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
945
+ }
946
+ if (this.dateWithinRange(newDate)){
947
+ this.date = newDate;
948
+ this.viewDate = newViewDate;
949
+ this.setValue();
950
+ this.update();
951
+ e.preventDefault();
952
+ dateChanged = true;
953
+ }
954
+ break;
955
+ case 13: // enter
956
+ this.hide();
957
+ e.preventDefault();
958
+ break;
959
+ case 9: // tab
960
+ this.hide();
961
+ break;
962
+ }
963
+ if (dateChanged){
964
+ this._trigger('changeDate');
965
+ var element;
966
+ if (this.isInput) {
967
+ element = this.element;
968
+ } else if (this.component){
969
+ element = this.element.find('input');
970
+ }
971
+ if (element) {
972
+ element.change();
973
+ }
974
+ }
975
+ },
976
+
977
+ showMode: function(dir) {
978
+ if (dir) {
979
+ this.viewMode = Math.max(this.o.minViewMode, Math.min(2, this.viewMode + dir));
980
+ }
981
+ /*
982
+ vitalets: fixing bug of very special conditions:
983
+ jquery 1.7.1 + webkit + show inline datepicker in bootstrap popover.
984
+ Method show() does not set display css correctly and datepicker is not shown.
985
+ Changed to .css('display', 'block') solve the problem.
986
+ See https://github.com/vitalets/x-editable/issues/37
987
+
988
+ In jquery 1.7.2+ everything works fine.
989
+ */
990
+ //this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
991
+ this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).css('display', 'block');
992
+ this.updateNavArrows();
993
+ }
994
+ };
995
+
996
+ var DateRangePicker = function(element, options){
997
+ this.element = $(element);
998
+ this.inputs = $.map(options.inputs, function(i){ return i.jquery ? i[0] : i; });
999
+ delete options.inputs;
1000
+
1001
+ $(this.inputs)
1002
+ .datepicker(options)
1003
+ .bind('changeDate', $.proxy(this.dateUpdated, this));
1004
+
1005
+ this.pickers = $.map(this.inputs, function(i){ return $(i).data('datepicker'); });
1006
+ this.updateDates();
1007
+ };
1008
+ DateRangePicker.prototype = {
1009
+ updateDates: function(){
1010
+ this.dates = $.map(this.pickers, function(i){ return i.date; });
1011
+ this.updateRanges();
1012
+ },
1013
+ updateRanges: function(){
1014
+ var range = $.map(this.dates, function(d){ return d.valueOf(); });
1015
+ $.each(this.pickers, function(i, p){
1016
+ p.setRange(range);
1017
+ });
1018
+ },
1019
+ dateUpdated: function(e){
1020
+ var dp = $(e.target).data('datepicker'),
1021
+ new_date = dp.getUTCDate(),
1022
+ i = $.inArray(e.target, this.inputs),
1023
+ l = this.inputs.length;
1024
+ if (i == -1) return;
1025
+
1026
+ $.each(this.pickers, function(i, p){
1027
+ if (!p.getUTCDate())
1028
+ p.setUTCDate(new_date);
1029
+ });
1030
+
1031
+ if (new_date < this.dates[i]){
1032
+ // Date being moved earlier/left
1033
+ while (i>=0 && new_date < this.dates[i]){
1034
+ this.pickers[i--].setUTCDate(new_date);
1035
+ }
1036
+ }
1037
+ else if (new_date > this.dates[i]){
1038
+ // Date being moved later/right
1039
+ while (i<l && new_date > this.dates[i]){
1040
+ this.pickers[i++].setUTCDate(new_date);
1041
+ }
1042
+ }
1043
+ this.updateDates();
1044
+ },
1045
+ remove: function(){
1046
+ $.map(this.pickers, function(p){ p.remove(); });
1047
+ delete this.element.data().datepicker;
1048
+ }
1049
+ };
1050
+
1051
+ function opts_from_el(el, prefix){
1052
+ // Derive options from element data-attrs
1053
+ var data = $(el).data(),
1054
+ out = {}, inkey,
1055
+ replace = new RegExp('^' + prefix.toLowerCase() + '([A-Z])'),
1056
+ prefix = new RegExp('^' + prefix.toLowerCase());
1057
+ for (var key in data)
1058
+ if (prefix.test(key)){
1059
+ inkey = key.replace(replace, function(_,a){ return a.toLowerCase(); });
1060
+ out[inkey] = data[key];
1061
+ }
1062
+ return out;
1063
+ }
1064
+
1065
+ function opts_from_locale(lang){
1066
+ // Derive options from locale plugins
1067
+ var out = {};
1068
+ // Check if "de-DE" style date is available, if not language should
1069
+ // fallback to 2 letter code eg "de"
1070
+ if (!dates[lang]) {
1071
+ lang = lang.split('-')[0];
1072
+ if (!dates[lang])
1073
+ return;
1074
+ }
1075
+ var d = dates[lang];
1076
+ $.each(locale_opts, function(i,k){
1077
+ if (k in d)
1078
+ out[k] = d[k];
1079
+ });
1080
+ return out;
1081
+ }
1082
+
1083
+ var old = $.fn.datepicker;
1084
+ $.fn.datepicker = function ( option ) {
1085
+ var args = Array.apply(null, arguments);
1086
+ args.shift();
1087
+ var internal_return;
1088
+ this.each(function () {
1089
+ var $this = $(this),
1090
+ data = $this.data('datepicker'),
1091
+ options = typeof option == 'object' && option;
1092
+ if (!data) {
1093
+ var elopts = opts_from_el(this, 'date'),
1094
+ // Preliminary otions
1095
+ xopts = $.extend({}, defaults, elopts, options),
1096
+ locopts = opts_from_locale(xopts.language),
1097
+ // Options priority: js args, data-attrs, locales, defaults
1098
+ opts = $.extend({}, defaults, locopts, elopts, options);
1099
+ if ($this.is('.input-daterange') || opts.inputs){
1100
+ var ropts = {
1101
+ inputs: opts.inputs || $this.find('input').toArray()
1102
+ };
1103
+ $this.data('datepicker', (data = new DateRangePicker(this, $.extend(opts, ropts))));
1104
+ }
1105
+ else{
1106
+ $this.data('datepicker', (data = new Datepicker(this, opts)));
1107
+ }
1108
+ }
1109
+ if (typeof option == 'string' && typeof data[option] == 'function') {
1110
+ internal_return = data[option].apply(data, args);
1111
+ if (internal_return !== undefined)
1112
+ return false;
1113
+ }
1114
+ });
1115
+ if (internal_return !== undefined)
1116
+ return internal_return;
1117
+ else
1118
+ return this;
1119
+ };
1120
+
1121
+ var defaults = $.fn.datepicker.defaults = {
1122
+ autoclose: false,
1123
+ beforeShowDay: $.noop,
1124
+ calendarWeeks: false,
1125
+ clearBtn: false,
1126
+ daysOfWeekDisabled: [],
1127
+ endDate: Infinity,
1128
+ forceParse: true,
1129
+ format: 'mm/dd/yyyy',
1130
+ keyboardNavigation: true,
1131
+ language: 'en',
1132
+ minViewMode: 0,
1133
+ orientation: "auto",
1134
+ rtl: false,
1135
+ startDate: -Infinity,
1136
+ startView: 0,
1137
+ todayBtn: false,
1138
+ todayHighlight: false,
1139
+ weekStart: 0
1140
+ };
1141
+ var locale_opts = $.fn.datepicker.locale_opts = [
1142
+ 'format',
1143
+ 'rtl',
1144
+ 'weekStart'
1145
+ ];
1146
+ $.fn.datepicker.Constructor = Datepicker;
1147
+ var dates = $.fn.datepicker.dates = {
1148
+ en: {
1149
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
1150
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
1151
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
1152
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
1153
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
1154
+ today: "Today",
1155
+ clear: "Clear"
1156
+ }
1157
+ };
1158
+
1159
+ var DPGlobal = {
1160
+ modes: [
1161
+ {
1162
+ clsName: 'days',
1163
+ navFnc: 'Month',
1164
+ navStep: 1
1165
+ },
1166
+ {
1167
+ clsName: 'months',
1168
+ navFnc: 'FullYear',
1169
+ navStep: 1
1170
+ },
1171
+ {
1172
+ clsName: 'years',
1173
+ navFnc: 'FullYear',
1174
+ navStep: 10
1175
+ }],
1176
+ isLeapYear: function (year) {
1177
+ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
1178
+ },
1179
+ getDaysInMonth: function (year, month) {
1180
+ return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
1181
+ },
1182
+ validParts: /dd?|DD?|mm?|MM?|yy(?:yy)?/g,
1183
+ nonpunctuation: /[^ -\/:-@\[\u3400-\u9fff-`{-~\t\n\r]+/g,
1184
+ parseFormat: function(format){
1185
+ // IE treats \0 as a string end in inputs (truncating the value),
1186
+ // so it's a bad format delimiter, anyway
1187
+ var separators = format.replace(this.validParts, '\0').split('\0'),
1188
+ parts = format.match(this.validParts);
1189
+ if (!separators || !separators.length || !parts || parts.length === 0){
1190
+ throw new Error("Invalid date format.");
1191
+ }
1192
+ return {separators: separators, parts: parts};
1193
+ },
1194
+ parseDate: function(date, format, language) {
1195
+ if (!date)
1196
+ return undefined;
1197
+ if (date instanceof Date) return date;
1198
+ if (typeof format === 'string')
1199
+ format = DPGlobal.parseFormat(format);
1200
+ if (/^[\-+]\d+[dmwy]([\s,]+[\-+]\d+[dmwy])*$/.test(date)) {
1201
+ var part_re = /([\-+]\d+)([dmwy])/,
1202
+ parts = date.match(/([\-+]\d+)([dmwy])/g),
1203
+ part, dir;
1204
+ date = new Date();
1205
+ for (var i=0; i<parts.length; i++) {
1206
+ part = part_re.exec(parts[i]);
1207
+ dir = parseInt(part[1]);
1208
+ switch(part[2]){
1209
+ case 'd':
1210
+ date.setUTCDate(date.getUTCDate() + dir);
1211
+ break;
1212
+ case 'm':
1213
+ date = Datepicker.prototype.moveMonth.call(Datepicker.prototype, date, dir);
1214
+ break;
1215
+ case 'w':
1216
+ date.setUTCDate(date.getUTCDate() + dir * 7);
1217
+ break;
1218
+ case 'y':
1219
+ date = Datepicker.prototype.moveYear.call(Datepicker.prototype, date, dir);
1220
+ break;
1221
+ }
1222
+ }
1223
+ return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 0, 0, 0);
1224
+ }
1225
+ var parts = date && date.match(this.nonpunctuation) || [],
1226
+ date = new Date(),
1227
+ parsed = {},
1228
+ setters_order = ['yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'],
1229
+ setters_map = {
1230
+ yyyy: function(d,v){ return d.setUTCFullYear(v); },
1231
+ yy: function(d,v){ return d.setUTCFullYear(2000+v); },
1232
+ m: function(d,v){
1233
+ if (isNaN(d))
1234
+ return d;
1235
+ v -= 1;
1236
+ while (v<0) v += 12;
1237
+ v %= 12;
1238
+ d.setUTCMonth(v);
1239
+ while (d.getUTCMonth() != v)
1240
+ d.setUTCDate(d.getUTCDate()-1);
1241
+ return d;
1242
+ },
1243
+ d: function(d,v){ return d.setUTCDate(v); }
1244
+ },
1245
+ val, filtered, part;
1246
+ setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
1247
+ setters_map['dd'] = setters_map['d'];
1248
+ date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
1249
+ var fparts = format.parts.slice();
1250
+ // Remove noop parts
1251
+ if (parts.length != fparts.length) {
1252
+ fparts = $(fparts).filter(function(i,p){
1253
+ return $.inArray(p, setters_order) !== -1;
1254
+ }).toArray();
1255
+ }
1256
+ // Process remainder
1257
+ if (parts.length == fparts.length) {
1258
+ for (var i=0, cnt = fparts.length; i < cnt; i++) {
1259
+ val = parseInt(parts[i], 10);
1260
+ part = fparts[i];
1261
+ if (isNaN(val)) {
1262
+ switch(part) {
1263
+ case 'MM':
1264
+ filtered = $(dates[language].months).filter(function(){
1265
+ var m = this.slice(0, parts[i].length),
1266
+ p = parts[i].slice(0, m.length);
1267
+ return m == p;
1268
+ });
1269
+ val = $.inArray(filtered[0], dates[language].months) + 1;
1270
+ break;
1271
+ case 'M':
1272
+ filtered = $(dates[language].monthsShort).filter(function(){
1273
+ var m = this.slice(0, parts[i].length),
1274
+ p = parts[i].slice(0, m.length);
1275
+ return m == p;
1276
+ });
1277
+ val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
1278
+ break;
1279
+ }
1280
+ }
1281
+ parsed[part] = val;
1282
+ }
1283
+ for (var i=0, _date, s; i<setters_order.length; i++){
1284
+ s = setters_order[i];
1285
+ if (s in parsed && !isNaN(parsed[s])){
1286
+ _date = new Date(date);
1287
+ setters_map[s](_date, parsed[s]);
1288
+ if (!isNaN(_date))
1289
+ date = _date;
1290
+ }
1291
+ }
1292
+ }
1293
+ return date;
1294
+ },
1295
+ formatDate: function(date, format, language){
1296
+ if (!date)
1297
+ return '';
1298
+ if (typeof format === 'string')
1299
+ format = DPGlobal.parseFormat(format);
1300
+ var val = {
1301
+ d: date.getUTCDate(),
1302
+ D: dates[language].daysShort[date.getUTCDay()],
1303
+ DD: dates[language].days[date.getUTCDay()],
1304
+ m: date.getUTCMonth() + 1,
1305
+ M: dates[language].monthsShort[date.getUTCMonth()],
1306
+ MM: dates[language].months[date.getUTCMonth()],
1307
+ yy: date.getUTCFullYear().toString().substring(2),
1308
+ yyyy: date.getUTCFullYear()
1309
+ };
1310
+ val.dd = (val.d < 10 ? '0' : '') + val.d;
1311
+ val.mm = (val.m < 10 ? '0' : '') + val.m;
1312
+ var date = [],
1313
+ seps = $.extend([], format.separators);
1314
+ for (var i=0, cnt = format.parts.length; i <= cnt; i++) {
1315
+ if (seps.length)
1316
+ date.push(seps.shift());
1317
+ date.push(val[format.parts[i]]);
1318
+ }
1319
+ return date.join('');
1320
+ },
1321
+ headTemplate: '<thead>'+
1322
+ '<tr>'+
1323
+ '<th class="prev">&laquo;</th>'+
1324
+ '<th colspan="5" class="datepicker-switch"></th>'+
1325
+ '<th class="next">&raquo;</th>'+
1326
+ '</tr>'+
1327
+ '</thead>',
1328
+ contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
1329
+ footTemplate: '<tfoot><tr><th colspan="7" class="today"></th></tr><tr><th colspan="7" class="clear"></th></tr></tfoot>'
1330
+ };
1331
+ DPGlobal.template = '<div class="datepicker">'+
1332
+ '<div class="datepicker-days">'+
1333
+ '<table class=" table-condensed">'+
1334
+ DPGlobal.headTemplate+
1335
+ '<tbody></tbody>'+
1336
+ DPGlobal.footTemplate+
1337
+ '</table>'+
1338
+ '</div>'+
1339
+ '<div class="datepicker-months">'+
1340
+ '<table class="table-condensed">'+
1341
+ DPGlobal.headTemplate+
1342
+ DPGlobal.contTemplate+
1343
+ DPGlobal.footTemplate+
1344
+ '</table>'+
1345
+ '</div>'+
1346
+ '<div class="datepicker-years">'+
1347
+ '<table class="table-condensed">'+
1348
+ DPGlobal.headTemplate+
1349
+ DPGlobal.contTemplate+
1350
+ DPGlobal.footTemplate+
1351
+ '</table>'+
1352
+ '</div>'+
1353
+ '</div>';
1354
+
1355
+ $.fn.datepicker.DPGlobal = DPGlobal;
1356
+
1357
+
1358
+ /* DATEPICKER NO CONFLICT
1359
+ * =================== */
1360
+
1361
+ $.fn.datepicker.noConflict = function(){
1362
+ $.fn.datepicker = old;
1363
+ return this;
1364
+ };
1365
+
1366
+
1367
+ /* DATEPICKER DATA-API
1368
+ * ================== */
1369
+
1370
+ $(document).on(
1371
+ 'focus.datepicker.data-api click.datepicker.data-api',
1372
+ '[data-provide="datepicker"]',
1373
+ function(e){
1374
+ var $this = $(this);
1375
+ if ($this.data('datepicker')) return;
1376
+ e.preventDefault();
1377
+ // component click requires us to explicitly show it
1378
+ $this.datepicker('show');
1379
+ }
1380
+ );
1381
+ $(function(){
1382
+ $('[data-provide="datepicker-inline"]').datepicker();
1383
+ });
1384
+
1385
+ }( window.jQuery ));