adminpanel 2.6.0 → 2.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07b1d664a1908016dc3c1c6edbfe94ef34d3a436
4
- data.tar.gz: 44347730618eb5d59457e22e6a3e2f0af550e323
3
+ metadata.gz: ac6557850182f084abce57361bae8b4795371062
4
+ data.tar.gz: 2c8c85e621b04e696d4a6d6211a49ead078ec4b2
5
5
  SHA512:
6
- metadata.gz: af9f53879426c218221f0ada55a0f02127b7291e8e468efe5446861fc9c4dcecf245e3d0b6a75113fca2826828579c17f378fb65570a5eceb527c530d3468ef1
7
- data.tar.gz: 54ee0f662db63098ca3b4b0b2ede6a91f491b5c5ab0eb250657aa7a714afdb6f9e3a3342331ab44843708f2e1cbf85721384dca24f3290ef125d0af7e5703874
6
+ metadata.gz: 65accf9535ccf3969b2efe0f0de26495778d9ee22a25b3f661905cc8e5564c6662bdacfec05b341ea42d9520374b913a9cc5772078b155ba65759b8adafce914
7
+ data.tar.gz: 6cef95e0b4dd0b6dd18794965ef97e6f2036fa47e30818c324d9e3478ad8b10da3ed2075df3a23cf4dd0f530b1825c5625ef6d80ab7bc0a732f2e06e8b21f96b
data/adminpanel.gemspec CHANGED
@@ -24,15 +24,15 @@ Gem::Specification.new do |spec|
24
24
  spec.requirements << 'imagemagick installed'
25
25
 
26
26
  spec.add_runtime_dependency 'rails', '>= 4.2.0', '< 5.0.0'
27
- spec.add_runtime_dependency 'mini_magick', '4.1.0'
27
+ spec.add_runtime_dependency 'mini_magick', '4.2.7'
28
28
  spec.add_runtime_dependency 'bcrypt', '~> 3.1', '>= 3.1.7'
29
29
  spec.add_runtime_dependency 'carrierwave', '~> 0.10', '>= 0.10.0'
30
- spec.add_runtime_dependency 'cancancan', '~> 1.10.1','>= 1.10.1'
30
+ spec.add_runtime_dependency 'cancancan', '~> 1.11.0','>= 1.11.0'
31
31
  spec.add_runtime_dependency 'friendly_id', '~> 5.1.0', '>= 5.1.0'
32
32
 
33
33
  # Implemented APIs
34
- spec.add_runtime_dependency 'google-api-client', '0.8.2' # Google analytics
35
- spec.add_runtime_dependency 'instagram', '1.1.3' # Instagram
34
+ spec.add_runtime_dependency 'google-api-client', '~> 0.8.6' # Google analytics
35
+ spec.add_runtime_dependency 'instagram', '~> 1.1.3'
36
36
  spec.add_runtime_dependency 'koala', '1.10.1' # Facebook
37
37
  spec.add_runtime_dependency 'omniauth-twitter', '1.1.0' # login Twitter
38
38
  spec.add_runtime_dependency 'twitter', '5.14.0' # Twitter
@@ -40,8 +40,8 @@ Gem::Specification.new do |spec|
40
40
  # Asset dependencies
41
41
  spec.add_runtime_dependency 'coffee-rails', '~> 4.1.0', '>= 4.1.0'
42
42
  spec.add_runtime_dependency 'font-awesome-rails', '~> 4.2', '>= 4.2.0'
43
- spec.add_runtime_dependency 'jquery-rails', '4.0.3'
44
- spec.add_runtime_dependency 'jquery-ui-rails', '5.0.3'
43
+ spec.add_runtime_dependency 'jquery-rails', '~> 4.0.4', '>= 4.0.4'
44
+ spec.add_runtime_dependency 'jquery-ui-rails', '~> 5.0.5', '>= 5.0.5'
45
45
  spec.add_runtime_dependency 'sass-rails', '~> 5.0.0', '>= 5.0.0'
46
46
  spec.add_runtime_dependency 'turbolinks', '~> 2.5.0', '>= 2.5.2'
47
47
 
