ffoundation_datepicker_rails 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ffoundation_datepicker_rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/foundation-datepicker-rails.js +1320 -1197
  4. data/vendor/assets/javascripts/locales/foundation-datepicker.ar.js +15 -0
  5. data/vendor/assets/javascripts/locales/foundation-datepicker.az.js +12 -0
  6. data/vendor/assets/javascripts/locales/foundation-datepicker.bg.js +14 -0
  7. data/vendor/assets/javascripts/locales/foundation-datepicker.bs.js +15 -0
  8. data/vendor/assets/javascripts/locales/foundation-datepicker.ca.js +17 -0
  9. data/vendor/assets/javascripts/locales/foundation-datepicker.cs.js +14 -0
  10. data/vendor/assets/javascripts/locales/foundation-datepicker.cy.js +14 -0
  11. data/vendor/assets/javascripts/locales/foundation-datepicker.da.js +14 -0
  12. data/vendor/assets/javascripts/locales/foundation-datepicker.de.js +14 -0
  13. data/vendor/assets/javascripts/locales/foundation-datepicker.el.js +13 -0
  14. data/vendor/assets/javascripts/locales/foundation-datepicker.en-GB.js +17 -0
  15. data/vendor/assets/javascripts/locales/foundation-datepicker.eo.js +17 -0
  16. data/vendor/assets/javascripts/locales/foundation-datepicker.es.js +14 -0
  17. data/vendor/assets/javascripts/locales/foundation-datepicker.et.js +18 -0
  18. data/vendor/assets/javascripts/locales/foundation-datepicker.eu.js +15 -0
  19. data/vendor/assets/javascripts/locales/foundation-datepicker.fa.js +17 -0
  20. data/vendor/assets/javascripts/locales/foundation-datepicker.fi.js +14 -0
  21. data/vendor/assets/javascripts/locales/foundation-datepicker.fo.js +15 -0
  22. data/vendor/assets/javascripts/locales/foundation-datepicker.fr-CH.js +20 -0
  23. data/vendor/assets/javascripts/locales/foundation-datepicker.fr.js +14 -0
  24. data/vendor/assets/javascripts/locales/foundation-datepicker.gl.js +13 -0
  25. data/vendor/assets/javascripts/locales/foundation-datepicker.he.js +15 -0
  26. data/vendor/assets/javascripts/locales/foundation-datepicker.hr.js +13 -0
  27. data/vendor/assets/javascripts/locales/foundation-datepicker.hu.js +13 -0
  28. data/vendor/assets/javascripts/locales/foundation-datepicker.hy.js +17 -0
  29. data/vendor/assets/javascripts/locales/foundation-datepicker.id.js +13 -0
  30. data/vendor/assets/javascripts/locales/foundation-datepicker.is.js +14 -0
  31. data/vendor/assets/javascripts/locales/foundation-datepicker.it-CH.js +20 -0
  32. data/vendor/assets/javascripts/locales/foundation-datepicker.it.js +14 -0
  33. data/vendor/assets/javascripts/locales/foundation-datepicker.ja.js +16 -0
  34. data/vendor/assets/javascripts/locales/foundation-datepicker.ka.js +17 -0
  35. data/vendor/assets/javascripts/locales/foundation-datepicker.kh.js +15 -0
  36. data/vendor/assets/javascripts/locales/foundation-datepicker.kk.js +15 -0
  37. data/vendor/assets/javascripts/locales/foundation-datepicker.ko.js +18 -0
  38. data/vendor/assets/javascripts/locales/foundation-datepicker.kr.js +13 -0
  39. data/vendor/assets/javascripts/locales/foundation-datepicker.lt.js +16 -0
  40. data/vendor/assets/javascripts/locales/foundation-datepicker.lv.js +16 -0
  41. data/vendor/assets/javascripts/locales/foundation-datepicker.me.js +17 -0
  42. data/vendor/assets/javascripts/locales/foundation-datepicker.mk.js +15 -0
  43. data/vendor/assets/javascripts/locales/foundation-datepicker.mn.js +17 -0
  44. data/vendor/assets/javascripts/locales/foundation-datepicker.ms.js +14 -0
  45. data/vendor/assets/javascripts/locales/foundation-datepicker.nb.js +14 -0
  46. data/vendor/assets/javascripts/locales/foundation-datepicker.nl-BE.js +17 -0
  47. data/vendor/assets/javascripts/locales/foundation-datepicker.nl.js +14 -0
  48. data/vendor/assets/javascripts/locales/foundation-datepicker.no.js +13 -0
  49. data/vendor/assets/javascripts/locales/foundation-datepicker.pl.js +15 -0
  50. data/vendor/assets/javascripts/locales/foundation-datepicker.pt-br.js +14 -0
  51. data/vendor/assets/javascripts/locales/foundation-datepicker.pt.js +14 -0
  52. data/vendor/assets/javascripts/locales/foundation-datepicker.ro.js +15 -0
  53. data/vendor/assets/javascripts/locales/foundation-datepicker.rs-latin.js +14 -0
  54. data/vendor/assets/javascripts/locales/foundation-datepicker.rs.js +14 -0
  55. data/vendor/assets/javascripts/locales/foundation-datepicker.ru.js +14 -0
  56. data/vendor/assets/javascripts/locales/foundation-datepicker.sk.js +14 -0
  57. data/vendor/assets/javascripts/locales/foundation-datepicker.sl.js +14 -0
  58. data/vendor/assets/javascripts/locales/foundation-datepicker.sq.js +15 -0
  59. data/vendor/assets/javascripts/locales/foundation-datepicker.sr-latin.js +16 -0
  60. data/vendor/assets/javascripts/locales/foundation-datepicker.sr.js +16 -0
  61. data/vendor/assets/javascripts/locales/foundation-datepicker.sv.js +14 -0
  62. data/vendor/assets/javascripts/locales/foundation-datepicker.sw.js +15 -0
  63. data/vendor/assets/javascripts/locales/foundation-datepicker.th.js +14 -0
  64. data/vendor/assets/javascripts/locales/foundation-datepicker.tr.js +15 -0
  65. data/vendor/assets/javascripts/locales/foundation-datepicker.uk.js +14 -0
  66. data/vendor/assets/javascripts/locales/foundation-datepicker.vi.js +15 -0
  67. data/vendor/assets/javascripts/locales/foundation-datepicker.zh-CN.js +14 -0
  68. data/vendor/assets/javascripts/locales/foundation-datepicker.zh-TW.js +14 -0
  69. metadata +67 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 631a161f18778a0f97262be3bd24280776caec39
4
- data.tar.gz: 2ec38323dd58738a885385474b4b8973ce564eaf
3
+ metadata.gz: 2a033b984d015ad1e88f197630543397fdafa2e7
4
+ data.tar.gz: 9792037b4544b7c5649fbc97b9e879c5737a97b8
5
5
  SHA512:
6
- metadata.gz: ca2ed81ca621714cbcf08c1547c3e37572f2bf99002991ed75c10c10fe8a6b1decd0beefcf14c542d5f7c0677a9dd0926d009a5bf9f6f1995ed0fb385ef3cbaf
7
- data.tar.gz: 10b7ee75eb98382e50743a1ea6de4f5856ef6129d0b0ea7a872e0f5e0fe0a6d0b8b56b654c33bf56959838e6958d314465cd098af6d5e6cd1d66295ed687fe1c
6
+ metadata.gz: f97323b8fd813598cf3478dd852816515710cd603fe5ff1508fb3f60f193116ff435a7890a5f8e988b596f513e6d1d0a3bcb727d886c22c11820f65f345a4c6e
7
+ data.tar.gz: e3e6879ad6f4b5ccbe5ef3b3483fcbd5b4ee76255eeb4372efbfe673d46e774b60d570777c9c2b58f05ef39abca8b2113c33566db3e656be0b034a55149deafe
@@ -1,3 +1,3 @@
1
1
  module FfoundationDatepickerRails
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -3,1200 +3,1323 @@
3
3
  * Copyright 2015 Peter Beno, najlepsiwebdesigner@gmail.com, @benopeter
4
4
  * project website http://foundation-datepicker.peterbeno.com
5
5
  * ========================================================= */
