bootstrap-datepicker 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. data/.gitignore +7 -0
  2. data/.hgignore +3 -0
  3. data/.hgtags +9 -0
  4. data/.travis.yml +4 -0
  5. data/CHANGELOG.md +89 -0
  6. data/CONTRIBUTING.md +40 -0
  7. data/Gemfile +4 -0
  8. data/Gruntfile.js +165 -0
  9. data/LICENSE +202 -0
  10. data/README.md +24 -0
  11. data/Rakefile +1 -0
  12. data/bootstrap-datepicker.gemspec +26 -0
  13. data/bower.json +9 -0
  14. data/build/build.less +67 -0
  15. data/build/build3.less +71 -0
  16. data/build/build_standalone.less +61 -0
  17. data/build/build_standalone3.less +63 -0
  18. data/composer.json +19 -0
  19. data/css/datepicker.css +509 -0
  20. data/css/datepicker3.css +790 -0
  21. data/docs/Makefile +153 -0
  22. data/docs/REAME.md +8 -0
  23. data/docs/_static/demo_head.png +0 -0
  24. data/docs/conf.py +248 -0
  25. data/docs/events.rst +48 -0
  26. data/docs/i18n.rst +28 -0
  27. data/docs/index.rst +122 -0
  28. data/docs/keyboard.rst +30 -0
  29. data/docs/make.bat +190 -0
  30. data/docs/markup.rst +50 -0
  31. data/docs/methods.rst +156 -0
  32. data/docs/options.rst +191 -0
  33. data/js/bootstrap-datepicker.js +1609 -0
  34. data/js/locales/bootstrap-datepicker.ar.js +15 -0
  35. data/js/locales/bootstrap-datepicker.bg.js +14 -0
  36. data/js/locales/bootstrap-datepicker.ca.js +14 -0
  37. data/js/locales/bootstrap-datepicker.cs.js +15 -0
  38. data/js/locales/bootstrap-datepicker.cy.js +14 -0
  39. data/js/locales/bootstrap-datepicker.da.js +15 -0
  40. data/js/locales/bootstrap-datepicker.de.js +17 -0
  41. data/js/locales/bootstrap-datepicker.el.js +13 -0
  42. data/js/locales/bootstrap-datepicker.es.js +14 -0
  43. data/js/locales/bootstrap-datepicker.et.js +18 -0
  44. data/js/locales/bootstrap-datepicker.fa.js +17 -0
  45. data/js/locales/bootstrap-datepicker.fi.js +16 -0
  46. data/js/locales/bootstrap-datepicker.fr.js +17 -0
  47. data/js/locales/bootstrap-datepicker.gl.js +11 -0
  48. data/js/locales/bootstrap-datepicker.he.js +15 -0
  49. data/js/locales/bootstrap-datepicker.hr.js +13 -0
  50. data/js/locales/bootstrap-datepicker.hu.js +16 -0
  51. data/js/locales/bootstrap-datepicker.id.js +15 -0
  52. data/js/locales/bootstrap-datepicker.is.js +14 -0
  53. data/js/locales/bootstrap-datepicker.it.js +16 -0
  54. data/js/locales/bootstrap-datepicker.ja.js +15 -0
  55. data/js/locales/bootstrap-datepicker.ka.js +17 -0
  56. data/js/locales/bootstrap-datepicker.kk.js +15 -0
  57. data/js/locales/bootstrap-datepicker.kr.js +13 -0
  58. data/js/locales/bootstrap-datepicker.lt.js +16 -0
  59. data/js/locales/bootstrap-datepicker.lv.js +16 -0
  60. data/js/locales/bootstrap-datepicker.mk.js +15 -0
  61. data/js/locales/bootstrap-datepicker.ms.js +14 -0
  62. data/js/locales/bootstrap-datepicker.nb.js +14 -0
  63. data/js/locales/bootstrap-datepicker.nl-BE.js +17 -0
  64. data/js/locales/bootstrap-datepicker.nl.js +14 -0
  65. data/js/locales/bootstrap-datepicker.no.js +16 -0
  66. data/js/locales/bootstrap-datepicker.pl.js +15 -0
  67. data/js/locales/bootstrap-datepicker.pt-BR.js +15 -0
  68. data/js/locales/bootstrap-datepicker.pt.js +16 -0
  69. data/js/locales/bootstrap-datepicker.ro.js +15 -0
  70. data/js/locales/bootstrap-datepicker.rs-latin.js +14 -0
  71. data/js/locales/bootstrap-datepicker.rs.js +14 -0
  72. data/js/locales/bootstrap-datepicker.ru.js +15 -0
  73. data/js/locales/bootstrap-datepicker.sk.js +15 -0
  74. data/js/locales/bootstrap-datepicker.sl.js +14 -0
  75. data/js/locales/bootstrap-datepicker.sq.js +15 -0
  76. data/js/locales/bootstrap-datepicker.sv.js +16 -0
  77. data/js/locales/bootstrap-datepicker.sw.js +15 -0
  78. data/js/locales/bootstrap-datepicker.th.js +14 -0
  79. data/js/locales/bootstrap-datepicker.tr.js +16 -0
  80. data/js/locales/bootstrap-datepicker.ua.js +15 -0
  81. data/js/locales/bootstrap-datepicker.uk.js +14 -0
  82. data/js/locales/bootstrap-datepicker.vi.js +16 -0
  83. data/js/locales/bootstrap-datepicker.zh-CN.js +16 -0
  84. data/js/locales/bootstrap-datepicker.zh-TW.js +17 -0
  85. data/less/datepicker.less +265 -0
  86. data/less/datepicker3.less +252 -0
  87. data/lib/bootstrap-datepicker.rb +11 -0
  88. data/lib/bootstrap-datepicker/version.rb +9 -0
  89. data/package.json +32 -0
  90. data/sass/build_standalone-sass.scss +70 -0
  91. data/sass/datepicker.scss +270 -0
  92. data/test/Readme.md +9 -0
  93. data/test/less_test.js +19 -0
  94. data/test/scss_test.js +19 -0
  95. data/test/support/less.patch +4 -0
  96. data/test/support/scss.patch +493 -0
  97. data/tests/README.md +55 -0
  98. data/tests/_coverage.html +26 -0
  99. data/tests/assets/coverage.js +48 -0
  100. data/tests/assets/jquery-1.7.1.min.js +4 -0
  101. data/tests/assets/mock.js +26 -0
  102. data/tests/assets/qunit-logging.js +29 -0
  103. data/tests/assets/qunit.css +235 -0
  104. data/tests/assets/qunit.js +1669 -0
  105. data/tests/assets/utils.js +21 -0
  106. data/tests/run-qunit.js +157 -0
  107. data/tests/suites/calendar-weeks.js +48 -0
  108. data/tests/suites/component.js +202 -0
  109. data/tests/suites/data-api.js +114 -0
  110. data/tests/suites/events.js +306 -0
  111. data/tests/suites/formats.js +235 -0
  112. data/tests/suites/inline.js +28 -0
  113. data/tests/suites/keyboard_navigation/2011.js +92 -0
  114. data/tests/suites/keyboard_navigation/2012.js +468 -0
  115. data/tests/suites/keyboard_navigation/all.js +26 -0
  116. data/tests/suites/methods.js +78 -0
  117. data/tests/suites/mouse_navigation/2011.js +66 -0
  118. data/tests/suites/mouse_navigation/2012.js +251 -0
  119. data/tests/suites/mouse_navigation/all.js +33 -0
  120. data/tests/suites/noconflict.js +20 -0
  121. data/tests/suites/options.js +648 -0
  122. data/tests/tests.html +50 -0
  123. metadata +240 -0