@@ -1,1159 +1,1813 @@
1
- /* =========================================================
2
- * bootstrap-datepicker.js
3
- * http://www.eyecon.ro/bootstrap-datepicker
4
- * =========================================================
1
+ /*!
2
+ * Datepicker for Bootstrap v1.5.0-dev (https://github.com/eternicode/bootstrap-datepicker)
3
+ *
5
4
  * Copyright 2012 Stefan Petre
6
5
  * Improvements by Andrew Rowls
7
- *
8
- * Licensed under the Apache License, Version 2.0 (the "License");
9
- * you may not use this file except in compliance with the License.
10
- * You may obtain a copy of the License at
11
- *
12
- * http://www.apache.org/licenses/LICENSE-2.0
13
- *
14
- * Unless required by applicable law or agreed to in writing, software
15
- * distributed under the License is distributed on an "AS IS" BASIS,
16
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
- * See the License for the specific language governing permissions and
18
- * limitations under the License.
19
- * ========================================================= */
20
-
21
- !function( $ ) {
22
-
23
- function UTCDate(){
24
- return new Date(Date.UTC.apply(Date, arguments));
25
- }
26
- function UTCToday(){
27
- var today = new Date();
28
- return UTCDate(today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate());
29
- }
30
-
31
- // Picker object
32
-
33
- var Datepicker = function(element, options) {
34
- var that = this;
35
-
36
- this.element = $(element);
37
- this.language = options.language||this.element.data('date-language')||"en";
38
- 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"
39
- this.language = this.language in dates ? this.language : "en";
40
- this.isRTL = dates[this.language].rtl||false;
41
- this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||dates[this.language].format||'mm/dd/yyyy');
42
- this.isInline = false;
43
- this.isInput = this.element.is('input');
44
- this.component = this.element.is('.date') ? this.element.find('.add-on, .btn') : false;
45
- this.hasInput = this.component && this.element.find('input').length;
46
- if(this.component && this.component.length === 0)
47
- this.component = false;
48
-
49
- this.forceParse = true;
50
- if ('forceParse' in options) {
51
- this.forceParse = options.forceParse;
52
- } else if ('dateForceParse' in this.element.data()) {
53
- this.forceParse = this.element.data('date-force-parse');
54
- }
55
-
56
- this.picker = $(DPGlobal.template);
57
- this._buildEvents();
58
- this._attachEvents();
59
-
60
- if(this.isInline) {
61
- this.picker.addClass('datepicker-inline').appendTo(this.element);
62
- } else {
63
- this.picker.addClass('datepicker-dropdown dropdown-menu');
64
- }
65
- if (this.isRTL){
66
- this.picker.addClass('datepicker-rtl');
67
- this.picker.find('.prev i, .next i')
68
- .toggleClass('fa fa-arrow-left fa fa-arrow-right');
69
- }
70
-
71
- this.autoclose = false;
72
- if ('autoclose' in options) {
73
- this.autoclose = options.autoclose;
74
- } else if ('dateAutoclose' in this.element.data()) {
75
- this.autoclose = this.element.data('date-autoclose');
76
- }
77
-
78
- this.keyboardNavigation = true;
79
- if ('keyboardNavigation' in options) {
80
- this.keyboardNavigation = options.keyboardNavigation;
81
- } else if ('dateKeyboardNavigation' in this.element.data()) {
82
- this.keyboardNavigation = this.element.data('date-keyboard-navigation');
83
- }
84
-
85
- this.viewMode = this.startViewMode = 0;
86
- switch(options.startView || this.element.data('date-start-view')){
87
- case 2:
88
- case 'decade':
89
- this.viewMode = this.startViewMode = 2;
90
- break;
91
- case 1:
92
- case 'year':
93
- this.viewMode = this.startViewMode = 1;
94
- break;
95
- }
96
-
97
- this.minViewMode = options.minViewMode||this.element.data('date-min-view-mode')||0;
98
- if (typeof this.minViewMode === 'string') {
99
- switch (this.minViewMode) {
100
- case 'months':
101
- this.minViewMode = 1;
102
- break;
103
- case 'years':
104
- this.minViewMode = 2;
105
- break;
106
- default:
107
- this.minViewMode = 0;
108
- break;
109
- }
110
- }
111
-
112
- this.viewMode = this.startViewMode = Math.max(this.startViewMode, this.minViewMode);
113
-
114
- this.todayBtn = (options.todayBtn||this.element.data('date-today-btn')||false);
115
- this.todayHighlight = (options.todayHighlight||this.element.data('date-today-highlight')||false);
116
-
117
- this.calendarWeeks = false;
118
- if ('calendarWeeks' in options) {
119
- this.calendarWeeks = options.calendarWeeks;
120
- } else if ('dateCalendarWeeks' in this.element.data()) {
121
- this.calendarWeeks = this.element.data('date-calendar-weeks');
122
- }
123
- if (this.calendarWeeks)
124
- this.picker.find('tfoot th.today')
125
- .attr('colspan', function(i, val){
126
- return parseInt(val) + 1;
127
- });
128
-
129
- this._allow_update = false;
130
-
131
- this.weekStart = ((options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0) % 7);
132
- this.weekEnd = ((this.weekStart + 6) % 7);
133
- this.startDate = -Infinity;
134
- this.endDate = Infinity;
135
- this.daysOfWeekDisabled = [];
136
- this.setStartDate(options.startDate||this.element.data('date-startdate'));
137
- this.setEndDate(options.endDate||this.element.data('date-enddate'));
138
- this.setDaysOfWeekDisabled(options.daysOfWeekDisabled||this.element.data('date-days-of-week-disabled'));
139
- this.fillDow();
140
- this.fillMonths();
141
- this.setRange(options.range);
142
-
143
- this._allow_update = true;
144
-
145
- this.update();
146
- this.showMode();
147
-
148
- if(this.isInline) {
149
- this.show();
150
- }
151
- };
152
-
153
- Datepicker.prototype = {
154
- constructor: Datepicker,
155
-
156
- _events: [],
157
- _secondaryEvents: [],
158
- _applyEvents: function(evs){
159
- for (var i=0, el, ev; i<evs.length; i++){
160
- el = evs[i][0];
161
- ev = evs[i][1];
162
- el.on(ev);
163
- }
164
- },
165
- _unapplyEvents: function(evs){
166
- for (var i=0, el, ev; i<evs.length; i++){
167
- el = evs[i][0];
168
- ev = evs[i][1];
169
- el.off(ev);
170
- }
171
- },
172
- _buildEvents: function(){
173
- if (this.isInput) { // single input
174
- this._events = [
175
- [this.element, {
176
- focus: $.proxy(this.show, this),
177
- keyup: $.proxy(this.update, this),
178
- keydown: $.proxy(this.keydown, this)
179
- }]
180
- ];
181
- }
182
- else if (this.component && this.hasInput){ // component: input + button
183
- this._events = [
184
- // For components that are not readonly, allow keyboard nav
185
- [this.element.find('input'), {
186
- focus: $.proxy(this.show, this),
187
- keyup: $.proxy(this.update, this),
188
- keydown: $.proxy(this.keydown, this)
189
- }],
190
- [this.component, {
191
- click: $.proxy(this.show, this)
192
- }]
193
- ];
194
- }
195
- else if (this.element.is('div')) { // inline datepicker
196
- this.isInline = true;
197
- }
198
- else {
199
- this._events = [
200
- [this.element, {
201
- click: $.proxy(this.show, this)
202
- }]
203
- ];
204
- }
205
-
206
- this._secondaryEvents = [
207
- [this.picker, {
208
- click: $.proxy(this.click, this)
209
- }],
210
- [$(window), {
211
- resize: $.proxy(this.place, this)
212
- }],
213
- [$(document), {
214
- mousedown: $.proxy(function (e) {
215
- // Clicked outside the datepicker, hide it
216
- if ($(e.target).closest('.datepicker.datepicker-inline, .datepicker.datepicker-dropdown').length === 0) {
217
- this.hide();
6
+ * Licensed under the Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0)
7
+ */(function($, undefined){
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.getFullYear(), today.getMonth(), today.getDate());
15
+ }
16
+ function isUTCEquals(date1, date2) {
17
+ return (
18
+ date1.getUTCFullYear() === date2.getUTCFullYear() &&
19
+ date1.getUTCMonth() === date2.getUTCMonth() &&
20
+ date1.getUTCDate() === date2.getUTCDate()
21
+ );
22
+ }
23
+ function alias(method){
24
+ return function(){
25
+ return this[method].apply(this, arguments);
26
+ };
27
+ }
28
+
29
+ var DateArray = (function(){
30
+ var extras = {
31
+ get: function(i){
32
+ return this.slice(i)[0];
33
+ },
34
+ contains: function(d){
35
+ // Array.indexOf is not cross-browser;
36
+ // $.inArray doesn't work with Dates
37
+ var val = d && d.valueOf();
38
+ for (var i=0, l=this.length; i < l; i++)
39
+ if (this[i].valueOf() === val)
40
+ return i;
41
+ return -1;
42
+ },
43
+ remove: function(i){
44
+ this.splice(i,1);
45
+ },
46
+ replace: function(new_array){
47
+ if (!new_array)
48
+ return;
49
+ if (!$.isArray(new_array))
50
+ new_array = [new_array];
51
+ this.clear();
52
+ this.push.apply(this, new_array);
53
+ },
54
+ clear: function(){
55
+ this.length = 0;
56
+ },
57
+ copy: function(){
58
+ var a = new DateArray();
59
+ a.replace(this);
60
+ return a;
61
+ }
62
+ };
63
+
64
+ return function(){
65
+ var a = [];
66
+ a.push.apply(a, arguments);
67
+ $.extend(a, extras);
68
+ return a;
69
+ };
70
+ })();
71
+
72
+
73
+ // Picker object
74
+
75
+ var Datepicker = function(element, options){
76
+ this._process_options(options);
77
+
78
+ this.dates = new DateArray();
79
+ this.viewDate = this.o.defaultViewDate;
80
+ this.focusDate = null;
81
+
82
+ this.element = $(element);
83
+ this.isInline = false;
84
+ this.isInput = this.element.is('input');
85
+ this.component = this.element.hasClass('date') ? this.element.find('.add-on, .input-group-addon, .btn') : false;
86
+ this.hasInput = this.component && this.element.find('input').length;
87
+ if (this.component && this.component.length === 0)
88
+ this.component = false;
89
+
90
+ this.picker = $(DPGlobal.template);
91
+ this._buildEvents();
92
+ this._attachEvents();
93
+
94
+ if (this.isInline){
95
+ this.picker.addClass('datepicker-inline').appendTo(this.element);
96
+ }
97
+ else {
98
+ this.picker.addClass('datepicker-dropdown dropdown-menu');
99
+ }
100
+
101
+ if (this.o.rtl){
102
+ this.picker.addClass('datepicker-rtl');
103
+ }
104
+
105
+ this.viewMode = this.o.startView;
106
+
107
+ if (this.o.calendarWeeks)
108
+ this.picker.find('tfoot .today, tfoot .clear')
109
+ .attr('colspan', function(i, val){
110
+ return parseInt(val) + 1;
111
+ });
112
+
113
+ this._allow_update = false;
114
+
115
+ this.setStartDate(this._o.startDate);
116
+ this.setEndDate(this._o.endDate);
117
+ this.setDaysOfWeekDisabled(this.o.daysOfWeekDisabled);
118
+ this.setDatesDisabled(this.o.datesDisabled);
119
+
120
+ this.fillDow();
121
+ this.fillMonths();
122
+
123
+ this._allow_update = true;
124
+
125
+ this.update();
126
+ this.showMode();
127
+
128
+ if (this.isInline){
129
+ this.show();
130
+ }
131
+ };
132
+
133
+ Datepicker.prototype = {
134
+ constructor: Datepicker,
135
+
136
+ _process_options: function(opts){
137
+ // Store raw options for reference
138
+ this._o = $.extend({}, this._o, opts);
139
+ // Processed options
140
+ var o = this.o = $.extend({}, this._o);
141
+
142
+ // Check if "de-DE" style date is available, if not language should
143
+ // fallback to 2 letter code eg "de"
144
+ var lang = o.language;
145
+ if (!dates[lang]){
146
+ lang = lang.split('-')[0];
147
+ if (!dates[lang])
148
+ lang = defaults.language;
149
+ }
150
+ o.language = lang;
151
+
152
+ switch (o.startView){
153
+ case 2:
154
+ case 'decade':
155
+ o.startView = 2;
156
+ break;
157
+ case 1:
158
+ case 'year':
159
+ o.startView = 1;
160
+ break;
161
+ default:
162
+ o.startView = 0;
163
+ }
164
+
165
+ switch (o.minViewMode){
166
+ case 1:
167
+ case 'months':
168
+ o.minViewMode = 1;
169
+ break;
170
+ case 2:
171
+ case 'years':
172
+ o.minViewMode = 2;
173
+ break;
174
+ default:
175
+ o.minViewMode = 0;
176
+ }
177
+
178
+ o.startView = Math.max(o.startView, o.minViewMode);
179
+
180
+ // true, false, or Number > 0
181
+ if (o.multidate !== true){
182
+ o.multidate = Number(o.multidate) || false;
183
+ if (o.multidate !== false)
184
+ o.multidate = Math.max(0, o.multidate);
185
+ }
186
+ o.multidateSeparator = String(o.multidateSeparator);
187
+
188
+ o.weekStart %= 7;
189
+ o.weekEnd = ((o.weekStart + 6) % 7);
190
+
191
+ var format = DPGlobal.parseFormat(o.format);
192
+ if (o.startDate !== -Infinity){
193
+ if (!!o.startDate){
194
+ if (o.startDate instanceof Date)
195
+ o.startDate = this._local_to_utc(this._zero_time(o.startDate));
196
+ else
197
+ o.startDate = DPGlobal.parseDate(o.startDate, format, o.language);
198
+ }
199
+ else {
200
+ o.startDate = -Infinity;
201
+ }
202
+ }
203
+ if (o.endDate !== Infinity){
204
+ if (!!o.endDate){
205
+ if (o.endDate instanceof Date)
206
+ o.endDate = this._local_to_utc(this._zero_time(o.endDate));
207
+ else
208
+ o.endDate = DPGlobal.parseDate(o.endDate, format, o.language);
209
+ }
210
+ else {
211
+ o.endDate = Infinity;
212
+ }
213
+ }
214
+
215
+ o.daysOfWeekDisabled = o.daysOfWeekDisabled||[];
216
+ if (!$.isArray(o.daysOfWeekDisabled))
217
+ o.daysOfWeekDisabled = o.daysOfWeekDisabled.split(/[,\s]*/);
218
+ o.daysOfWeekDisabled = $.map(o.daysOfWeekDisabled, function(d){
219
+ return parseInt(d, 10);
220
+ });
221
+
222
+ o.datesDisabled = o.datesDisabled||[];
223
+ if (!$.isArray(o.datesDisabled)) {
224
+ var datesDisabled = [];
225
+ datesDisabled.push(DPGlobal.parseDate(o.datesDisabled, format, o.language));
226
+ o.datesDisabled = datesDisabled;
227
+ }
228
+ o.datesDisabled = $.map(o.datesDisabled,function(d){
229
+ return DPGlobal.parseDate(d, format, o.language);
230
+ });
231
+
232
+ var plc = String(o.orientation).toLowerCase().split(/\s+/g),
233
+ _plc = o.orientation.toLowerCase();
234
+ plc = $.grep(plc, function(word){
235
+ return /^auto|left|right|top|bottom$/.test(word);
236
+ });
237
+ o.orientation = {x: 'auto', y: 'auto'};
238
+ if (!_plc || _plc === 'auto')
239
+ ; // no action
240
+ else if (plc.length === 1){
241
+ switch (plc[0]){
242
+ case 'top':
243
+ case 'bottom':
244
+ o.orientation.y = plc[0];
245
+ break;
246
+ case 'left':
247
+ case 'right':
248
+ o.orientation.x = plc[0];
249
+ break;
250
+ }
251
+ }
252
+ else {
253
+ _plc = $.grep(plc, function(word){
254
+ return /^left|right$/.test(word);
255
+ });
256
+ o.orientation.x = _plc[0] || 'auto';
257
+
258
+ _plc = $.grep(plc, function(word){
259
+ return /^top|bottom$/.test(word);
260
+ });
261
+ o.orientation.y = _plc[0] || 'auto';
262
+ }
263
+ if (o.defaultViewDate) {
264
+ var year = o.defaultViewDate.year || new Date().getFullYear();
265
+ var month = o.defaultViewDate.month || 0;
266
+ var day = o.defaultViewDate.day || 1;
267
+ o.defaultViewDate = UTCDate(year, month, day);
268
+ } else {
269
+ o.defaultViewDate = UTCToday();
270
+ }
271
+ o.showOnFocus = o.showOnFocus !== undefined ? o.showOnFocus : true;
272
+ },
273
+ _events: [],
274
+ _secondaryEvents: [],
275
+ _applyEvents: function(evs){
276
+ for (var i=0, el, ch, ev; i < evs.length; i++){
277
+ el = evs[i][0];
278
+ if (evs[i].length === 2){
279
+ ch = undefined;
280
+ ev = evs[i][1];
281
+ }
282
+ else if (evs[i].length === 3){
283
+ ch = evs[i][1];
284
+ ev = evs[i][2];
285
+ }
286
+ el.on(ev, ch);
287
+ }
288
+ },
289
+ _unapplyEvents: function(evs){
290
+ for (var i=0, el, ev, ch; i < evs.length; i++){
291
+ el = evs[i][0];
292
+ if (evs[i].length === 2){
293
+ ch = undefined;
294
+ ev = evs[i][1];
295
+ }
296
+ else if (evs[i].length === 3){
297
+ ch = evs[i][1];
298
+ ev = evs[i][2];
299
+ }
300
+ el.off(ev, ch);
301
+ }
302
+ },
303
+ _buildEvents: function(){
304
+ var events = {
305
+ keyup: $.proxy(function(e){
306
+ if ($.inArray(e.keyCode, [27, 37, 39, 38, 40, 32, 13, 9]) === -1)
307
+ this.update();
308
+ }, this),
309
+ keydown: $.proxy(this.keydown, this),
310
+ paste: $.proxy(this.paste, this)
311
+ };
312
+
313
+ if (this.o.showOnFocus === true) {
314
+ events.focus = $.proxy(this.show, this);
218
315
  }
219
- }, this)
220
- }]
221
- ];
222
- },
223
- _attachEvents: function(){
224
- this._detachEvents();
225
- this._applyEvents(this._events);
226
- },
227
- _detachEvents: function(){
228
- this._unapplyEvents(this._events);
229
- },
230
- _attachSecondaryEvents: function(){
231
- this._detachSecondaryEvents();
232
- this._applyEvents(this._secondaryEvents);
233
- },
234
- _detachSecondaryEvents: function(){
235
- this._unapplyEvents(this._secondaryEvents);
236
- },
237
-
238
- show: function(e) {
239
- if (!this.isInline)
240
- this.picker.appendTo('body');
241
- this.picker.show();
242
- this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
243
- this.place();
244
- this._attachSecondaryEvents();
245
- if (e) {
246
- e.preventDefault();
247
- }
248
- this.element.trigger({
249
- type: 'show',
250
- date: this.date
251
- });
252
- },
253
-
254
- hide: function(e){
255
- if(this.isInline) return;
256
- if (!this.picker.is(':visible')) return;
257
- this.picker.hide().detach();
258
- this._detachSecondaryEvents();
259
- this.viewMode = this.startViewMode;
260
- this.showMode();
261
-
262
- if (
263
- this.forceParse &&
264
- (
265
- this.isInput && this.element.val() ||
266
- this.hasInput && this.element.find('input').val()
267
- )
268
- )
269
- this.setValue();
270
- this.element.trigger({
271
- type: 'hide',
272
- date: this.date
273
- });
274
- },
275
-
276
- remove: function() {
277
- this.hide();
278
- this._detachEvents();
279
- this._detachSecondaryEvents();
280
- this.picker.remove();
281
- delete this.element.data().datepicker;
282
- if (!this.isInput) {
283
- delete this.element.data().date;
284
- }
285
- },
286
-
287
- getDate: function() {
288
- var d = this.getUTCDate();
289
- return new Date(d.getTime() + (d.getTimezoneOffset()*60000));
290
- },
291
-
292
- getUTCDate: function() {
293
- return this.date;
294
- },
295
-
296
- setDate: function(d) {
297
- this.setUTCDate(new Date(d.getTime() - (d.getTimezoneOffset()*60000)));
298
- },
299
-
300
- setUTCDate: function(d) {
301
- this.date = d;
302
- this.setValue();
303
- },
304
-
305
- setValue: function() {
306
- var formatted = this.getFormattedDate();
307
- if (!this.isInput) {
308
- if (this.component){
309
- this.element.find('input').val(formatted);
310
- }
311
- } else {
312
- this.element.val(formatted);
313
- }
314
- },
315
-
316
- getFormattedDate: function(format) {
317
- if (format === undefined)
318
- format = this.format;
319
- return DPGlobal.formatDate(this.date, format, this.language);
320
- },
321
-
322
- setStartDate: function(startDate){
323
- this.startDate = startDate||-Infinity;
324
- if (this.startDate !== -Infinity) {
325
- this.startDate = DPGlobal.parseDate(this.startDate, this.format, this.language);
326
- }
327
- this.update();
328
- this.updateNavArrows();
329
- },
330
-
331
- setEndDate: function(endDate){
332
- this.endDate = endDate||Infinity;
333
- if (this.endDate !== Infinity) {
334
- this.endDate = DPGlobal.parseDate(this.endDate, this.format, this.language);
335
- }
336
- this.update();
337
- this.updateNavArrows();
338
- },
339
-
340
- setDaysOfWeekDisabled: function(daysOfWeekDisabled){
341
- this.daysOfWeekDisabled = daysOfWeekDisabled||[];
342
- if (!$.isArray(this.daysOfWeekDisabled)) {
343
- this.daysOfWeekDisabled = this.daysOfWeekDisabled.split(/,\s*/);
344
- }
345
- this.daysOfWeekDisabled = $.map(this.daysOfWeekDisabled, function (d) {
346
- return parseInt(d, 10);
347
- });
348
- this.update();
349
- this.updateNavArrows();
350
- },
351
-
352
- place: function(){
353
- if(this.isInline) return;
354
- var zIndex = parseInt(this.element.parents().filter(function() {
355
- return $(this).css('z-index') != 'auto';
356
- }).first().css('z-index'))+10;
357
- var offset = this.component ? this.component.parent().offset() : this.element.offset();
358
- var height = this.component ? this.component.outerHeight(true) : this.element.outerHeight(true);
359
- this.picker.css({
360
- top: offset.top + height,
361
- left: offset.left,
362
- zIndex: zIndex
363
- });
364
- },
365
-
366
- _allow_update: true,
367
- update: function(){
368
- if (!this._allow_update) return;
369
-
370
- var date, fromArgs = false;
371
- if(arguments && arguments.length && (typeof arguments[0] === 'string' || arguments[0] instanceof Date)) {
372
- date = arguments[0];
373
- fromArgs = true;
374
- } else {
375
- date = this.isInput ? this.element.val() : this.element.data('date') || this.element.find('input').val();
376
- delete this.element.data().date;
377
- }
378
-
379
- this.date = DPGlobal.parseDate(date, this.format, this.language);
380
-
381
- if(fromArgs) this.setValue();
382
-
383
- if (this.date < this.startDate) {
384
- this.viewDate = new Date(this.startDate);
385
- } else if (this.date > this.endDate) {
386
- this.viewDate = new Date(this.endDate);
387
- } else {
388
- this.viewDate = new Date(this.date);
389
- }
390
- this.fill();
391
- },
392
-
393
- fillDow: function(){
394
- var dowCnt = this.weekStart,
395
- html = '<tr>';
396
- if(this.calendarWeeks){
397
- var cell = '<th class="cw">&nbsp;</th>';
398
- html += cell;
399
- this.picker.find('.datepicker-days thead tr:first-child').prepend(cell);
400
- }
401
- while (dowCnt < this.weekStart + 7) {
402
- html += '<th class="dow">'+dates[this.language].daysMin[(dowCnt++)%7]+'</th>';
403
- }
404
- html += '</tr>';
405
- this.picker.find('.datepicker-days thead').append(html);
406
- },
407
-
408
- fillMonths: function(){
409
- var html = '',
410
- i = 0;
411
- while (i < 12) {
412
- html += '<span class="month">'+dates[this.language].monthsShort[i++]+'</span>';
413
- }
414
- this.picker.find('.datepicker-months td').html(html);
415
- },
416
-
417
- setRange: function(range){
418
- if (!range || !range.length)
419
- delete this.range;
420
- else
421
- this.range = $.map(range, function(d){ return d.valueOf(); });
422
- this.fill();
423
- },
424
-
425
- getClassNames: function(date){
426
- var cls = [],
427
- year = this.viewDate.getUTCFullYear(),
428
- month = this.viewDate.getUTCMonth(),
429
- currentDate = this.date.valueOf(),
430
- today = new Date();
431
- if (date.getUTCFullYear() < year || (date.getUTCFullYear() == year && date.getUTCMonth() < month)) {
432
- cls.push('old');
433
- } else if (date.getUTCFullYear() > year || (date.getUTCFullYear() == year && date.getUTCMonth() > month)) {
434
- cls.push('new');
435
- }
436
- // Compare internal UTC date with local today, not UTC today
437
- if (this.todayHighlight &&
438
- date.getUTCFullYear() == today.getFullYear() &&
439
- date.getUTCMonth() == today.getMonth() &&
440
- date.getUTCDate() == today.getDate()) {
441
- cls.push('today');
442
- }
443
- if (currentDate && date.valueOf() == currentDate) {
444
- cls.push('active');
445
- }
446
- if (date.valueOf() < this.startDate || date.valueOf() > this.endDate ||
447
- $.inArray(date.getUTCDay(), this.daysOfWeekDisabled) !== -1) {
448
- cls.push('disabled');
449
- }
450
- if (this.range){
451
- if (date > this.range[0] && date < this.range[this.range.length-1]){
452
- cls.push('range');
453
- }
454
- if ($.inArray(date.valueOf(), this.range) != -1){
455
- cls.push('selected');
456
- }
457
- }
458
- return cls;
459
- },
460
-
461
- fill: function() {
462
- var d = new Date(this.viewDate),
463
- year = d.getUTCFullYear(),
464
- month = d.getUTCMonth(),
465
- startYear = this.startDate !== -Infinity ? this.startDate.getUTCFullYear() : -Infinity,
466
- startMonth = this.startDate !== -Infinity ? this.startDate.getUTCMonth() : -Infinity,
467
- endYear = this.endDate !== Infinity ? this.endDate.getUTCFullYear() : Infinity,
468
- endMonth = this.endDate !== Infinity ? this.endDate.getUTCMonth() : Infinity,
469
- currentDate = this.date && this.date.valueOf();
470
- this.picker.find('.datepicker-days thead th.datepicker-switch')
471
- .text(dates[this.language].months[month]+' '+year);
472
- this.picker.find('tfoot th.today')
473
- .text(dates[this.language].today)
474
- .toggle(this.todayBtn !== false);
475
- this.updateNavArrows();
476
- this.fillMonths();
477
- var prevMonth = UTCDate(year, month-1, 28,0,0,0,0),
478
- day = DPGlobal.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
479
- prevMonth.setUTCDate(day);
480
- prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7)%7);
481
- var nextMonth = new Date(prevMonth);
482
- nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
483
- nextMonth = nextMonth.valueOf();
484
- var html = [];
485
- var clsName;
486
- while(prevMonth.valueOf() < nextMonth) {
487
- if (prevMonth.getUTCDay() == this.weekStart) {
488
- html.push('<tr>');
489
- if(this.calendarWeeks){
490
- // ISO 8601: First week contains first thursday.
491
- // ISO also states week starts on Monday, but we can be more abstract here.
492
- var
493
- // Start of current week: based on weekstart/current date
494
- ws = new Date(+prevMonth + (this.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
495
- // Thursday of this week
496
- th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
497
- // First Thursday of year, year from thursday
498
- yth = new Date(+(yth = UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
499
- // Calendar week: ms between thursdays, div ms per day, div 7 days
500
- calWeek = (th - yth) / 864e5 / 7 + 1;
501
- html.push('<td class="cw">'+ calWeek +'</td>');
502
-
503
- }
504
- }
505
- clsName = this.getClassNames(prevMonth);
506
- clsName.push('day');
507
- html.push('<td class="'+clsName.join(' ')+'">'+prevMonth.getUTCDate() + '</td>');
508
- if (prevMonth.getUTCDay() == this.weekEnd) {
509
- html.push('</tr>');
510
- }
511
- prevMonth.setUTCDate(prevMonth.getUTCDate()+1);
512
- }
513
- this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
514
- var currentYear = this.date && this.date.getUTCFullYear();
515
-
516
- var months = this.picker.find('.datepicker-months')
517
- .find('th:eq(1)')
518
- .text(year)
519
- .end()
520
- .find('span').removeClass('active');
521
- if (currentYear && currentYear == year) {
522
- months.eq(this.date.getUTCMonth()).addClass('active');
523
- }
524
- if (year < startYear || year > endYear) {
525
- months.addClass('disabled');
526
- }
527
- if (year == startYear) {
528
- months.slice(0, startMonth).addClass('disabled');
529
- }
530
- if (year == endYear) {
531
- months.slice(endMonth+1).addClass('disabled');
532
- }
533
-
534
- html = '';
535
- year = parseInt(year/10, 10) * 10;
536
- var yearCont = this.picker.find('.datepicker-years')
537
- .find('th:eq(1)')
538
- .text(year + '-' + (year + 9))
539
- .end()
540
- .find('td');
541
- year -= 1;
542
- for (var i = -1; i < 11; i++) {
543
- html += '<span class="year'+(i == -1 || i == 10 ? ' old' : '')+(currentYear == year ? ' active' : '')+(year < startYear || year > endYear ? ' disabled' : '')+'">'+year+'</span>';
544
- year += 1;
545
- }
546
- yearCont.html(html);
547
- },
548
-
549
- updateNavArrows: function() {
550
- if (!this._allow_update) return;
551
-
552
- var d = new Date(this.viewDate),
553
- year = d.getUTCFullYear(),
554
- month = d.getUTCMonth();
555
- switch (this.viewMode) {
556
- case 0:
557
- if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear() && month <= this.startDate.getUTCMonth()) {
558
- this.picker.find('.prev').css({visibility: 'hidden'});
559
- } else {
560
- this.picker.find('.prev').css({visibility: 'visible'});
561
- }
562
- if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear() && month >= this.endDate.getUTCMonth()) {
563
- this.picker.find('.next').css({visibility: 'hidden'});
564
- } else {
565
- this.picker.find('.next').css({visibility: 'visible'});
566
- }
567
- break;
568
- case 1:
569
- case 2:
570
- if (this.startDate !== -Infinity && year <= this.startDate.getUTCFullYear()) {
571
- this.picker.find('.prev').css({visibility: 'hidden'});
572
- } else {
573
- this.picker.find('.prev').css({visibility: 'visible'});
574
- }
575
- if (this.endDate !== Infinity && year >= this.endDate.getUTCFullYear()) {
576
- this.picker.find('.next').css({visibility: 'hidden'});
577
- } else {
578
- this.picker.find('.next').css({visibility: 'visible'});
579
- }
580
- break;
581
- }
582
- },
583
-
584
- click: function(e) {
585
- e.preventDefault();
586
- var target = $(e.target).closest('span, td, th');
587
- if (target.length == 1) {
588
- switch(target[0].nodeName.toLowerCase()) {
589
- case 'th':
590
- switch(target[0].className) {
591
- case 'datepicker-switch':
592
- this.showMode(1);
593
- break;
594
- case 'prev':
595
- case 'next':
596
- var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1);
597
- switch(this.viewMode){
598
- case 0:
599
- this.viewDate = this.moveMonth(this.viewDate, dir);
600
- break;
601
- case 1:
602
- case 2:
603
- this.viewDate = this.moveYear(this.viewDate, dir);
604
- break;
605
- }
606
- this.fill();
607
- break;
608
- case 'today':
609
- var date = new Date();
610
- date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
611
-
612
- this.showMode(-2);
613
- var which = this.todayBtn == 'linked' ? null : 'view';
614
- this._setDate(date, which);
615
- break;
616
- }
617
- break;
618
- case 'span':
619
- if (!target.is('.disabled')) {
620
- this.viewDate.setUTCDate(1);
621
- if (target.is('.month')) {
622
- var day = 1;
623
- var month = target.parent().find('span').index(target);
624
- var year = this.viewDate.getUTCFullYear();
625
- this.viewDate.setUTCMonth(month);
626
- this.element.trigger({
627
- type: 'changeMonth',
628
- date: this.viewDate
629
- });
630
- if ( this.minViewMode == 1 ) {
631
- this._setDate(UTCDate(year, month, day,0,0,0,0));
632
- }
633
- } else {
634
- var year = parseInt(target.text(), 10)||0;
635
- var day = 1;
636
- var month = 0;
637
- this.viewDate.setUTCFullYear(year);
638
- this.element.trigger({
639
- type: 'changeYear',
640
- date: this.viewDate
641
- });
642
- if ( this.minViewMode == 2 ) {
643
- this._setDate(UTCDate(year, month, day,0,0,0,0));
644
- }
645
- }
646
- this.showMode(-1);
647
- this.fill();
648
- }
649
- break;
650
- case 'td':
651
- if (target.is('.day') && !target.is('.disabled')){
652
- var day = parseInt(target.text(), 10)||1;
653
- var year = this.viewDate.getUTCFullYear(),
654
- month = this.viewDate.getUTCMonth();
655
- if (target.is('.old')) {
656
- if (month === 0) {
657
- month = 11;
658
- year -= 1;
659
- } else {
660
- month -= 1;
661
- }
662
- } else if (target.is('.new')) {
663
- if (month == 11) {
664
- month = 0;
665
- year += 1;
666
- } else {
667
- month += 1;
668
- }
669
- }
670
- this._setDate(UTCDate(year, month, day,0,0,0,0));
316
+
317
+ if (this.isInput) { // single input
318
+ this._events = [
319
+ [this.element, events]
320
+ ];
671
321
  }
672
- break;
673
- }
674
- }
675
- },
676
-
677
- _setDate: function(date, which){
678
- if (!which || which == 'date')
679
- this.date = date;
680
- if (!which || which == 'view')
681
- this.viewDate = date;
682
- this.fill();
683
- this.setValue();
684
- this.element.trigger({
685
- type: 'changeDate',
686
- date: this.date
687
- });
688
- var element;
689
- if (this.isInput) {
690
- element = this.element;
691
- } else if (this.component){
692
- element = this.element.find('input');
693
- }
694
- if (element) {
695
- element.change();
696
- if (this.autoclose && (!which || which == 'date')) {
697
- this.hide();
698
- }
699
- }
700
- },
701
-
702
- moveMonth: function(date, dir){
703
- if (!dir) return date;
704
- var new_date = new Date(date.valueOf()),
705
- day = new_date.getUTCDate(),
706
- month = new_date.getUTCMonth(),
707
- mag = Math.abs(dir),
708
- new_month, test;
709
- dir = dir > 0 ? 1 : -1;
710
- if (mag == 1){
711
- test = dir == -1
712
- // If going back one month, make sure month is not current month
713
- // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
714
- ? function(){ return new_date.getUTCMonth() == month; }
715
- // If going forward one month, make sure month is as expected
716
- // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
717
- : function(){ return new_date.getUTCMonth() != new_month; };
718
- new_month = month + dir;
719
- new_date.setUTCMonth(new_month);
720
- // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
721
- if (new_month < 0 || new_month > 11)
722
- new_month = (new_month + 12) % 12;
723
- } else {
724
- // For magnitudes >1, move one month at a time...
725
- for (var i=0; i<mag; i++)
726
- // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
727
- new_date = this.moveMonth(new_date, dir);
728
- // ...then reset the day, keeping it in the new month
729
- new_month = new_date.getUTCMonth();
730
- new_date.setUTCDate(day);
731
- test = function(){ return new_month != new_date.getUTCMonth(); };
732
- }
733
- // Common date-resetting loop -- if date is beyond end of month, make it
734
- // end of month
735
- while (test()){
736
- new_date.setUTCDate(--day);
737
- new_date.setUTCMonth(new_month);
738
- }
739
- return new_date;
740
- },
741
-
742
- moveYear: function(date, dir){
743
- return this.moveMonth(date, dir*12);
744
- },
745
-
746
- dateWithinRange: function(date){
747
- return date >= this.startDate && date <= this.endDate;
748
- },
749
-
750
- keydown: function(e){
751
- if (this.picker.is(':not(:visible)')){
752
- if (e.keyCode == 27) // allow escape to hide and re-show picker
753
- this.show();
754
- return;
755
- }
756
- var dateChanged = false,
757
- dir, day, month,
758
- newDate, newViewDate;
759
- switch(e.keyCode){
760
- case 27: // escape
761
- this.hide();
762
- e.preventDefault();
763
- break;
764
- case 37: // left
765
- case 39: // right
766
- if (!this.keyboardNavigation) break;
767
- dir = e.keyCode == 37 ? -1 : 1;
768
- if (e.ctrlKey){
769
- newDate = this.moveYear(this.date, dir);
770
- newViewDate = this.moveYear(this.viewDate, dir);
771
- } else if (e.shiftKey){
772
- newDate = this.moveMonth(this.date, dir);
773
- newViewDate = this.moveMonth(this.viewDate, dir);
774
- } else {
775
- newDate = new Date(this.date);
776
- newDate.setUTCDate(this.date.getUTCDate() + dir);
777
- newViewDate = new Date(this.viewDate);
778
- newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir);
779
- }
780
- if (this.dateWithinRange(newDate)){
781
- this.date = newDate;
782
- this.viewDate = newViewDate;
783
- this.setValue();
784
- this.update();
785
- e.preventDefault();
786
- dateChanged = true;
787
- }
788
- break;
789
- case 38: // up
790
- case 40: // down
791
- if (!this.keyboardNavigation) break;
792
- dir = e.keyCode == 38 ? -1 : 1;
793
- if (e.ctrlKey){
794
- newDate = this.moveYear(this.date, dir);
795
- newViewDate = this.moveYear(this.viewDate, dir);
796
- } else if (e.shiftKey){
797
- newDate = this.moveMonth(this.date, dir);
798
- newViewDate = this.moveMonth(this.viewDate, dir);
799
- } else {
800
- newDate = new Date(this.date);
801
- newDate.setUTCDate(this.date.getUTCDate() + dir * 7);
802
- newViewDate = new Date(this.viewDate);
803
- newViewDate.setUTCDate(this.viewDate.getUTCDate() + dir * 7);
804
- }
805
- if (this.dateWithinRange(newDate)){
806
- this.date = newDate;
807
- this.viewDate = newViewDate;
808
- this.setValue();
809
- this.update();
810
- e.preventDefault();
811
- dateChanged = true;
812
- }
813
- break;
814
- case 13: // enter
815
- this.hide();
816
- e.preventDefault();
817
- break;
818
- case 9: // tab
819
- this.hide();
820
- break;
821
- }
822
- if (dateChanged){
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
- }
836
- }
837
- },
838
-
839
- showMode: function(dir) {
840
- if (dir) {
841
- this.viewMode = Math.max(this.minViewMode, Math.min(2, this.viewMode + dir));
842
- }
843
- /*
844
- vitalets: fixing bug of very special conditions:
845
- jquery 1.7.1 + webkit + show inline datepicker in bootstrap popover.
846
- Method show() does not set display css correctly and datepicker is not shown.
847
- Changed to .css('display', 'block') solve the problem.
848
- See https://github.com/vitalets/x-editable/issues/37
849
-
850
- In jquery 1.7.2+ everything works fine.
851
- */
852
- //this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
853
- this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).css('display', 'block');
854
- this.updateNavArrows();
855
- }
856
- };
857
-
858
- var DateRangePicker = function(element, options){
859
- this.element = $(element);
860
- this.inputs = $.map(options.inputs, function(i){ return i.jquery ? i[0] : i; });
861
- delete options.inputs;
862
-
863
- $(this.inputs)
864
- .datepicker(options)
865
- .bind('changeDate', $.proxy(this.dateUpdated, this));
866
-
867
- this.pickers = $.map(this.inputs, function(i){ return $(i).data('datepicker'); });
868
- this.updateDates();
869
- };
870
- DateRangePicker.prototype = {
871
- updateDates: function(){
872
- this.dates = $.map(this.pickers, function(i){ return i.date; });
873
- this.updateRanges();
874
- },
875
- updateRanges: function(){
876
- var range = $.map(this.dates, function(d){ return d.valueOf(); });
877
- $.each(this.pickers, function(i, p){
878
- p.setRange(range);
879
- });
880
- },
881
- dateUpdated: function(e){
882
- var dp = $(e.target).data('datepicker'),
883
- new_date = e.date,
884
- i = $.inArray(e.target, this.inputs),
885
- l = this.inputs.length;
886
- if (i == -1) return;
887
-
888
- if (new_date < this.dates[i]){
889
- // Date being moved earlier/left
890
- while (i>=0 && new_date < this.dates[i]){
891
- this.pickers[i--].setUTCDate(new_date);
892
- }
893
- }
894
- else if (new_date > this.dates[i]){
895
- // Date being moved later/right
896
- while (i<l && new_date > this.dates[i]){
897
- this.pickers[i++].setUTCDate(new_date);
898
- }
899
- }
900
- this.updateDates();
901
- },
902
- remove: function(){
903
- $.map(this.pickers, function(p){ p.remove(); });
904
- delete this.element.data().datepicker;
905
- }
906
- };
907
-
908
- var old = $.fn.datepicker;
909
- $.fn.datepicker = function ( option ) {
910
- var args = Array.apply(null, arguments);
911
- args.shift();
912
- return this.each(function () {
913
- var $this = $(this),
914
- data = $this.data('datepicker'),
915
- options = typeof option == 'object' && option;
916
- if (!data) {
917
- if ($this.is('.input-daterange') || options.inputs){
918
- var opts = {
919
- inputs: options.inputs || $this.find('input').toArray()
920
- };
921
- $this.data('datepicker', (data = new DateRangePicker(this, $.extend(opts, $.fn.datepicker.defaults,options))));
922
- }
923
- else{
924
- $this.data('datepicker', (data = new Datepicker(this, $.extend({}, $.fn.datepicker.defaults,options))));
925
- }
926
- }
927
- if (typeof option == 'string' && typeof data[option] == 'function') {
928
- data[option].apply(data, args);
929
- }
930
- });
931
- };
932
-
933
- $.fn.datepicker.defaults = {
934
- };
935
- $.fn.datepicker.Constructor = Datepicker;
936
- var dates = $.fn.datepicker.dates = {
937
- en: {
938
- days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
939
- daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
940
- daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
941
- months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
942
- monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
943
- today: "Today"
944
- }
945
- };
946
-
947
- var DPGlobal = {
948
- modes: [
949
- {
950
- clsName: 'days',
951
- navFnc: 'Month',
952
- navStep: 1
953
- },
954
- {
955
- clsName: 'months',
956
- navFnc: 'FullYear',
957
- navStep: 1
958
- },
959
- {
960
- clsName: 'years',
961
- navFnc: 'FullYear',
962
- navStep: 10
963
- }],
964
- isLeapYear: function (year) {
965
- return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
966
- },
967
- getDaysInMonth: function (year, month) {
968
- return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
969
- },
970
- validParts: /dd?|DD?|mm?|MM?|yy(?:yy)?/g,
971
- nonpunctuation: /[^ -\/:-@\[\u3400-\u9fff-`{-~\t\n\r]+/g,
972
- parseFormat: function(format){
973
- // IE treats \0 as a string end in inputs (truncating the value),
974
- // so it's a bad format delimiter, anyway
975
- var separators = format.replace(this.validParts, '\0').split('\0'),
976
- parts = format.match(this.validParts);
977
- if (!separators || !separators.length || !parts || parts.length === 0){
978
- throw new Error("Invalid date format.");
979
- }
980
- return {separators: separators, parts: parts};
981
- },
982
- parseDate: function(date, format, language) {
983
- if (date instanceof Date) return date;
984
- if (/^[\-+]\d+[dmwy]([\s,]+[\-+]\d+[dmwy])*$/.test(date)) {
985
- var part_re = /([\-+]\d+)([dmwy])/,
986
- parts = date.match(/([\-+]\d+)([dmwy])/g),
987
- part, dir;
988
- date = new Date();
989
- for (var i=0; i<parts.length; i++) {
990
- part = part_re.exec(parts[i]);
991
- dir = parseInt(part[1]);
992
- switch(part[2]){
993
- case 'd':
994
- date.setUTCDate(date.getUTCDate() + dir);
995
- break;
996
- case 'm':
997
- date = Datepicker.prototype.moveMonth.call(Datepicker.prototype, date, dir);
998
- break;
999
- case 'w':
1000
- date.setUTCDate(date.getUTCDate() + dir * 7);
1001
- break;
1002
- case 'y':
1003
- date = Datepicker.prototype.moveYear.call(Datepicker.prototype, date, dir);
1004
- break;
1005
- }
1006
- }
1007
- return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 0, 0, 0);
1008
- }
1009
- var parts = date && date.match(this.nonpunctuation) || [],
1010
- date = new Date(),
1011
- parsed = {},
1012
- setters_order = ['yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'],
1013
- setters_map = {
1014
- yyyy: function(d,v){ return d.setUTCFullYear(v); },
1015
- yy: function(d,v){ return d.setUTCFullYear(2000+v); },
1016
- m: function(d,v){
1017
- v -= 1;
1018
- while (v<0) v += 12;
1019
- v %= 12;
1020
- d.setUTCMonth(v);
1021
- while (d.getUTCMonth() != v)
1022
- d.setUTCDate(d.getUTCDate()-1);
1023
- return d;
1024
- },
1025
- d: function(d,v){ return d.setUTCDate(v); }
1026
- },
1027
- val, filtered, part;
1028
- setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
1029
- setters_map['dd'] = setters_map['d'];
1030
- date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
1031
- var fparts = format.parts.slice();
1032
- // Remove noop parts
1033
- if (parts.length != fparts.length) {
1034
- fparts = $(fparts).filter(function(i,p){
1035
- return $.inArray(p, setters_order) !== -1;
1036
- }).toArray();
1037
- }
1038
- // Process remainder
1039
- if (parts.length == fparts.length) {
1040
- for (var i=0, cnt = fparts.length; i < cnt; i++) {
1041
- val = parseInt(parts[i], 10);
1042
- part = fparts[i];
1043
- if (isNaN(val)) {
1044
- switch(part) {
1045
- case 'MM':
1046
- filtered = $(dates[language].months).filter(function(){
1047
- var m = this.slice(0, parts[i].length),
1048
- p = parts[i].slice(0, m.length);
1049
- return m == p;
1050
- });
1051
- val = $.inArray(filtered[0], dates[language].months) + 1;
1052
- break;
1053
- case 'M':
1054
- filtered = $(dates[language].monthsShort).filter(function(){
1055
- var m = this.slice(0, parts[i].length),
1056
- p = parts[i].slice(0, m.length);
1057
- return m == p;
1058
- });
1059
- val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
1060
- break;
322
+ else if (this.component && this.hasInput) { // component: input + button
323
+ this._events = [
324
+ // For components that are not readonly, allow keyboard nav
325
+ [this.element.find('input'), events],
326
+ [this.component, {
327
+ click: $.proxy(this.show, this)
328
+ }]
329
+ ];
1061
330
  }
1062
- }
1063
- parsed[part] = val;
1064
- }
1065
- for (var i=0, s; i<setters_order.length; i++){
1066
- s = setters_order[i];
1067
- if (s in parsed && !isNaN(parsed[s]))
1068
- setters_map[s](date, parsed[s]);
1069
- }
1070
- }
1071
- return date;
1072
- },
1073
- formatDate: function(date, format, language){
1074
- var val = {
1075
- d: date.getUTCDate(),
1076
- D: dates[language].daysShort[date.getUTCDay()],
1077
- DD: dates[language].days[date.getUTCDay()],
1078
- m: date.getUTCMonth() + 1,
1079
- M: dates[language].monthsShort[date.getUTCMonth()],
1080
- MM: dates[language].months[date.getUTCMonth()],
1081
- yy: date.getUTCFullYear().toString().substring(2),
1082
- yyyy: date.getUTCFullYear()
1083
- };
1084
- val.dd = (val.d < 10 ? '0' : '') + val.d;
1085
- val.mm = (val.m < 10 ? '0' : '') + val.m;
1086
- var date = [],
1087
- seps = $.extend([], format.separators);
1088
- for (var i=0, cnt = format.parts.length; i < cnt; i++) {
1089
- if (seps.length)
1090
- date.push(seps.shift());
1091
- date.push(val[format.parts[i]]);
1092
- }
1093
- return date.join('');
1094
- },
1095
- headTemplate: '<thead>'+
1096
- '<tr>'+
1097
- '<th class="prev"><i class="fa fa-arrow-left"/></th>'+
1098
- '<th colspan="5" class="datepicker-switch"></th>'+
1099
- '<th class="next"><i class="fa fa-arrow-right"/></th>'+
1100
- '</tr>'+
1101
- '</thead>',
1102
- contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
1103
- footTemplate: '<tfoot><tr><th colspan="7" class="today"></th></tr></tfoot>'
1104
- };
1105
- DPGlobal.template = '<div class="datepicker">'+
1106
- '<div class="datepicker-days">'+
1107
- '<table class=" table-condensed">'+
1108
- DPGlobal.headTemplate+
1109
- '<tbody></tbody>'+
1110
- DPGlobal.footTemplate+
1111
- '</table>'+
1112
- '</div>'+
1113
- '<div class="datepicker-months">'+
1114
- '<table class="table-condensed">'+
1115
- DPGlobal.headTemplate+
1116
- DPGlobal.contTemplate+
1117
- DPGlobal.footTemplate+
1118
- '</table>'+
1119
- '</div>'+
1120
- '<div class="datepicker-years">'+
1121
- '<table class="table-condensed">'+
1122
- DPGlobal.headTemplate+
1123
- DPGlobal.contTemplate+
1124
- DPGlobal.footTemplate+
1125
- '</table>'+
1126
- '</div>'+
1127
- '</div>';
1128
-
1129
- $.fn.datepicker.DPGlobal = DPGlobal;
1130
-
1131
-
1132
- /* DATEPICKER NO CONFLICT
1133
- * =================== */
1134
-
1135
- $.fn.datepicker.noConflict = function(){
1136
- $.fn.datepicker = old;
1137
- return this;
1138
- };
1139
-
1140
-
1141
- /* DATEPICKER DATA-API
1142
- * ================== */
1143
-
1144
- $(document).on(
1145
- 'focus.datepicker.data-api click.datepicker.data-api',
1146
- '[data-provide="datepicker"]',
1147
- function(e){
1148
- var $this = $(this);
1149
- if ($this.data('datepicker')) return;
1150
- e.preventDefault();
1151
- // component click requires us to explicitly show it
1152
- $this.datepicker('show');
1153
- }
1154
- );
1155
- $(function(){
1156
- $('[data-provide="datepicker-inline"]').datepicker();
1157
- });
1158
-
1159
- }( window.jQuery );
331
+ else if (this.element.is('div')){ // inline datepicker
332
+ this.isInline = true;
333
+ }
334
+ else {
335
+ this._events = [
336
+ [this.element, {
337
+ click: $.proxy(this.show, this)
338
+ }]
339
+ ];
340
+ }
341
+ this._events.push(
342
+ // Component: listen for blur on element descendants
343
+ [this.element, '*', {
344
+ blur: $.proxy(function(e){
345
+ this._focused_from = e.target;
346
+ }, this)
347
+ }],
348
+ // Input: listen for blur on element
349
+ [this.element, {
350
+ blur: $.proxy(function(e){
351
+ this._focused_from = e.target;
352
+ }, this)
353
+ }]
354
+ );
355
+
356
+ if (this.o.immediateUpdates) {
357
+ // Trigger input updates immediately on changed year/month
358
+ this._events.push([this.element, {
359
+ 'changeYear changeMonth': $.proxy(function(e){
360
+ this.update(e.date);
361
+ }, this)
362
+ }]);
363
+ }
364
+
365
+ this._secondaryEvents = [
366
+ [this.picker, {
367
+ click: $.proxy(this.click, this)
368
+ }],
369
+ [$(window), {
370
+ resize: $.proxy(this.place, this)
371
+ }],
372
+ [$(document), {
373
+ mousedown: $.proxy(function(e){
374
+ // Clicked outside the datepicker, hide it
375
+ if (!(
376
+ this.element.is(e.target) ||
377
+ this.element.find(e.target).length ||
378
+ this.picker.is(e.target) ||
379
+ this.picker.find(e.target).length
380
+ )){
381
+ $(this.picker).hide();
382
+ }
383
+ }, this)
384
+ }]
385
+ ];
386
+ },
387
+ _attachEvents: function(){
388
+ this._detachEvents();
389
+ this._applyEvents(this._events);
390
+ },
391
+ _detachEvents: function(){
392
+ this._unapplyEvents(this._events);
393
+ },
394
+ _attachSecondaryEvents: function(){
395
+ this._detachSecondaryEvents();
396
+ this._applyEvents(this._secondaryEvents);
397
+ },
398
+ _detachSecondaryEvents: function(){
399
+ this._unapplyEvents(this._secondaryEvents);
400
+ },
401
+ _trigger: function(event, altdate){
402
+ var date = altdate || this.dates.get(-1),
403
+ local_date = this._utc_to_local(date);
404
+
405
+ this.element.trigger({
406
+ type: event,
407
+ date: local_date,
408
+ dates: $.map(this.dates, this._utc_to_local),
409
+ format: $.proxy(function(ix, format){
410
+ if (arguments.length === 0){
411
+ ix = this.dates.length - 1;
412
+ format = this.o.format;
413
+ }
414
+ else if (typeof ix === 'string'){
415
+ format = ix;
416
+ ix = this.dates.length - 1;
417
+ }
418
+ format = format || this.o.format;
419
+ var date = this.dates.get(ix);
420
+ return DPGlobal.formatDate(date, format, this.o.language);
421
+ }, this)
422
+ });
423
+ },
424
+
425
+ show: function(){
426
+ if (this.element.attr('readonly') && this.o.enableOnReadonly === false)
427
+ return;
428
+ if (!this.isInline)
429
+ this.picker.appendTo(this.o.container);
430
+ this.place();
431
+ this.picker.show();
432
+ this._attachSecondaryEvents();
433
+ this._trigger('show');
434
+ if ((window.navigator.msMaxTouchPoints || 'ontouchstart' in document) && this.o.disableTouchKeyboard) {
435
+ $(this.element).blur();
436
+ }
437
+ return this;
438
+ },
439
+
440
+ hide: function(){
441
+ if (this.isInline)
442
+ return this;
443
+ if (!this.picker.is(':visible'))
444
+ return this;
445
+ this.focusDate = null;
446
+ this.picker.hide().detach();
447
+ this._detachSecondaryEvents();
448
+ this.viewMode = this.o.startView;
449
+ this.showMode();
450
+
451
+ if (
452
+ this.o.forceParse &&
453
+ (
454
+ this.isInput && this.element.val() ||
455
+ this.hasInput && this.element.find('input').val()
456
+ )
457
+ )
458
+ this.setValue();
459
+ this._trigger('hide');
460
+ return this;
461
+ },
462
+
463
+ remove: function(){
464
+ this.hide();
465
+ this._detachEvents();
466
+ this._detachSecondaryEvents();
467
+ this.picker.remove();
468
+ delete this.element.data().datepicker;
469
+ if (!this.isInput){
470
+ delete this.element.data().date;
471
+ }
472
+ return this;
473
+ },
474
+
475
+ paste: function(evt){
476
+ var dateString;
477
+ if (evt.originalEvent.clipboardData && evt.originalEvent.clipboardData.types
478
+ && $.inArray('text/plain', evt.originalEvent.clipboardData.types) !== -1) {
479
+ dateString = evt.originalEvent.clipboardData.getData('text/plain');
480
+ }
481
+ else if (window.clipboardData) {
482
+ dateString = window.clipboardData.getData('Text');
483
+ }
484
+ else {
485
+ return;
486
+ }
487
+ this.setDate(dateString);
488
+ this.update();
489
+ evt.preventDefault();
490
+ },
491
+
492
+ _utc_to_local: function(utc){
493
+ return utc && new Date(utc.getTime() + (utc.getTimezoneOffset()*60000));
494
+ },
495
+ _local_to_utc: function(local){
496
+ return local && new Date(local.getTime() - (local.getTimezoneOffset()*60000));
497
+ },
498
+ _zero_time: function(local){
499
+ return local && new Date(local.getFullYear(), local.getMonth(), local.getDate());
500
+ },
501
+ _zero_utc_time: function(utc){
502
+ return utc && new Date(Date.UTC(utc.getUTCFullYear(), utc.getUTCMonth(), utc.getUTCDate()));
503
+ },
504
+
505
+ getDates: function(){
506
+ return $.map(this.dates, this._utc_to_local);
507
+ },
508
+
509
+ getUTCDates: function(){
510
+ return $.map(this.dates, function(d){
511
+ return new Date(d);
512
+ });
513
+ },
514
+
515
+ getDate: function(){
516
+ return this._utc_to_local(this.getUTCDate());
517
+ },
518
+
519
+ getUTCDate: function(){
520
+ var selected_date = this.dates.get(-1);
521
+ if (typeof selected_date !== 'undefined') {
522
+ return new Date(selected_date);
523
+ } else {
524
+ return null;
525
+ }
526
+ },
527
+
528
+ clearDates: function(){
529
+ var element;
530
+ if (this.isInput) {
531
+ element = this.element;
532
+ } else if (this.component) {
533
+ element = this.element.find('input');
534
+ }
535
+
536
+ if (element) {
537
+ element.val('').change();
538
+ }
539
+
540
+ this.update();
541
+ this._trigger('changeDate');
542
+
543
+ if (this.o.autoclose) {
544
+ this.hide();
545
+ }
546
+ },
547
+ setDates: function(){
548
+ var args = $.isArray(arguments[0]) ? arguments[0] : arguments;
549
+ this.update.apply(this, args);
550
+ this._trigger('changeDate');
551
+ this.setValue();
552
+ return this;
553
+ },
554
+
555
+ setUTCDates: function(){
556
+ var args = $.isArray(arguments[0]) ? arguments[0] : arguments;
557
+ this.update.apply(this, $.map(args, this._utc_to_local));
558
+ this._trigger('changeDate');
559
+ this.setValue();
560
+ return this;
561
+ },
562
+
563
+ setDate: alias('setDates'),
564
+ setUTCDate: alias('setUTCDates'),
565
+
566
+ setValue: function(){
567
+ var formatted = this.getFormattedDate();
568
+ if (!this.isInput){
569
+ if (this.component){
570
+ this.element.find('input').val(formatted).change();
571
+ }
572
+ }
573
+ else {
574
+ this.element.val(formatted).change();
575
+ }
576
+ return this;
577
+ },
578
+
579
+ getFormattedDate: function(format){
580
+ if (format === undefined)
581
+ format = this.o.format;
582
+
583
+ var lang = this.o.language;
584
+ return $.map(this.dates, function(d){
585
+ return DPGlobal.formatDate(d, format, lang);
586
+ }).join(this.o.multidateSeparator);
587
+ },
588
+
589
+ setStartDate: function(startDate){
590
+ this._process_options({startDate: startDate});
591
+ this.update();
592
+ this.updateNavArrows();
593
+ return this;
594
+ },
595
+
596
+ setEndDate: function(endDate){
597
+ this._process_options({endDate: endDate});
598
+ this.update();
599
+ this.updateNavArrows();
600
+ return this;
601
+ },
602
+
603
+ setDaysOfWeekDisabled: function(daysOfWeekDisabled){
604
+ this._process_options({daysOfWeekDisabled: daysOfWeekDisabled});
605
+ this.update();
606
+ this.updateNavArrows();
607
+ return this;
608
+ },
609
+
610
+ setDatesDisabled: function(datesDisabled){
611
+ this._process_options({datesDisabled: datesDisabled});
612
+ this.update();
613
+ this.updateNavArrows();
614
+ },
615
+
616
+ place: function(){
617
+ if (this.isInline)
618
+ return this;
619
+ var calendarWidth = this.picker.outerWidth(),
620
+ calendarHeight = this.picker.outerHeight(),
621
+ visualPadding = 10,
622
+ windowWidth = $(this.o.container).width(),
623
+ windowHeight = $(this.o.container).height(),
624
+ scrollTop = $(this.o.container).scrollTop(),
625
+ appendOffset = $(this.o.container).offset();
626
+
627
+ var parentsZindex = [];
628
+ this.element.parents().each(function(){
629
+ var itemZIndex = $(this).css('z-index');
630
+ if (itemZIndex !== 'auto' && itemZIndex !== 0) parentsZindex.push(parseInt(itemZIndex));
631
+ });
632
+ var zIndex = Math.max.apply(Math, parentsZindex) + 10;
633
+ var offset = this.component ? this.component.parent().offset() : this.element.offset();
634
+ var height = this.component ? this.component.outerHeight(true) : this.element.outerHeight(false);
635
+ var width = this.component ? this.component.outerWidth(true) : this.element.outerWidth(false);
636
+ var left = offset.left - appendOffset.left,
637
+ top = offset.top - appendOffset.top;
638
+
639
+ this.picker.removeClass(
640
+ 'datepicker-orient-top datepicker-orient-bottom '+
641
+ 'datepicker-orient-right datepicker-orient-left'
642
+ );
643
+
644
+ if (this.o.orientation.x !== 'auto'){
645
+ this.picker.addClass('datepicker-orient-' + this.o.orientation.x);
646
+ if (this.o.orientation.x === 'right')
647
+ left -= calendarWidth - width;
648
+ }
649
+ // auto x orientation is best-placement: if it crosses a window
650
+ // edge, fudge it sideways
651
+ else {
652
+ if (offset.left < 0) {
653
+ // component is outside the window on the left side. Move it into visible range
654
+ this.picker.addClass('datepicker-orient-left');
655
+ left -= offset.left - visualPadding;
656
+ } else if (left + calendarWidth > windowWidth) {
657
+ // the calendar passes the widow right edge. Align it to component right side
658
+ this.picker.addClass('datepicker-orient-right');
659
+ left = offset.left + width - calendarWidth;
660
+ } else {
661
+ // Default to left
662
+ this.picker.addClass('datepicker-orient-left');
663
+ }
664
+ }
665
+
666
+ // auto y orientation is best-situation: top or bottom, no fudging,
667
+ // decision based on which shows more of the calendar
668
+ var yorient = this.o.orientation.y,
669
+ top_overflow, bottom_overflow;
670
+ if (yorient === 'auto'){
671
+ top_overflow = -scrollTop + top - calendarHeight;
672
+ bottom_overflow = scrollTop + windowHeight - (top + height + calendarHeight);
673
+ if (Math.max(top_overflow, bottom_overflow) === bottom_overflow)
674
+ yorient = 'top';
675
+ else
676
+ yorient = 'bottom';
677
+ }
678
+ this.picker.addClass('datepicker-orient-' + yorient);
679
+ if (yorient === 'top')
680
+ top += height;
681
+ else
682
+ top -= calendarHeight + parseInt(this.picker.css('padding-top'));
683
+
684
+ if (this.o.rtl) {
685
+ var right = windowWidth - (left + width);
686
+ this.picker.css({
687
+ top: top,
688
+ right: right,
689
+ zIndex: zIndex
690
+ });
691
+ } else {
692
+ this.picker.css({
693
+ top: top,
694
+ left: left,
695
+ zIndex: zIndex
696
+ });
697
+ }
698
+ return this;
699
+ },
700
+
701
+ _allow_update: true,
702
+ update: function(){
703
+ if (!this._allow_update)
704
+ return this;
705
+
706
+ var oldDates = this.dates.copy(),
707
+ dates = [],
708
+ fromArgs = false;
709
+ if (arguments.length){
710
+ $.each(arguments, $.proxy(function(i, date){
711
+ if (date instanceof Date)
712
+ date = this._local_to_utc(date);
713
+ dates.push(date);
714
+ }, this));
715
+ fromArgs = true;
716
+ }
717
+ else {
718
+ dates = this.isInput
719
+ ? this.element.val()
720
+ : this.element.data('date') || this.element.find('input').val();
721
+ if (dates && this.o.multidate)
722
+ dates = dates.split(this.o.multidateSeparator);
723
+ else
724
+ dates = [dates];
725
+ delete this.element.data().date;
726
+ }
727
+
728
+ dates = $.map(dates, $.proxy(function(date){
729
+ return DPGlobal.parseDate(date, this.o.format, this.o.language);
730
+ }, this));
731
+ dates = $.grep(dates, $.proxy(function(date){
732
+ return (
733
+ date < this.o.startDate ||
734
+ date > this.o.endDate ||
735
+ !date
736
+ );
737
+ }, this), true);
738
+ this.dates.replace(dates);
739
+
740
+ if (this.dates.length)
741
+ this.viewDate = new Date(this.dates.get(-1));
742
+ else if (this.viewDate < this.o.startDate)
743
+ this.viewDate = new Date(this.o.startDate);
744
+ else if (this.viewDate > this.o.endDate)
745
+ this.viewDate = new Date(this.o.endDate);
746
+
747
+ if (fromArgs){
748
+ // setting date by clicking
749
+ this.setValue();
750
+ }
751
+ else if (dates.length){
752
+ // setting date by typing
753
+ if (String(oldDates) !== String(this.dates))
754
+ this._trigger('changeDate');
755
+ }
756
+ if (!this.dates.length && oldDates.length)
757
+ this._trigger('clearDate');
758
+
759
+ this.fill();
760
+ return this;
761
+ },
762
+
763
+ fillDow: function(){
764
+ var dowCnt = this.o.weekStart,
765
+ html = '<tr>';
766
+ if (this.o.calendarWeeks){
767
+ this.picker.find('.datepicker-days thead tr:first-child .datepicker-switch')
768
+ .attr('colspan', function(i, val){
769
+ return parseInt(val) + 1;
770
+ });
771
+ var cell = '<th class="cw">&#160;</th>';
772
+ html += cell;
773
+ }
774
+ while (dowCnt < this.o.weekStart + 7){
775
+ html += '<th class="dow">'+dates[this.o.language].daysMin[(dowCnt++)%7]+'</th>';
776
+ }
777
+ html += '</tr>';
778
+ this.picker.find('.datepicker-days thead').append(html);
779
+ },
780
+
781
+ fillMonths: function(){
782
+ var html = '',
783
+ i = 0;
784
+ while (i < 12){
785
+ html += '<span class="month">'+dates[this.o.language].monthsShort[i++]+'</span>';
786
+ }
787
+ this.picker.find('.datepicker-months td').html(html);
788
+ },
789
+
790
+ setRange: function(range){
791
+ if (!range || !range.length)
792
+ delete this.range;
793
+ else
794
+ this.range = $.map(range, function(d){
795
+ return d.valueOf();
796
+ });
797
+ this.fill();
798
+ },
799
+
800
+ getClassNames: function(date){
801
+ var cls = [],
802
+ year = this.viewDate.getUTCFullYear(),
803
+ month = this.viewDate.getUTCMonth(),
804
+ today = new Date();
805
+ if (date.getUTCFullYear() < year || (date.getUTCFullYear() === year && date.getUTCMonth() < month)){
806
+ cls.push('old');
807
+ }
808
+ else if (date.getUTCFullYear() > year || (date.getUTCFullYear() === year && date.getUTCMonth() > month)){
809
+ cls.push('new');
810
+ }
811
+ if (this.focusDate && date.valueOf() === this.focusDate.valueOf())
812
+ cls.push('focused');
813
+ // Compare internal UTC date with local today, not UTC today
814
+ if (this.o.todayHighlight &&
815
+ date.getUTCFullYear() === today.getFullYear() &&
816
+ date.getUTCMonth() === today.getMonth() &&
817
+ date.getUTCDate() === today.getDate()){
818
+ cls.push('today');
819
+ }
820
+ if (this.dates.contains(date) !== -1)
821
+ cls.push('active');
822
+ if (date.valueOf() < this.o.startDate || date.valueOf() > this.o.endDate ||
823
+ $.inArray(date.getUTCDay(), this.o.daysOfWeekDisabled) !== -1){
824
+ cls.push('disabled');
825
+ }
826
+ if (this.o.datesDisabled.length > 0 &&
827
+ $.grep(this.o.datesDisabled, function(d){
828
+ return isUTCEquals(date, d); }).length > 0) {
829
+ cls.push('disabled', 'disabled-date');
830
+ }
831
+
832
+ if (this.range){
833
+ if (date > this.range[0] && date < this.range[this.range.length-1]){
834
+ cls.push('range');
835
+ }
836
+ if ($.inArray(date.valueOf(), this.range) !== -1){
837
+ cls.push('selected');
838
+ }
839
+ }
840
+ return cls;
841
+ },
842
+
843
+ fill: function(){
844
+ var d = new Date(this.viewDate),
845
+ year = d.getUTCFullYear(),
846
+ month = d.getUTCMonth(),
847
+ startYear = this.o.startDate !== -Infinity ? this.o.startDate.getUTCFullYear() : -Infinity,
848
+ startMonth = this.o.startDate !== -Infinity ? this.o.startDate.getUTCMonth() : -Infinity,
849
+ endYear = this.o.endDate !== Infinity ? this.o.endDate.getUTCFullYear() : Infinity,
850
+ endMonth = this.o.endDate !== Infinity ? this.o.endDate.getUTCMonth() : Infinity,
851
+ todaytxt = dates[this.o.language].today || dates['en'].today || '',
852
+ cleartxt = dates[this.o.language].clear || dates['en'].clear || '',
853
+ tooltip;
854
+ if (isNaN(year) || isNaN(month))
855
+ return;
856
+ this.picker.find('.datepicker-days thead .datepicker-switch')
857
+ .text(dates[this.o.language].months[month]+' '+year);
858
+ this.picker.find('tfoot .today')
859
+ .text(todaytxt)
860
+ .toggle(this.o.todayBtn !== false);
861
+ this.picker.find('tfoot .clear')
862
+ .text(cleartxt)
863
+ .toggle(this.o.clearBtn !== false);
864
+ this.updateNavArrows();
865
+ this.fillMonths();
866
+ var prevMonth = UTCDate(year, month-1, 28),
867
+ day = DPGlobal.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
868
+ prevMonth.setUTCDate(day);
869
+ prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.o.weekStart + 7)%7);
870
+ var nextMonth = new Date(prevMonth);
871
+ nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
872
+ nextMonth = nextMonth.valueOf();
873
+ var html = [];
874
+ var clsName;
875
+ while (prevMonth.valueOf() < nextMonth){
876
+ if (prevMonth.getUTCDay() === this.o.weekStart){
877
+ html.push('<tr>');
878
+ if (this.o.calendarWeeks){
879
+ // ISO 8601: First week contains first thursday.
880
+ // ISO also states week starts on Monday, but we can be more abstract here.
881
+ var
882
+ // Start of current week: based on weekstart/current date
883
+ ws = new Date(+prevMonth + (this.o.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
884
+ // Thursday of this week
885
+ th = new Date(Number(ws) + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
886
+ // First Thursday of year, year from thursday
887
+ yth = new Date(Number(yth = UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
888
+ // Calendar week: ms between thursdays, div ms per day, div 7 days
889
+ calWeek = (th - yth) / 864e5 / 7 + 1;
890
+ html.push('<td class="cw">'+ calWeek +'</td>');
891
+
892
+ }
893
+ }
894
+ clsName = this.getClassNames(prevMonth);
895
+ clsName.push('day');
896
+
897
+ if (this.o.beforeShowDay !== $.noop){
898
+ var before = this.o.beforeShowDay(this._utc_to_local(prevMonth));
899
+ if (before === undefined)
900
+ before = {};
901
+ else if (typeof(before) === 'boolean')
902
+ before = {enabled: before};
903
+ else if (typeof(before) === 'string')
904
+ before = {classes: before};
905
+ if (before.enabled === false)
906
+ clsName.push('disabled');
907
+ if (before.classes)
908
+ clsName = clsName.concat(before.classes.split(/\s+/));
909
+ if (before.tooltip)
910
+ tooltip = before.tooltip;
911
+ }
912
+
913
+ clsName = $.unique(clsName);
914
+ html.push('<td class="'+clsName.join(' ')+'"' + (tooltip ? ' title="'+tooltip+'"' : '') + '>'+prevMonth.getUTCDate() + '</td>');
915
+ tooltip = null;
916
+ if (prevMonth.getUTCDay() === this.o.weekEnd){
917
+ html.push('</tr>');
918
+ }
919
+ prevMonth.setUTCDate(prevMonth.getUTCDate()+1);
920
+ }
921
+ this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
922
+
923
+ var months = this.picker.find('.datepicker-months')
924
+ .find('th:eq(1)')
925
+ .text(year)
926
+ .end()
927
+ .find('span').removeClass('active');
928
+
929
+ $.each(this.dates, function(i, d){
930
+ if (d.getUTCFullYear() === year)
931
+ months.eq(d.getUTCMonth()).addClass('active');
932
+ });
933
+
934
+ if (year < startYear || year > endYear){
935
+ months.addClass('disabled');
936
+ }
937
+ if (year === startYear){
938
+ months.slice(0, startMonth).addClass('disabled');
939
+ }
940
+ if (year === endYear){
941
+ months.slice(endMonth+1).addClass('disabled');
942
+ }
943
+
944
+ if (this.o.beforeShowMonth !== $.noop){
945
+ var that = this;
946
+ $.each(months, function(i, month){
947
+ if (!$(month).hasClass('disabled')) {
948
+ var moDate = new Date(year, i, 1);
949
+ var before = that.o.beforeShowMonth(moDate);
950
+ if (before === false)
951
+ $(month).addClass('disabled');
952
+ }
953
+ });
954
+ }
955
+
956
+ html = '';
957
+ year = parseInt(year/10, 10) * 10;
958
+ var yearCont = this.picker.find('.datepicker-years')
959
+ .find('th:eq(1)')
960
+ .text(year + '-' + (year + 9))
961
+ .end()
962
+ .find('td');
963
+ year -= 1;
964
+ var years = $.map(this.dates, function(d){
965
+ return d.getUTCFullYear();
966
+ }),
967
+ classes;
968
+ for (var i = -1; i < 11; i++){
969
+ classes = ['year'];
970
+ if (i === -1)
971
+ classes.push('old');
972
+ else if (i === 10)
973
+ classes.push('new');
974
+ if ($.inArray(year, years) !== -1)
975
+ classes.push('active');
976
+ if (year < startYear || year > endYear)
977
+ classes.push('disabled');
978
+ html += '<span class="' + classes.join(' ') + '">' + year + '</span>';
979
+ year += 1;
980
+ }
981
+ yearCont.html(html);
982
+ },
983
+
984
+ updateNavArrows: function(){
985
+ if (!this._allow_update)
986
+ return;
987
+
988
+ var d = new Date(this.viewDate),
989
+ year = d.getUTCFullYear(),
990
+ month = d.getUTCMonth();
991
+ switch (this.viewMode){
992
+ case 0:
993
+ if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear() && month <= this.o.startDate.getUTCMonth()){
994
+ this.picker.find('.prev').css({visibility: 'hidden'});
995
+ }
996
+ else {
997
+ this.picker.find('.prev').css({visibility: 'visible'});
998
+ }
999
+ if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear() && month >= this.o.endDate.getUTCMonth()){
1000
+ this.picker.find('.next').css({visibility: 'hidden'});
1001
+ }
1002
+ else {
1003
+ this.picker.find('.next').css({visibility: 'visible'});
1004
+ }
1005
+ break;
1006
+ case 1:
1007
+ case 2:
1008
+ if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear()){
1009
+ this.picker.find('.prev').css({visibility: 'hidden'});
1010
+ }
1011
+ else {
1012
+ this.picker.find('.prev').css({visibility: 'visible'});
1013
+ }
1014
+ if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear()){
1015
+ this.picker.find('.next').css({visibility: 'hidden'});
1016
+ }
1017
+ else {
1018
+ this.picker.find('.next').css({visibility: 'visible'});
1019
+ }
1020
+ break;
1021
+ }
1022
+ },
1023
+
1024
+ click: function(e){
1025
+ e.preventDefault();
1026
+ var target = $(e.target).closest('span, td, th'),
1027
+ year, month, day;
1028
+ if (target.length === 1){
1029
+ switch (target[0].nodeName.toLowerCase()){
1030
+ case 'th':
1031
+ switch (target[0].className){
1032
+ case 'datepicker-switch':
1033
+ this.showMode(1);
1034
+ break;
1035
+ case 'prev':
1036
+ case 'next':
1037
+ var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className === 'prev' ? -1 : 1);
1038
+ switch (this.viewMode){
1039
+ case 0:
1040
+ this.viewDate = this.moveMonth(this.viewDate, dir);
1041
+ this._trigger('changeMonth', this.viewDate);
1042
+ break;
1043
+ case 1:
1044
+ case 2:
1045
+ this.viewDate = this.moveYear(this.viewDate, dir);
1046
+ if (this.viewMode === 1)
1047
+ this._trigger('changeYear', this.viewDate);
1048
+ break;
1049
+ }
1050
+ this.fill();
1051
+ break;
1052
+ case 'today':
1053
+ var date = new Date();
1054
+ date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
1055
+
1056
+ this.showMode(-2);
1057
+ var which = this.o.todayBtn === 'linked' ? null : 'view';
1058
+ this._setDate(date, which);
1059
+ break;
1060
+ case 'clear':
1061
+ this.clearDates();
1062
+ break;
1063
+ }
1064
+ break;
1065
+ case 'span':
1066
+ if (!target.hasClass('disabled')){
1067
+ this.viewDate.setUTCDate(1);
1068
+ if (target.hasClass('month')){
1069
+ day = 1;
1070
+ month = target.parent().find('span').index(target);
1071
+ year = this.viewDate.getUTCFullYear();
1072
+ this.viewDate.setUTCMonth(month);
1073
+ this._trigger('changeMonth', this.viewDate);
1074
+ if (this.o.minViewMode === 1){
1075
+ this._setDate(UTCDate(year, month, day));
1076
+ this.showMode();
1077
+ } else {
1078
+ this.showMode(-1);
1079
+ }
1080
+ }
1081
+ else {
1082
+ day = 1;
1083
+ month = 0;
1084
+ year = parseInt(target.text(), 10)||0;
1085
+ this.viewDate.setUTCFullYear(year);
1086
+ this._trigger('changeYear', this.viewDate);
1087
+ if (this.o.minViewMode === 2){
1088
+ this._setDate(UTCDate(year, month, day));
1089
+ }
1090
+ this.showMode(-1);
1091
+ }
1092
+ this.fill();
1093
+ }
1094
+ break;
1095
+ case 'td':
1096
+ if (target.hasClass('day') && !target.hasClass('disabled')){
1097
+ day = parseInt(target.text(), 10)||1;
1098
+ year = this.viewDate.getUTCFullYear();
1099
+ month = this.viewDate.getUTCMonth();
1100
+ if (target.hasClass('old')){
1101
+ if (month === 0){
1102
+ month = 11;
1103
+ year -= 1;
1104
+ }
1105
+ else {
1106
+ month -= 1;
1107
+ }
1108
+ }
1109
+ else if (target.hasClass('new')){
1110
+ if (month === 11){
1111
+ month = 0;
1112
+ year += 1;
1113
+ }
1114
+ else {
1115
+ month += 1;
1116
+ }
1117
+ }
1118
+ this._setDate(UTCDate(year, month, day));
1119
+ }
1120
+ break;
1121
+ }
1122
+ }
1123
+ if (this.picker.is(':visible') && this._focused_from){
1124
+ $(this._focused_from).focus();
1125
+ }
1126
+ delete this._focused_from;
1127
+ },
1128
+
1129
+ _toggle_multidate: function(date){
1130
+ var ix = this.dates.contains(date);
1131
+ if (!date){
1132
+ this.dates.clear();
1133
+ }
1134
+
1135
+ if (ix !== -1){
1136
+ if (this.o.multidate === true || this.o.multidate > 1 || this.o.toggleActive){
1137
+ this.dates.remove(ix);
1138
+ }
1139
+ } else if (this.o.multidate === false) {
1140
+ this.dates.clear();
1141
+ this.dates.push(date);
1142
+ }
1143
+ else {
1144
+ this.dates.push(date);
1145
+ }
1146
+
1147
+ if (typeof this.o.multidate === 'number')
1148
+ while (this.dates.length > this.o.multidate)
1149
+ this.dates.remove(0);
1150
+ },
1151
+
1152
+ _setDate: function(date, which){
1153
+ if (!which || which === 'date')
1154
+ this._toggle_multidate(date && new Date(date));
1155
+ if (!which || which === 'view')
1156
+ this.viewDate = date && new Date(date);
1157
+
1158
+ this.fill();
1159
+ this.setValue();
1160
+ if (!which || which !== 'view') {
1161
+ this._trigger('changeDate');
1162
+ }
1163
+ var element;
1164
+ if (this.isInput){
1165
+ element = this.element;
1166
+ }
1167
+ else if (this.component){
1168
+ element = this.element.find('input');
1169
+ }
1170
+ if (element){
1171
+ element.change();
1172
+ }
1173
+ if (this.o.autoclose && (!which || which === 'date')){
1174
+ this.hide();
1175
+ }
1176
+ },
1177
+
1178
+ moveMonth: function(date, dir){
1179
+ if (!date)
1180
+ return undefined;
1181
+ if (!dir)
1182
+ return date;
1183
+ var new_date = new Date(date.valueOf()),
1184
+ day = new_date.getUTCDate(),
1185
+ month = new_date.getUTCMonth(),
1186
+ mag = Math.abs(dir),
1187
+ new_month, test;
1188
+ dir = dir > 0 ? 1 : -1;
1189
+ if (mag === 1){
1190
+ test = dir === -1
1191
+ // If going back one month, make sure month is not current month
1192
+ // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
1193
+ ? function(){
1194
+ return new_date.getUTCMonth() === month;
1195
+ }
1196
+ // If going forward one month, make sure month is as expected
1197
+ // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
1198
+ : function(){
1199
+ return new_date.getUTCMonth() !== new_month;
1200
+ };
1201
+ new_month = month + dir;
1202
+ new_date.setUTCMonth(new_month);
1203
+ // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
1204
+ if (new_month < 0 || new_month > 11)
1205
+ new_month = (new_month + 12) % 12;
1206
+ }
1207
+ else {
1208
+ // For magnitudes >1, move one month at a time...
1209
+ for (var i=0; i < mag; i++)
1210
+ // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
1211
+ new_date = this.moveMonth(new_date, dir);
1212
+ // ...then reset the day, keeping it in the new month
1213
+ new_month = new_date.getUTCMonth();
1214
+ new_date.setUTCDate(day);
1215
+ test = function(){
1216
+ return new_month !== new_date.getUTCMonth();
1217
+ };
1218
+ }
1219
+ // Common date-resetting loop -- if date is beyond end of month, make it
1220
+ // end of month
1221
+ while (test()){
1222
+ new_date.setUTCDate(--day);
1223
+ new_date.setUTCMonth(new_month);
1224
+ }
1225
+ return new_date;
1226
+ },
1227
+
1228
+ moveYear: function(date, dir){
1229
+ return this.moveMonth(date, dir*12);
1230
+ },
1231
+
1232
+ dateWithinRange: function(date){
1233
+ return date >= this.o.startDate && date <= this.o.endDate;
1234
+ },
1235
+
1236
+ keydown: function(e){
1237
+ if (!this.picker.is(':visible')){
1238
+ if (e.keyCode === 40 || e.keyCode === 27) // allow down to re-show picker
1239
+ this.show();
1240
+ return;
1241
+ }
1242
+ var dateChanged = false,
1243
+ dir, newDate, newViewDate,
1244
+ focusDate = this.focusDate || this.viewDate;
1245
+ switch (e.keyCode){
1246
+ case 27: // escape
1247
+ if (this.focusDate){
1248
+ this.focusDate = null;
1249
+ this.viewDate = this.dates.get(-1) || this.viewDate;
1250
+ this.fill();
1251
+ }
1252
+ else
1253
+ this.hide();
1254
+ e.preventDefault();
1255
+ break;
1256
+ case 37: // left
1257
+ case 39: // right
1258
+ if (!this.o.keyboardNavigation)
1259
+ break;
1260
+ dir = e.keyCode === 37 ? -1 : 1;
1261
+ if (e.ctrlKey){
1262
+ newDate = this.moveYear(this.dates.get(-1) || UTCToday(), dir);
1263
+ newViewDate = this.moveYear(focusDate, dir);
1264
+ this._trigger('changeYear', this.viewDate);
1265
+ }
1266
+ else if (e.shiftKey){
1267
+ newDate = this.moveMonth(this.dates.get(-1) || UTCToday(), dir);
1268
+ newViewDate = this.moveMonth(focusDate, dir);
1269
+ this._trigger('changeMonth', this.viewDate);
1270
+ }
1271
+ else {
1272
+ newDate = new Date(this.dates.get(-1) || UTCToday());
1273
+ newDate.setUTCDate(newDate.getUTCDate() + dir);
1274
+ newViewDate = new Date(focusDate);
1275
+ newViewDate.setUTCDate(focusDate.getUTCDate() + dir);
1276
+ }
1277
+ if (this.dateWithinRange(newViewDate)){
1278
+ this.focusDate = this.viewDate = newViewDate;
1279
+ this.setValue();
1280
+ this.fill();
1281
+ e.preventDefault();
1282
+ }
1283
+ break;
1284
+ case 38: // up
1285
+ case 40: // down
1286
+ if (!this.o.keyboardNavigation)
1287
+ break;
1288
+ dir = e.keyCode === 38 ? -1 : 1;
1289
+ if (e.ctrlKey){
1290
+ newDate = this.moveYear(this.dates.get(-1) || UTCToday(), dir);
1291
+ newViewDate = this.moveYear(focusDate, dir);
1292
+ this._trigger('changeYear', this.viewDate);
1293
+ }
1294
+ else if (e.shiftKey){
1295
+ newDate = this.moveMonth(this.dates.get(-1) || UTCToday(), dir);
1296
+ newViewDate = this.moveMonth(focusDate, dir);
1297
+ this._trigger('changeMonth', this.viewDate);
1298
+ }
1299
+ else {
1300
+ newDate = new Date(this.dates.get(-1) || UTCToday());
1301
+ newDate.setUTCDate(newDate.getUTCDate() + dir * 7);
1302
+ newViewDate = new Date(focusDate);
1303
+ newViewDate.setUTCDate(focusDate.getUTCDate() + dir * 7);
1304
+ }
1305
+ if (this.dateWithinRange(newViewDate)){
1306
+ this.focusDate = this.viewDate = newViewDate;
1307
+ this.setValue();
1308
+ this.fill();
1309
+ e.preventDefault();
1310
+ }
1311
+ break;
1312
+ case 32: // spacebar
1313
+ // Spacebar is used in manually typing dates in some formats.
1314
+ // As such, its behavior should not be hijacked.
1315
+ break;
1316
+ case 13: // enter
1317
+ focusDate = this.focusDate || this.dates.get(-1) || this.viewDate;
1318
+ if (this.o.keyboardNavigation) {
1319
+ this._toggle_multidate(focusDate);
1320
+ dateChanged = true;
1321
+ }
1322
+ this.focusDate = null;
1323
+ this.viewDate = this.dates.get(-1) || this.viewDate;
1324
+ this.setValue();
1325
+ this.fill();
1326
+ if (this.picker.is(':visible')){
1327
+ e.preventDefault();
1328
+ if (typeof e.stopPropagation === 'function') {
1329
+ e.stopPropagation(); // All modern browsers, IE9+
1330
+ } else {
1331
+ e.cancelBubble = true; // IE6,7,8 ignore "stopPropagation"
1332
+ }
1333
+ if (this.o.autoclose)
1334
+ this.hide();
1335
+ }
1336
+ break;
1337
+ case 9: // tab
1338
+ this.focusDate = null;
1339
+ this.viewDate = this.dates.get(-1) || this.viewDate;
1340
+ this.fill();
1341
+ this.hide();
1342
+ break;
1343
+ }
1344
+ if (dateChanged){
1345
+ if (this.dates.length)
1346
+ this._trigger('changeDate');
1347
+ else
1348
+ this._trigger('clearDate');
1349
+ var element;
1350
+ if (this.isInput){
1351
+ element = this.element;
1352
+ }
1353
+ else if (this.component){
1354
+ element = this.element.find('input');
1355
+ }
1356
+ if (element){
1357
+ element.change();
1358
+ }
1359
+ }
1360
+ },
1361
+
1362
+ showMode: function(dir){
1363
+ if (dir){
1364
+ this.viewMode = Math.max(this.o.minViewMode, Math.min(2, this.viewMode + dir));
1365
+ }
1366
+ this.picker
1367
+ .children('div')
1368
+ .hide()
1369
+ .filter('.datepicker-' + DPGlobal.modes[this.viewMode].clsName)
1370
+ .css('display', 'block');
1371
+ this.updateNavArrows();
1372
+ }
1373
+ };
1374
+
1375
+ var DateRangePicker = function(element, options){
1376
+ this.element = $(element);
1377
+ this.inputs = $.map(options.inputs, function(i){
1378
+ return i.jquery ? i[0] : i;
1379
+ });
1380
+ delete options.inputs;
1381
+
1382
+ datepickerPlugin.call($(this.inputs), options)
1383
+ .on('changeDate', $.proxy(this.dateUpdated, this));
1384
+
1385
+ this.pickers = $.map(this.inputs, function(i){
1386
+ return $(i).data('datepicker');
1387
+ });
1388
+ this.updateDates();
1389
+ };
1390
+ DateRangePicker.prototype = {
1391
+ updateDates: function(){
1392
+ this.dates = $.map(this.pickers, function(i){
1393
+ return i.getUTCDate();
1394
+ });
1395
+ this.updateRanges();
1396
+ },
1397
+ updateRanges: function(){
1398
+ var range = $.map(this.dates, function(d){
1399
+ return d.valueOf();
1400
+ });
1401
+ $.each(this.pickers, function(i, p){
1402
+ p.setRange(range);
1403
+ });
1404
+ },
1405
+ dateUpdated: function(e){
1406
+ // `this.updating` is a workaround for preventing infinite recursion
1407
+ // between `changeDate` triggering and `setUTCDate` calling. Until
1408
+ // there is a better mechanism.
1409
+ if (this.updating)
1410
+ return;
1411
+ this.updating = true;
1412
+
1413
+ var dp = $(e.target).data('datepicker'),
1414
+ new_date = dp.getUTCDate(),
1415
+ i = $.inArray(e.target, this.inputs),
1416
+ j = i - 1,
1417
+ k = i + 1,
1418
+ l = this.inputs.length;
1419
+ if (i === -1)
1420
+ return;
1421
+
1422
+ $.each(this.pickers, function(i, p){
1423
+ if (!p.getUTCDate())
1424
+ p.setUTCDate(new_date);
1425
+ });
1426
+
1427
+ if (new_date < this.dates[j]){
1428
+ // Date being moved earlier/left
1429
+ while (j >= 0 && new_date < this.dates[j]){
1430
+ this.pickers[j--].setUTCDate(new_date);
1431
+ }
1432
+ }
1433
+ else if (new_date > this.dates[k]){
1434
+ // Date being moved later/right
1435
+ while (k < l && new_date > this.dates[k]){
1436
+ this.pickers[k++].setUTCDate(new_date);
1437
+ }
1438
+ }
1439
+ this.updateDates();
1440
+
1441
+ delete this.updating;
1442
+ },
1443
+ remove: function(){
1444
+ $.map(this.pickers, function(p){ p.remove(); });
1445
+ delete this.element.data().datepicker;
1446
+ }
1447
+ };
1448
+
1449
+ function opts_from_el(el, prefix){
1450
+ // Derive options from element data-attrs
1451
+ var data = $(el).data(),
1452
+ out = {}, inkey,
1453
+ replace = new RegExp('^' + prefix.toLowerCase() + '([A-Z])');
1454
+ prefix = new RegExp('^' + prefix.toLowerCase());
1455
+ function re_lower(_,a){
1456
+ return a.toLowerCase();
1457
+ }
1458
+ for (var key in data)
1459
+ if (prefix.test(key)){
1460
+ inkey = key.replace(replace, re_lower);
1461
+ out[inkey] = data[key];
1462
+ }
1463
+ return out;
1464
+ }
1465
+
1466
+ function opts_from_locale(lang){
1467
+ // Derive options from locale plugins
1468
+ var out = {};
1469
+ // Check if "de-DE" style date is available, if not language should
1470
+ // fallback to 2 letter code eg "de"
1471
+ if (!dates[lang]){
1472
+ lang = lang.split('-')[0];
1473
+ if (!dates[lang])
1474
+ return;
1475
+ }
1476
+ var d = dates[lang];
1477
+ $.each(locale_opts, function(i,k){
1478
+ if (k in d)
1479
+ out[k] = d[k];
1480
+ });
1481
+ return out;
1482
+ }
1483
+
1484
+ var old = $.fn.datepicker;
1485
+ var datepickerPlugin = function(option){
1486
+ var args = Array.apply(null, arguments);
1487
+ args.shift();
1488
+ var internal_return;
1489
+ this.each(function(){
1490
+ var $this = $(this),
1491
+ data = $this.data('datepicker'),
1492
+ options = typeof option === 'object' && option;
1493
+ if (!data){
1494
+ var elopts = opts_from_el(this, 'date'),
1495
+ // Preliminary otions
1496
+ xopts = $.extend({}, defaults, elopts, options),
1497
+ locopts = opts_from_locale(xopts.language),
1498
+ // Options priority: js args, data-attrs, locales, defaults
1499
+ opts = $.extend({}, defaults, locopts, elopts, options);
1500
+ if ($this.hasClass('input-daterange') || opts.inputs){
1501
+ var ropts = {
1502
+ inputs: opts.inputs || $this.find('input').toArray()
1503
+ };
1504
+ $this.data('datepicker', (data = new DateRangePicker(this, $.extend(opts, ropts))));
1505
+ }
1506
+ else {
1507
+ $this.data('datepicker', (data = new Datepicker(this, opts)));
1508
+ }
1509
+ }
1510
+ if (typeof option === 'string' && typeof data[option] === 'function'){
1511
+ internal_return = data[option].apply(data, args);
1512
+ if (internal_return !== undefined)
1513
+ return false;
1514
+ }
1515
+ });
1516
+ if (internal_return !== undefined)
1517
+ return internal_return;
1518
+ else
1519
+ return this;
1520
+ };
1521
+ $.fn.datepicker = datepickerPlugin;
1522
+
1523
+ var defaults = $.fn.datepicker.defaults = {
1524
+ autoclose: false,
1525
+ beforeShowDay: $.noop,
1526
+ beforeShowMonth: $.noop,
1527
+ calendarWeeks: false,
1528
+ clearBtn: false,
1529
+ toggleActive: false,
1530
+ daysOfWeekDisabled: [],
1531
+ datesDisabled: [],
1532
+ endDate: Infinity,
1533
+ forceParse: true,
1534
+ format: 'mm/dd/yyyy',
1535
+ keyboardNavigation: true,
1536
+ language: 'en',
1537
+ minViewMode: 0,
1538
+ multidate: false,
1539
+ multidateSeparator: ',',
1540
+ orientation: "auto",
1541
+ rtl: false,
1542
+ startDate: -Infinity,
1543
+ startView: 0,
1544
+ todayBtn: false,
1545
+ todayHighlight: false,
1546
+ weekStart: 0,
1547
+ disableTouchKeyboard: false,
1548
+ enableOnReadonly: true,
1549
+ container: 'body',
1550
+ immediateUpdates: false
1551
+ };
1552
+ var locale_opts = $.fn.datepicker.locale_opts = [
1553
+ 'format',
1554
+ 'rtl',
1555
+ 'weekStart'
1556
+ ];
1557
+ $.fn.datepicker.Constructor = Datepicker;
1558
+ var dates = $.fn.datepicker.dates = {
1559
+ en: {
1560
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
1561
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
1562
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
1563
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
1564
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
1565
+ today: "Today",
1566
+ clear: "Clear"
1567
+ }
1568
+ };
1569
+
1570
+ var DPGlobal = {
1571
+ modes: [
1572
+ {
1573
+ clsName: 'days',
1574
+ navFnc: 'Month',
1575
+ navStep: 1
1576
+ },
1577
+ {
1578
+ clsName: 'months',
1579
+ navFnc: 'FullYear',
1580
+ navStep: 1
1581
+ },
1582
+ {
1583
+ clsName: 'years',
1584
+ navFnc: 'FullYear',
1585
+ navStep: 10
1586
+ }],
1587
+ isLeapYear: function(year){
1588
+ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
1589
+ },
1590
+ getDaysInMonth: function(year, month){
1591
+ return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
1592
+ },
1593
+ validParts: /dd?|DD?|mm?|MM?|yy(?:yy)?/g,
1594
+ nonpunctuation: /[^ -\/:-@\[\u3400-\u9fff-`{-~\t\n\r]+/g,
1595
+ parseFormat: function(format){
1596
+ // IE treats \0 as a string end in inputs (truncating the value),
1597
+ // so it's a bad format delimiter, anyway
1598
+ var separators = format.replace(this.validParts, '\0').split('\0'),
1599
+ parts = format.match(this.validParts);
1600
+ if (!separators || !separators.length || !parts || parts.length === 0){
1601
+ throw new Error("Invalid date format.");
1602
+ }
1603
+ return {separators: separators, parts: parts};
1604
+ },
1605
+ parseDate: function(date, format, language){
1606
+ if (!date)
1607
+ return undefined;
1608
+ if (date instanceof Date)
1609
+ return date;
1610
+ if (typeof format === 'string')
1611
+ format = DPGlobal.parseFormat(format);
1612
+ var part_re = /([\-+]\d+)([dmwy])/,
1613
+ parts = date.match(/([\-+]\d+)([dmwy])/g),
1614
+ part, dir, i;
1615
+ if (/^[\-+]\d+[dmwy]([\s,]+[\-+]\d+[dmwy])*$/.test(date)){
1616
+ date = new Date();
1617
+ for (i=0; i < parts.length; i++){
1618
+ part = part_re.exec(parts[i]);
1619
+ dir = parseInt(part[1]);
1620
+ switch (part[2]){
1621
+ case 'd':
1622
+ date.setUTCDate(date.getUTCDate() + dir);
1623
+ break;
1624
+ case 'm':
1625
+ date = Datepicker.prototype.moveMonth.call(Datepicker.prototype, date, dir);
1626
+ break;
1627
+ case 'w':
1628
+ date.setUTCDate(date.getUTCDate() + dir * 7);
1629
+ break;
1630
+ case 'y':
1631
+ date = Datepicker.prototype.moveYear.call(Datepicker.prototype, date, dir);
1632
+ break;
1633
+ }
1634
+ }
1635
+ return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 0, 0, 0);
1636
+ }
1637
+ parts = date && date.match(this.nonpunctuation) || [];
1638
+ date = new Date();
1639
+ var parsed = {},
1640
+ setters_order = ['yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'],
1641
+ setters_map = {
1642
+ yyyy: function(d,v){
1643
+ return d.setUTCFullYear(v);
1644
+ },
1645
+ yy: function(d,v){
1646
+ return d.setUTCFullYear(2000+v);
1647
+ },
1648
+ m: function(d,v){
1649
+ if (isNaN(d))
1650
+ return d;
1651
+ v -= 1;
1652
+ while (v < 0) v += 12;
1653
+ v %= 12;
1654
+ d.setUTCMonth(v);
1655
+ while (d.getUTCMonth() !== v)
1656
+ d.setUTCDate(d.getUTCDate()-1);
1657
+ return d;
1658
+ },
1659
+ d: function(d,v){
1660
+ return d.setUTCDate(v);
1661
+ }
1662
+ },
1663
+ val, filtered;
1664
+ setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
1665
+ setters_map['dd'] = setters_map['d'];
1666
+ date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
1667
+ var fparts = format.parts.slice();
1668
+ // Remove noop parts
1669
+ if (parts.length !== fparts.length){
1670
+ fparts = $(fparts).filter(function(i,p){
1671
+ return $.inArray(p, setters_order) !== -1;
1672
+ }).toArray();
1673
+ }
1674
+ // Process remainder
1675
+ function match_part(){
1676
+ var m = this.slice(0, parts[i].length),
1677
+ p = parts[i].slice(0, m.length);
1678
+ return m.toLowerCase() === p.toLowerCase();
1679
+ }
1680
+ if (parts.length === fparts.length){
1681
+ var cnt;
1682
+ for (i=0, cnt = fparts.length; i < cnt; i++){
1683
+ val = parseInt(parts[i], 10);
1684
+ part = fparts[i];
1685
+ if (isNaN(val)){
1686
+ switch (part){
1687
+ case 'MM':
1688
+ filtered = $(dates[language].months).filter(match_part);
1689
+ val = $.inArray(filtered[0], dates[language].months) + 1;
1690
+ break;
1691
+ case 'M':
1692
+ filtered = $(dates[language].monthsShort).filter(match_part);
1693
+ val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
1694
+ break;
1695
+ }
1696
+ }
1697
+ parsed[part] = val;
1698
+ }
1699
+ var _date, s;
1700
+ for (i=0; i < setters_order.length; i++){
1701
+ s = setters_order[i];
1702
+ if (s in parsed && !isNaN(parsed[s])){
1703
+ _date = new Date(date);
1704
+ setters_map[s](_date, parsed[s]);
1705
+ if (!isNaN(_date))
1706
+ date = _date;
1707
+ }
1708
+ }
1709
+ }
1710
+ return date;
1711
+ },
1712
+ formatDate: function(date, format, language){
1713
+ if (!date)
1714
+ return '';
1715
+ if (typeof format === 'string')
1716
+ format = DPGlobal.parseFormat(format);
1717
+ var val = {
1718
+ d: date.getUTCDate(),
1719
+ D: dates[language].daysShort[date.getUTCDay()],
1720
+ DD: dates[language].days[date.getUTCDay()],
1721
+ m: date.getUTCMonth() + 1,
1722
+ M: dates[language].monthsShort[date.getUTCMonth()],
1723
+ MM: dates[language].months[date.getUTCMonth()],
1724
+ yy: date.getUTCFullYear().toString().substring(2),
1725
+ yyyy: date.getUTCFullYear()
1726
+ };
1727
+ val.dd = (val.d < 10 ? '0' : '') + val.d;
1728
+ val.mm = (val.m < 10 ? '0' : '') + val.m;
1729
+ date = [];
1730
+ var seps = $.extend([], format.separators);
1731
+ for (var i=0, cnt = format.parts.length; i <= cnt; i++){
1732
+ if (seps.length)
1733
+ date.push(seps.shift());
1734
+ date.push(val[format.parts[i]]);
1735
+ }
1736
+ return date.join('');
1737
+ },
1738
+ headTemplate: '<thead>'+
1739
+ '<tr>'+
1740
+ '<th class="prev">&#171;</th>'+
1741
+ '<th colspan="5" class="datepicker-switch"></th>'+
1742
+ '<th class="next">&#187;</th>'+
1743
+ '</tr>'+
1744
+ '</thead>',
1745
+ contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
1746
+ footTemplate: '<tfoot>'+
1747
+ '<tr>'+
1748
+ '<th colspan="7" class="today"></th>'+
1749
+ '</tr>'+
1750
+ '<tr>'+
1751
+ '<th colspan="7" class="clear"></th>'+
1752
+ '</tr>'+
1753
+ '</tfoot>'
1754
+ };
1755
+ DPGlobal.template = '<div class="datepicker">'+
1756
+ '<div class="datepicker-days">'+
1757
+ '<table class=" table-condensed">'+
1758
+ DPGlobal.headTemplate+
1759
+ '<tbody></tbody>'+
1760
+ DPGlobal.footTemplate+
1761
+ '</table>'+
1762
+ '</div>'+
1763
+ '<div class="datepicker-months">'+
1764
+ '<table class="table-condensed">'+
1765
+ DPGlobal.headTemplate+
1766
+ DPGlobal.contTemplate+
1767
+ DPGlobal.footTemplate+
1768
+ '</table>'+
1769
+ '</div>'+
1770
+ '<div class="datepicker-years">'+
1771
+ '<table class="table-condensed">'+
1772
+ DPGlobal.headTemplate+
1773
+ DPGlobal.contTemplate+
1774
+ DPGlobal.footTemplate+
1775
+ '</table>'+
1776
+ '</div>'+
1777
+ '</div>';
1778
+
1779
+ $.fn.datepicker.DPGlobal = DPGlobal;
1780
+
1781
+
1782
+ /* DATEPICKER NO CONFLICT
1783
+ * =================== */
1784
+
1785
+ $.fn.datepicker.noConflict = function(){
1786
+ $.fn.datepicker = old;
1787
+ return this;
1788
+ };
1789
+
1790
+ /* DATEPICKER VERSION
1791
+ * =================== */
1792
+ $.fn.datepicker.version = "1.4.1-dev";
1793
+
1794
+ /* DATEPICKER DATA-API
1795
+ * ================== */
1796
+
1797
+ $(document).on(
1798
+ 'focus.datepicker.data-api click.datepicker.data-api',
1799
+ '[data-provide="datepicker"]',
1800
+ function(e){
1801
+ var $this = $(this);
1802
+ if ($this.data('datepicker'))
1803
+ return;
1804
+ e.preventDefault();
1805
+ // component click requires us to explicitly show it
1806
+ datepickerPlugin.call($this, 'show');
1807
+ }
1808
+ );
1809
+ $(function(){
1810
+ datepickerPlugin.call($('[data-provide="datepicker-inline"]'));
1811
+ });
1812
+
1813
+ }(window.jQuery));