6
-
7
- !function( $ ) {
8
-
9
- function UTCDate(){
10
- return new Date(Date.UTC.apply(Date, arguments));
11
- }
12
- function UTCToday(){
13
- var today = new Date();
14
- return UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
15
- }
16
-
17
- // Picker object
18
-
19
- var Datepicker = function(element, options) {
20
- var that = this;
21
-
22
- this.element = $(element);
23
- this.autoShow = options.autoShow || true;
24
- this.appendTo = options.appendTo || 'body';
25
- this.closeButton = options.closeButton;
26
- this.language = options.language||this.element.data('date-language')||"en";
27
- this.language = this.language in dates ? this.language : this.language.split('-')[0]; //Check if "de-DE" style date is available, if not language should fallback to 2 letter code eg "de"
28
- this.language = this.language in dates ? this.language : "en";
29
- this.isRTL = dates[this.language].rtl||false;
30
- this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||dates[this.language].format||'mm/dd/yyyy');
31
- this.isInline = false;
32
- this.isInput = this.element.is('input');
33
- this.component = this.element.is('.date') ? this.element.find('.prefix, .postfix') : false;
34
- this.hasInput = this.component && this.element.find('input').length;
35
- this.disableDblClickSelection = options.disableDblClickSelection;
36
-
37
-
38
- this.onRender = options.onRender || function () {};
39
- if(this.component && this.component.length === 0)
40
- this.component = false;
41
-
42
- this._attachEvents();
43
-
44
- this.forceParse = true;
45
- if ('forceParse' in options) {
46
- this.forceParse = options.forceParse;
47
- } else if ('dateForceParse' in this.element.data()) {
48
- this.forceParse = this.element.data('date-force-parse');
49
- }
50
-
51
-
52
- this.picker = $(DPGlobal.template)
53
- .appendTo(this.isInline ? this.element : this.appendTo)
54
- .on({
55
- click: $.proxy(this.click, this),
56
- mousedown: $.proxy(this.mousedown, this)
57
- });
58
- if (this.closeButton){
59
- this.picker.find('a.datepicker-close').show();
60
- } else {
61
- this.picker.find('a.datepicker-close').hide();
62
- }
63
-
64
- if(this.isInline) {
65
- this.picker.addClass('datepicker-inline');
66
- } else {
67
- this.picker.addClass('datepicker-dropdown dropdown-menu');
68
- }
69
- if (this.isRTL){
70
- this.picker.addClass('datepicker-rtl');
71
- this.picker.find('.prev i, .next i')
72
- .toggleClass('fa fa-chevron-left fa-chevron-right').toggleClass('fa-chevron-left fa-chevron-right');
73
- }
74
- $(document).on('mousedown', function (e) {
75
- // Clicked outside the datepicker, hide it
76
- if ($(e.target).closest('.datepicker.datepicker-inline, .datepicker.datepicker-dropdown').length === 0) {
77
- that.hide();
78
- }
79
- });
80
-
81
- this.autoclose = true;
82
- if ('autoclose' in options) {
83
- this.autoclose = options.autoclose;
84
- } else if ('dateAutoclose' in this.element.data()) {
85
- this.autoclose = this.element.data('date-autoclose');
86
- }
87
-
88
- this.keyboardNavigation = true;
89
- if ('keyboardNavigation' in options) {
90
- this.keyboardNavigation = options.keyboardNavigation;
91
- } else if ('dateKeyboardNavigation' in this.element.data()) {
92
- this.keyboardNavigation = this.element.data('date-keyboard-navigation');
93
- }
94
-
95
- this.viewMode = this.startViewMode = 0;
96
- switch(options.startView || this.element.data('date-start-view')){
97
- case 2:
98
- case 'decade':
99
- this.viewMode = this.startViewMode = 2;
100
- break;
101
- case 1:
102
- case 'year':
103
- this.viewMode = this.startViewMode = 1;
104
- break;
105
- }
106
-
107
- this.todayBtn = (options.todayBtn||this.element.data('date-today-btn')||false);
108
- this.todayHighlight = (options.todayHighlight||this.element.data('date-today-highlight')||false);
109
-
110
- this.calendarWeeks = false;
111
- if ('calendarWeeks' in options) {
112
- this.calendarWeeks = options.calendarWeeks;
113
- } else if ('dateCalendarWeeks' in this.element.data()) {
114
- this.calendarWeeks = this.element.data('date-calendar-weeks');
115
- }
116
- if (this.calendarWeeks)
117
- this.picker.find('tfoot th.today')
118
- .attr('colspan', function(i, val){
119
- return parseInt(val) + 1;
120
- });
121
-
122
- this.weekStart = ((options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0) % 7);
123
- this.weekEnd = ((this.weekStart + 6) % 7);
124
- this.startDate = -Infinity;
125
- this.endDate = Infinity;
126
- this.daysOfWeekDisabled = [];
127
- this.setStartDate(options.startDate||this.element.data('date-startdate'));
128
- this.setEndDate(options.endDate||this.element.data('date-enddate'));
129
- this.setDaysOfWeekDisabled(options.daysOfWeekDisabled||this.element.data('date-days-of-week-disabled'));
130
-
131
- this.fillDow();
132
- this.fillMonths();
133
- this.update();
134
- this.showMode();
135
-
136
- if(this.isInline) {
137
- this.show();
138
- }
139
- };
140
-
141
- Datepicker.prototype = {
142
- constructor: Datepicker,
143
-
144
- _events: [],
145
- _attachEvents: function(){
146
- this._detachEvents();
147
- if (this.isInput) { // single input
148
- this._events = [
149
- [this.element, {
150
- focus: (this.autoShow)? $.proxy(this.show, this):function(){},
151
- keyup: $.proxy(this.update, this),
152
- keydown: $.proxy(this.keydown, this)
153
- }]
154
- ];
155
- }
156
- else if (this.component && this.hasInput){ // component: input + button
157
- this._events = [
158
- // For components that are not readonly, allow keyboard nav
159
- [this.element.find('input'), {
160
- focus: (this.autoShow)? $.proxy(this.show, this):function(){},
161
- keyup: $.proxy(this.update, this),
162
- keydown: $.proxy(this.keydown, this)
163
- }],
164
- [this.component, {
165
- click: $.proxy(this.show, this)
166
- }]
167
- ];
168
- }
169
- else if (this.element.is('div')) { // inline datepicker
170
- this.isInline = true;
171
- }
172
- else {
173
- this._events = [
174
- [this.element, {
175
- click: $.proxy(this.show, this)
176
- }]
177
- ];
178
- }
179
-
180
- if (this.disableDblClickSelection) {
181
- this._events[this._events.length] = [
182
- this.element, {
183
- dblclick: function (e) {
184
- e.preventDefault();
185
- e.stopPropagation();
186
- $(this).blur()
187
- }
188
- }
189
- ];
190
- }
191
-
192
- for (var i=0, el, ev; i<this._events.length; i++){
193
- el = this._events[i][0];
194
- ev = this._events[i][1];
195
- el.on(ev);
196
- }
197
- },
198
- _detachEvents: function(){
199
- for (var i=0, el, ev; i<this._events.length; i++){
200
- el = this._events[i][0];
201
- ev = this._events[i][1];
202
- el.off(ev);
203
- }
204
- this._events = [];
205
- },
206
-
207
- show: function(e) {
208
- this.picker.show();
209
- this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
210
- this.update();
211
- this.place();
212
- $(window).on('resize', $.proxy(this.place, this));
213
- if (e ) {
214
- e.stopPropagation();
215
- e.preventDefault();
216
- }
217
- this.element.trigger({
218
- type: 'show',
219
- date: this.date
220
- });
221
- },
222
-
223
- hide: function(e){
224
- if(this.isInline) return;
225
- if (!this.picker.is(':visible')) return;
226
- this.picker.hide();
227
- $(window).off('resize', this.place);
228
- this.viewMode = this.startViewMode;
229
- this.showMode();
230
- if (!this.isInput) {
231
- $(document).off('mousedown', this.hide);
232
- }
233
-
234
- if (
235
- this.forceParse &&
236
- (
237
- this.isInput && this.element.val() ||
238
- this.hasInput && this.element.find('input').val()
239
- )
240
- )
241
- this.setValue();
242
- this.element.trigger({
243
- type: 'hide',
244
- date: this.date
245
- });
246
- },
247
-
248
- remove: function() {
249
- this._detachEvents();
250
- this.picker.remove();
251
- delete this.element.data().datepicker;
252
- },
253
-
254
- getDate: function() {
255
- var d = this.getUTCDate();
256
- return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
257
- },
258
-
259
- getUTCDate: function() {
260
- return this.date;
261
- },
262
-
263
- setDate: function(d) {
264
- this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
265
- },
266
-
267
- setUTCDate: function(d) {
268
- this.date = d;
269
- this.setValue();
270
- },
271
-
272
- setValue: function() {
273
- var formatted = this.getFormattedDate();
274
- if (!this.isInput) {
275
- if (this.component){
276
- this.element.find('input').val(formatted);
277
- }
278
- this.element.data('date', formatted);
279
- } else {
280
- this.element.val(formatted);
281
- }
282
- },
283
-
284
- getFormattedDate: function(format) {
285
- if (format === undefined)
286
- format = this.format;
287
- return DPGlobal.formatDate(this.date, format, this.language);
288
- },
289
-
290
- setStartDate: function(startDate){
291
- this.startDate = startDate||-Infinity;
292
- if (this.startDate !== -Infinity) {
293
- this.startDate = DPGlobal.parseDate(this.startDate, this.format, this.language);
294
- }
295
- this.update();
296
- this.updateNavArrows();
297
- },
298
-
299
- setEndDate: function(endDate){
300
- this.endDate = endDate||Infinity;
301
- if (this.endDate !== Infinity) {
302
- this.endDate = DPGlobal.parseDate(this.endDate, this.format, this.language);
303
- }
304
- this.update();
305
- this.updateNavArrows();
306
- },
307
-
308
- setDaysOfWeekDisabled: function(daysOfWeekDisabled){
309
- this.daysOfWeekDisabled = daysOfWeekDisabled||[];
310
- if (!$.isArray(this.daysOfWeekDisabled)) {
311
- this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
312
- }
313
- this.daysOfWeekDisabled = $.map(this.daysOfWeekDisabled, function (d) {
314
- return parseInt(d, 10);
315
- });
316
- this.update();
317
- this.updateNavArrows();
318
- },
319
-
320
- place: function(){
321
- if(this.isInline) return;
322
- var zIndex = parseInt(this.element.parents().filter(function() {
323
- return $(this).css('z-index') != 'auto';
324
- }).first().css('z-index'))+10;
325
- var textbox = this.component ? this.component : this.element;
326
- var offset = textbox.offset();
327
- var height = textbox.outerHeight() + parseInt(textbox.css('margin-top'));
328
- var width = textbox.outerWidth() + parseInt(textbox.css('margin-left'));
329
- var fullOffsetTop = offset.top + height;
330
- var offsetLeft = offset.left;
331
- // if the datepicker is going to be below the window, show it on top of the input
332
- if((fullOffsetTop + this.picker.outerHeight()) >= $(window).scrollTop() + $(window).height()){
333
- fullOffsetTop = offset.top - this.picker.outerHeight();
334
- }
335
-
336
- // if the datepicker is going to go past the right side of the window, we want
337
- // to set the right position so the datepicker lines up with the textbox
338
- if(offset.left + this.picker.width() >= $(window).width()){
339
- offsetLeft = (offset.left + width) - this.picker.width();
340
- }
341
- this.picker.css({
342
- top: fullOffsetTop,
343
- left: offsetLeft,
344
- zIndex: zIndex
345
- });
346
- },
347
-
348
- update: function(){
349
- var date, fromArgs = false;
350
- if(arguments && arguments.length && (typeof arguments[0] === 'string' || arguments[0] instanceof Date)) {
351
- date = arguments[0];
352
- fromArgs = true;
353
- } else {
354
- date = this.isInput ? this.element.val() : this.element.data('date') || this.element.find('input').val();
355
- }
356
-
357
- this.date = DPGlobal.parseDate(date, this.format, this.language);
358
-
359
- if(fromArgs) this.setValue();
360
-
361
- if (this.date < this.startDate) {
362
- this.viewDate = new Date(this.startDate.valueOf());
363
- } else if (this.date > this.endDate) {
364
- this.viewDate = new Date(this.endDate.valueOf());
365
- } else {
366
- this.viewDate = new Date(this.date.valueOf());
367
- }
368
- this.fill();
369
- },
370
-
371
- fillDow: function(){
372
- var dowCnt = this.weekStart,
373
- html = '<tr>';
374
- if(this.calendarWeeks){
375
- var cell = '<th class="cw">&nbsp;</th>';
376
- html += cell;
377
- this.picker.find('.datepicker-days thead tr:first-child').prepend(cell);
378
- }
379
- while (dowCnt < this.weekStart + 7) {
380
- html += '<th class="dow">'+dates[this.language].daysMin[(dowCnt++)%7]+'</th>';
381
- }
382
- html += '</tr>';
383
- this.picker.find('.datepicker-days thead').append(html);
384
- },
385
-
386
- fillMonths: function(){
387
- var html = '',
388
- i = 0;
389
- while (i < 12) {
390
- html += '<span class="month">'+dates[this.language].monthsShort[i++]+'</span>';
391
- }
392
- this.picker.find('.datepicker-months td').html(html);
393
- },
394
-
395
- fill: function() {
396
- var d = new Date(this.viewDate.valueOf()),
397
- year = d.getUTCFullYear(),
398
- month = d.getUTCMonth(),
399
- startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
400
- startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
401
- endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
402
- endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
403
- currentDate = this.date && this.date.valueOf(),
404
- today = new Date(),
405
- titleFormat = dates[this.language].titleFormat || dates['en'].titleFormat;
406
- this.picker.find('.datepicker-days thead th.date-switch')
407
- .text(DPGlobal.formatDate(new UTCDate(year, month), titleFormat, this.language));
408
- this.picker.find('tfoot th.today')
409
- .text(dates[this.language].today)
410
- .toggle(this.todayBtn !== false);
411
- this.updateNavArrows();
412
- this.fillMonths();
413
- var prevMonth = UTCDate(year, month-1, 28,0,0,0,0),
414
- day = DPGlobal.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
415
- prevMonth.setUTCDate(day);
416
- prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
417
- var nextMonth = new Date(prevMonth.valueOf());
418
- nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
419
- nextMonth = nextMonth.valueOf();
420
- var html = [];
421
- var clsName;
422
- while(prevMonth.valueOf() < nextMonth) {
423
- if (prevMonth.getUTCDay() == this.weekStart) {
424
- html.push('<tr>');
425
- if(this.calendarWeeks){
426
- // adapted from https://github.com/timrwood/moment/blob/master/moment.js#L128
427
- var a = new Date(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth(), prevMonth.getUTCDate() - prevMonth.getDay() + 10 - (this.weekStart && this.weekStart%7 < 5 && 7)),
428
- b = new Date(a.getFullYear(), 0, 4),
429
- calWeek = ~~((a - b) / 864e5 / 7 + 1.5);
430
- html.push('<td class="cw">'+ calWeek +'</td>');
431
- }
432
- }
433
- clsName = ' '+this.onRender(prevMonth)+' ';
434
- if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
435
- clsName += ' old';
436
- } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
437
- clsName += ' new';
438
- }
439
- // Compare internal UTC date with local today, not UTC today
440
- if (this.todayHighlight &&
441
- prevMonth.getUTCFullYear() == today.getFullYear() &&
442
- prevMonth.getUTCMonth() == today.getMonth() &&
443
- prevMonth.getUTCDate() == today.getDate()) {
444
- clsName += ' today';
445
- }
446
- if (currentDate && prevMonth.valueOf() == currentDate) {
447
- clsName += ' active';
448
- }
449
- if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
450
- $.inArray(prevMonth.getUTCDay(), this.daysOfWeekDisabled) !== -1) {
451
- clsName += ' disabled';
452
- }
453
- html.push('<td class="day'+clsName+'">'+prevMonth.getUTCDate() + '</td>');
454
- if (prevMonth.getUTCDay() == this.weekEnd) {
455
- html.push('</tr>');
456
- }
457
- prevMonth.setUTCDate(prevMonth.getUTCDate()+1);
458
- }
459
- this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
460
- var currentYear = this.date && this.date.getUTCFullYear();
461
-
462
- var months = this.picker.find('.datepicker-months')
463
- .find('th:eq(1)')
464
- .text(year)
465
- .end()
466
- .find('span').removeClass('active');
467
- if (currentYear && currentYear == year) {
468
- months.eq(this.date.getUTCMonth()).addClass('active');
469
- }
470
- if (year < startYear || year > endYear) {
471
- months.addClass('disabled');
472
- }
473
- if (year == startYear) {
474
- months.slice(0, startMonth).addClass('disabled');
475
- }
476
- if (year == endYear) {
477
- months.slice(endMonth+1).addClass('disabled');
478
- }
479
-
480
- html = '';
481
- year = parseInt(year/10, 10) * 10;
482
- var yearCont = this.picker.find('.datepicker-years')
483
- .find('th:eq(1)')
484
- .text(year + '-' + (year + 9))
485
- .end()
486
- .find('td');
487
- year -= 1;
488
- for (var i = -1; i < 11; i++) {
489
- html += '<span class="year'+(i == -1 || i == 10 ? ' old' : '')+(currentYear == year ? ' active' : '')+(year < startYear || year > endYear ? ' disabled' : '')+'">'+year+'</span>';
490
- year += 1;
491
- }
492
- yearCont.html(html);
493
- },
494
-
495
- updateNavArrows: function() {
496
- var d = new Date(this.viewDate.valueOf()),
497
- year = d.getUTCFullYear(),
498
- month = d.getUTCMonth();
499
- switch (this.viewMode) {
500
- case 0:
501
- if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
502
- this.picker.find('.prev').css({visibility: 'hidden'});
503
- } else {
504
- this.picker.find('.prev').css({visibility: 'visible'});
505
- }
506
- if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
507
- this.picker.find('.next').css({visibility: 'hidden'});
508
- } else {
509
- this.picker.find('.next').css({visibility: 'visible'});
510
- }
511
- break;
512
- case 1:
513
- case 2:
514
- if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
515
- this.picker.find('.prev').css({visibility: 'hidden'});
516
- } else {
517
- this.picker.find('.prev').css({visibility: 'visible'});
518
- }
519
- if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
520
- this.picker.find('.next').css({visibility: 'hidden'});
521
- } else {
522
- this.picker.find('.next').css({visibility: 'visible'});
523
- }
524
- break;
525
- }
526
- },
527
-
528
- click: function(e) {
529
- e.stopPropagation();
530
- e.preventDefault();
531
-
532
- if ($(e.target).hasClass('datepicker-close') || $(e.target).parent().hasClass('datepicker-close')){
533
- this.hide();
534
- }
535
-
536
- var target = $(e.target).closest('span, td, th');
537
- if (target.length == 1) {
538
- switch(target[0].nodeName.toLowerCase()) {
539
- case 'th':
540
- switch(target[0].className) {
541
- case 'date-switch':
542
- this.showMode(1);
543
- break;
544
- case 'prev':
545
- case 'next':
546
- var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1);
547
- switch(this.viewMode){
548
- case 0:
549
- this.viewDate = this.moveMonth(this.viewDate, dir);
550
- break;
551
- case 1:
552
- case 2:
553
- this.viewDate = this.moveYear(this.viewDate, dir);
554
- break;
555
- }
556
- this.fill();
557
- break;
558
- case 'today':
559
- var date = new Date();
560
- date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
561
-
562
- this.showMode(-2);
563
- var which = this.todayBtn == 'linked' ? null : 'view';
564
- this._setDate(date, which);
565
- break;
566
- }
567
- break;
568
- case 'span':
569
- if (!target.is('.disabled')) {
570
- this.viewDate.setUTCDate(1);
571
- if (target.is('.month')) {
572
- var month = target.parent().find('span').index(target);
573
- this.viewDate.setUTCMonth(month);
574
- this.element.trigger({
575
- type: 'changeMonth',
576
- date: this.viewDate
577
- });
578
- } else {
579
- var year = parseInt(target.text(), 10)||0;
580
- this.viewDate.setUTCFullYear(year);
581
- this.element.trigger({
582
- type: 'changeYear',
583
- date: this.viewDate
584
- });
585
- }
586
- this.showMode(-1);
587
- this.fill();
588
- }
589
- break;
590
- case 'td':
591
- if (target.is('.day') && !target.is('.disabled')){
592
- var day = parseInt(target.text(), 10)||1;
593
- var year = this.viewDate.getUTCFullYear(),
594
- month = this.viewDate.getUTCMonth();
595
- if (target.is('.old')) {
596
- if (month === 0) {
597
- month = 11;
598
- year -= 1;
599
- } else {
600
- month -= 1;
601
- }
602
- } else if (target.is('.new')) {
603
- if (month == 11) {
604
- month = 0;
605
- year += 1;
606
- } else {
607
- month += 1;
608
- }
609
- }
610
- this._setDate(UTCDate(year, month, day,0,0,0,0));
611
- }
612
- break;
613
- }
614
- }
615
- },
616
-
617
- _setDate: function(date, which){
618
- if (!which || which == 'date')
619
- this.date = date;
620
- if (!which || which == 'view')
621
- this.viewDate = date;
622
- this.fill();
623
- this.setValue();
624
- this.element.trigger({
625
- type: 'changeDate',
626
- date: this.date
627
- });
628
- var element;
629
- if (this.isInput) {
630
- element = this.element;
631
- } else if (this.component){
632
- element = this.element.find('input');
633
- }
634
- if (element) {
635
- element.change();
636
- if (this.autoclose && (!which || which == 'date')) {
637
- this.hide();
638
- }
639
- }
640
- },
641
-
642
- moveMonth: function(date, dir){
643
- if (!dir) return date;
644
- var new_date = new Date(date.valueOf()),
645
- day = new_date.getUTCDate(),
646
- month = new_date.getUTCMonth(),
647
- mag = Math.abs(dir),
648
- new_month, test;
649
- dir = dir > 0 ? 1 : -1;
650
- if (mag == 1){
651
- test = dir == -1
652
- // If going back one month, make sure month is not current month
653
- // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
654
- ? function(){ return new_date.getUTCMonth() == month; }
655
- // If going forward one month, make sure month is as expected
656
- // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
657
- : function(){ return new_date.getUTCMonth() != new_month; };
658
- new_month = month + dir;
659
- new_date.setUTCMonth(new_month);
660
- // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
661
- if (new_month < 0 || new_month > 11)
662
- new_month = (new_month + 12) % 12;
663
- } else {
664
- // For magnitudes >1, move one month at a time...
665
- for (var i=0; i<mag; i++)
666
- // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
667
- new_date = this.moveMonth(new_date, dir);
668
- // ...then reset the day, keeping it in the new month
669
- new_month = new_date.getUTCMonth();
670
- new_date.setUTCDate(day);
671
- test = function(){ return new_month != new_date.getUTCMonth(); };
672
- }
673
- // Common date-resetting loop -- if date is beyond end of month, make it
674
- // end of month
675
- while (test()){
676
- new_date.setUTCDate(--day);
677
- new_date.setUTCMonth(new_month);
678
- }
679
- return new_date;
680
- },
681
-
682
- moveYear: function(date, dir){
683
- return this.moveMonth(date, dir*12);
684
- },
685
-
686
- dateWithinRange: function(date){
687
- return date >= this.startDate && date <= this.endDate;
688
- },
689
-
690
- keydown: function(e){
691
- if (this.picker.is(':not(:visible)')){
692
- if (e.keyCode == 27) // allow escape to hide and re-show picker
693
- this.show();
694
- return;
695
- }
696
- var dateChanged = false,
697
- dir, day, month,
698
- newDate, newViewDate;
699
- switch(e.keyCode){
700
- case 27: // escape
701
- this.hide();
702
- e.preventDefault();
703
- break;
704
- case 37: // left
705
- case 39: // right
706
- if (!this.keyboardNavigation) break;
707
- dir = e.keyCode == 37 ? -1 : 1;
708
- if (e.ctrlKey){
709
- newDate = this.moveYear(this.date, dir);
710
- newViewDate = this.moveYear(this.viewDate, dir);
711
- } else if (e.shiftKey){
712
- newDate = this.moveMonth(this.date, dir);
713
- newViewDate = this.moveMonth(this.viewDate, dir);
714
- } else {
715
- newDate = new Date(this.date.valueOf());
716
- newDate.setUTCDate(this.date.getUTCDate() + dir);
717
- newViewDate = new Date(this.viewDate.valueOf());
718
- newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
719
- }
720
- if (this.dateWithinRange(newDate)){
721
- this.date = newDate;
722
- this.viewDate = newViewDate;
723
- this.setValue();
724
- this.update();
725
- e.preventDefault();
726
- dateChanged = true;
727
- }
728
- break;
729
- case 38: // up
730
- case 40: // down
731
- if (!this.keyboardNavigation) break;
732
- dir = e.keyCode == 38 ? -1 : 1;
733
- if (e.ctrlKey){
734
- newDate = this.moveYear(this.date, dir);
735
- newViewDate = this.moveYear(this.viewDate, dir);
736
- } else if (e.shiftKey){
737
- newDate = this.moveMonth(this.date, dir);
738
- newViewDate = this.moveMonth(this.viewDate, dir);
739
- } else {
740
- newDate = new Date(this.date.valueOf());
741
- newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
742
- newViewDate = new Date(this.viewDate.valueOf());
743
- newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
744
- }
745
- if (this.dateWithinRange(newDate)){
746
- this.date = newDate;
747
- this.viewDate = newViewDate;
748
- this.setValue();
749
- this.update();
750
- e.preventDefault();
751
- dateChanged = true;
752
- }
753
- break;
754
- case 13: // enter
755
- this.hide();
756
- e.preventDefault();
757
- break;
758
- case 9: // tab
759
- this.hide();
760
- break;
761
- }
762
- if (dateChanged){
763
- this.element.trigger({
764
- type: 'changeDate',
765
- date: this.date
766
- });
767
- var element;
768
- if (this.isInput) {
769
- element = this.element;
770
- } else if (this.component){
771
- element = this.element.find('input');
772
- }
773
- if (element) {
774
- element.change();
775
- }
776
- }
777
- },
778
-
779
- showMode: function(dir) {
780
- if (dir) {
781
- this.viewMode = Math.max(0, Math.min(2, this.viewMode + dir));
782
- }
783
- /*
784
- vitalets: fixing bug of very special conditions:
785
- jquery 1.7.1 + webkit + show inline datepicker in bootstrap popover.
786
- Method show() does not set display css correctly and datepicker is not shown.
787
- Changed to .css('display', 'block') solve the problem.
788
- See https://github.com/vitalets/x-editable/issues/37
789
-
790
- In jquery 1.7.2+ everything works fine.
791
- */
792
- //this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
793
- this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).css('display', 'block');
794
- this.updateNavArrows();
795
- }
796
- };
797
-
798
- $.fn.fdatepicker = function ( option ) {
799
- var args = Array.apply(null, arguments);
800
- args.shift();
801
- return this.each(function () {
802
- var $this = $(this),
803
- data = $this.data('datepicker'),
804
- options = typeof option == 'object' && option;
805
- if (!data) {
806
- $this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.fdatepicker.defaults,options))));
807
- }
808
- if (typeof option == 'string' && typeof data[option] == 'function') {
809
- data[option].apply(data, args);
810
- }
811
- });
812
- };
813
-
814
- $.fn.fdatepicker.defaults = {
815
- onRender: function(date) {
816
- return '';
817
- }
818
- };
819
- $.fn.fdatepicker.Constructor = Datepicker;
820
- var dates = $.fn.fdatepicker.dates = {
821
- 'en': {
822
- days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
823
- daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
824
- daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
825
- months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
826
- monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
827
- today: "Today",
828
- titleFormat: "MM yyyy"
829
- },
830
- 'sk': {
831
- days: ["Nedeľa", "Pondelok", "Utorok", "Streda", "Štvrtok", "Piatok", "Sobota", "Nedeľa"],
832
- daysShort: ["Neď", "Pon", "Utr", "Str", "Štv", "Pia", "Sob", "Ned"],
833
- daysMin: ["Ne", "Po", "Ut", "St", "Št", "Pi", "So", "Ne"],
834
- months: ["Január", "Február", "Marec", "Apríl", "Máj", "Jún", "Júl", "August", "September", "Október", "November", "December"],
835
- monthsShort: ["Jan", "Feb", "Mar", "Apr", "Máj", "Jún", "Júl", "Aug", "Sep", "Oct", "Nov", "Dec"],
836
- today: "Dnes"
837
- },
838
- 'tr': {
839
- days: ["Pazar", "Pazartesi", "Salı", "Çarşamba", "Perşembe", "Cuma", "Cumartesi", "Pazar"],
840
- daysShort: ["Pzr", "Pzt", "Sal", "Çarş", "Perş", "Cum", "Cmt", "Pzr"],
841
- daysMin: ["Pz", "Pt", "Sa", "Ça", "Pe", "Cu", "Ct", "Pz"],
842
- months: ["Ocak", "Şubat", "Mart", "Nisan", "Mayıs", "Haziran", "Temmuz", "Ağustos", "Eylül", "Ekim", "Kasım", "Aralık"],
843
- monthsShort: ["Oca", "Şub", "Mar", "Nis", "May", "Haz", "Tem", "Ağu", "Eyl", "Eki", "Kas", "Ara"],
844
- today: "Bugün"
845
- },
846
- 'fr': {
847
- days: ["Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"],
848
- daysShort: ["Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam", "Dim"],
849
- daysMin: ["Di", "Lu", "Ma", "Me", "Je", "Ve", "Sa", "Di"],
850
- months: ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"],
851
- monthsShort: ["Jan", "Fev", "Mar", "Avr", "Mai", "Jun", "Jul", "Aoû", "Sep", "Oct", "Nov", "Dec"],
852
- today: "Aujourd'hui"
853
- },
854
- 'pl': {
855
- days: ["Niedziela", "Poniedziałek", "Wtorek", "Środa", "Czwartek", "Piątek", "Sobota", "Niedziela"],
856
- daysShort: ["Nie", "Pon", "Wt", "Śr", "Czw", "Pt", "Sob", "Nie"],
857
- daysMin: ["Nd", "Po", "Wt", "Śr", "Czw", "Pt", "So", "Nd"],
858
- months: ["Styczeń", "Luty", "Marzec", "Kwiecień", "Maj", "Czerwiec", "Lipiec", "Sierpień", "Wrzesień", "Październik", "Listopad", "Grudzień"],
859
- monthsShort: ["Sty", "Lut", "Mar", "Kwi", "Maj", "Cze", "Lip", "Sie", "Wrz", "Paź", "Lit", "Gru"],
860
- today: "Dzisiaj"
861
- },
862
- 'es': {
863
- days: ["Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado", "Domingo"],
864
- daysShort: ["Dom", "Lun", "Mar", "Mie", "Jue", "Vie", "Sab", "Dom"],
865
- daysMin: ["Do", "Lu", "Ma", "Mi", "Ju", "Vi", "Sa", "Do"],
866
- months: ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Deciembre"],
867
- monthsShort: ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"],
868
- today: "Hoy"
869
- },
870
- 'pt': {
871
- days: ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado", "Domingo"],
872
- daysShort: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb", "Dom"],
873
- daysMin: ["Do", "Se", "Te", "Qu", "Qu", "Se", "Sá", "Do"],
874
- months: ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
875
- monthsShort: ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"],
876
- today: "Hoje"
877
- },
878
- 'pt_br': {
879
- days: ["Domingo", "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sábado", "Domingo"],
880
- daysShort: ["Dom", "Seg", "Ter", "Qua", "Qui", "Sex", "Sáb", "Dom"],
881
- daysMin: ["D", "S", "T", "Q", "Q", "S", "S", "D"],
882
- months: ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"],
883
- monthsShort: ["Jan", "Fev", "Mar", "Abr", "Mai", "Jun", "Jul", "Ago", "Set", "Out", "Nov", "Dez"],
884
- today: "Hoje"
885
- },
886
- 'it': {
887
- days: ["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato", "Domenica"],
888
- daysShort: ["Dom", "Lun", "Mar", "Mer", "Gio", "Veb", "Sab", "Dom"],
889
- daysMin: ["Do", "Lu", "Ma", "Me", "Gi", "Ve", "Sa", "Do"],
890
- months: ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"],
891
- monthsShort: ["Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic"],
892
- today: "Oggi"
893
- },
894
- 'de': {
895
- days: ["Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"],
896
- daysShort: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"],
897
- daysMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"],
898
- months: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
899
- monthsShort: ["Jan", "Feb", "Mär", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dez"],
900
- today: "Heute"
901
- },
902
- 'ro': {
903
- days: ["Duminica", "Luni", "Marti", "Miercuri", "Joi", "Vineri", "Sambata", "Duminica"],
904
- daysShort: ["Dum", "Lun", "Mar", "Mie", "Joi", "Vin", "Sam", "Dum"],
905
- daysMin: ["Du", "Lu", "Ma", "Mi", "Jo", "Vi", "Sa", "Du"],
906
- months: ["Ianuarie", "Februarie", "Martie", "Aprilie", "Mai", "Iunie", "Iulie", "August", "Septembrie", "Octombrie", "Noiembrie", "Decembrie"],
907
- monthsShort: ["Ian", "Feb", "Mar", "Apr", "Mai", "Iun", "Iul", "Aug", "Sep", "Oct", "Noi", "Dec"],
908
- today: "Astazi"
909
- },
910
- 'hu': {
911
- days: ["Vasárnap", "Hétfő", "Kedd", "Szerda", "Csütörtök", "Péntek", "Szombat", "Vasárnap"],
912
- daysShort: ["Vas", "Hét", "Kedd", "Sze", "Csü", "Pén", "Szo", "Vas"],
913
- daysMin: ["Va", "Hé", "Ke", "Sz", "Cs", "Pé", "Sz", "Va"],
914
- months: ["Január", "Február", "Március", "Április", "Május", "Június", "Július", "Augusztus", "Szeptember", "Október", "November", "December"],
915
- monthsShort: ["Jan", "Feb", "Már", "Ápr", "Máj", "Jún", "Júl", "Aug", "Szep", "Okt", "Nov", "Dec"],
916
- today: "Ma"
917
- },
918
- 'ru': {
919
- days: ["Воскресенье", "Понедельник", "Вторник", "Среда", "Четверг", "Пятница", "Суббота", "Воскресенье"],
920
- daysShort: ["Вск", "Пнд", "Втр", "Срд", "Чтв", "Птн", "Суб", "Вск"],
921
- daysMin: ["Вс", "Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"],
922
- months: ["Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь"],
923
- monthsShort: ["Янв", "Фев", "Мар", "Апр", "Май", "Июн", "Июл", "Авг", "Сен", "Окт", "Ноя", "Дек"],
924
- today: "Сегодня"
925
- },
926
- 'cs': {
927
- days: ["Neděle", "Pondělí", "Úterý", "Středa", "Čtvrtek", "Pátek", "Sobota", "Neděle"],
928
- daysShort: ["Ne", "Po", "Út", "St", "Čt", "Pá", "So", "Ne"],
929
- daysMin: ["Ne", "Po", "Út", "St", "Čt", "Pá", "So", "Ne"],
930
- months: ["Leden", "Únor", "Březen", "Duben", "Květen", "Červen", "Červenec", "Srpen", "Září", "Říjen", "Listopad", "Prosinec"],
931
- monthsShort: ["Led", "Úno", "Bře", "Dub", "Kvě", "Čer", "Čnc", "Srp", "Zář", "Říj", "Lis", "Pro"],
932
- today: "Dnes"
933
- },
934
- 'nl': {
935
- days: ["Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag", "Zaterdag", "Zondag"],
936
- daysShort: ["Zon", "Maa", "Din", "Woe", "Don", "Vri", "Zat", "Zon"],
937
- daysMin: ["Zo", "Ma", "Di", "Wo", "Do", "Vr", "Za", "Zo"],
938
- months: ["Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December"],
939
- monthsShort: ["Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"],
940
- today: "Vandaag"
941
- },
942
- 'el': {
943
- days: ["Κυριακή", "Δευτέρα", "Τρίτη", "Τετάρτη", "Πέμπτη", "Παρασκευή", "Σάββατο", "Κυριακή"],
944
- daysShort: ["Κυρ", "Δευ", "Τρί", "Τετ", "Πέμ", "Παρ", "Σάβ", "Κυρ"],
945
- daysMin: ["Κυ", "Δε", "Τρ", "Τε", "Πέ", "Πα", "Σά", "Κυ"],
946
- months: ["Ιανουάριος", "Φεβρουάριος", "Μάρτιος", "Απρίλιος", "Μάιος", "Ιούνιος", "Ιούλιος", "Αύγουστος", "Σεπτέμβριος", "Οκτώβριος", "Νοέμβριος", "Δεκέμβριος"],
947
- monthsShort: ["Ιαν", "Φεβ", "Μαρ", "Απρ", "Μαϊ", "Ιου", "Ιου", "Αυγ", "Σεπ", "Οκτ", "Νοε", "Δεκ"],
948
- today: "Σήμερα"
949
- },
950
- 'uk': {
951
- days: ["Понедiлок ", "Вiвторок ", "Середа ", "Четвер ", "П'ятниця ", "Субота ", "Недiля"],
952
- daysShort: ["Пнд", "Втр", "Срд", "Чтв", "Птн", "Сбт", "Ндл"],
953
- daysMin: ["Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Нд"],
954
- months: ["Січень", "Лютий", "Березень", "Квітень", "Травень", "Червень", "Липень", "Серпень", "Вересень", "Жовтень", "Листопад", "Грудень"],
955
- monthsShort: ["Сiч", "Лют", "Бер", "Квiт", "Трав", "Черв", "Лип", "Серп", "Вер", "Жовт", "Лист", "Груд"],
956
- today: "Сьогодні"
957
- },
958
- 'no': {
959
- days: ["Søndag", "Mandag", "Tirsdag", "Onsdag", "Torsdag", "Fredag", "Lørdag", "Søndag"],
960
- daysShort: ["Søn", "Man", "Tir", "Ons", "Tor", "Fre", "Lør", "Søn"],
961
- daysMin: ["Sø", "Ma", "Ti", "On", "To", "Fr", "Lø", "Sø"],
962
- months: ["Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Desember"],
963
- monthsShort: ["Jan", "Feb", "Mar", "Apr", "Mai", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Des"],
964
- today: "I dag"
965
- },
966
- 'sv': {
967
- days: ["Söndag", "Måndag", "Tisdag", "Onsdag", "Torsdag", "Fredag", "Lördag", "Söndag"],
968
- daysShort: ["Sön", "Mån", "Tis", "Ons", "Tor", "Fre", "Lör", "Sön"],
969
- daysMin: ["Sö", "Må", "Ti", "On", "To", "Fr", "Lö", "Sö"],
970
- months: ["Januari", "Februari", "Mars", "April", "Maj", "Juni", "Juli", "Augusti", "September", "Oktober", "November", "December"],
971
- monthsShort: ["Jan", "Feb", "Mar", "Apr", "Maj", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"],
972
- today: "Idag"
973
- },
974
- 'zh-CN': {
975
- days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
976
- daysShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
977
- daysMin: ["日", "一", "二", "三", "四", "五", "六"],
978
- months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
979
- monthsShort: ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"],
980
- today: '今天'
981
- },
982
- 'zh-TW': {
983
- days: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
984
- daysShort: ["週日", "週一", "週二", "週三", "週四", "週五", "週六"],
985
- daysMin: ["日", "一", "二", "三", "四", "五", "六"],
986
- months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
987
- monthsShort: ["一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"],
988
- today: '今天'
989
- },
990
- 'ja': {
991
- days: ["日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"],
992
- daysShort: ["日", "月", "火", "水", "木", "金", "土"],
993
- daysMin: ["日", "月", "火", "水", "木", "金", "土"],
994
- months: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
995
- monthsShort: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
996
- today: "今日",
997
- format: "yyyy/mm/dd",
998
- titleFormat: "yyyy年 MM月"
999
- }
1000
- };
1001
-
1002
- var DPGlobal = {
1003
- modes: [
1004
- {
1005
- clsName: 'days',
1006
- navFnc: 'Month',
1007
- navStep: 1
1008
- },
1009
- {
1010
- clsName: 'months',
1011
- navFnc: 'FullYear',
1012
- navStep: 1
1013
- },
1014
- {
1015
- clsName: 'years',
1016
- navFnc: 'FullYear',
1017
- navStep: 10
1018
- }],
1019
- isLeapYear: function (year) {
1020
- return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
1021
- },
1022
- getDaysInMonth: function (year, month) {
1023
- return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
1024
- },
1025
- validParts: /dd?|DD?|mm?|MM?|yy(?:yy)?/g,
1026
- nonpunctuation: /[^ -\/:-@\[\u3400-\u9fff-`{-~\t\n\r]+/g,
1027
- parseFormat: function(format){
1028
- // IE treats \0 as a string end in inputs (truncating the value),
1029
- // so it's a bad format delimiter, anyway
1030
- var separators = format.replace(this.validParts, '\0').split('\0'),
1031
- parts = format.match(this.validParts);
1032
- if (!separators || !separators.length || !parts || parts.length === 0){
1033
- throw new Error("Invalid date format.");
1034
- }
1035
- return {separators: separators, parts: parts};
1036
- },
1037
- parseDate: function(date, format, language) {
1038
- if (date instanceof Date) return date;
1039
- if (/^[\-+]\d+[dmwy]([\s,]+[\-+]\d+[dmwy])*$/.test(date)) {
1040
- var part_re = /([\-+]\d+)([dmwy])/,
1041
- parts = date.match(/([\-+]\d+)([dmwy])/g),
1042
- part, dir;
1043
- date = new Date();
1044
- for (var i=0; i<parts.length; i++) {
1045
- part = part_re.exec(parts[i]);
1046
- dir = parseInt(part[1]);
1047
- switch(part[2]){
1048
- case 'd':
1049
- date.setUTCDate(date.getUTCDate() + dir);
1050
- break;
1051
- case 'm':
1052
- date = Datepicker.prototype.moveMonth.call(Datepicker.prototype, date, dir);
1053
- break;
1054
- case 'w':
1055
- date.setUTCDate(date.getUTCDate() + dir * 7);
1056
- break;
1057
- case 'y':
1058
- date = Datepicker.prototype.moveYear.call(Datepicker.prototype, date, dir);
1059
- break;
1060
- }
1061
- }
1062
- return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 0, 0, 0);
1063
- }
1064
- var parts = date && date.match(this.nonpunctuation) || [],
1065
- date = new Date(),
1066
- parsed = {},
1067
- setters_order = ['yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'],
1068
- setters_map = {
1069
- yyyy: function(d,v){ return d.setUTCFullYear(v); },
1070
- yy: function(d,v){ return d.setUTCFullYear(2000+v); },
1071
- m: function(d,v){
1072
- v -= 1;
1073
- while (v<0) v += 12;
1074
- v %= 12;
1075
- d.setUTCMonth(v);
1076
- while (d.getUTCMonth() != v)
1077
- d.setUTCDate(d.getUTCDate()-1);
1078
- return d;
1079
- },
1080
- d: function(d,v){ return d.setUTCDate(v); }
1081
- },
1082
- val, filtered, part;
1083
- setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
1084
- setters_map['dd'] = setters_map['d'];
1085
- date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
1086
- var fparts = format.parts.slice();
1087
- // Remove noop parts
1088
- if (parts.length != fparts.length) {
1089
- fparts = $(fparts).filter(function(i,p){
1090
- return $.inArray(p, setters_order) !== -1;
1091
- }).toArray();
1092
- }
1093
- // Process remainder
1094
- if (parts.length == fparts.length) {
1095
- for (var i=0, cnt = fparts.length; i < cnt; i++) {
1096
- val = parseInt(parts[i], 10);
1097
- part = fparts[i];
1098
- if (isNaN(val)) {
1099
- switch(part) {
1100
- case 'MM':
1101
- filtered = $(dates[language].months).filter(function(){
1102
- var m = this.slice(0, parts[i].length),
1103
- p = parts[i].slice(0, m.length);
1104
- return m == p;
1105
- });
1106
- val = $.inArray(filtered[0], dates[language].months) + 1;
1107
- break;
1108
- case 'M':
1109
- filtered = $(dates[language].monthsShort).filter(function(){
1110
- var m = this.slice(0, parts[i].length),
1111
- p = parts[i].slice(0, m.length);
1112
- return m == p;
1113
- });
1114
- val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
1115
- break;
1116
- }
1117
- }
1118
- parsed[part] = val;
1119
- }
1120
- for (var i=0, s; i<setters_order.length; i++){
1121
- s = setters_order[i];
1122
- if (s in parsed && !isNaN(parsed[s]))
1123
- setters_map[s](date, parsed[s]);
1124
- }
1125
- }
1126
- return date;
1127
- },
1128
- formatDate: function(date, format, language){
1129
- if (!date)
1130
- return '';
1131
- if (typeof format === 'string')
1132
- format = DPGlobal.parseFormat(format);
1133
- if (format.toDisplay)
1134
- return format.toDisplay(date, format, language);
1135
- var val = {
1136
- d: date.getUTCDate(),
1137
- D: dates[language].daysShort[date.getUTCDay()],
1138
- DD: dates[language].days[date.getUTCDay()],
1139
- m: date.getUTCMonth() + 1,
1140
- M: dates[language].monthsShort[date.getUTCMonth()],
1141
- MM: dates[language].months[date.getUTCMonth()],
1142
- yy: date.getUTCFullYear().toString().substring(2),
1143
- yyyy: date.getUTCFullYear()
1144
- };
1145
- val.dd = (val.d < 10 ? '0' : '') + val.d;
1146
- val.mm = (val.m < 10 ? '0' : '') + val.m;
1147
- date = [];
1148
- var seps = $.extend([], format.separators);
1149
- for (var i=0, cnt = format.parts.length; i <= cnt; i++){
1150
- if (seps.length)
1151
- date.push(seps.shift());
1152
- date.push(val[format.parts[i]]);
1153
- }
1154
- return date.join('');
1155
- },
1156
- headTemplate: '<thead>'+
1157
- '<tr>'+
1158
- '<th class="prev"><i class="fa fa-chevron-left fi-arrow-left"/></th>'+
1159
- '<th colspan="5" class="date-switch"></th>'+
1160
- '<th class="next"><i class="fa fa-chevron-right fi-arrow-right"/></th>'+
1161
- '</tr>'+
1162
- '</thead>',
1163
- contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
1164
- footTemplate: '<tfoot><tr><th colspan="7" class="today"></th></tr></tfoot>',
1165
- headTemplateDays: '<thead>'+
1166
- '<tr>'+
1167
- '<th class="prev"><i class="fa fa-chevron-left fi-arrow-left"/></th>'+
1168
- '<th colspan="5" class="date-switch"></th>'+
1169
- '<th class="next"><i class="fa fa-chevron-right fi-arrow-right"/></th>'+
1170
- '</tr>'+
1171
- '</thead>',
1172
- footTemplateDays: '<tfoot><tr><th colspan="7" class="today"></th></tr></tfoot>'
1173
- };
1174
- DPGlobal.template = '<div class="datepicker">'+
1175
-
1176
- '<div class="datepicker-days">'+
1177
- '<table class=" table-condensed">'+
1178
- DPGlobal.headTemplateDays+
1179
- '<tbody></tbody>'+
1180
- DPGlobal.footTemplateDays+
1181
- '</table>'+
1182
- '</div>'+
1183
- '<div class="datepicker-months">'+
1184
- '<table class="table-condensed">'+
1185
- DPGlobal.headTemplate+
1186
- DPGlobal.contTemplate+
1187
- DPGlobal.footTemplate+
1188
- '</table>'+
1189
- '</div>'+
1190
- '<div class="datepicker-years">'+
1191
- '<table class="table-condensed">'+
1192
- DPGlobal.headTemplate+
1193
- DPGlobal.contTemplate+
1194
- DPGlobal.footTemplate+
1195
- '</table>'+
1196
- '</div>'+
1197
- '<a class="button datepicker-close tiny alert right" style="width:auto;"><i class="fa fa-remove fa-times fi-x"></i></a>'+
1198
- '</div>';
1199
-
1200
- $.fn.fdatepicker.DPGlobal = DPGlobal;
1201
-
1202
- }( window.jQuery );
6
+ ! function($) {
7
+
8
+ function UTCDate() {
9
+ return new Date(Date.UTC.apply(Date, arguments));
10
+ }
11
+
12
+ function UTCToday() {
13
+ var today = new Date();
14
+ return UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
15
+ }
16
+
17
+ var Datepicker = function(element, options) {
18
+ var that = this;
19
+
20
+ this.element = $(element);
21
+ this.autoShow = options.autoShow || true;
22
+ this.appendTo = options.appendTo || 'body';
23
+ this.closeButton = options.closeButton;
24
+ this.language = options.language || this.element.data('date-language') || "en";
25
+ this.language = this.language in dates ? this.language : this.language.split('-')[0]; //Check if "de-DE" style date is available, if not language should fallback to 2 letter code eg "de"
26
+ this.language = this.language in dates ? this.language : "en";
27
+ this.isRTL = dates[this.language].rtl || false;
28
+ this.format = DPGlobal.parseFormat(options.format || this.element.data('date-format') || dates[this.language].format || 'mm/dd/yyyy');
29
+ this.isInline = false;
30
+ this.isInput = this.element.is('input');
31
+ this.component = this.element.is('.date') ? this.element.find('.prefix, .postfix') : false;
32
+ this.hasInput = this.component && this.element.find('input').length;
33
+ this.disableDblClickSelection = options.disableDblClickSelection;
34
+ this.onRender = options.onRender || function() {};
35
+ if (this.component && this.component.length === 0) {
36
+ this.component = false;
37
+ }
38
+ this.linkField = options.linkField || this.element.data('link-field') || false;
39
+ this.linkFormat = DPGlobal.parseFormat(options.linkFormat || this.element.data('link-format') || 'yyyy-mm-dd hh:ii:ss');
40
+ this.minuteStep = options.minuteStep || this.element.data('minute-step') || 5;
41
+ this.pickerPosition = options.pickerPosition || this.element.data('picker-position') || 'bottom-right';
42
+
43
+ this._attachEvents();
44
+
45
+
46
+ this.minView = 0;
47
+ if ('minView' in options) {
48
+ this.minView = options.minView;
49
+ } else if ('minView' in this.element.data()) {
50
+ this.minView = this.element.data('min-view');
51
+ }
52
+ this.minView = DPGlobal.convertViewMode(this.minView);
53
+
54
+ this.maxView = DPGlobal.modes.length - 1;
55
+ if ('maxView' in options) {
56
+ this.maxView = options.maxView;
57
+ } else if ('maxView' in this.element.data()) {
58
+ this.maxView = this.element.data('max-view');
59
+ }
60
+ this.maxView = DPGlobal.convertViewMode(this.maxView);
61
+
62
+ this.startViewMode = 'month';
63
+ if ('startView' in options) {
64
+ this.startViewMode = options.startView;
65
+ } else if ('startView' in this.element.data()) {
66
+ this.startViewMode = this.element.data('start-view');
67
+ }
68
+ this.startViewMode = DPGlobal.convertViewMode(this.startViewMode);
69
+ this.viewMode = this.startViewMode;
70
+
71
+ if (!('minView' in options) && !('maxView' in options) && !(this.element.data('min-view') && !(this.element.data('max-view')))) {
72
+ this.pickTime = false;
73
+ if ('pickTime' in options) {
74
+ this.pickTime = options.pickTime;
75
+ }
76
+ if (this.pickTime == true) {
77
+ this.minView = 0;
78
+ this.maxView = 4;
79
+ } else {
80
+ this.minView = 2;
81
+ this.maxView = 4;
82
+ }
83
+ }
84
+
85
+ this.forceParse = true;
86
+ if ('forceParse' in options) {
87
+ this.forceParse = options.forceParse;
88
+ } else if ('dateForceParse' in this.element.data()) {
89
+ this.forceParse = this.element.data('date-force-parse');
90
+ }
91
+
92
+
93
+ this.picker = $(DPGlobal.template)
94
+ .appendTo(this.isInline ? this.element : this.appendTo)
95
+ .on({
96
+ click: $.proxy(this.click, this),
97
+ mousedown: $.proxy(this.mousedown, this)
98
+ });
99
+ if (this.closeButton) {
100
+ this.picker.find('a.datepicker-close').show();
101
+ } else {
102
+ this.picker.find('a.datepicker-close').hide();
103
+ }
104
+
105
+ if (this.isInline) {
106
+ this.picker.addClass('datepicker-inline');
107
+ } else {
108
+ this.picker.addClass('datepicker-dropdown dropdown-menu');
109
+ }
110
+ if (this.isRTL) {
111
+ this.picker.addClass('datepicker-rtl');
112
+ this.picker.find('.prev i, .next i')
113
+ .toggleClass('fa fa-chevron-left fa-chevron-right').toggleClass('fa-chevron-left fa-chevron-right');
114
+ }
115
+ $(document).on('mousedown', function(e) {
116
+ // Clicked outside the datepicker, hide it
117
+ if ($(e.target).closest('.datepicker.datepicker-inline, .datepicker.datepicker-dropdown').length === 0) {
118
+ that.hide();
119
+ }
120
+ });
121
+
122
+ this.autoclose = true;
123
+ if ('autoclose' in options) {
124
+ this.autoclose = options.autoclose;
125
+ } else if ('dateAutoclose' in this.element.data()) {
126
+ this.autoclose = this.element.data('date-autoclose');
127
+ }
128
+
129
+ this.keyboardNavigation = true;
130
+ if ('keyboardNavigation' in options) {
131
+ this.keyboardNavigation = options.keyboardNavigation;
132
+ } else if ('dateKeyboardNavigation' in this.element.data()) {
133
+ this.keyboardNavigation = this.element.data('date-keyboard-navigation');
134
+ }
135
+
136
+ this.todayBtn = (options.todayBtn || this.element.data('date-today-btn') || false);
137
+ this.todayHighlight = (options.todayHighlight || this.element.data('date-today-highlight') || false);
138
+
139
+ this.calendarWeeks = false;
140
+ if ('calendarWeeks' in options) {
141
+ this.calendarWeeks = options.calendarWeeks;
142
+ } else if ('dateCalendarWeeks' in this.element.data()) {
143
+ this.calendarWeeks = this.element.data('date-calendar-weeks');
144
+ }
145
+ if (this.calendarWeeks)
146
+ this.picker.find('tfoot th.today')
147
+ .attr('colspan', function(i, val) {
148
+ return parseInt(val) + 1;
149
+ });
150
+
151
+ this.weekStart = ((options.weekStart || this.element.data('date-weekstart') || dates[this.language].weekStart || 0) % 7);
152
+ this.weekEnd = ((this.weekStart + 6) % 7);
153
+ this.startDate = -Infinity;
154
+ this.endDate = Infinity;
155
+ this.daysOfWeekDisabled = [];
156
+ this.setStartDate(options.startDate || this.element.data('date-startdate'));
157
+ this.setEndDate(options.endDate || this.element.data('date-enddate'));
158
+ this.setDaysOfWeekDisabled(options.daysOfWeekDisabled || this.element.data('date-days-of-week-disabled'));
159
+
160
+ this.fillDow();
161
+ this.fillMonths();
162
+ this.update();
163
+
164
+ this.showMode();
165
+
166
+ if (this.isInline) {
167
+ this.show();
168
+ }
169
+ };
170
+
171
+ Datepicker.prototype = {
172
+ constructor: Datepicker,
173
+
174
+ _events: [],
175
+ _attachEvents: function() {
176
+ this._detachEvents();
177
+ if (this.isInput) { // single input
178
+ this._events = [
179
+ [this.element, {
180
+ focus: (this.autoShow) ? $.proxy(this.show, this) : function() {},
181
+ keyup: $.proxy(this.update, this),
182
+ keydown: $.proxy(this.keydown, this)
183
+ }]
184
+ ];
185
+ } else if (this.component && this.hasInput) { // component: input + button
186
+ this._events = [
187
+ // For components that are not readonly, allow keyboard nav
188
+ [this.element.find('input'), {
189
+ focus: (this.autoShow) ? $.proxy(this.show, this) : function() {},
190
+ keyup: $.proxy(this.update, this),
191
+ keydown: $.proxy(this.keydown, this)
192
+ }],
193
+ [this.component, {
194
+ click: $.proxy(this.show, this)
195
+ }]
196
+ ];
197
+ } else if (this.element.is('div')) { // inline datepicker
198
+ this.isInline = true;
199
+ } else {
200
+ this._events = [
201
+ [this.element, {
202
+ click: $.proxy(this.show, this)
203
+ }]
204
+ ];
205
+ }
206
+
207
+ if (this.disableDblClickSelection) {
208
+ this._events[this._events.length] = [
209
+ this.element, {
210
+ dblclick: function(e) {
211
+ e.preventDefault();
212
+ e.stopPropagation();
213
+ $(this).blur()
214
+ }
215
+ }
216
+ ];
217
+ }
218
+
219
+ for (var i = 0, el, ev; i < this._events.length; i++) {
220
+ el = this._events[i][0];
221
+ ev = this._events[i][1];
222
+ el.on(ev);
223
+ }
224
+ },
225
+ _detachEvents: function() {
226
+ for (var i = 0, el, ev; i < this._events.length; i++) {
227
+ el = this._events[i][0];
228
+ ev = this._events[i][1];
229
+ el.off(ev);
230
+ }
231
+ this._events = [];
232
+ },
233
+
234
+ show: function(e) {
235
+ this.picker.show();
236
+ this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
237
+ this.update();
238
+ this.place();
239
+ $(window).on('resize', $.proxy(this.place, this));
240
+ if (e) {
241
+ e.stopPropagation();
242
+ e.preventDefault();
243
+ }
244
+ this.element.trigger({
245
+ type: 'show',
246
+ date: this.date
247
+ });
248
+ },
249
+
250
+ hide: function(e) {
251
+ if (this.isInline) return;
252
+ if (!this.picker.is(':visible')) return;
253
+ this.picker.hide();
254
+ $(window).off('resize', this.place);
255
+ this.viewMode = this.startViewMode;
256
+ this.showMode();
257
+ if (!this.isInput) {
258
+ $(document).off('mousedown', this.hide);
259
+ }
260
+
261
+ if (
262
+ this.forceParse &&
263
+ (
264
+ this.isInput && this.element.val() ||
265
+ this.hasInput && this.element.find('input').val()
266
+ )
267
+ )
268
+ this.setValue();
269
+ this.element.trigger({
270
+ type: 'hide',
271
+ date: this.date
272
+ });
273
+ },
274
+
275
+ remove: function() {
276
+ this._detachEvents();
277
+ this.picker.remove();
278
+ delete this.element.data().datepicker;
279
+ },
280
+
281
+ getDate: function() {
282
+ var d = this.getUTCDate();
283
+ return new Date(d.getTime() + (d.getTimezoneOffset() * 60000));
284
+ },
285
+
286
+ getUTCDate: function() {
287
+ return this.date;
288
+ },
289
+
290
+ setDate: function(d) {
291
+ this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset() * 60000)));
292
+ },
293
+
294
+ setUTCDate: function(d) {
295
+ this.date = d;
296
+ this.setValue();
297
+ },
298
+
299
+ setValue: function() {
300
+ var formatted = this.getFormattedDate();
301
+ if (!this.isInput) {
302
+ if (this.component) {
303
+ this.element.find('input').val(formatted);
304
+ }
305
+ this.element.data('date', formatted);
306
+ } else {
307
+ this.element.val(formatted);
308
+ }
309
+ },
310
+
311
+ getFormattedDate: function(format) {
312
+ if (format === undefined)
313
+ format = this.format;
314
+ return DPGlobal.formatDate(this.date, format, this.language);
315
+ },
316
+
317
+ setStartDate: function(startDate) {
318
+ this.startDate = startDate || -Infinity;
319
+ if (this.startDate !== -Infinity) {
320
+ this.startDate = DPGlobal.parseDate(this.startDate, this.format, this.language);
321
+ }
322
+ this.update();
323
+ this.updateNavArrows();
324
+ },
325
+
326
+ setEndDate: function(endDate) {
327
+ this.endDate = endDate || Infinity;
328
+ if (this.endDate !== Infinity) {
329
+ this.endDate = DPGlobal.parseDate(this.endDate, this.format, this.language);
330
+ }
331
+ this.update();
332
+ this.updateNavArrows();
333
+ },
334
+
335
+ setDaysOfWeekDisabled: function(daysOfWeekDisabled) {
336
+ this.daysOfWeekDisabled = daysOfWeekDisabled || [];
337
+ if (!$.isArray(this.daysOfWeekDisabled)) {
338
+ this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
339
+ }
340
+ this.daysOfWeekDisabled = $.map(this.daysOfWeekDisabled, function(d) {
341
+ return parseInt(d, 10);
342
+ });
343
+ this.update();
344
+ this.updateNavArrows();
345
+ },
346
+
347
+ place: function() {
348
+ if (this.isInline) return;
349
+ var zIndex = parseInt(this.element.parents().filter(function() {
350
+ return $(this).css('z-index') != 'auto';
351
+ }).first().css('z-index')) + 10;
352
+ var textbox = this.component ? this.component : this.element;
353
+ var offset = textbox.offset();
354
+ var height = textbox.outerHeight() + parseInt(textbox.css('margin-top'));
355
+ var width = textbox.outerWidth() + parseInt(textbox.css('margin-left'));
356
+ var fullOffsetTop = offset.top + height;
357
+ var offsetLeft = offset.left;
358
+ // if the datepicker is going to be below the window, show it on top of the input
359
+ if ((fullOffsetTop + this.picker.outerHeight()) >= $(window).scrollTop() + $(window).height()) {
360
+ fullOffsetTop = offset.top - this.picker.outerHeight();
361
+ }
362
+
363
+ // if the datepicker is going to go past the right side of the window, we want
364
+ // to set the right position so the datepicker lines up with the textbox
365
+ if (offset.left + this.picker.width() >= $(window).width()) {
366
+ offsetLeft = (offset.left + width) - this.picker.width();
367
+ }
368
+ this.picker.css({
369
+ top: fullOffsetTop,
370
+ left: offsetLeft,
371
+ zIndex: zIndex
372
+ });
373
+ },
374
+
375
+ update: function() {
376
+ var date, fromArgs = false;
377
+ if (arguments && arguments.length && (typeof arguments[0] === 'string' || arguments[0] instanceof Date)) {
378
+ date = arguments[0];
379
+ fromArgs = true;
380
+ } else {
381
+ date = this.isInput ? this.element.val() : this.element.data('date') || this.element.find('input').val();
382
+ }
383
+
384
+ this.date = DPGlobal.parseDate(date, this.format, this.language);
385
+
386
+ if (fromArgs) this.setValue();
387
+
388
+ if (this.date < this.startDate) {
389
+ this.viewDate = new Date(this.startDate.valueOf());
390
+ } else if (this.date > this.endDate) {
391
+ this.viewDate = new Date(this.endDate.valueOf());
392
+ } else {
393
+ this.viewDate = new Date(this.date.valueOf());
394
+ }
395
+ this.fill();
396
+ },
397
+
398
+ fillDow: function() {
399
+ var dowCnt = this.weekStart,
400
+ html = '<tr>';
401
+ if (this.calendarWeeks) {
402
+ var cell = '<th class="cw">&nbsp;</th>';
403
+ html += cell;
404
+ this.picker.find('.datepicker-days thead tr:first-child').prepend(cell);
405
+ }
406
+ while (dowCnt < this.weekStart + 7) {
407
+ html += '<th class="dow">' + dates[this.language].daysMin[(dowCnt++) % 7] + '</th>';
408
+ }
409
+ html += '</tr>';
410
+ this.picker.find('.datepicker-days thead').append(html);
411
+ },
412
+
413
+ fillMonths: function() {
414
+ var html = '',
415
+ i = 0;
416
+ while (i < 12) {
417
+ html += '<span class="month">' + dates[this.language].monthsShort[i++] + '</span>';
418
+ }
419
+ this.picker.find('.datepicker-months td').html(html);
420
+ },
421
+
422
+ fill: function() {
423
+ if (this.date == null || this.viewDate == null) {
424
+ return;
425
+ }
426
+
427
+ var d = new Date(this.viewDate.valueOf()),
428
+ year = d.getUTCFullYear(),
429
+ month = d.getUTCMonth(),
430
+ dayMonth = d.getUTCDate(),
431
+ hours = d.getUTCHours(),
432
+ minutes = d.getUTCMinutes(),
433
+ startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
434
+ startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
435
+ endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
436
+ endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
437
+ currentDate = this.date && this.date.valueOf(),
438
+ today = new Date(),
439
+ titleFormat = dates[this.language].titleFormat || dates['en'].titleFormat;
440
+ // this.picker.find('.datepicker-days thead th.date-switch')
441
+ // .text(DPGlobal.formatDate(new UTCDate(year, month), titleFormat, this.language));
442
+
443
+ this.picker.find('.datepicker-days thead th:eq(1)')
444
+ .text(dates[this.language].months[month] + ' ' + year);
445
+ this.picker.find('.datepicker-hours thead th:eq(1)')
446
+ .text(dayMonth + ' ' + dates[this.language].months[month] + ' ' + year);
447
+ this.picker.find('.datepicker-minutes thead th:eq(1)')
448
+ .text(dayMonth + ' ' + dates[this.language].months[month] + ' ' + year);
449
+
450
+
451
+ this.picker.find('tfoot th.today')
452
+ .text(dates[this.language].today)
453
+ .toggle(this.todayBtn !== false);
454
+ this.updateNavArrows();
455
+ this.fillMonths();
456
+ var prevMonth = UTCDate(year, month - 1, 28, 0, 0, 0, 0),
457
+ day = DPGlobal.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
458
+ prevMonth.setUTCDate(day);
459
+ prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7) % 7);
460
+ var nextMonth = new Date(prevMonth.valueOf());
461
+ nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
462
+ nextMonth = nextMonth.valueOf();
463
+ var html = [];
464
+ var clsName;
465
+ while (prevMonth.valueOf() < nextMonth) {
466
+ if (prevMonth.getUTCDay() == this.weekStart) {
467
+ html.push('<tr>');
468
+ if (this.calendarWeeks) {
469
+ // adapted from https://github.com/timrwood/moment/blob/master/moment.js#L128
470
+ var a = new Date(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth(), prevMonth.getUTCDate() - prevMonth.getDay() + 10 - (this.weekStart && this.weekStart % 7 < 5 && 7)),
471
+ b = new Date(a.getFullYear(), 0, 4),
472
+ calWeek = ~~((a - b) / 864e5 / 7 + 1.5);
473
+ html.push('<td class="cw">' + calWeek + '</td>');
474
+ }
475
+ }
476
+ clsName = ' ' + this.onRender(prevMonth) + ' ';
477
+ if (prevMonth.getUTCFullYear() < year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() < month)) {
478
+ clsName += ' old';
479
+ } else if (prevMonth.getUTCFullYear() > year || (prevMonth.getUTCFullYear() == year && prevMonth.getUTCMonth() > month)) {
480
+ clsName += ' new';
481
+ }
482
+ // Compare internal UTC date with local today, not UTC today
483
+ if (this.todayHighlight &&
484
+ prevMonth.getUTCFullYear() == today.getFullYear() &&
485
+ prevMonth.getUTCMonth() == today.getMonth() &&
486
+ prevMonth.getUTCDate() == today.getDate()) {
487
+ clsName += ' today';
488
+ }
489
+ if (currentDate && prevMonth.valueOf() == currentDate) {
490
+ clsName += ' active';
491
+ }
492
+ if (prevMonth.valueOf() < this.startDate || prevMonth.valueOf() > this.endDate ||
493
+ $.inArray(prevMonth.getUTCDay(), this.daysOfWeekDisabled) !== -1) {
494
+ clsName += ' disabled';
495
+ }
496
+ html.push('<td class="day' + clsName + '">' + prevMonth.getUTCDate() + '</td>');
497
+ if (prevMonth.getUTCDay() == this.weekEnd) {
498
+ html.push('</tr>');
499
+ }
500
+ prevMonth.setUTCDate(prevMonth.getUTCDate() + 1);
501
+ }
502
+ this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
503
+
504
+ html = [];
505
+ for (var i = 0; i < 24; i++) {
506
+ var actual = UTCDate(year, month, dayMonth, i);
507
+ clsName = '';
508
+ // We want the previous hour for the startDate
509
+ if ((actual.valueOf() + 3600000) < this.startDate || actual.valueOf() > this.endDate) {
510
+ clsName += ' disabled';
511
+ } else if (hours == i) {
512
+ clsName += ' active';
513
+ }
514
+ html.push('<span class="hour' + clsName + '">' + i + ':00</span>');
515
+ }
516
+ this.picker.find('.datepicker-hours td').html(html.join(''));
517
+
518
+ html = [];
519
+ for (var i = 0; i < 60; i += this.minuteStep) {
520
+ var actual = UTCDate(year, month, dayMonth, hours, i);
521
+ clsName = '';
522
+ if (actual.valueOf() < this.startDate || actual.valueOf() > this.endDate) {
523
+ clsName += ' disabled';
524
+ } else if (Math.floor(minutes / this.minuteStep) == Math.floor(i / this.minuteStep)) {
525
+ clsName += ' active';
526
+ }
527
+ html.push('<span class="minute' + clsName + '">' + hours + ':' + (i < 10 ? '0' + i : i) + '</span>');
528
+ }
529
+ this.picker.find('.datepicker-minutes td').html(html.join(''));
530
+
531
+
532
+ var currentYear = this.date && this.date.getUTCFullYear();
533
+ var months = this.picker.find('.datepicker-months')
534
+ .find('th:eq(1)')
535
+ .text(year)
536
+ .end()
537
+ .find('span').removeClass('active');
538
+ if (currentYear && currentYear == year) {
539
+ months.eq(this.date.getUTCMonth()).addClass('active');
540
+ }
541
+ if (year < startYear || year > endYear) {
542
+ months.addClass('disabled');
543
+ }
544
+ if (year == startYear) {
545
+ months.slice(0, startMonth).addClass('disabled');
546
+ }
547
+ if (year == endYear) {
548
+ months.slice(endMonth + 1).addClass('disabled');
549
+ }
550
+
551
+ html = '';
552
+ year = parseInt(year / 10, 10) * 10;
553
+ var yearCont = this.picker.find('.datepicker-years')
554
+ .find('th:eq(1)')
555
+ .text(year + '-' + (year + 9))
556
+ .end()
557
+ .find('td');
558
+ year -= 1;
559
+ for (var i = -1; i < 11; i++) {
560
+ html += '<span class="year' + (i == -1 || i == 10 ? ' old' : '') + (currentYear == year ? ' active' : '') + (year < startYear || year > endYear ? ' disabled' : '') + '">' + year + '</span>';
561
+ year += 1;
562
+ }
563
+ yearCont.html(html);
564
+ },
565
+
566
+ updateNavArrows: function() {
567
+ var d = new Date(this.viewDate),
568
+ year = d.getUTCFullYear(),
569
+ month = d.getUTCMonth(),
570
+ day = d.getUTCDate(),
571
+ hour = d.getUTCHours();
572
+ switch (this.viewMode) {
573
+ case 0:
574
+ if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth() && day <= this.startDate.getUTCDate() && hour <= this.startDate.getUTCHours()) {
575
+ this.picker.find('.prev').css({
576
+ visibility: 'hidden'
577
+ });
578
+ } else {
579
+ this.picker.find('.prev').css({
580
+ visibility: 'visible'
581
+ });
582
+ }
583
+ if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth() && day >= this.endDate.getUTCDate() && hour >= this.endDate.getUTCHours()) {
584
+ this.picker.find('.next').css({
585
+ visibility: 'hidden'
586
+ });
587
+ } else {
588
+ this.picker.find('.next').css({
589
+ visibility: 'visible'
590
+ });
591
+ }
592
+ break;
593
+ case 1:
594
+ if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth() && day <= this.startDate.getUTCDate()) {
595
+ this.picker.find('.prev').css({
596
+ visibility: 'hidden'
597
+ });
598
+ } else {
599
+ this.picker.find('.prev').css({
600
+ visibility: 'visible'
601
+ });
602
+ }
603
+ if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth() && day >= this.endDate.getUTCDate()) {
604
+ this.picker.find('.next').css({
605
+ visibility: 'hidden'
606
+ });
607
+ } else {
608
+ this.picker.find('.next').css({
609
+ visibility: 'visible'
610
+ });
611
+ }
612
+ break;
613
+ case 2:
614
+ if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
615
+ this.picker.find('.prev').css({
616
+ visibility: 'hidden'
617
+ });
618
+ } else {
619
+ this.picker.find('.prev').css({
620
+ visibility: 'visible'
621
+ });
622
+ }
623
+ if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
624
+ this.picker.find('.next').css({
625
+ visibility: 'hidden'
626
+ });
627
+ } else {
628
+ this.picker.find('.next').css({
629
+ visibility: 'visible'
630
+ });
631
+ }
632
+ break;
633
+ case 3:
634
+ case 4:
635
+ if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
636
+ this.picker.find('.prev').css({
637
+ visibility: 'hidden'
638
+ });
639
+ } else {
640
+ this.picker.find('.prev').css({
641
+ visibility: 'visible'
642
+ });
643
+ }
644
+ if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
645
+ this.picker.find('.next').css({
646
+ visibility: 'hidden'
647
+ });
648
+ } else {
649
+ this.picker.find('.next').css({
650
+ visibility: 'visible'
651
+ });
652
+ }
653
+ break;
654
+ }
655
+ },
656
+
657
+ click: function(e) {
658
+ e.stopPropagation();
659
+ e.preventDefault();
660
+
661
+ if ($(e.target).hasClass('datepicker-close') || $(e.target).parent().hasClass('datepicker-close')) {
662
+ this.hide();
663
+ }
664
+
665
+ var target = $(e.target).closest('span, td, th');
666
+ if (target.length == 1) {
667
+ if (target.is('.disabled')) {
668
+ this.element.trigger({
669
+ type: 'outOfRange',
670
+ date: this.viewDate,
671
+ startDate: this.startDate,
672
+ endDate: this.endDate
673
+ });
674
+ return;
675
+ }
676
+
677
+ switch (target[0].nodeName.toLowerCase()) {
678
+ case 'th':
679
+ switch (target[0].className) {
680
+ case 'date-switch':
681
+ this.showMode(1);
682
+ break;
683
+ case 'prev':
684
+ case 'next':
685
+ var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1);
686
+ switch (this.viewMode) {
687
+ case 0:
688
+ this.viewDate = this.moveHour(this.viewDate, dir);
689
+ break;
690
+ case 1:
691
+ this.viewDate = this.moveDate(this.viewDate, dir);
692
+ break;
693
+ case 2:
694
+ this.viewDate = this.moveMonth(this.viewDate, dir);
695
+ break;
696
+ case 3:
697
+ case 4:
698
+ this.viewDate = this.moveYear(this.viewDate, dir);
699
+ break;
700
+ }
701
+ this.fill();
702
+ break;
703
+ case 'today':
704
+ var date = new Date();
705
+ date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
706
+
707
+ this.viewMode = this.startViewMode;
708
+ this.showMode(0);
709
+ this._setDate(date);
710
+ break;
711
+ }
712
+ break;
713
+ case 'span':
714
+ if (!target.is('.disabled')) {
715
+ if (target.is('.month')) {
716
+ this.viewDate.setUTCDate(1);
717
+ var month = target.parent().find('span').index(target);
718
+ this.viewDate.setUTCMonth(month);
719
+ this.element.trigger({
720
+ type: 'changeMonth',
721
+ date: this.viewDate
722
+ });
723
+ } else if (target.is('.year')) {
724
+ this.viewDate.setUTCDate(1);
725
+ var year = parseInt(target.text(), 10) || 0;
726
+ this.viewDate.setUTCFullYear(year);
727
+ this.element.trigger({
728
+ type: 'changeYear',
729
+ date: this.viewDate
730
+ });
731
+ } else if (target.is('.hour')) {
732
+ var hours = parseInt(target.text(), 10) || 0;
733
+ var year = this.viewDate.getUTCFullYear(),
734
+ month = this.viewDate.getUTCMonth(),
735
+ day = this.viewDate.getUTCDate(),
736
+ minutes = this.viewDate.getUTCMinutes(),
737
+ seconds = this.viewDate.getUTCSeconds();
738
+ this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0));
739
+ } else if (target.is('.minute')) {
740
+ var minutes = parseInt(target.text().substr(target.text().indexOf(':') + 1), 10) || 0;
741
+ var year = this.viewDate.getUTCFullYear(),
742
+ month = this.viewDate.getUTCMonth(),
743
+ day = this.viewDate.getUTCDate(),
744
+ hours = this.viewDate.getUTCHours(),
745
+ seconds = this.viewDate.getUTCSeconds();
746
+ this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0));
747
+ }
748
+
749
+
750
+
751
+ if (this.viewMode != 0) {
752
+
753
+
754
+
755
+ var oldViewMode = this.viewMode;
756
+ this.showMode(-1);
757
+ this.fill();
758
+ if (oldViewMode == this.viewMode && this.autoclose) {
759
+ this.hide();
760
+ }
761
+ } else {
762
+ this.fill();
763
+ if (this.autoclose) {
764
+ this.hide();
765
+ }
766
+ }
767
+ }
768
+ break;
769
+ case 'td':
770
+
771
+
772
+
773
+ if (target.is('.day') && !target.is('.disabled')) {
774
+ var day = parseInt(target.text(), 10) || 1;
775
+ var year = this.viewDate.getUTCFullYear(),
776
+ month = this.viewDate.getUTCMonth(),
777
+ hours = this.viewDate.getUTCHours(),
778
+ minutes = this.viewDate.getUTCMinutes(),
779
+ seconds = this.viewDate.getUTCSeconds();
780
+ if (target.is('.old')) {
781
+ if (month === 0) {
782
+ month = 11;
783
+ year -= 1;
784
+ } else {
785
+ month -= 1;
786
+ }
787
+ } else if (target.is('.new')) {
788
+ if (month == 11) {
789
+ month = 0;
790
+ year += 1;
791
+ } else {
792
+ month += 1;
793
+ }
794
+ }
795
+ this._setDate(UTCDate(year, month, day, hours, minutes, seconds, 0));
796
+ }
797
+
798
+
799
+
800
+ var oldViewMode = this.viewMode;
801
+
802
+
803
+ this.showMode(-1);
804
+
805
+
806
+ this.fill();
807
+ if (oldViewMode == this.viewMode && this.autoclose) {
808
+ this.hide();
809
+ }
810
+ break;
811
+ }
812
+ }
813
+ },
814
+
815
+ _setDate: function(date, which) {
816
+
817
+ if (!which || which == 'date')
818
+ this.date = date;
819
+ if (!which || which == 'view')
820
+ this.viewDate = date;
821
+ this.fill();
822
+ this.setValue();
823
+ this.element.trigger({
824
+ type: 'changeDate',
825
+ date: this.date
826
+ });
827
+ var element;
828
+ if (this.isInput) {
829
+ element = this.element;
830
+ } else if (this.component) {
831
+ element = this.element.find('input');
832
+ }
833
+ if (element) {
834
+ element.change();
835
+ if (this.autoclose && (!which || which == 'date')) {
836
+ // this.hide();
837
+ }
838
+ }
839
+ },
840
+
841
+ moveHour: function(date, dir) {
842
+ if (!dir) return date;
843
+ var new_date = new Date(date.valueOf());
844
+ dir = dir > 0 ? 1 : -1;
845
+ new_date.setUTCHours(new_date.getUTCHours() + dir);
846
+ return new_date;
847
+ },
848
+
849
+ moveDate: function(date, dir) {
850
+ if (!dir) return date;
851
+ var new_date = new Date(date.valueOf());
852
+ dir = dir > 0 ? 1 : -1;
853
+ new_date.setUTCDate(new_date.getUTCDate() + dir);
854
+ return new_date;
855
+ },
856
+
857
+ moveMonth: function(date, dir) {
858
+ if (!dir) return date;
859
+ var new_date = new Date(date.valueOf()),
860
+ day = new_date.getUTCDate(),
861
+ month = new_date.getUTCMonth(),
862
+ mag = Math.abs(dir),
863
+ new_month, test;
864
+ dir = dir > 0 ? 1 : -1;
865
+ if (mag == 1) {
866
+ test = dir == -1
867
+ // If going back one month, make sure month is not current month
868
+ // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
869
+ ? function() {
870
+ return new_date.getUTCMonth() == month;
871
+ }
872
+ // If going forward one month, make sure month is as expected
873
+ // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
874
+ : function() {
875
+ return new_date.getUTCMonth() != new_month;
876
+ };
877
+ new_month = month + dir;
878
+ new_date.setUTCMonth(new_month);
879
+ // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
880
+ if (new_month < 0 || new_month > 11)
881
+ new_month = (new_month + 12) % 12;
882
+ } else {
883
+ // For magnitudes >1, move one month at a time...
884
+ for (var i = 0; i < mag; i++)
885
+ // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
886
+ new_date = this.moveMonth(new_date, dir);
887
+ // ...then reset the day, keeping it in the new month
888
+ new_month = new_date.getUTCMonth();
889
+ new_date.setUTCDate(day);
890
+ test = function() {
891
+ return new_month != new_date.getUTCMonth();
892
+ };
893
+ }
894
+ // Common date-resetting loop -- if date is beyond end of month, make it
895
+ // end of month
896
+ while (test()) {
897
+ new_date.setUTCDate(--day);
898
+ new_date.setUTCMonth(new_month);
899
+ }
900
+ return new_date;
901
+ },
902
+
903
+ moveYear: function(date, dir) {
904
+ return this.moveMonth(date, dir * 12);
905
+ },
906
+
907
+ dateWithinRange: function(date) {
908
+ return date >= this.startDate && date <= this.endDate;
909
+ },
910
+
911
+ keydown: function(e) {
912
+ if (this.picker.is(':not(:visible)')) {
913
+ if (e.keyCode == 27) // allow escape to hide and re-show picker
914
+ this.show();
915
+ return;
916
+ }
917
+ var dateChanged = false,
918
+ dir, day, month,
919
+ newDate, newViewDate;
920
+ switch (e.keyCode) {
921
+ case 27: // escape
922
+ this.hide();
923
+ e.preventDefault();
924
+ break;
925
+ case 37: // left
926
+ case 39: // right
927
+ if (!this.keyboardNavigation) break;
928
+ dir = e.keyCode == 37 ? -1 : 1;
929
+ if (e.ctrlKey) {
930
+ newDate = this.moveYear(this.date, dir);
931
+ newViewDate = this.moveYear(this.viewDate, dir);
932
+ } else if (e.shiftKey) {
933
+ newDate = this.moveMonth(this.date, dir);
934
+ newViewDate = this.moveMonth(this.viewDate, dir);
935
+ } else {
936
+ newDate = new Date(this.date.valueOf());
937
+ newDate.setUTCDate(this.date.getUTCDate() + dir);
938
+ newViewDate = new Date(this.viewDate.valueOf());
939
+ newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
940
+ }
941
+ if (this.dateWithinRange(newDate)) {
942
+ this.date = newDate;
943
+ this.viewDate = newViewDate;
944
+ this.setValue();
945
+ this.update();
946
+ e.preventDefault();
947
+ dateChanged = true;
948
+ }
949
+ break;
950
+ case 38: // up
951
+ case 40: // down
952
+ if (!this.keyboardNavigation) break;
953
+ dir = e.keyCode == 38 ? -1 : 1;
954
+ if (e.ctrlKey) {
955
+ newDate = this.moveYear(this.date, dir);
956
+ newViewDate = this.moveYear(this.viewDate, dir);
957
+ } else if (e.shiftKey) {
958
+ newDate = this.moveMonth(this.date, dir);
959
+ newViewDate = this.moveMonth(this.viewDate, dir);
960
+ } else {
961
+ newDate = new Date(this.date.valueOf());
962
+ newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
963
+ newViewDate = new Date(this.viewDate.valueOf());
964
+ newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
965
+ }
966
+ if (this.dateWithinRange(newDate)) {
967
+ this.date = newDate;
968
+ this.viewDate = newViewDate;
969
+ this.setValue();
970
+ this.update();
971
+ e.preventDefault();
972
+ dateChanged = true;
973
+ }
974
+ break;
975
+ case 13: // enter
976
+ this.hide();
977
+ e.preventDefault();
978
+ break;
979
+ case 9: // tab
980
+ this.hide();
981
+ break;
982
+ }
983
+ if (dateChanged) {
984
+ this.element.trigger({
985
+ type: 'changeDate',
986
+ date: this.date
987
+ });
988
+ var element;
989
+ if (this.isInput) {
990
+ element = this.element;
991
+ } else if (this.component) {
992
+ element = this.element.find('input');
993
+ }
994
+ if (element) {
995
+ element.change();
996
+ }
997
+ }
998
+ },
999
+
1000
+ showMode: function(dir) {
1001
+
1002
+ if (dir) {
1003
+ var newViewMode = Math.max(0, Math.min(DPGlobal.modes.length - 1, this.viewMode + dir));
1004
+ if (newViewMode >= this.minView && newViewMode <= this.maxView) {
1005
+ this.viewMode = newViewMode;
1006
+ }
1007
+ }
1008
+ /*
1009
+ vitalets: fixing bug of very special conditions:
1010
+ jquery 1.7.1 + webkit + show inline datepicker in bootstrap popover.
1011
+ Method show() does not set display css correctly and datepicker is not shown.
1012
+ Changed to .css('display', 'block') solve the problem.
1013
+ See https://github.com/vitalets/x-editable/issues/37
1014
+
1015
+ In jquery 1.7.2+ everything works fine.
1016
+ */
1017
+ //this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
1018
+ this.picker.find('>div').hide().filter('.datepicker-' + DPGlobal.modes[this.viewMode].clsName).css('display', 'block');
1019
+ this.updateNavArrows();
1020
+ },
1021
+ reset: function(e) {
1022
+ this._setDate(null, 'date');
1023
+ }
1024
+ };
1025
+
1026
+ $.fn.fdatepicker = function(option) {
1027
+ var args = Array.apply(null, arguments);
1028
+ args.shift();
1029
+ return this.each(function() {
1030
+ var $this = $(this),
1031
+ data = $this.data('datepicker'),
1032
+ options = typeof option == 'object' && option;
1033
+ if (!data) {
1034
+ $this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.fdatepicker.defaults, options))));
1035
+ }
1036
+ if (typeof option == 'string' && typeof data[option] == 'function') {
1037
+ data[option].apply(data, args);
1038
+ }
1039
+ });
1040
+ };
1041
+
1042
+ $.fn.fdatepicker.defaults = {
1043
+ onRender: function(date) {
1044
+ return '';
1045
+ }
1046
+ };
1047
+ $.fn.fdatepicker.Constructor = Datepicker;
1048
+ var dates = $.fn.fdatepicker.dates = {
1049
+ 'en': {
1050
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
1051
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
1052
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
1053
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
1054
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
1055
+ today: "Today",
1056
+ titleFormat: "MM yyyy"
1057
+ }
1058
+ };
1059
+
1060
+ var DPGlobal = {
1061
+ modes: [{
1062
+ clsName: 'minutes',
1063
+ navFnc: 'Hours',
1064
+ navStep: 1
1065
+ }, {
1066
+ clsName: 'hours',
1067
+ navFnc: 'Date',
1068
+ navStep: 1
1069
+ }, {
1070
+ clsName: 'days',
1071
+ navFnc: 'Month',
1072
+ navStep: 1
1073
+ }, {
1074
+ clsName: 'months',
1075
+ navFnc: 'FullYear',
1076
+ navStep: 1
1077
+ }, {
1078
+ clsName: 'years',
1079
+ navFnc: 'FullYear',
1080
+ navStep: 10
1081
+ }],
1082
+ isLeapYear: function(year) {
1083
+ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
1084
+ },
1085
+ getDaysInMonth: function(year, month) {
1086
+ return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
1087
+ },
1088
+ validParts: /hh?|ii?|ss?|dd?|mm?|MM?|yy(?:yy)?/g,
1089
+ nonpunctuation: /[^ -\/:-@\[\u3400-\u9fff-`{-~\t\n\r]+/g,
1090
+ parseFormat: function(format) {
1091
+ // IE treats \0 as a string end in inputs (truncating the value),
1092
+ // so it's a bad format delimiter, anyway
1093
+ var separators = format.replace(this.validParts, '\0').split('\0'),
1094
+ parts = format.match(this.validParts);
1095
+ if (!separators || !separators.length || !parts || parts.length === 0) {
1096
+ throw new Error("Invalid date format.");
1097
+ }
1098
+ return {
1099
+ separators: separators,
1100
+ parts: parts
1101
+ };
1102
+ },
1103
+ parseDate: function(date, format, language) {
1104
+ if (date instanceof Date) return new Date(date.valueOf() - date.getTimezoneOffset() * 60000);
1105
+ if (/^\d{4}\-\d{1,2}\-\d{1,2}$/.test(date)) {
1106
+ format = this.parseFormat('yyyy-mm-dd');
1107
+ }
1108
+ if (/^\d{4}\-\d{1,2}\-\d{1,2}[T ]\d{1,2}\:\d{1,2}$/.test(date)) {
1109
+ format = this.parseFormat('yyyy-mm-dd hh:ii');
1110
+ }
1111
+ if (/^\d{4}\-\d{1,2}\-\d{1,2}[T ]\d{1,2}\:\d{1,2}\:\d{1,2}[Z]{0,1}$/.test(date)) {
1112
+ format = this.parseFormat('yyyy-mm-dd hh:ii:ss');
1113
+ }
1114
+ if (/^[-+]\d+[dmwy]([\s,]+[-+]\d+[dmwy])*$/.test(date)) {
1115
+ var part_re = /([-+]\d+)([dmwy])/,
1116
+ parts = date.match(/([-+]\d+)([dmwy])/g),
1117
+ part, dir;
1118
+ date = new Date();
1119
+ for (var i = 0; i < parts.length; i++) {
1120
+ part = part_re.exec(parts[i]);
1121
+ dir = parseInt(part[1]);
1122
+ switch (part[2]) {
1123
+ case 'd':
1124
+ date.setUTCDate(date.getUTCDate() + dir);
1125
+ break;
1126
+ case 'm':
1127
+ date = Datetimepicker.prototype.moveMonth.call(Datetimepicker.prototype, date, dir);
1128
+ break;
1129
+ case 'w':
1130
+ date.setUTCDate(date.getUTCDate() + dir * 7);
1131
+ break;
1132
+ case 'y':
1133
+ date = Datetimepicker.prototype.moveYear.call(Datetimepicker.prototype, date, dir);
1134
+ break;
1135
+ }
1136
+ }
1137
+ return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds());
1138
+ }
1139
+ var parts = date && date.match(this.nonpunctuation) || [],
1140
+ date = new Date(),
1141
+ parsed = {},
1142
+ setters_order = ['hh', 'h', 'ii', 'i', 'ss', 's', 'yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'],
1143
+ setters_map = {
1144
+ hh: function(d, v) {
1145
+ return d.setUTCHours(v);
1146
+ },
1147
+ h: function(d, v) {
1148
+ return d.setUTCHours(v);
1149
+ },
1150
+ ii: function(d, v) {
1151
+ return d.setUTCMinutes(v);
1152
+ },
1153
+ i: function(d, v) {
1154
+ return d.setUTCMinutes(v);
1155
+ },
1156
+ ss: function(d, v) {
1157
+ return d.setUTCSeconds(v);
1158
+ },
1159
+ s: function(d, v) {
1160
+ return d.setUTCSeconds(v);
1161
+ },
1162
+ yyyy: function(d, v) {
1163
+ return d.setUTCFullYear(v);
1164
+ },
1165
+ yy: function(d, v) {
1166
+ return d.setUTCFullYear(2000 + v);
1167
+ },
1168
+ m: function(d, v) {
1169
+ v -= 1;
1170
+ while (v < 0) v += 12;
1171
+ v %= 12;
1172
+ d.setUTCMonth(v);
1173
+ while (d.getUTCMonth() != v)
1174
+ d.setUTCDate(d.getUTCDate() - 1);
1175
+ return d;
1176
+ },
1177
+ d: function(d, v) {
1178
+ return d.setUTCDate(v);
1179
+ }
1180
+ },
1181
+ val, filtered, part;
1182
+ setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
1183
+ setters_map['dd'] = setters_map['d'];
1184
+ date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0); //date.getHours(), date.getMinutes(), date.getSeconds());
1185
+ if (parts.length == format.parts.length) {
1186
+ for (var i = 0, cnt = format.parts.length; i < cnt; i++) {
1187
+ val = parseInt(parts[i], 10);
1188
+ part = format.parts[i];
1189
+ if (isNaN(val)) {
1190
+ switch (part) {
1191
+ case 'MM':
1192
+ filtered = $(dates[language].months).filter(function() {
1193
+ var m = this.slice(0, parts[i].length),
1194
+ p = parts[i].slice(0, m.length);
1195
+ return m == p;
1196
+ });
1197
+ val = $.inArray(filtered[0], dates[language].months) + 1;
1198
+ break;
1199
+ case 'M':
1200
+ filtered = $(dates[language].monthsShort).filter(function() {
1201
+ var m = this.slice(0, parts[i].length),
1202
+ p = parts[i].slice(0, m.length);
1203
+ return m == p;
1204
+ });
1205
+ val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
1206
+ break;
1207
+ }
1208
+ }
1209
+ parsed[part] = val;
1210
+ }
1211
+ for (var i = 0, s; i < setters_order.length; i++) {
1212
+ s = setters_order[i];
1213
+ if (s in parsed && !isNaN(parsed[s]))
1214
+ setters_map[s](date, parsed[s])
1215
+ }
1216
+ }
1217
+ return date;
1218
+ },
1219
+ formatDate: function(date, format, language) {
1220
+ if (date == null) {
1221
+ return '';
1222
+ }
1223
+ var val = {
1224
+ h: date.getUTCHours(),
1225
+ i: date.getUTCMinutes(),
1226
+ s: date.getUTCSeconds(),
1227
+ d: date.getUTCDate(),
1228
+ m: date.getUTCMonth() + 1,
1229
+ M: dates[language].monthsShort[date.getUTCMonth()],
1230
+ MM: dates[language].months[date.getUTCMonth()],
1231
+ yy: date.getUTCFullYear().toString().substring(2),
1232
+ yyyy: date.getUTCFullYear()
1233
+ };
1234
+ val.hh = (val.h < 10 ? '0' : '') + val.h;
1235
+ val.ii = (val.i < 10 ? '0' : '') + val.i;
1236
+ val.ss = (val.s < 10 ? '0' : '') + val.s;
1237
+ val.dd = (val.d < 10 ? '0' : '') + val.d;
1238
+ val.mm = (val.m < 10 ? '0' : '') + val.m;
1239
+ var date = [],
1240
+ seps = $.extend([], format.separators);
1241
+ for (var i = 0, cnt = format.parts.length; i < cnt; i++) {
1242
+ if (seps.length)
1243
+ date.push(seps.shift())
1244
+ date.push(val[format.parts[i]]);
1245
+ }
1246
+ return date.join('');
1247
+ },
1248
+ convertViewMode: function(viewMode) {
1249
+ switch (viewMode) {
1250
+ case 4:
1251
+ case 'decade':
1252
+ viewMode = 4;
1253
+ break;
1254
+ case 3:
1255
+ case 'year':
1256
+ viewMode = 3;
1257
+ break;
1258
+ case 2:
1259
+ case 'month':
1260
+ viewMode = 2;
1261
+ break;
1262
+ case 1:
1263
+ case 'day':
1264
+ viewMode = 1;
1265
+ break;
1266
+ case 0:
1267
+ case 'hour':
1268
+ viewMode = 0;
1269
+ break;
1270
+ }
1271
+
1272
+ return viewMode;
1273
+ },
1274
+ headTemplate: '<thead>' +
1275
+ '<tr>' +
1276
+ '<th class="prev"><i class="fa fa-chevron-left fi-arrow-left"/></th>' +
1277
+ '<th colspan="5" class="date-switch"></th>' +
1278
+ '<th class="next"><i class="fa fa-chevron-right fi-arrow-right"/></th>' +
1279
+ '</tr>' +
1280
+ '</thead>',
1281
+ contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
1282
+ footTemplate: '<tfoot><tr><th colspan="7" class="today"></th></tr></tfoot>'
1283
+ };
1284
+ DPGlobal.template = '<div class="datepicker">' +
1285
+ '<div class="datepicker-minutes">' +
1286
+ '<table class=" table-condensed">' +
1287
+ DPGlobal.headTemplate +
1288
+ DPGlobal.contTemplate +
1289
+ DPGlobal.footTemplate +
1290
+ '</table>' +
1291
+ '</div>' +
1292
+ '<div class="datepicker-hours">' +
1293
+ '<table class=" table-condensed">' +
1294
+ DPGlobal.headTemplate +
1295
+ DPGlobal.contTemplate +
1296
+ DPGlobal.footTemplate +
1297
+ '</table>' +
1298
+ '</div>' +
1299
+ '<div class="datepicker-days">' +
1300
+ '<table class=" table-condensed">' +
1301
+ DPGlobal.headTemplate +
1302
+ '<tbody></tbody>' +
1303
+ DPGlobal.footTemplate +
1304
+ '</table>' +
1305
+ '</div>' +
1306
+ '<div class="datepicker-months">' +
1307
+ '<table class="table-condensed">' +
1308
+ DPGlobal.headTemplate +
1309
+ DPGlobal.contTemplate +
1310
+ DPGlobal.footTemplate +
1311
+ '</table>' +
1312
+ '</div>' +
1313
+ '<div class="datepicker-years">' +
1314
+ '<table class="table-condensed">' +
1315
+ DPGlobal.headTemplate +
1316
+ DPGlobal.contTemplate +
1317
+ DPGlobal.footTemplate +
1318
+ '</table>' +
1319
+ '</div>' +
1320
+ '<a class="button datepicker-close tiny alert right" style="width:auto;"><i class="fa fa-remove fa-times fi-x"></i></a>' +
1321
+ '</div>';
1322
+
1323
+ $.fn.fdatepicker.DPGlobal = DPGlobal;
1324
+
1325
+ }(window.jQuery);