@@ -0,0 +1,191 @@
1
+ Options
2
+ =======
3
+
4
+ All options that take a "Date" can handle a ``Date`` object; a String formatted according to the given ``format``; or a timedelta relative to today, eg "-1d", "+6m +1y", etc, where valid units are "d" (day), "w" (week), "m" (month), and "y" (year).
5
+
6
+ Most options can be provided via data-attributes. An option can be converted to a data-attribute by taking its name, replacing each uppercase letter with its lowercase equivalent preceded by a dash, and prepending "data-date-" to the result. For example, ``startDate`` would be ``data-date-start-date``, ``format`` would be ``data-date-format``, and ``daysOfWeekDisabled`` would be ``data-date-days-of-week-disabled``.
7
+
8
+
9
+ autoclose
10
+ ---------
11
+
12
+ Boolean. Default: false
13
+
14
+ Whether or not to close the datepicker immediately when a date is selected.
15
+
16
+
17
+ beforeShowDay
18
+ -------------
19
+
20
+ Function(Date). Default: $.noop
21
+
22
+ A function that takes a date as a parameter and returns one of the following values:
23
+
24
+ * undefined to have no effect
25
+ * A Boolean, indicating whether or not this date is selectable
26
+ * A String representing additional CSS classes to apply to the date's cell
27
+ * An object with the following properties:
28
+
29
+ * ``enabled``: same as the Boolean value above
30
+ * ``classes``: same as the String value above
31
+ * ``tooltip``: a tooltip to apply to this date, via the ``title`` HTML attribute
32
+
33
+
34
+ calendarWeeks
35
+ -------------
36
+
37
+ Boolean. Default: false
38
+
39
+ Whether or not to show week numbers to the left of week rows.
40
+
41
+
42
+ clearBtn
43
+ --------
44
+
45
+ Boolean. Default: false
46
+
47
+ If true, displays a "Clear" button at the bottom of the datepicker to clear the input value. If "autoclose" is also set to true, this button will also close the datepicker.
48
+
49
+
50
+ .. _daysofweekdisabled:
51
+
52
+ daysOfWeekDisabled
53
+ ------------------
54
+
55
+ String, Array. Default: '', []
56
+
57
+ Days of the week that should be disabled. Values are 0 (Sunday) to 6 (Saturday). Multiple values should be comma-separated. Example: disable weekends: ``'0,6'`` or ``[0,6]``.
58
+
59
+
60
+ .. _enddate:
61
+
62
+ endDate
63
+ -------
64
+
65
+ Date. Default: End of time
66
+
67
+ The latest date that may be selected; all later dates will be disabled.
68
+
69
+
70
+ forceParse
71
+ ----------
72
+
73
+ Boolean. Default: true
74
+
75
+ Whether or not to force parsing of the input value when the picker is closed. That is, when an invalid date is left in the input field by the user, the picker will forcibly parse that value, and set the input's value to the new, valid date, conforming to the given `format`.
76
+
77
+
78
+ format
79
+ ------
80
+
81
+ String. Default: "mm/dd/yyyy"
82
+
83
+ The date format, combination of d, dd, D, DD, m, mm, M, MM, yy, yyyy.
84
+
85
+ * d, dd: Numeric date, no leading zero and leading zero, respectively. Eg, 5, 05.
86
+ * D, DD: Abbreviated and full weekday names, respectively. Eg, Mon, Monday.
87
+ * m, mm: Numeric month, no leading zero and leading zero, respectively. Eg, 7, 07.
88
+ * M, MM: Abbreviated and full month names, respectively. Eg, Jan, January
89
+ * yy, yyyy: 2- and 4-digit years, respectively. Eg, 12, 2012.
90
+
91
+
92
+ inputs
93
+ ------
94
+
95
+ Array. Default: None
96
+
97
+ A list of inputs to be used in a range picker, which will be attached to the selected element. Allows for explicitly creating a range picker on a non-standard element.
98
+
99
+
100
+ keyboardNavigation
101
+ ------------------
102
+
103
+ Boolean. Default: true
104
+
105
+ Whether or not to allow date navigation by arrow keys.
106
+
107
+
108
+ language
109
+ --------
110
+
111
+ String. Default: "en"
112
+
113
+ The IETF code (eg "en" for English, "pt-BR" for Brazilian Portuguese) of the language to use for month and day names. These will also be used as the input's value (and subsequently sent to the server in the case of form submissions). If a full code (eg "de-DE") is supplied the picker will first check for an "de-DE" language and if not found will fallback and check for a "de" language. If an unknown language code is given, English will be used. See :doc:`i18n`.
114
+
115
+
116
+ minViewMode
117
+ -----------
118
+
119
+ Number, String. Default: 0, "days"
120
+
121
+ Set a limit for the view mode. Accepts: "days" or 0, "months" or 1, and "years" or 2.
122
+ Gives the ability to pick only a month or an year. The day is set to the 1st for "months", and the month is set to January for "years".
123
+
124
+
125
+ multidate
126
+ ---------
127
+
128
+ Boolean, Number. Default: false
129
+
130
+ Enable multidate picking. Each date in month view acts as a toggle button, keeping track of which dates the user has selected in order. If a number is given, the picker will limit how many dates can be selected to that number, dropping the oldest dates from the list when the number is exceeded. ``true`` equates to no limit. The input's value (if present) is set to a string generated by joining the dates, formatted, with ``multidateSeparator``.
131
+
132
+
133
+ multidateSeparator
134
+ ------------------
135
+
136
+ String. Default: ","
137
+
138
+ The string that will appear between dates when generating the input's value. When parsing the input's value for a multidate picker, this will also be used to split the incoming string to separate multiple formatted dates; as such, it is highly recommended that you not use a string that could be a substring of a formatted date (eg, using '-' to separate dates when your format is 'yyyy-mm-dd').
139
+
140
+
141
+ orientation
142
+ -----------
143
+
144
+ String. Default: "auto"
145
+
146
+ A space-separated string consisting of one or two of "left" or "right", "top" or "bottom", and "auto" (may be omitted); for example, "top left", "bottom" (horizontal orientation will default to "auto"), "right" (vertical orientation will default to "auto"), "auto top". Allows for fixed placement of the picker popup.
147
+
148
+ "orientation" refers to the location of the picker popup's "anchor"; you can also think of it as the location of the trigger element (input, component, etc) relative to the picker.
149
+
150
+ "auto" triggers "smart orientation" of the picker. Horizontal orientation will default to "left" and left offset will be tweaked to keep the picker inside the browser viewport; vertical orientation will simply choose "top" or "bottom", whichever will show more of the picker in the viewport.
151
+
152
+ .. _startdate:
153
+
154
+ startDate
155
+ ---------
156
+
157
+ Date. Default: Beginning of time
158
+
159
+ The earliest date that may be selected; all earlier dates will be disabled.
160
+
161
+
162
+ startView
163
+ ---------
164
+
165
+ Number, String. Default: 0, "month"
166
+
167
+ The view that the datepicker should show when it is opened. Accepts values of 0 or "month" for month view (the default), 1 or "year" for the 12-month overview, and 2 or "decade" for the 10-year overview. Useful for date-of-birth datepickers.
168
+
169
+
170
+ todayBtn
171
+ --------
172
+
173
+ Boolean, "linked". Default: false
174
+
175
+ If true or "linked", displays a "Today" button at the bottom of the datepicker to select the current date. If true, the "Today" button will only move the current date into view; if "linked", the current date will also be selected.
176
+
177
+
178
+ todayHighlight
179
+ --------------
180
+
181
+ Boolean. Default: false
182
+
183
+ If true, highlights the current date.
184
+
185
+
186
+ weekStart
187
+ ---------
188
+
189
+ Integer. Default: 0
190
+
191
+ Day of the week start. 0 (Sunday) to 6 (Saturday)
@@ -0,0 +1,1609 @@
1
+ /* =========================================================
2
+ * bootstrap-datepicker.js
3
+ * Repo: https://github.com/eternicode/bootstrap-datepicker/
4
+ * Demo: http://eternicode.github.io/bootstrap-datepicker/
5
+ * Docs: http://bootstrap-datepicker.readthedocs.org/
6
+ * Forked from http://www.eyecon.ro/bootstrap-datepicker
7
+ * =========================================================
8
+ * Started by Stefan Petre; improvements by Andrew Rowls + contributors
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License");
11
+ * you may not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ * ========================================================= */
22
+
23
+ (function($, undefined) {
24
+
25
+ var $window = $(window);
26
+
27
+ function UTCDate(){
28
+ return new Date(Date.UTC.apply(Date, arguments));
29
+ }
30
+ function UTCToday(){
31
+ var today = new Date();
32
+ return UTCDate(today.getFullYear(), today.getMonth(), today.getDate());
33
+ }
34
+ function alias(method){
35
+ return function(){
36
+ return this[method].apply(this, arguments);
37
+ }
38
+ }
39
+
40
+ var DateArray = (function(){
41
+ var extras = {
42
+ get: function(i){
43
+ return this.slice(i)[0];
44
+ },
45
+ contains: function(d){
46
+ // Array.indexOf is not cross-browser;
47
+ // $.inArray doesn't work with Dates
48
+ var val = d && d.valueOf();
49
+ for (var i=0, l=this.length; i<l; i++)
50
+ if (this[i].valueOf() === val)
51
+ return i;
52
+ return -1;
53
+ },
54
+ remove: function(i){
55
+ this.splice(i,1);
56
+ },
57
+ replace: function(new_array){
58
+ if (!new_array)
59
+ return;
60
+ if (!$.isArray(new_array))
61
+ new_array = [new_array];
62
+ this.clear();
63
+ this.push.apply(this, new_array);
64
+ },
65
+ clear: function(){
66
+ this.splice(0);
67
+ },
68
+ copy: function(){
69
+ var a = new DateArray();
70
+ a.replace(this);
71
+ return a;
72
+ }
73
+ };
74
+
75
+ return function(){
76
+ var a = [];
77
+ a.push.apply(a, arguments);
78
+ $.extend(a, extras);
79
+ return a;
80
+ }
81
+ })();
82
+
83
+
84
+ // Picker object
85
+
86
+ var Datepicker = function(element, options) {
87
+ this.dates = new DateArray();
88
+ this.viewDate = UTCToday();
89
+ this.focusDate = null;
90
+
91
+ this._process_options(options);
92
+
93
+ this.element = $(element);
94
+ this.isInline = false;
95
+ this.isInput = this.element.is('input');
96
+ this.component = this.element.is('.date') ? this.element.find('.add-on, .input-group-addon, .btn') : false;
97
+ this.hasInput = this.component && this.element.find('input').length;
98
+ if(this.component && this.component.length === 0)
99
+ this.component = false;
100
+
101
+ this.picker = $(DPGlobal.template);
102
+ this._buildEvents();
103
+ this._attachEvents();
104
+
105
+ if(this.isInline) {
106
+ this.picker.addClass('datepicker-inline').appendTo(this.element);
107
+ } else {
108
+ this.picker.addClass('datepicker-dropdown dropdown-menu');
109
+ }
110
+
111
+ if (this.o.rtl){
112
+ this.picker.addClass('datepicker-rtl');
113
+ }
114
+
115
+ this.viewMode = this.o.startView;
116
+
117
+ if (this.o.calendarWeeks)
118
+ this.picker.find('tfoot th.today')
119
+ .attr('colspan', function(i, val){
120
+ return parseInt(val) + 1;
121
+ });
122
+
123
+ this._allow_update = false;
124
+
125
+ this.setStartDate(this._o.startDate);
126
+ this.setEndDate(this._o.endDate);
127
+ this.setDaysOfWeekDisabled(this.o.daysOfWeekDisabled);
128
+
129
+ this.fillDow();
130
+ this.fillMonths();
131
+
132
+ this._allow_update = true;
133
+
134
+ this.update();
135
+ this.showMode();
136
+
137
+ if(this.isInline) {
138
+ this.show();
139
+ }
140
+ };
141
+
142
+ Datepicker.prototype = {
143
+ constructor: Datepicker,
144
+
145
+ _process_options: function(opts){
146
+ // Store raw options for reference
147
+ this._o = $.extend({}, this._o, opts);
148
+ // Processed options
149
+ var o = this.o = $.extend({}, this._o);
150
+
151
+ // Check if "de-DE" style date is available, if not language should
152
+ // fallback to 2 letter code eg "de"
153
+ var lang = o.language;
154
+ if (!dates[lang]) {
155
+ lang = lang.split('-')[0];
156
+ if (!dates[lang])
157
+ lang = defaults.language;
158
+ }
159
+ o.language = lang;
160
+
161
+ switch(o.startView){
162
+ case 2:
163
+ case 'decade':
164
+ o.startView = 2;
165
+ break;
166
+ case 1:
167
+ case 'year':
168
+ o.startView = 1;
169
+ break;
170
+ default:
171
+ o.startView = 0;
172
+ }
173
+
174
+ switch (o.minViewMode) {
175
+ case 1:
176
+ case 'months':
177
+ o.minViewMode = 1;
178
+ break;
179
+ case 2:
180
+ case 'years':
181
+ o.minViewMode = 2;
182
+ break;
183
+ default:
184
+ o.minViewMode = 0;
185
+ }
186
+
187
+ o.startView = Math.max(o.startView, o.minViewMode);
188
+
189
+ // true, false, or Number > 0
190
+ if (o.multidate !== true){
191
+ o.multidate = Number(o.multidate) || false;
192
+ if (o.multidate !== false)
193
+ o.multidate = Math.max(0, o.multidate);
194
+ else
195
+ o.multidate = 1;
196
+ }
197
+ o.multidateSeparator = String(o.multidateSeparator);
198
+
199
+ o.weekStart %= 7;
200
+ o.weekEnd = ((o.weekStart + 6) % 7);
201
+
202
+ var format = DPGlobal.parseFormat(o.format);
203
+ if (o.startDate !== -Infinity) {
204
+ if (!!o.startDate) {
205
+ if (o.startDate instanceof Date)
206
+ o.startDate = this._local_to_utc(this._zero_time(o.startDate));
207
+ else
208
+ o.startDate = DPGlobal.parseDate(o.startDate, format, o.language);
209
+ } else {
210
+ o.startDate = -Infinity;
211
+ }
212
+ }
213
+ if (o.endDate !== Infinity) {
214
+ if (!!o.endDate) {
215
+ if (o.endDate instanceof Date)
216
+ o.endDate = this._local_to_utc(this._zero_time(o.endDate));
217
+ else
218
+ o.endDate = DPGlobal.parseDate(o.endDate, format, o.language);
219
+ } else {
220
+ o.endDate = Infinity;
221
+ }
222
+ }
223
+
224
+ o.daysOfWeekDisabled = o.daysOfWeekDisabled||[];
225
+ if (!$.isArray(o.daysOfWeekDisabled))
226
+ o.daysOfWeekDisabled = o.daysOfWeekDisabled.split(/[,\s]*/);
227
+ o.daysOfWeekDisabled = $.map(o.daysOfWeekDisabled, function (d) {
228
+ return parseInt(d, 10);
229
+ });
230
+
231
+ var plc = String(o.orientation).toLowerCase().split(/\s+/g),
232
+ _plc = o.orientation.toLowerCase();
233
+ plc = $.grep(plc, function(word){
234
+ return (/^auto|left|right|top|bottom$/).test(word);
235
+ });
236
+ o.orientation = {x: 'auto', y: 'auto'};
237
+ if (!_plc || _plc === 'auto')
238
+ ; // no action
239
+ else if (plc.length === 1){
240
+ switch(plc[0]){
241
+ case 'top':
242
+ case 'bottom':
243
+ o.orientation.y = plc[0];
244
+ break;
245
+ case 'left':
246
+ case 'right':
247
+ o.orientation.x = plc[0];
248
+ break;
249
+ }
250
+ }
251
+ else {
252
+ _plc = $.grep(plc, function(word){
253
+ return (/^left|right$/).test(word);
254
+ });
255
+ o.orientation.x = _plc[0] || 'auto';
256
+
257
+ _plc = $.grep(plc, function(word){
258
+ return (/^top|bottom$/).test(word);
259
+ });
260
+ o.orientation.y = _plc[0] || 'auto';
261
+ }
262
+ },
263
+ _events: [],
264
+ _secondaryEvents: [],
265
+ _applyEvents: function(evs){
266
+ for (var i=0, el, ch, ev; i<evs.length; i++){
267
+ el = evs[i][0];
268
+ if (evs[i].length == 2){
269
+ ch = undefined;
270
+ ev = evs[i][1];
271
+ }
272
+ else if (evs[i].length == 3){
273
+ ch = evs[i][1];
274
+ ev = evs[i][2];
275
+ }
276
+ el.on(ev, ch);
277
+ }
278
+ },
279
+ _unapplyEvents: function(evs){
280
+ for (var i=0, el, ev, ch; i<evs.length; i++){
281
+ el = evs[i][0];
282
+ if (evs[i].length == 2){
283
+ ch = undefined;
284
+ ev = evs[i][1];
285
+ }
286
+ else if (evs[i].length == 3){
287
+ ch = evs[i][1];
288
+ ev = evs[i][2];
289
+ }
290
+ el.off(ev, ch);
291
+ }
292
+ },
293
+ _buildEvents: function(){
294
+ if (this.isInput) { // single input
295
+ this._events = [
296
+ [this.element, {
297
+ focus: $.proxy(this.show, this),
298
+ keyup: $.proxy(function(e){
299
+ if ($.inArray(e.keyCode, [27,37,39,38,40,32,13,9]) === -1)
300
+ this.update();
301
+ }, this),
302
+ keydown: $.proxy(this.keydown, this)
303
+ }]
304
+ ];
305
+ }
306
+ else if (this.component && this.hasInput){ // component: input + button
307
+ this._events = [
308
+ // For components that are not readonly, allow keyboard nav
309
+ [this.element.find('input'), {
310
+ focus: $.proxy(this.show, this),
311
+ keyup: $.proxy(function(e){
312
+ if ($.inArray(e.keyCode, [27,37,39,38,40,32,13,9]) === -1)
313
+ this.update()
314
+ }, this),
315
+ keydown: $.proxy(this.keydown, this)
316
+ }],
317
+ [this.component, {
318
+ click: $.proxy(this.show, this)
319
+ }]
320
+ ];
321
+ }
322
+ else if (this.element.is('div')) { // inline datepicker
323
+ this.isInline = true;
324
+ }
325
+ else {
326
+ this._events = [
327
+ [this.element, {
328
+ click: $.proxy(this.show, this)
329
+ }]
330
+ ];
331
+ }
332
+ this._events.push(
333
+ // Component: listen for blur on element descendants
334
+ [this.element, '*', {
335
+ blur: $.proxy(function(e){
336
+ this._focused_from = e.target;
337
+ }, this)
338
+ }],
339
+ // Input: listen for blur on element
340
+ [this.element, {
341
+ blur: $.proxy(function(e){
342
+ this._focused_from = e.target;
343
+ }, this)
344
+ }]
345
+ );
346
+
347
+ this._secondaryEvents = [
348
+ [this.picker, {
349
+ click: $.proxy(this.click, this)
350
+ }],
351
+ [$(window), {
352
+ resize: $.proxy(this.place, this)
353
+ }],
354
+ [$(document), {
355
+ 'mousedown touchstart': $.proxy(function (e) {
356
+ // Clicked outside the datepicker, hide it
357
+ if (!(
358
+ this.element.is(e.target) ||
359
+ this.element.find(e.target).length ||
360
+ this.picker.is(e.target) ||
361
+ this.picker.find(e.target).length
362
+ )) {
363
+ this.hide();
364
+ }
365
+ }, this)
366
+ }]
367
+ ];
368
+ },
369
+ _attachEvents: function(){
370
+ this._detachEvents();
371
+ this._applyEvents(this._events);
372
+ },
373
+ _detachEvents: function(){
374
+ this._unapplyEvents(this._events);
375
+ },
376
+ _attachSecondaryEvents: function(){
377
+ this._detachSecondaryEvents();
378
+ this._applyEvents(this._secondaryEvents);
379
+ },
380
+ _detachSecondaryEvents: function(){
381
+ this._unapplyEvents(this._secondaryEvents);
382
+ },
383
+ _trigger: function(event, altdate){
384
+ var date = altdate || this.dates.get(-1),
385
+ local_date = this._utc_to_local(date);
386
+
387
+ this.element.trigger({
388
+ type: event,
389
+ date: local_date,
390
+ dates: $.map(this.dates, this._utc_to_local),
391
+ format: $.proxy(function(ix, format){
392
+ if (arguments.length === 0){
393
+ ix = this.dates.length - 1;
394
+ format = this.o.format;
395
+ }
396
+ else if (typeof ix == 'string'){
397
+ format = ix;
398
+ ix = this.dates.length - 1;
399
+ }
400
+ format = format || this.o.format;
401
+ var date = this.dates.get(ix);
402
+ return DPGlobal.formatDate(date, format, this.o.language);
403
+ }, this)
404
+ });
405
+ },
406
+
407
+ show: function(e) {
408
+ if (!this.isInline)
409
+ this.picker.appendTo('body');
410
+ this.picker.show();
411
+ this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
412
+ this.place();
413
+ this._attachSecondaryEvents();
414
+ this._trigger('show');
415
+ },
416
+
417
+ hide: function(){
418
+ if(this.isInline) return;
419
+ if (!this.picker.is(':visible')) return;
420
+ this.focusDate = null;
421
+ this.picker.hide().detach();
422
+ this._detachSecondaryEvents();
423
+ this.viewMode = this.o.startView;
424
+ this.showMode();
425
+
426
+ if (
427
+ this.o.forceParse &&
428
+ (
429
+ this.isInput && this.element.val() ||
430
+ this.hasInput && this.element.find('input').val()
431
+ )
432
+ )
433
+ this.setValue();
434
+ this._trigger('hide');
435
+ },
436
+
437
+ remove: function() {
438
+ this.hide();
439
+ this._detachEvents();
440
+ this._detachSecondaryEvents();
441
+ this.picker.remove();
442
+ delete this.element.data().datepicker;
443
+ if (!this.isInput) {
444
+ delete this.element.data().date;
445
+ }
446
+ },
447
+
448
+ _utc_to_local: function(utc){
449
+ return utc && new Date(utc.getTime() + (utc.getTimezoneOffset()*60000));
450
+ },
451
+ _local_to_utc: function(local){
452
+ return local && new Date(local.getTime() - (local.getTimezoneOffset()*60000));
453
+ },
454
+ _zero_time: function(local){
455
+ return local && new Date(local.getFullYear(), local.getMonth(), local.getDate());
456
+ },
457
+ _zero_utc_time: function(utc){
458
+ return utc && new Date(Date.UTC(utc.getUTCFullYear(), utc.getUTCMonth(), utc.getUTCDate()));
459
+ },
460
+
461
+ getDates: function(){
462
+ return $.map(this.dates, this._utc_to_local);
463
+ },
464
+
465
+ getUTCDates: function(){
466
+ return $.map(this.dates, function(d){ return new Date(d); });
467
+ },
468
+
469
+ getDate: function() {
470
+ return this._utc_to_local(this.getUTCDate());
471
+ },
472
+
473
+ getUTCDate: function() {
474
+ return new Date(this.dates.get(-1));
475
+ },
476
+
477
+ setDates: function() {
478
+ this.update.apply(this, arguments);
479
+ this._trigger('changeDate');
480
+ this.setValue();
481
+ },
482
+
483
+ setUTCDates: function() {
484
+ this.update.apply(this, $.map(arguments, this._utc_to_local));
485
+ this._trigger('changeDate');
486
+ this.setValue();
487
+ },
488
+
489
+ setDate: alias('setDates'),
490
+ setUTCDate: alias('setUTCDates'),
491
+
492
+ setValue: function() {
493
+ var formatted = this.getFormattedDate();
494
+ if (!this.isInput) {
495
+ if (this.component){
496
+ this.element.find('input').val(formatted).change();
497
+ }
498
+ } else {
499
+ this.element.val(formatted).change();
500
+ }
501
+ },
502
+
503
+ getFormattedDate: function(format) {
504
+ if (format === undefined)
505
+ format = this.o.format;
506
+
507
+ var lang = this.o.language;
508
+ return $.map(this.dates, function(d){
509
+ return DPGlobal.formatDate(d, format, lang);
510
+ }).join(this.o.multidateSeparator);
511
+ },
512
+
513
+ setStartDate: function(startDate){
514
+ this._process_options({startDate: startDate});
515
+ this.update();
516
+ this.updateNavArrows();
517
+ },
518
+
519
+ setEndDate: function(endDate){
520
+ this._process_options({endDate: endDate});
521
+ this.update();
522
+ this.updateNavArrows();
523
+ },
524
+
525
+ setDaysOfWeekDisabled: function(daysOfWeekDisabled){
526
+ this._process_options({daysOfWeekDisabled: daysOfWeekDisabled});
527
+ this.update();
528
+ this.updateNavArrows();
529
+ },
530
+
531
+ place: function(){
532
+ if(this.isInline) return;
533
+ var calendarWidth = this.picker.outerWidth(),
534
+ calendarHeight = this.picker.outerHeight(),
535
+ visualPadding = 10,
536
+ windowWidth = $window.width(),
537
+ windowHeight = $window.height(),
538
+ scrollTop = $window.scrollTop();
539
+
540
+ var zIndex = parseInt(this.element.parents().filter(function() {
541
+ return $(this).css('z-index') != 'auto';
542
+ }).first().css('z-index'))+10;
543
+ var offset = this.component ? this.component.parent().offset() : this.element.offset();
544
+ var height = this.component ? this.component.outerHeight(true) : this.element.outerHeight(false);
545
+ var width = this.component ? this.component.outerWidth(true) : this.element.outerWidth(false);
546
+ var left = offset.left,
547
+ top = offset.top;
548
+
549
+ this.picker.removeClass(
550
+ 'datepicker-orient-top datepicker-orient-bottom '+
551
+ 'datepicker-orient-right datepicker-orient-left'
552
+ );
553
+
554
+ if (this.o.orientation.x !== 'auto') {
555
+ this.picker.addClass('datepicker-orient-' + this.o.orientation.x);
556
+ if (this.o.orientation.x === 'right')
557
+ left -= calendarWidth - width;
558
+ }
559
+ // auto x orientation is best-placement: if it crosses a window
560
+ // edge, fudge it sideways
561
+ else {
562
+ // Default to left
563
+ this.picker.addClass('datepicker-orient-left');
564
+ if (offset.left < 0)
565
+ left -= offset.left - visualPadding;
566
+ else if (offset.left + calendarWidth > windowWidth)
567
+ left = windowWidth - calendarWidth - visualPadding;
568
+ }
569
+
570
+ // auto y orientation is best-situation: top or bottom, no fudging,
571
+ // decision based on which shows more of the calendar
572
+ var yorient = this.o.orientation.y,
573
+ top_overflow, bottom_overflow;
574
+ if (yorient === 'auto') {
575
+ top_overflow = -scrollTop + offset.top - calendarHeight;
576
+ bottom_overflow = scrollTop + windowHeight - (offset.top + height + calendarHeight);
577
+ if (Math.max(top_overflow, bottom_overflow) === bottom_overflow)
578
+ yorient = 'top';
579
+ else
580
+ yorient = 'bottom';
581
+ }
582
+ this.picker.addClass('datepicker-orient-' + yorient);
583
+ if (yorient === 'top')
584
+ top += height;
585
+ else
586
+ top -= calendarHeight + parseInt(this.picker.css('padding-top'));
587
+
588
+ this.picker.css({
589
+ top: top,
590
+ left: left,
591
+ zIndex: zIndex
592
+ });
593
+ },
594
+
595
+ _allow_update: true,
596
+ update: function(){
597
+ if (!this._allow_update) return;
598
+
599
+ var oldDates = this.dates.copy(),
600
+ dates = [],
601
+ fromArgs = false;
602
+ if(arguments.length) {
603
+ $.each(arguments, $.proxy(function(i, date){
604
+ if (date instanceof Date)
605
+ date = this._local_to_utc(date);
606
+ dates.push(date);
607
+ }, this));
608
+ fromArgs = true;
609
+ } else {
610
+ dates = this.isInput
611
+ ? this.element.val()
612
+ : this.element.data('date') || this.element.find('input').val();
613
+ if (dates && this.o.multidate)
614
+ dates = dates.split(this.o.multidateSeparator);
615
+ else
616
+ dates = [dates];
617
+ delete this.element.data().date;
618
+ }
619
+
620
+ dates = $.map(dates, $.proxy(function(date){
621
+ return DPGlobal.parseDate(date, this.o.format, this.o.language);
622
+ }, this));
623
+ dates = $.grep(dates, $.proxy(function(date){
624
+ return (
625
+ date < this.o.startDate ||
626
+ date > this.o.endDate ||
627
+ !date
628
+ );
629
+ }, this), true);
630
+ this.dates.replace(dates);
631
+
632
+ if (this.dates.length)
633
+ this.viewDate = new Date(this.dates.get(-1));
634
+ else if (this.viewDate < this.o.startDate)
635
+ this.viewDate = new Date(this.o.startDate);
636
+ else if (this.viewDate > this.o.endDate)
637
+ this.viewDate = new Date(this.o.endDate);
638
+
639
+ if (fromArgs) {
640
+ // setting date by clicking
641
+ this.setValue();
642
+ } else if (dates.length) {
643
+ // setting date by typing
644
+ if (String(oldDates) !== String(this.dates))
645
+ this._trigger('changeDate');
646
+ }
647
+ if (!this.dates.length && oldDates.length)
648
+ this._trigger('clearDate');
649
+
650
+ this.fill();
651
+ },
652
+
653
+ fillDow: function(){
654
+ var dowCnt = this.o.weekStart,
655
+ html = '<tr>';
656
+ if(this.o.calendarWeeks){
657
+ var cell = '<th class="cw">&nbsp;</th>';
658
+ html += cell;
659
+ this.picker.find('.datepicker-days thead tr:first-child').prepend(cell);
660
+ }
661
+ while (dowCnt < this.o.weekStart + 7) {
662
+ html += '<th class="dow">'+dates[this.o.language].daysMin[(dowCnt++)%7]+'</th>';
663
+ }
664
+ html += '</tr>';
665
+ this.picker.find('.datepicker-days thead').append(html);
666
+ },
667
+
668
+ fillMonths: function(){
669
+ var html = '',
670
+ i = 0;
671
+ while (i < 12) {
672
+ html += '<span class="month">'+dates[this.o.language].monthsShort[i++]+'</span>';
673
+ }
674
+ this.picker.find('.datepicker-months td').html(html);
675
+ },
676
+
677
+ setRange: function(range){
678
+ if (!range || !range.length)
679
+ delete this.range;
680
+ else
681
+ this.range = $.map(range, function(d){ return d.valueOf(); });
682
+ this.fill();
683
+ },
684
+
685
+ getClassNames: function(date){
686
+ var cls = [],
687
+ year = this.viewDate.getUTCFullYear(),
688
+ month = this.viewDate.getUTCMonth(),
689
+ today = new Date();
690
+ if (date.getUTCFullYear() < year || (date.getUTCFullYear() == year && date.getUTCMonth() < month)) {
691
+ cls.push('old');
692
+ } else if (date.getUTCFullYear() > year || (date.getUTCFullYear() == year && date.getUTCMonth() > month)) {
693
+ cls.push('new');
694
+ }
695
+ if (this.focusDate && date.valueOf() === this.focusDate.valueOf())
696
+ cls.push('focused');
697
+ // Compare internal UTC date with local today, not UTC today
698
+ if (this.o.todayHighlight &&
699
+ date.getUTCFullYear() == today.getFullYear() &&
700
+ date.getUTCMonth() == today.getMonth() &&
701
+ date.getUTCDate() == today.getDate()) {
702
+ cls.push('today');
703
+ }
704
+ if (this.dates.contains(date) !== -1)
705
+ cls.push('active');
706
+ if (date.valueOf() < this.o.startDate || date.valueOf() > this.o.endDate ||
707
+ $.inArray(date.getUTCDay(), this.o.daysOfWeekDisabled) !== -1) {
708
+ cls.push('disabled');
709
+ }
710
+ if (this.range){
711
+ if (date > this.range[0] && date < this.range[this.range.length-1]){
712
+ cls.push('range');
713
+ }
714
+ if ($.inArray(date.valueOf(), this.range) != -1){
715
+ cls.push('selected');
716
+ }
717
+ }
718
+ return cls;
719
+ },
720
+
721
+ fill: function() {
722
+ var d = new Date(this.viewDate),
723
+ year = d.getUTCFullYear(),
724
+ month = d.getUTCMonth(),
725
+ startYear = this.o.startDate !== -Infinity ? this.o.startDate.getUTCFullYear() : -Infinity,
726
+ startMonth = this.o.startDate !== -Infinity ? this.o.startDate.getUTCMonth() : -Infinity,
727
+ endYear = this.o.endDate !== Infinity ? this.o.endDate.getUTCFullYear() : Infinity,
728
+ endMonth = this.o.endDate !== Infinity ? this.o.endDate.getUTCMonth() : Infinity,
729
+ tooltip, currentYear;
730
+ this.picker.find('.datepicker-days thead th.datepicker-switch')
731
+ .text(dates[this.o.language].months[month]+' '+year);
732
+ this.picker.find('tfoot th.today')
733
+ .text(dates[this.o.language].today)
734
+ .toggle(this.o.todayBtn !== false);
735
+ this.picker.find('tfoot th.clear')
736
+ .text(dates[this.o.language].clear)
737
+ .toggle(this.o.clearBtn !== false);
738
+ this.updateNavArrows();
739
+ this.fillMonths();
740
+ var prevMonth = UTCDate(year, month-1, 28),
741
+ day = DPGlobal.getDaysInMonth(prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
742
+ prevMonth.setUTCDate(day);
743
+ prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.o.weekStart + 7)%7);
744
+ var nextMonth = new Date(prevMonth);
745
+ nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
746
+ nextMonth = nextMonth.valueOf();
747
+ var html = [];
748
+ var clsName;
749
+ while(prevMonth.valueOf() < nextMonth) {
750
+ if (prevMonth.getUTCDay() == this.o.weekStart) {
751
+ html.push('<tr>');
752
+ if(this.o.calendarWeeks){
753
+ // ISO 8601: First week contains first thursday.
754
+ // ISO also states week starts on Monday, but we can be more abstract here.
755
+ var
756
+ // Start of current week: based on weekstart/current date
757
+ ws = new Date(+prevMonth + (this.o.weekStart - prevMonth.getUTCDay() - 7) % 7 * 864e5),
758
+ // Thursday of this week
759
+ th = new Date(+ws + (7 + 4 - ws.getUTCDay()) % 7 * 864e5),
760
+ // First Thursday of year, year from thursday
761
+ yth = new Date(+(yth = UTCDate(th.getUTCFullYear(), 0, 1)) + (7 + 4 - yth.getUTCDay())%7*864e5),
762
+ // Calendar week: ms between thursdays, div ms per day, div 7 days
763
+ calWeek = (th - yth) / 864e5 / 7 + 1;
764
+ html.push('<td class="cw">'+ calWeek +'</td>');
765
+
766
+ }
767
+ }
768
+ clsName = this.getClassNames(prevMonth);
769
+ clsName.push('day');
770
+
771
+ if (this.o.beforeShowDay !== $.noop){
772
+ var before = this.o.beforeShowDay(this._utc_to_local(prevMonth));
773
+ if (before === undefined)
774
+ before = {};
775
+ else if (typeof(before) === 'boolean')
776
+ before = {enabled: before};
777
+ else if (typeof(before) === 'string')
778
+ before = {classes: before};
779
+ if (before.enabled === false)
780
+ clsName.push('disabled');
781
+ if (before.classes)
782
+ clsName = clsName.concat(before.classes.split(/\s+/));
783
+ if (before.tooltip)
784
+ tooltip = before.tooltip;
785
+ }
786
+
787
+ clsName = $.unique(clsName);
788
+ html.push('<td class="'+clsName.join(' ')+'"' + (tooltip ? ' title="'+tooltip+'"' : '') + '>'+prevMonth.getUTCDate() + '</td>');
789
+ if (prevMonth.getUTCDay() == this.o.weekEnd) {
790
+ html.push('</tr>');
791
+ }
792
+ prevMonth.setUTCDate(prevMonth.getUTCDate()+1);
793
+ }
794
+ this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
795
+
796
+ var months = this.picker.find('.datepicker-months')
797
+ .find('th:eq(1)')
798
+ .text(year)
799
+ .end()
800
+ .find('span').removeClass('active');
801
+
802
+ $.each(this.dates, function(i, d){
803
+ if (d.getUTCFullYear() == year)
804
+ months.eq(d.getUTCMonth()).addClass('active');
805
+ });
806
+
807
+ if (year < startYear || year > endYear) {
808
+ months.addClass('disabled');
809
+ }
810
+ if (year == startYear) {
811
+ months.slice(0, startMonth).addClass('disabled');
812
+ }
813
+ if (year == endYear) {
814
+ months.slice(endMonth+1).addClass('disabled');
815
+ }
816
+
817
+ html = '';
818
+ year = parseInt(year/10, 10) * 10;
819
+ var yearCont = this.picker.find('.datepicker-years')
820
+ .find('th:eq(1)')
821
+ .text(year + '-' + (year + 9))
822
+ .end()
823
+ .find('td');
824
+ year -= 1;
825
+ var years = $.map(this.dates, function(d){ return d.getUTCFullYear(); }),
826
+ classes;
827
+ for (var i = -1; i < 11; i++) {
828
+ classes = ['year'];
829
+ if (i === -1)
830
+ classes.push('old');
831
+ else if (i === 10)
832
+ classes.push('new');
833
+ if ($.inArray(year, years) !== -1)
834
+ classes.push('active');
835
+ if (year < startYear || year > endYear)
836
+ classes.push('disabled');
837
+ html += '<span class="' + classes.join(' ') + '">'+year+'</span>';
838
+ year += 1;
839
+ }
840
+ yearCont.html(html);
841
+ },
842
+
843
+ updateNavArrows: function() {
844
+ if (!this._allow_update) return;
845
+
846
+ var d = new Date(this.viewDate),
847
+ year = d.getUTCFullYear(),
848
+ month = d.getUTCMonth();
849
+ switch (this.viewMode) {
850
+ case 0:
851
+ if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear() && month <= this.o.startDate.getUTCMonth()) {
852
+ this.picker.find('.prev').css({visibility: 'hidden'});
853
+ } else {
854
+ this.picker.find('.prev').css({visibility: 'visible'});
855
+ }
856
+ if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear() && month >= this.o.endDate.getUTCMonth()) {
857
+ this.picker.find('.next').css({visibility: 'hidden'});
858
+ } else {
859
+ this.picker.find('.next').css({visibility: 'visible'});
860
+ }
861
+ break;
862
+ case 1:
863
+ case 2:
864
+ if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear()) {
865
+ this.picker.find('.prev').css({visibility: 'hidden'});
866
+ } else {
867
+ this.picker.find('.prev').css({visibility: 'visible'});
868
+ }
869
+ if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear()) {
870
+ this.picker.find('.next').css({visibility: 'hidden'});
871
+ } else {
872
+ this.picker.find('.next').css({visibility: 'visible'});
873
+ }
874
+ break;
875
+ }
876
+ },
877
+
878
+ click: function(e) {
879
+ e.preventDefault();
880
+ var target = $(e.target).closest('span, td, th'),
881
+ year, month, day;
882
+ if (target.length == 1) {
883
+ switch(target[0].nodeName.toLowerCase()) {
884
+ case 'th':
885
+ switch(target[0].className) {
886
+ case 'datepicker-switch':
887
+ this.showMode(1);
888
+ break;
889
+ case 'prev':
890
+ case 'next':
891
+ var dir = DPGlobal.modes[this.viewMode].navStep * (target[0].className == 'prev' ? -1 : 1);
892
+ switch(this.viewMode){
893
+ case 0:
894
+ this.viewDate = this.moveMonth(this.viewDate, dir);
895
+ this._trigger('changeMonth', this.viewDate);
896
+ break;
897
+ case 1:
898
+ case 2:
899
+ this.viewDate = this.moveYear(this.viewDate, dir);
900
+ if (this.viewMode === 1)
901
+ this._trigger('changeYear', this.viewDate);
902
+ break;
903
+ }
904
+ this.fill();
905
+ break;
906
+ case 'today':
907
+ var date = new Date();
908
+ date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
909
+
910
+ this.showMode(-2);
911
+ var which = this.o.todayBtn == 'linked' ? null : 'view';
912
+ this._setDate(date, which);
913
+ break;
914
+ case 'clear':
915
+ var element;
916
+ if (this.isInput)
917
+ element = this.element;
918
+ else if (this.component)
919
+ element = this.element.find('input');
920
+ if (element)
921
+ element.val("").change();
922
+ this.update();
923
+ this._trigger('changeDate');
924
+ if (this.o.autoclose)
925
+ this.hide();
926
+ break;
927
+ }
928
+ break;
929
+ case 'span':
930
+ if (!target.is('.disabled')) {
931
+ this.viewDate.setUTCDate(1);
932
+ if (target.is('.month')) {
933
+ day = 1;
934
+ month = target.parent().find('span').index(target);
935
+ year = this.viewDate.getUTCFullYear();
936
+ this.viewDate.setUTCMonth(month);
937
+ this._trigger('changeMonth', this.viewDate);
938
+ if (this.o.minViewMode === 1) {
939
+ this._setDate(UTCDate(year, month, day));
940
+ }
941
+ } else {
942
+ day = 1;
943
+ month = 0;
944
+ year = parseInt(target.text(), 10)||0;
945
+ this.viewDate.setUTCFullYear(year);
946
+ this._trigger('changeYear', this.viewDate);
947
+ if (this.o.minViewMode === 2) {
948
+ this._setDate(UTCDate(year, month, day));
949
+ }
950
+ }
951
+ this.showMode(-1);
952
+ this.fill();
953
+ }
954
+ break;
955
+ case 'td':
956
+ if (target.is('.day') && !target.is('.disabled')){
957
+ day = parseInt(target.text(), 10)||1;
958
+ year = this.viewDate.getUTCFullYear();
959
+ month = this.viewDate.getUTCMonth();
960
+ if (target.is('.old')) {
961
+ if (month === 0) {
962
+ month = 11;
963
+ year -= 1;
964
+ } else {
965
+ month -= 1;
966
+ }
967
+ } else if (target.is('.new')) {
968
+ if (month == 11) {
969
+ month = 0;
970
+ year += 1;
971
+ } else {
972
+ month += 1;
973
+ }
974
+ }
975
+ this._setDate(UTCDate(year, month, day));
976
+ }
977
+ break;
978
+ }
979
+ }
980
+ if (this.picker.is(':visible') && this._focused_from){
981
+ $(this._focused_from).focus();
982
+ }
983
+ delete this._focused_from;
984
+ },
985
+
986
+ _toggle_multidate: function( date ) {
987
+ var ix = this.dates.contains(date);
988
+ if (!date){
989
+ this.dates.clear();
990
+ }
991
+ else if (ix !== -1){
992
+ this.dates.remove(ix);
993
+ }
994
+ else{
995
+ this.dates.push(date);
996
+ }
997
+ if (typeof this.o.multidate == 'number')
998
+ while (this.dates.length > this.o.multidate)
999
+ this.dates.remove(0);
1000
+ },
1001
+
1002
+ _setDate: function(date, which){
1003
+ if (!which || which == 'date')
1004
+ this._toggle_multidate(date && new Date(date));
1005
+ if (!which || which == 'view')
1006
+ this.viewDate = date && new Date(date);
1007
+
1008
+ this.fill();
1009
+ this.setValue();
1010
+ this._trigger('changeDate');
1011
+ var element;
1012
+ if (this.isInput) {
1013
+ element = this.element;
1014
+ } else if (this.component){
1015
+ element = this.element.find('input');
1016
+ }
1017
+ if (element) {
1018
+ element.change();
1019
+ }
1020
+ if (this.o.autoclose && (!which || which == 'date')) {
1021
+ this.hide();
1022
+ }
1023
+ },
1024
+
1025
+ moveMonth: function(date, dir){
1026
+ if (!date) return undefined;
1027
+ if (!dir) return date;
1028
+ var new_date = new Date(date.valueOf()),
1029
+ day = new_date.getUTCDate(),
1030
+ month = new_date.getUTCMonth(),
1031
+ mag = Math.abs(dir),
1032
+ new_month, test;
1033
+ dir = dir > 0 ? 1 : -1;
1034
+ if (mag == 1){
1035
+ test = dir == -1
1036
+ // If going back one month, make sure month is not current month
1037
+ // (eg, Mar 31 -> Feb 31 == Feb 28, not Mar 02)
1038
+ ? function(){ return new_date.getUTCMonth() == month; }
1039
+ // If going forward one month, make sure month is as expected
1040
+ // (eg, Jan 31 -> Feb 31 == Feb 28, not Mar 02)
1041
+ : function(){ return new_date.getUTCMonth() != new_month; };
1042
+ new_month = month + dir;
1043
+ new_date.setUTCMonth(new_month);
1044
+ // Dec -> Jan (12) or Jan -> Dec (-1) -- limit expected date to 0-11
1045
+ if (new_month < 0 || new_month > 11)
1046
+ new_month = (new_month + 12) % 12;
1047
+ } else {
1048
+ // For magnitudes >1, move one month at a time...
1049
+ for (var i=0; i<mag; i++)
1050
+ // ...which might decrease the day (eg, Jan 31 to Feb 28, etc)...
1051
+ new_date = this.moveMonth(new_date, dir);
1052
+ // ...then reset the day, keeping it in the new month
1053
+ new_month = new_date.getUTCMonth();
1054
+ new_date.setUTCDate(day);
1055
+ test = function(){ return new_month != new_date.getUTCMonth(); };
1056
+ }
1057
+ // Common date-resetting loop -- if date is beyond end of month, make it
1058
+ // end of month
1059
+ while (test()){
1060
+ new_date.setUTCDate(--day);
1061
+ new_date.setUTCMonth(new_month);
1062
+ }
1063
+ return new_date;
1064
+ },
1065
+
1066
+ moveYear: function(date, dir){
1067
+ return this.moveMonth(date, dir*12);
1068
+ },
1069
+
1070
+ dateWithinRange: function(date){
1071
+ return date >= this.o.startDate && date <= this.o.endDate;
1072
+ },
1073
+
1074
+ keydown: function(e){
1075
+ if (this.picker.is(':not(:visible)')){
1076
+ if (e.keyCode == 27) // allow escape to hide and re-show picker
1077
+ this.show();
1078
+ return;
1079
+ }
1080
+ var dateChanged = false,
1081
+ dir, newDate, newViewDate,
1082
+ focusDate = this.focusDate || this.viewDate;
1083
+ switch(e.keyCode){
1084
+ case 27: // escape
1085
+ if (this.focusDate){
1086
+ this.focusDate = null;
1087
+ this.viewDate = this.dates.get(-1) || this.viewDate;
1088
+ this.fill();
1089
+ }
1090
+ else
1091
+ this.hide();
1092
+ e.preventDefault();
1093
+ break;
1094
+ case 37: // left
1095
+ case 39: // right
1096
+ if (!this.o.keyboardNavigation) break;
1097
+ dir = e.keyCode == 37 ? -1 : 1;
1098
+ if (e.ctrlKey){
1099
+ newDate = this.moveYear(this.dates.get(-1) || UTCToday(), dir);
1100
+ newViewDate = this.moveYear(focusDate, dir);
1101
+ this._trigger('changeYear', this.viewDate);
1102
+ } else if (e.shiftKey){
1103
+ newDate = this.moveMonth(this.dates.get(-1) || UTCToday(), dir);
1104
+ newViewDate = this.moveMonth(focusDate, dir);
1105
+ this._trigger('changeMonth', this.viewDate);
1106
+ } else {
1107
+ newDate = new Date(this.dates.get(-1) || UTCToday());
1108
+ newDate.setUTCDate(newDate.getUTCDate() + dir);
1109
+ newViewDate = new Date(focusDate);
1110
+ newViewDate.setUTCDate(focusDate.getUTCDate() + dir);
1111
+ }
1112
+ if (this.dateWithinRange(newDate)){
1113
+ this.focusDate = this.viewDate = newViewDate;
1114
+ this.setValue();
1115
+ this.fill();
1116
+ e.preventDefault();
1117
+ }
1118
+ break;
1119
+ case 38: // up
1120
+ case 40: // down
1121
+ if (!this.o.keyboardNavigation) break;
1122
+ dir = e.keyCode == 38 ? -1 : 1;
1123
+ if (e.ctrlKey){
1124
+ newDate = this.moveYear(this.dates.get(-1) || UTCToday(), dir);
1125
+ newViewDate = this.moveYear(focusDate, dir);
1126
+ this._trigger('changeYear', this.viewDate);
1127
+ } else if (e.shiftKey){
1128
+ newDate = this.moveMonth(this.dates.get(-1) || UTCToday(), dir);
1129
+ newViewDate = this.moveMonth(focusDate, dir);
1130
+ this._trigger('changeMonth', this.viewDate);
1131
+ } else {
1132
+ newDate = new Date(this.dates.get(-1) || UTCToday());
1133
+ newDate.setUTCDate(newDate.getUTCDate() + dir * 7);
1134
+ newViewDate = new Date(focusDate);
1135
+ newViewDate.setUTCDate(focusDate.getUTCDate() + dir * 7);
1136
+ }
1137
+ if (this.dateWithinRange(newDate)){
1138
+ this.focusDate = this.viewDate = newViewDate;
1139
+ this.setValue();
1140
+ this.fill();
1141
+ e.preventDefault();
1142
+ }
1143
+ break;
1144
+ case 32: // spacebar
1145
+ focusDate = this.focusDate || this.dates.get(-1) || this.viewDate;
1146
+ this._toggle_multidate(focusDate);
1147
+ dateChanged = true;
1148
+ this.focusDate = null;
1149
+ this.viewDate = this.dates.get(-1) || this.viewDate;
1150
+ this.setValue();
1151
+ this.fill();
1152
+ e.preventDefault();
1153
+ break;
1154
+ case 13: // enter
1155
+ if (this.focusDate){
1156
+ this._toggle_multidate(this.focusDate);
1157
+ dateChanged = true;
1158
+ this.focusDate = null;
1159
+ this.viewDate = this.dates.get(-1) || this.viewDate;
1160
+ this.setValue();
1161
+ this.fill();
1162
+ }
1163
+ this.hide();
1164
+ e.preventDefault();
1165
+ break;
1166
+ case 9: // tab
1167
+ this.focusDate = null;
1168
+ this.viewDate = this.dates.get(-1) || this.viewDate;
1169
+ this.fill();
1170
+ this.hide();
1171
+ break;
1172
+ }
1173
+ if (dateChanged){
1174
+ if (this.dates.length)
1175
+ this._trigger('changeDate');
1176
+ else
1177
+ this._trigger('clearDate');
1178
+ var element;
1179
+ if (this.isInput) {
1180
+ element = this.element;
1181
+ } else if (this.component){
1182
+ element = this.element.find('input');
1183
+ }
1184
+ if (element) {
1185
+ element.change();
1186
+ }
1187
+ }
1188
+ },
1189
+
1190
+ showMode: function(dir) {
1191
+ if (dir) {
1192
+ this.viewMode = Math.max(this.o.minViewMode, Math.min(2, this.viewMode + dir));
1193
+ }
1194
+ /*
1195
+ vitalets: fixing bug of very special conditions:
1196
+ jquery 1.7.1 + webkit + show inline datepicker in bootstrap popover.
1197
+ Method show() does not set display css correctly and datepicker is not shown.
1198
+ Changed to .css('display', 'block') solve the problem.
1199
+ See https://github.com/vitalets/x-editable/issues/37
1200
+
1201
+ In jquery 1.7.2+ everything works fine.
1202
+ */
1203
+ //this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
1204
+ this.picker.find('>div').hide().filter('.datepicker-'+DPGlobal.modes[this.viewMode].clsName).css('display', 'block');
1205
+ this.updateNavArrows();
1206
+ }
1207
+ };
1208
+
1209
+ var DateRangePicker = function(element, options){
1210
+ this.element = $(element);
1211
+ this.inputs = $.map(options.inputs, function(i){ return i.jquery ? i[0] : i; });
1212
+ delete options.inputs;
1213
+
1214
+ $(this.inputs)
1215
+ .datepicker(options)
1216
+ .bind('changeDate', $.proxy(this.dateUpdated, this));
1217
+
1218
+ this.pickers = $.map(this.inputs, function(i){ return $(i).data('datepicker'); });
1219
+ this.updateDates();
1220
+ };
1221
+ DateRangePicker.prototype = {
1222
+ updateDates: function(){
1223
+ this.dates = $.map(this.pickers, function(i){ return i.getUTCDate(); });
1224
+ this.updateRanges();
1225
+ },
1226
+ updateRanges: function(){
1227
+ var range = $.map(this.dates, function(d){ return d.valueOf(); });
1228
+ $.each(this.pickers, function(i, p){
1229
+ p.setRange(range);
1230
+ });
1231
+ },
1232
+ dateUpdated: function(e){
1233
+ // `this.updating` is a workaround for preventing infinite recursion
1234
+ // between `changeDate` triggering and `setUTCDate` calling. Until
1235
+ // there is a better mechanism.
1236
+ if (this.updating)
1237
+ return;
1238
+ this.updating = true;
1239
+
1240
+ var dp = $(e.target).data('datepicker'),
1241
+ new_date = dp.getUTCDate(),
1242
+ i = $.inArray(e.target, this.inputs),
1243
+ l = this.inputs.length;
1244
+ if (i == -1) return;
1245
+
1246
+ $.each(this.pickers, function(i, p){
1247
+ if (!p.getUTCDate())
1248
+ p.setUTCDate(new_date);
1249
+ });
1250
+
1251
+ if (new_date < this.dates[i]){
1252
+ // Date being moved earlier/left
1253
+ while (i>=0 && new_date < this.dates[i]){
1254
+ this.pickers[i--].setUTCDate(new_date);
1255
+ }
1256
+ }
1257
+ else if (new_date > this.dates[i]){
1258
+ // Date being moved later/right
1259
+ while (i<l && new_date > this.dates[i]){
1260
+ this.pickers[i++].setUTCDate(new_date);
1261
+ }
1262
+ }
1263
+ this.updateDates();
1264
+
1265
+ delete this.updating;
1266
+ },
1267
+ remove: function(){
1268
+ $.map(this.pickers, function(p){ p.remove(); });
1269
+ delete this.element.data().datepicker;
1270
+ }
1271
+ };
1272
+
1273
+ function opts_from_el(el, prefix){
1274
+ // Derive options from element data-attrs
1275
+ var data = $(el).data(),
1276
+ out = {}, inkey,
1277
+ replace = new RegExp('^' + prefix.toLowerCase() + '([A-Z])'),
1278
+ prefix = new RegExp('^' + prefix.toLowerCase());
1279
+ for (var key in data)
1280
+ if (prefix.test(key)){
1281
+ inkey = key.replace(replace, function(_,a){ return a.toLowerCase(); });
1282
+ out[inkey] = data[key];
1283
+ }
1284
+ return out;
1285
+ }
1286
+
1287
+ function opts_from_locale(lang){
1288
+ // Derive options from locale plugins
1289
+ var out = {};
1290
+ // Check if "de-DE" style date is available, if not language should
1291
+ // fallback to 2 letter code eg "de"
1292
+ if (!dates[lang]) {
1293
+ lang = lang.split('-')[0];
1294
+ if (!dates[lang])
1295
+ return;
1296
+ }
1297
+ var d = dates[lang];
1298
+ $.each(locale_opts, function(i,k){
1299
+ if (k in d)
1300
+ out[k] = d[k];
1301
+ });
1302
+ return out;
1303
+ }
1304
+
1305
+ var old = $.fn.datepicker;
1306
+ $.fn.datepicker = function ( option ) {
1307
+ var args = Array.apply(null, arguments);
1308
+ args.shift();
1309
+ var internal_return;
1310
+ this.each(function () {
1311
+ var $this = $(this),
1312
+ data = $this.data('datepicker'),
1313
+ options = typeof option == 'object' && option;
1314
+ if (!data) {
1315
+ var elopts = opts_from_el(this, 'date'),
1316
+ // Preliminary otions
1317
+ xopts = $.extend({}, defaults, elopts, options),
1318
+ locopts = opts_from_locale(xopts.language),
1319
+ // Options priority: js args, data-attrs, locales, defaults
1320
+ opts = $.extend({}, defaults, locopts, elopts, options);
1321
+ if ($this.is('.input-daterange') || opts.inputs){
1322
+ var ropts = {
1323
+ inputs: opts.inputs || $this.find('input').toArray()
1324
+ };
1325
+ $this.data('datepicker', (data = new DateRangePicker(this, $.extend(opts, ropts))));
1326
+ }
1327
+ else{
1328
+ $this.data('datepicker', (data = new Datepicker(this, opts)));
1329
+ }
1330
+ }
1331
+ if (typeof option == 'string' && typeof data[option] == 'function') {
1332
+ internal_return = data[option].apply(data, args);
1333
+ if (internal_return !== undefined)
1334
+ return false;
1335
+ }
1336
+ });
1337
+ if (internal_return !== undefined)
1338
+ return internal_return;
1339
+ else
1340
+ return this;
1341
+ };
1342
+
1343
+ var defaults = $.fn.datepicker.defaults = {
1344
+ autoclose: false,
1345
+ beforeShowDay: $.noop,
1346
+ calendarWeeks: false,
1347
+ clearBtn: false,
1348
+ daysOfWeekDisabled: [],
1349
+ endDate: Infinity,
1350
+ forceParse: true,
1351
+ format: 'mm/dd/yyyy',
1352
+ keyboardNavigation: true,
1353
+ language: 'en',
1354
+ minViewMode: 0,
1355
+ multidate: false,
1356
+ multidateSeparator: ',',
1357
+ orientation: "auto",
1358
+ rtl: false,
1359
+ startDate: -Infinity,
1360
+ startView: 0,
1361
+ todayBtn: false,
1362
+ todayHighlight: false,
1363
+ weekStart: 0
1364
+ };
1365
+ var locale_opts = $.fn.datepicker.locale_opts = [
1366
+ 'format',
1367
+ 'rtl',
1368
+ 'weekStart'
1369
+ ];
1370
+ $.fn.datepicker.Constructor = Datepicker;
1371
+ var dates = $.fn.datepicker.dates = {
1372
+ en: {
1373
+ days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
1374
+ daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
1375
+ daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
1376
+ months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
1377
+ monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
1378
+ today: "Today",
1379
+ clear: "Clear"
1380
+ }
1381
+ };
1382
+
1383
+ var DPGlobal = {
1384
+ modes: [
1385
+ {
1386
+ clsName: 'days',
1387
+ navFnc: 'Month',
1388
+ navStep: 1
1389
+ },
1390
+ {
1391
+ clsName: 'months',
1392
+ navFnc: 'FullYear',
1393
+ navStep: 1
1394
+ },
1395
+ {
1396
+ clsName: 'years',
1397
+ navFnc: 'FullYear',
1398
+ navStep: 10
1399
+ }],
1400
+ isLeapYear: function (year) {
1401
+ return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0));
1402
+ },
1403
+ getDaysInMonth: function (year, month) {
1404
+ return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month];
1405
+ },
1406
+ validParts: /dd?|DD?|mm?|MM?|yy(?:yy)?/g,
1407
+ nonpunctuation: /[^ -\/:-@\[\u3400-\u9fff-`{-~\t\n\r]+/g,
1408
+ parseFormat: function(format){
1409
+ // IE treats \0 as a string end in inputs (truncating the value),
1410
+ // so it's a bad format delimiter, anyway
1411
+ var separators = format.replace(this.validParts, '\0').split('\0'),
1412
+ parts = format.match(this.validParts);
1413
+ if (!separators || !separators.length || !parts || parts.length === 0){
1414
+ throw new Error("Invalid date format.");
1415
+ }
1416
+ return {separators: separators, parts: parts};
1417
+ },
1418
+ parseDate: function(date, format, language) {
1419
+ if (!date)
1420
+ return undefined;
1421
+ if (date instanceof Date) return date;
1422
+ if (typeof format === 'string')
1423
+ format = DPGlobal.parseFormat(format);
1424
+ if (/^[\-+]\d+[dmwy]([\s,]+[\-+]\d+[dmwy])*$/.test(date)) {
1425
+ var part_re = /([\-+]\d+)([dmwy])/,
1426
+ parts = date.match(/([\-+]\d+)([dmwy])/g),
1427
+ part, dir;
1428
+ date = new Date();
1429
+ for (var i=0; i<parts.length; i++) {
1430
+ part = part_re.exec(parts[i]);
1431
+ dir = parseInt(part[1]);
1432
+ switch(part[2]){
1433
+ case 'd':
1434
+ date.setUTCDate(date.getUTCDate() + dir);
1435
+ break;
1436
+ case 'm':
1437
+ date = Datepicker.prototype.moveMonth.call(Datepicker.prototype, date, dir);
1438
+ break;
1439
+ case 'w':
1440
+ date.setUTCDate(date.getUTCDate() + dir * 7);
1441
+ break;
1442
+ case 'y':
1443
+ date = Datepicker.prototype.moveYear.call(Datepicker.prototype, date, dir);
1444
+ break;
1445
+ }
1446
+ }
1447
+ return UTCDate(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), 0, 0, 0);
1448
+ }
1449
+ var parts = date && date.match(this.nonpunctuation) || [],
1450
+ date = new Date(),
1451
+ parsed = {},
1452
+ setters_order = ['yyyy', 'yy', 'M', 'MM', 'm', 'mm', 'd', 'dd'],
1453
+ setters_map = {
1454
+ yyyy: function(d,v){ return d.setUTCFullYear(v); },
1455
+ yy: function(d,v){ return d.setUTCFullYear(2000+v); },
1456
+ m: function(d,v){
1457
+ if (isNaN(d))
1458
+ return d;
1459
+ v -= 1;
1460
+ while (v<0) v += 12;
1461
+ v %= 12;
1462
+ d.setUTCMonth(v);
1463
+ while (d.getUTCMonth() != v)
1464
+ d.setUTCDate(d.getUTCDate()-1);
1465
+ return d;
1466
+ },
1467
+ d: function(d,v){ return d.setUTCDate(v); }
1468
+ },
1469
+ val, filtered, part;
1470
+ setters_map['M'] = setters_map['MM'] = setters_map['mm'] = setters_map['m'];
1471
+ setters_map['dd'] = setters_map['d'];
1472
+ date = UTCDate(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0);
1473
+ var fparts = format.parts.slice();
1474
+ // Remove noop parts
1475
+ if (parts.length != fparts.length) {
1476
+ fparts = $(fparts).filter(function(i,p){
1477
+ return $.inArray(p, setters_order) !== -1;
1478
+ }).toArray();
1479
+ }
1480
+ // Process remainder
1481
+ if (parts.length == fparts.length) {
1482
+ for (var i=0, cnt = fparts.length; i < cnt; i++) {
1483
+ val = parseInt(parts[i], 10);
1484
+ part = fparts[i];
1485
+ if (isNaN(val)) {
1486
+ switch(part) {
1487
+ case 'MM':
1488
+ filtered = $(dates[language].months).filter(function(){
1489
+ var m = this.slice(0, parts[i].length),
1490
+ p = parts[i].slice(0, m.length);
1491
+ return m == p;
1492
+ });
1493
+ val = $.inArray(filtered[0], dates[language].months) + 1;
1494
+ break;
1495
+ case 'M':
1496
+ filtered = $(dates[language].monthsShort).filter(function(){
1497
+ var m = this.slice(0, parts[i].length),
1498
+ p = parts[i].slice(0, m.length);
1499
+ return m == p;
1500
+ });
1501
+ val = $.inArray(filtered[0], dates[language].monthsShort) + 1;
1502
+ break;
1503
+ }
1504
+ }
1505
+ parsed[part] = val;
1506
+ }
1507
+ for (var i=0, _date, s; i<setters_order.length; i++){
1508
+ s = setters_order[i];
1509
+ if (s in parsed && !isNaN(parsed[s])){
1510
+ _date = new Date(date);
1511
+ setters_map[s](_date, parsed[s]);
1512
+ if (!isNaN(_date))
1513
+ date = _date;
1514
+ }
1515
+ }
1516
+ }
1517
+ return date;
1518
+ },
1519
+ formatDate: function(date, format, language){
1520
+ if (!date)
1521
+ return '';
1522
+ if (typeof format === 'string')
1523
+ format = DPGlobal.parseFormat(format);
1524
+ var val = {
1525
+ d: date.getUTCDate(),
1526
+ D: dates[language].daysShort[date.getUTCDay()],
1527
+ DD: dates[language].days[date.getUTCDay()],
1528
+ m: date.getUTCMonth() + 1,
1529
+ M: dates[language].monthsShort[date.getUTCMonth()],
1530
+ MM: dates[language].months[date.getUTCMonth()],
1531
+ yy: date.getUTCFullYear().toString().substring(2),
1532
+ yyyy: date.getUTCFullYear()
1533
+ };
1534
+ val.dd = (val.d < 10 ? '0' : '') + val.d;
1535
+ val.mm = (val.m < 10 ? '0' : '') + val.m;
1536
+ var date = [],
1537
+ seps = $.extend([], format.separators);
1538
+ for (var i=0, cnt = format.parts.length; i <= cnt; i++) {
1539
+ if (seps.length)
1540
+ date.push(seps.shift());
1541
+ date.push(val[format.parts[i]]);
1542
+ }
1543
+ return date.join('');
1544
+ },
1545
+ headTemplate: '<thead>'+
1546
+ '<tr>'+
1547
+ '<th class="prev">&laquo;</th>'+
1548
+ '<th colspan="5" class="datepicker-switch"></th>'+
1549
+ '<th class="next">&raquo;</th>'+
1550
+ '</tr>'+
1551
+ '</thead>',
1552
+ contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>',
1553
+ footTemplate: '<tfoot><tr><th colspan="7" class="today"></th></tr><tr><th colspan="7" class="clear"></th></tr></tfoot>'
1554
+ };
1555
+ DPGlobal.template = '<div class="datepicker">'+
1556
+ '<div class="datepicker-days">'+
1557
+ '<table class=" table-condensed">'+
1558
+ DPGlobal.headTemplate+
1559
+ '<tbody></tbody>'+
1560
+ DPGlobal.footTemplate+
1561
+ '</table>'+
1562
+ '</div>'+
1563
+ '<div class="datepicker-months">'+
1564
+ '<table class="table-condensed">'+
1565
+ DPGlobal.headTemplate+
1566
+ DPGlobal.contTemplate+
1567
+ DPGlobal.footTemplate+
1568
+ '</table>'+
1569
+ '</div>'+
1570
+ '<div class="datepicker-years">'+
1571
+ '<table class="table-condensed">'+
1572
+ DPGlobal.headTemplate+
1573
+ DPGlobal.contTemplate+
1574
+ DPGlobal.footTemplate+
1575
+ '</table>'+
1576
+ '</div>'+
1577
+ '</div>';
1578
+
1579
+ $.fn.datepicker.DPGlobal = DPGlobal;
1580
+
1581
+
1582
+ /* DATEPICKER NO CONFLICT
1583
+ * =================== */
1584
+
1585
+ $.fn.datepicker.noConflict = function(){
1586
+ $.fn.datepicker = old;
1587
+ return this;
1588
+ };
1589
+
1590
+
1591
+ /* DATEPICKER DATA-API
1592
+ * ================== */
1593
+
1594
+ $(document).on(
1595
+ 'focus.datepicker.data-api click.datepicker.data-api',
1596
+ '[data-provide="datepicker"]',
1597
+ function(e){
1598
+ var $this = $(this);
1599
+ if ($this.data('datepicker')) return;
1600
+ e.preventDefault();
1601
+ // component click requires us to explicitly show it
1602
+ $this.datepicker('show');
1603
+ }
1604
+ );
1605
+ $(function(){
1606
+ $('[data-provide="datepicker-inline"]').datepicker();
1607
+ });
1608
+
1609
+ }( window.jQuery ));