bootstrap-datetimepicker-rails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/lib/bootstrap-datetimepicker-rails.rb +9 -0
- data/lib/bootstrap-datetimepicker-rails/version.rb +5 -0
- data/vendor/assets/javascripts/bootstrap-datetimepicker.js +1148 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.bg.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.cs.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.da.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.de.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.es.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.fi.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.fr.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.hr.js +13 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.id.js +13 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.is.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.it.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.ja.js +13 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.kr.js +13 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.lt.js +16 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.lv.js +16 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.ms.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.nb.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.nl.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.pl.js +15 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.pt-BR.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.pt.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.ro.js +15 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.rs-latin.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.rs.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.ru.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.sk.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.sl.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.sv.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.th.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.tr.js +15 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.zh-CN.js +14 -0
- data/vendor/assets/javascripts/locales/bootstrap-datetimepicker.zh-TW.js +13 -0
- data/vendor/assets/stylesheets/bootstrap-datetimepicker.less +141 -0
- metadata +85 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Adam Nowak
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# bootstrap-datetimepicker-rails
|
2
|
+
|
3
|
+
This gem packages the bootstrap-datetimepicker (JavaScripts & stylesheets) for Rails 3.1+ asset pipeline. It adds ability to use [bootstrap-datetimepicker plugin](http://tarruda.github.com/bootstrap-datetimepicker/) within your Rails app without puting files inside `vendor` directory.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'bootstrap-datetimepicker-rails'
|
10
|
+
|
11
|
+
Add the following directive to your Javascript manifest file (`application.js`):
|
12
|
+
|
13
|
+
//= require bootstrap-datetimepicker
|
14
|
+
|
15
|
+
If you want to include a localization file, also add the following directive:
|
16
|
+
|
17
|
+
//= require locales/bootstrap-datetimepicker.<locale>.js>
|
18
|
+
|
19
|
+
Add the following line to your stylesheet file (**warning**: seems to be working currently only with `*.css.less` files):
|
20
|
+
|
21
|
+
@import 'bootstrap-datetimepicker';
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
See the excellent demo provided by plugin's author (@tarruda) [here]( http://tarruda.github.com/bootstrap-datetimepicker/().
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
@@ -0,0 +1,1148 @@
|
|
1
|
+
/**
|
2
|
+
* @license
|
3
|
+
* =========================================================
|
4
|
+
* bootstrap-datetimepicker.js
|
5
|
+
* http://www.eyecon.ro/bootstrap-datepicker
|
6
|
+
* =========================================================
|
7
|
+
* Copyright 2012 Stefan Petre
|
8
|
+
*
|
9
|
+
* Contributions:
|
10
|
+
* - Andrew Rowls
|
11
|
+
* - Thiago de Arruda
|
12
|
+
*
|
13
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
14
|
+
* you may not use this file except in compliance with the License.
|
15
|
+
* You may obtain a copy of the License at
|
16
|
+
*
|
17
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
18
|
+
*
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
21
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
22
|
+
* See the License for the specific language governing permissions and
|
23
|
+
* limitations under the License.
|
24
|
+
* =========================================================
|
25
|
+
*/
|
26
|
+
|
27
|
+
(function($) {
|
28
|
+
|
29
|
+
// Picker object
|
30
|
+
var smartPhone = (window.orientation != undefined);
|
31
|
+
var DateTimePicker = function(element, options) {
|
32
|
+
this.id = dpgId++;
|
33
|
+
this.init(element, options);
|
34
|
+
};
|
35
|
+
|
36
|
+
DateTimePicker.prototype = {
|
37
|
+
constructor: DateTimePicker,
|
38
|
+
|
39
|
+
init: function(element, options) {
|
40
|
+
var icon;
|
41
|
+
if (!(options.pickTime || options.pickDate))
|
42
|
+
throw new Error('Must choose at least one picker');
|
43
|
+
this.options = options;
|
44
|
+
this.$element = $(element);
|
45
|
+
this.language = options.language in dates ? options.language : 'en'
|
46
|
+
this.pickDate = options.pickDate;
|
47
|
+
this.pickTime = options.pickTime;
|
48
|
+
this.isInput = this.$element.is('input');
|
49
|
+
this.component = this.$element.is('.input-append') ? this.$element.find('.add-on') : false;
|
50
|
+
this.format = options.format;
|
51
|
+
if (!this.format) {
|
52
|
+
if (this.isInput) this.format = this.$element.data('format');
|
53
|
+
else this.format = this.$element.find('input').data('format');
|
54
|
+
if (!this.format) this.format = 'MM/dd/yyyy';
|
55
|
+
}
|
56
|
+
this._compileFormat();
|
57
|
+
if (this.component) {
|
58
|
+
icon = this.component.find('i');
|
59
|
+
}
|
60
|
+
if (this.pickTime) {
|
61
|
+
if (icon && icon.length) this.timeIcon = icon.data('time-icon');
|
62
|
+
if (!this.timeIcon) this.timeIcon = 'icon-time';
|
63
|
+
icon.addClass(this.timeIcon);
|
64
|
+
}
|
65
|
+
if (this.pickDate) {
|
66
|
+
if (icon && icon.length) this.dateIcon = icon.data('date-icon');
|
67
|
+
if (!this.dateIcon) this.dateIcon = 'icon-calendar';
|
68
|
+
icon.removeClass(this.timeIcon);
|
69
|
+
icon.addClass(this.dateIcon);
|
70
|
+
}
|
71
|
+
this.widget = $(getTemplate(this.timeIcon, options.pickDate, options.pickTime, options.pick12HourFormat)).appendTo('body');
|
72
|
+
this.minViewMode = options.minViewMode||this.$element.data('date-minviewmode')||0;
|
73
|
+
if (typeof this.minViewMode === 'string') {
|
74
|
+
switch (this.minViewMode) {
|
75
|
+
case 'months':
|
76
|
+
this.minViewMode = 1;
|
77
|
+
break;
|
78
|
+
case 'years':
|
79
|
+
this.minViewMode = 2;
|
80
|
+
break;
|
81
|
+
default:
|
82
|
+
this.minViewMode = 0;
|
83
|
+
break;
|
84
|
+
}
|
85
|
+
}
|
86
|
+
this.viewMode = options.viewMode||this.$element.data('date-viewmode')||0;
|
87
|
+
if (typeof this.viewMode === 'string') {
|
88
|
+
switch (this.viewMode) {
|
89
|
+
case 'months':
|
90
|
+
this.viewMode = 1;
|
91
|
+
break;
|
92
|
+
case 'years':
|
93
|
+
this.viewMode = 2;
|
94
|
+
break;
|
95
|
+
default:
|
96
|
+
this.viewMode = 0;
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
this.startViewMode = this.viewMode;
|
101
|
+
this.weekStart = options.weekStart||this.$element.data('date-weekstart')||0;
|
102
|
+
this.weekEnd = this.weekStart === 0 ? 6 : this.weekStart - 1;
|
103
|
+
this.fillDow();
|
104
|
+
this.fillMonths();
|
105
|
+
this.fillHours();
|
106
|
+
this.fillMinutes();
|
107
|
+
this.fillSeconds();
|
108
|
+
this.update();
|
109
|
+
this.showMode();
|
110
|
+
this._attachDatePickerEvents();
|
111
|
+
},
|
112
|
+
|
113
|
+
show: function(e) {
|
114
|
+
this.widget.show();
|
115
|
+
this.height = this.component ? this.component.outerHeight() : this.$element.outerHeight();
|
116
|
+
this.place();
|
117
|
+
this.$element.trigger({
|
118
|
+
type: 'show',
|
119
|
+
date: this._date
|
120
|
+
});
|
121
|
+
this._attachDatePickerGlobalEvents();
|
122
|
+
if (e) {
|
123
|
+
e.stopPropagation();
|
124
|
+
e.preventDefault();
|
125
|
+
}
|
126
|
+
},
|
127
|
+
|
128
|
+
hide: function() {
|
129
|
+
// Ignore event if in the middle of a picker transition
|
130
|
+
var collapse = this.widget.find('.collapse')
|
131
|
+
for (var i = 0; i < collapse.length; i++) {
|
132
|
+
var collapseData = collapse.eq(i).data('collapse');
|
133
|
+
if (collapseData && collapseData.transitioning)
|
134
|
+
return;
|
135
|
+
}
|
136
|
+
this.widget.hide();
|
137
|
+
this.viewMode = this.startViewMode;
|
138
|
+
this.showMode();
|
139
|
+
this.set();
|
140
|
+
this.$element.trigger({
|
141
|
+
type: 'hide',
|
142
|
+
date: this._date
|
143
|
+
});
|
144
|
+
this._detachDatePickerGlobalEvents();
|
145
|
+
},
|
146
|
+
|
147
|
+
set: function() {
|
148
|
+
var formatted = '';
|
149
|
+
if (!this._unset) formatted = this.formatDate(this._date);
|
150
|
+
if (!this.isInput) {
|
151
|
+
if (this.component){
|
152
|
+
var input = this.$element.find('input');
|
153
|
+
input.val(formatted);
|
154
|
+
this._resetMaskPos(input);
|
155
|
+
}
|
156
|
+
this.$element.data('date', formatted);
|
157
|
+
} else {
|
158
|
+
this.$element.val(formatted);
|
159
|
+
this._resetMaskPos(this.$element);
|
160
|
+
}
|
161
|
+
},
|
162
|
+
|
163
|
+
setValue: function(newDate) {
|
164
|
+
if (!newDate) {
|
165
|
+
this._unset = true;
|
166
|
+
} else {
|
167
|
+
this._unset = false;
|
168
|
+
}
|
169
|
+
if (typeof newDate === 'string') {
|
170
|
+
this._date = this.parseDate(newDate);
|
171
|
+
} else {
|
172
|
+
this._date = new Date(newDate);
|
173
|
+
}
|
174
|
+
this.set();
|
175
|
+
this.viewDate = UTCDate(this._date.getUTCFullYear(), this._date.getUTCMonth(), 1, 0, 0, 0, 0);
|
176
|
+
this.fillDate();
|
177
|
+
this.fillTime();
|
178
|
+
},
|
179
|
+
|
180
|
+
getDate: function() {
|
181
|
+
if (this._unset) return null;
|
182
|
+
return new Date(this._date.valueOf());
|
183
|
+
},
|
184
|
+
|
185
|
+
setDate: function(date) {
|
186
|
+
if (!date) this.setValue(null);
|
187
|
+
else this.setValue(date.valueOf());
|
188
|
+
},
|
189
|
+
|
190
|
+
getLocalDate: function() {
|
191
|
+
if (this._unset) return null;
|
192
|
+
var d = this._date;
|
193
|
+
return new Date(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate(),
|
194
|
+
d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
|
195
|
+
},
|
196
|
+
|
197
|
+
setLocalDate: function(localDate) {
|
198
|
+
if (!localDate) this.setValue(null);
|
199
|
+
else
|
200
|
+
this.setValue(Date.UTC(
|
201
|
+
localDate.getFullYear(),
|
202
|
+
localDate.getMonth(),
|
203
|
+
localDate.getDate(),
|
204
|
+
localDate.getHours(),
|
205
|
+
localDate.getMinutes(),
|
206
|
+
localDate.getSeconds(),
|
207
|
+
localDate.getMilliseconds()));
|
208
|
+
},
|
209
|
+
|
210
|
+
place: function(){
|
211
|
+
var offset = this.component ? this.component.offset() : this.$element.offset();
|
212
|
+
this.widget.css({
|
213
|
+
top: offset.top + this.height,
|
214
|
+
left: offset.left
|
215
|
+
});
|
216
|
+
},
|
217
|
+
|
218
|
+
notifyChange: function(){
|
219
|
+
this.$element.trigger({
|
220
|
+
type: 'changeDate',
|
221
|
+
date: this.getDate(),
|
222
|
+
localDate: this.getLocalDate()
|
223
|
+
});
|
224
|
+
},
|
225
|
+
|
226
|
+
update: function(newDate){
|
227
|
+
var dateStr = newDate;
|
228
|
+
if (!dateStr) {
|
229
|
+
if (this.isInput) {
|
230
|
+
dateStr = this.$element.val();
|
231
|
+
} else {
|
232
|
+
dateStr = this.$element.find('input').val();
|
233
|
+
}
|
234
|
+
if (!dateStr) {
|
235
|
+
var tmp = new Date()
|
236
|
+
this._date = UTCDate(tmp.getFullYear(),
|
237
|
+
tmp.getMonth(),
|
238
|
+
tmp.getDate(),
|
239
|
+
tmp.getHours(),
|
240
|
+
tmp.getMinutes(),
|
241
|
+
tmp.getSeconds(),
|
242
|
+
tmp.getMilliseconds())
|
243
|
+
} else {
|
244
|
+
this._date = this.parseDate(dateStr);
|
245
|
+
}
|
246
|
+
}
|
247
|
+
this.viewDate = UTCDate(this._date.getUTCFullYear(), this._date.getUTCMonth(), 1, 0, 0, 0, 0);
|
248
|
+
this.fillDate();
|
249
|
+
this.fillTime();
|
250
|
+
},
|
251
|
+
|
252
|
+
fillDow: function() {
|
253
|
+
var dowCnt = this.weekStart;
|
254
|
+
var html = '<tr>';
|
255
|
+
while (dowCnt < this.weekStart + 7) {
|
256
|
+
html += '<th class="dow">' + dates[this.language].daysMin[(dowCnt++) % 7] + '</th>';
|
257
|
+
}
|
258
|
+
html += '</tr>';
|
259
|
+
this.widget.find('.datepicker-days thead').append(html);
|
260
|
+
},
|
261
|
+
|
262
|
+
fillMonths: function() {
|
263
|
+
var html = '';
|
264
|
+
var i = 0
|
265
|
+
while (i < 12) {
|
266
|
+
html += '<span class="month">' + dates[this.language].monthsShort[i++] + '</span>';
|
267
|
+
}
|
268
|
+
this.widget.find('.datepicker-months td').append(html);
|
269
|
+
},
|
270
|
+
|
271
|
+
fillDate: function() {
|
272
|
+
var year = this.viewDate.getUTCFullYear();
|
273
|
+
var month = this.viewDate.getUTCMonth();
|
274
|
+
var currentDate = UTCDate(
|
275
|
+
this._date.getUTCFullYear(),
|
276
|
+
this._date.getUTCMonth(),
|
277
|
+
this._date.getUTCDate(),
|
278
|
+
0, 0, 0, 0
|
279
|
+
);
|
280
|
+
this.widget.find('.datepicker-days th:eq(1)').text(
|
281
|
+
dates[this.language].months[month] + ' ' + year);
|
282
|
+
var prevMonth = UTCDate(year, month-1, 28, 0, 0, 0, 0);
|
283
|
+
var day = DPGlobal.getDaysInMonth(
|
284
|
+
prevMonth.getUTCFullYear(), prevMonth.getUTCMonth());
|
285
|
+
prevMonth.setUTCDate(day);
|
286
|
+
prevMonth.setUTCDate(day - (prevMonth.getUTCDay() - this.weekStart + 7) % 7);
|
287
|
+
var nextMonth = new Date(prevMonth.valueOf());
|
288
|
+
nextMonth.setUTCDate(nextMonth.getUTCDate() + 42);
|
289
|
+
nextMonth = nextMonth.valueOf();
|
290
|
+
var html = [];
|
291
|
+
var clsName;
|
292
|
+
while (prevMonth.valueOf() < nextMonth) {
|
293
|
+
if (prevMonth.getUTCDay() === this.weekStart) {
|
294
|
+
html.push('<tr>');
|
295
|
+
}
|
296
|
+
clsName = '';
|
297
|
+
if (prevMonth.getUTCFullYear() < year ||
|
298
|
+
(prevMonth.getUTCFullYear() == year &&
|
299
|
+
prevMonth.getUTCMonth() < month)) {
|
300
|
+
clsName += ' old';
|
301
|
+
} else if (prevMonth.getUTCFullYear() > year ||
|
302
|
+
(prevMonth.getUTCFullYear() == year &&
|
303
|
+
prevMonth.getUTCMonth() > month)) {
|
304
|
+
clsName += ' new';
|
305
|
+
}
|
306
|
+
if (prevMonth.valueOf() === currentDate.valueOf()) {
|
307
|
+
clsName += ' active';
|
308
|
+
}
|
309
|
+
html.push('<td class="day' + clsName + '">' + prevMonth.getUTCDate() + '</td>');
|
310
|
+
if (prevMonth.getUTCDay() === this.weekEnd) {
|
311
|
+
html.push('</tr>');
|
312
|
+
}
|
313
|
+
prevMonth.setUTCDate(prevMonth.getUTCDate() + 1);
|
314
|
+
}
|
315
|
+
this.widget.find('.datepicker-days tbody').empty().append(html.join(''));
|
316
|
+
var currentYear = this._date.getUTCFullYear();
|
317
|
+
|
318
|
+
var months = this.widget.find('.datepicker-months').find(
|
319
|
+
'th:eq(1)').text(year).end().find('span').removeClass('active');
|
320
|
+
if (currentYear === year) {
|
321
|
+
months.eq(this._date.getUTCMonth()).addClass('active');
|
322
|
+
}
|
323
|
+
|
324
|
+
html = '';
|
325
|
+
year = parseInt(year/10, 10) * 10;
|
326
|
+
var yearCont = this.widget.find('.datepicker-years').find(
|
327
|
+
'th:eq(1)').text(year + '-' + (year + 9)).end().find('td');
|
328
|
+
year -= 1;
|
329
|
+
for (var i = -1; i < 11; i++) {
|
330
|
+
html += '<span class="year' + (i === -1 || i === 10 ? ' old' : '') + (currentYear === year ? ' active' : '') + '">' + year + '</span>';
|
331
|
+
year += 1;
|
332
|
+
}
|
333
|
+
yearCont.html(html);
|
334
|
+
},
|
335
|
+
|
336
|
+
fillHours: function() {
|
337
|
+
var table = this.widget.find(
|
338
|
+
'.timepicker .timepicker-hours table');
|
339
|
+
table.parent().hide();
|
340
|
+
var html = '';
|
341
|
+
if (this.options.pick12HourFormat) {
|
342
|
+
var current = 1;
|
343
|
+
for (var i = 0; i < 3; i += 1) {
|
344
|
+
html += '<tr>';
|
345
|
+
for (var j = 0; j < 4; j += 1) {
|
346
|
+
var c = current.toString();
|
347
|
+
html += '<td class="hour">' + padLeft(c, 2, '0') + '</td>';
|
348
|
+
current++;
|
349
|
+
}
|
350
|
+
html += '</tr>'
|
351
|
+
}
|
352
|
+
} else {
|
353
|
+
var current = 0;
|
354
|
+
for (var i = 0; i < 6; i += 1) {
|
355
|
+
html += '<tr>';
|
356
|
+
for (var j = 0; j < 4; j += 1) {
|
357
|
+
var c = current.toString();
|
358
|
+
html += '<td class="hour">' + padLeft(c, 2, '0') + '</td>';
|
359
|
+
current++;
|
360
|
+
}
|
361
|
+
html += '</tr>'
|
362
|
+
}
|
363
|
+
}
|
364
|
+
table.html(html);
|
365
|
+
},
|
366
|
+
|
367
|
+
fillMinutes: function() {
|
368
|
+
var table = this.widget.find(
|
369
|
+
'.timepicker .timepicker-minutes table');
|
370
|
+
table.parent().hide();
|
371
|
+
var html = '';
|
372
|
+
var current = 0;
|
373
|
+
for (var i = 0; i < 5; i++) {
|
374
|
+
html += '<tr>';
|
375
|
+
for (var j = 0; j < 4; j += 1) {
|
376
|
+
var c = current.toString();
|
377
|
+
html += '<td class="minute">' + padLeft(c, 2, '0') + '</td>';
|
378
|
+
current += 3;
|
379
|
+
}
|
380
|
+
html += '</tr>';
|
381
|
+
}
|
382
|
+
table.html(html);
|
383
|
+
},
|
384
|
+
|
385
|
+
fillSeconds: function() {
|
386
|
+
var table = this.widget.find(
|
387
|
+
'.timepicker .timepicker-seconds table');
|
388
|
+
table.parent().hide();
|
389
|
+
var html = '';
|
390
|
+
var current = 0;
|
391
|
+
for (var i = 0; i < 5; i++) {
|
392
|
+
html += '<tr>';
|
393
|
+
for (var j = 0; j < 4; j += 1) {
|
394
|
+
var c = current.toString();
|
395
|
+
html += '<td class="second">' + padLeft(c, 2, '0') + '</td>';
|
396
|
+
current += 3;
|
397
|
+
}
|
398
|
+
html += '</tr>';
|
399
|
+
}
|
400
|
+
table.html(html);
|
401
|
+
},
|
402
|
+
|
403
|
+
fillTime: function() {
|
404
|
+
if (!this._date)
|
405
|
+
return;
|
406
|
+
var timeComponents = this.widget.find('.timepicker span[data-time-component]');
|
407
|
+
var table = timeComponents.closest('table');
|
408
|
+
var is12HourFormat = this.options.pick12HourFormat;
|
409
|
+
var hour = this._date.getUTCHours();
|
410
|
+
var period = 'AM';
|
411
|
+
if (is12HourFormat) {
|
412
|
+
if (hour >= 12) period = 'PM';
|
413
|
+
if (hour === 0) hour = 12;
|
414
|
+
else if (hour != 12) hour = hour % 12;
|
415
|
+
this.widget.find(
|
416
|
+
'.timepicker [data-action=togglePeriod]').text(period);
|
417
|
+
}
|
418
|
+
hour = padLeft(hour.toString(), 2, '0');
|
419
|
+
var minute = padLeft(this._date.getUTCMinutes().toString(), 2, '0');
|
420
|
+
var second = padLeft(this._date.getUTCSeconds().toString(), 2, '0');
|
421
|
+
timeComponents.filter('[data-time-component=hours]').text(hour);
|
422
|
+
timeComponents.filter('[data-time-component=minutes]').text(minute);
|
423
|
+
timeComponents.filter('[data-time-component=seconds]').text(second);
|
424
|
+
},
|
425
|
+
|
426
|
+
click: function(e) {
|
427
|
+
e.stopPropagation();
|
428
|
+
e.preventDefault();
|
429
|
+
var target = $(e.target).closest('span, td, th');
|
430
|
+
if (target.length === 1) {
|
431
|
+
switch(target[0].nodeName.toLowerCase()) {
|
432
|
+
case 'th':
|
433
|
+
switch(target[0].className) {
|
434
|
+
case 'switch':
|
435
|
+
this.showMode(1);
|
436
|
+
break;
|
437
|
+
case 'prev':
|
438
|
+
case 'next':
|
439
|
+
var vd = this.viewDate;
|
440
|
+
var navFnc = DPGlobal.modes[this.viewMode].navFnc;
|
441
|
+
var step = DPGlobal.modes[this.viewMode].navStep;
|
442
|
+
if (target[0].className === 'prev') step = step * -1;
|
443
|
+
vd['set' + navFnc](vd['get' + navFnc]() + step);
|
444
|
+
this.fillDate();
|
445
|
+
this.set();
|
446
|
+
break;
|
447
|
+
}
|
448
|
+
break;
|
449
|
+
case 'span':
|
450
|
+
if (target.is('.month')) {
|
451
|
+
var month = target.parent().find('span').index(target);
|
452
|
+
this.viewDate.setUTCMonth(month);
|
453
|
+
} else {
|
454
|
+
var year = parseInt(target.text(), 10) || 0;
|
455
|
+
this.viewDate.setUTCFullYear(year);
|
456
|
+
}
|
457
|
+
if (this.viewMode !== 0) {
|
458
|
+
this._date = UTCDate(
|
459
|
+
this.viewDate.getUTCFullYear(),
|
460
|
+
this.viewDate.getUTCMonth(),
|
461
|
+
this.viewDate.getUTCDate(),
|
462
|
+
this._date.getUTCHours(),
|
463
|
+
this._date.getUTCMinutes(),
|
464
|
+
this._date.getUTCSeconds(),
|
465
|
+
this._date.getUTCMilliseconds()
|
466
|
+
);
|
467
|
+
this.notifyChange();
|
468
|
+
}
|
469
|
+
this.showMode(-1);
|
470
|
+
this.fillDate();
|
471
|
+
this.set();
|
472
|
+
break;
|
473
|
+
case 'td':
|
474
|
+
if (target.is('.day')) {
|
475
|
+
var day = parseInt(target.text(), 10) || 1;
|
476
|
+
var month = this.viewDate.getUTCMonth();
|
477
|
+
var year = this.viewDate.getUTCFullYear();
|
478
|
+
if (target.is('.old')) {
|
479
|
+
if (month === 0) {
|
480
|
+
month = 11;
|
481
|
+
year -= 1;
|
482
|
+
} else {
|
483
|
+
month -= 1;
|
484
|
+
}
|
485
|
+
} else if (target.is('.new')) {
|
486
|
+
if (month == 11) {
|
487
|
+
month = 0;
|
488
|
+
year += 1;
|
489
|
+
} else {
|
490
|
+
month += 1;
|
491
|
+
}
|
492
|
+
}
|
493
|
+
this._date = UTCDate(
|
494
|
+
year, month, day,
|
495
|
+
this._date.getUTCHours(),
|
496
|
+
this._date.getUTCMinutes(),
|
497
|
+
this._date.getUTCSeconds(),
|
498
|
+
this._date.getUTCMilliseconds()
|
499
|
+
);
|
500
|
+
this.viewDate = UTCDate(
|
501
|
+
year, month, Math.min(28, day) , 0, 0, 0, 0);
|
502
|
+
this.fillDate();
|
503
|
+
this.set();
|
504
|
+
this.notifyChange();
|
505
|
+
}
|
506
|
+
break;
|
507
|
+
}
|
508
|
+
}
|
509
|
+
},
|
510
|
+
|
511
|
+
actions: {
|
512
|
+
incrementHours: function(e) {
|
513
|
+
this._date.setUTCHours(this._date.getUTCHours() + 1);
|
514
|
+
},
|
515
|
+
|
516
|
+
incrementMinutes: function(e) {
|
517
|
+
this._date.setUTCMinutes(this._date.getUTCMinutes() + 1);
|
518
|
+
},
|
519
|
+
|
520
|
+
incrementSeconds: function(e) {
|
521
|
+
this._date.setUTCSeconds(this._date.getUTCSeconds() + 1);
|
522
|
+
},
|
523
|
+
|
524
|
+
decrementHours: function(e) {
|
525
|
+
this._date.setUTCHours(this._date.getUTCHours() - 1);
|
526
|
+
},
|
527
|
+
|
528
|
+
decrementMinutes: function(e) {
|
529
|
+
this._date.setUTCMinutes(this._date.getUTCMinutes() - 1);
|
530
|
+
},
|
531
|
+
|
532
|
+
decrementSeconds: function(e) {
|
533
|
+
this._date.setUTCSeconds(this._date.getUTCSeconds() - 1);
|
534
|
+
},
|
535
|
+
|
536
|
+
togglePeriod: function(e) {
|
537
|
+
var hour = this._date.getUTCHours();
|
538
|
+
if (hour >= 12) hour -= 12;
|
539
|
+
else hour += 12;
|
540
|
+
this._date.setUTCHours(hour);
|
541
|
+
},
|
542
|
+
|
543
|
+
showPicker: function() {
|
544
|
+
this.widget.find('.timepicker > div:not(.timepicker-picker)').hide();
|
545
|
+
this.widget.find('.timepicker .timepicker-picker').show();
|
546
|
+
},
|
547
|
+
|
548
|
+
showHours: function() {
|
549
|
+
this.widget.find('.timepicker .timepicker-picker').hide();
|
550
|
+
this.widget.find('.timepicker .timepicker-hours').show();
|
551
|
+
},
|
552
|
+
|
553
|
+
showMinutes: function() {
|
554
|
+
this.widget.find('.timepicker .timepicker-picker').hide();
|
555
|
+
this.widget.find('.timepicker .timepicker-minutes').show();
|
556
|
+
},
|
557
|
+
|
558
|
+
showSeconds: function() {
|
559
|
+
this.widget.find('.timepicker .timepicker-picker').hide();
|
560
|
+
this.widget.find('.timepicker .timepicker-seconds').show();
|
561
|
+
},
|
562
|
+
|
563
|
+
selectHour: function(e) {
|
564
|
+
var tgt = $(e.target);
|
565
|
+
var value = parseInt(tgt.text(), 10);
|
566
|
+
if (this.options.pick12HourFormat) {
|
567
|
+
var current = this._date.getUTCHours();
|
568
|
+
if (current >= 12) {
|
569
|
+
if (value != 12) value = (value + 12) % 24;
|
570
|
+
} else {
|
571
|
+
if (value === 12) value = 0;
|
572
|
+
else value = value % 12;
|
573
|
+
}
|
574
|
+
}
|
575
|
+
this._date.setUTCHours(value);
|
576
|
+
this.actions.showPicker.call(this);
|
577
|
+
},
|
578
|
+
|
579
|
+
selectMinute: function(e) {
|
580
|
+
var tgt = $(e.target);
|
581
|
+
var value = parseInt(tgt.text(), 10);
|
582
|
+
this._date.setUTCMinutes(value);
|
583
|
+
this.actions.showPicker.call(this);
|
584
|
+
},
|
585
|
+
|
586
|
+
selectSecond: function(e) {
|
587
|
+
var tgt = $(e.target);
|
588
|
+
var value = parseInt(tgt.text(), 10);
|
589
|
+
this._date.setUTCSeconds(value);
|
590
|
+
this.actions.showPicker.call(this);
|
591
|
+
}
|
592
|
+
},
|
593
|
+
|
594
|
+
doAction: function(e) {
|
595
|
+
e.stopPropagation();
|
596
|
+
e.preventDefault();
|
597
|
+
if (!this._date) this._date = UTCDate(1970, 0, 0, 0, 0, 0, 0);
|
598
|
+
var action = $(e.currentTarget).data('action');
|
599
|
+
var rv = this.actions[action].apply(this, arguments);
|
600
|
+
this.set();
|
601
|
+
this.fillTime();
|
602
|
+
this.notifyChange();
|
603
|
+
return rv;
|
604
|
+
},
|
605
|
+
|
606
|
+
stopEvent: function(e) {
|
607
|
+
e.stopPropagation();
|
608
|
+
e.preventDefault();
|
609
|
+
},
|
610
|
+
|
611
|
+
// part of the following code was taken from
|
612
|
+
// http://cloud.github.com/downloads/digitalBush/jquery.maskedinput/jquery.maskedinput-1.3.js
|
613
|
+
keydown: function(e) {
|
614
|
+
var self = this, k = e.which, input = $(e.target);
|
615
|
+
if (k == 8 || k == 46) {
|
616
|
+
// backspace and delete cause the maskPosition
|
617
|
+
// to be recalculated
|
618
|
+
setTimeout(function() {
|
619
|
+
self._resetMaskPos(input);
|
620
|
+
});
|
621
|
+
}
|
622
|
+
},
|
623
|
+
|
624
|
+
keypress: function(e) {
|
625
|
+
var k = e.which;
|
626
|
+
if (k == 8 || k == 46) {
|
627
|
+
// For those browsers which will trigger
|
628
|
+
// keypress on backspace/delete
|
629
|
+
return;
|
630
|
+
}
|
631
|
+
var input = $(e.target);
|
632
|
+
var c = String.fromCharCode(k);
|
633
|
+
var val = input.val() || '';
|
634
|
+
val += c;
|
635
|
+
var mask = this._mask[this._maskPos];
|
636
|
+
if (!mask) {
|
637
|
+
return false;
|
638
|
+
}
|
639
|
+
if (mask.end != val.length) {
|
640
|
+
return;
|
641
|
+
}
|
642
|
+
if (!mask.pattern.test(val.slice(mask.start))) {
|
643
|
+
val = val.slice(0, val.length - 1);
|
644
|
+
while ((mask = this._mask[this._maskPos]) && mask.character) {
|
645
|
+
val += mask.character;
|
646
|
+
// advance mask position past static
|
647
|
+
// part
|
648
|
+
this._maskPos++;
|
649
|
+
}
|
650
|
+
val += c;
|
651
|
+
if (mask.end != val.length) {
|
652
|
+
input.val(val);
|
653
|
+
return false;
|
654
|
+
} else {
|
655
|
+
if (!mask.pattern.test(val.slice(mask.start))) {
|
656
|
+
input.val(val.slice(0, mask.start));
|
657
|
+
return false;
|
658
|
+
} else {
|
659
|
+
input.val(val);
|
660
|
+
this._maskPos++;
|
661
|
+
return false;
|
662
|
+
}
|
663
|
+
}
|
664
|
+
} else {
|
665
|
+
this._maskPos++;
|
666
|
+
}
|
667
|
+
},
|
668
|
+
|
669
|
+
change: function(e) {
|
670
|
+
var input = $(e.target);
|
671
|
+
var val = input.val();
|
672
|
+
if (this._formatPattern.test(val)) {
|
673
|
+
this.update();
|
674
|
+
this.setValue(this._date.getTime());
|
675
|
+
this.notifyChange();
|
676
|
+
this.set();
|
677
|
+
} else if (val && val.trim()) {
|
678
|
+
this.setValue(this._date.getTime());
|
679
|
+
if (this._date) this.set();
|
680
|
+
else input.val('');
|
681
|
+
} else {
|
682
|
+
if (this._date) {
|
683
|
+
this.setValue(null);
|
684
|
+
// unset the date when the input is
|
685
|
+
// erased
|
686
|
+
this.notifyChange();
|
687
|
+
}
|
688
|
+
}
|
689
|
+
this._resetMaskPos(input);
|
690
|
+
},
|
691
|
+
|
692
|
+
showMode: function(dir) {
|
693
|
+
if (dir) {
|
694
|
+
this.viewMode = Math.max(this.minViewMode, Math.min(
|
695
|
+
2, this.viewMode + dir));
|
696
|
+
}
|
697
|
+
this.widget.find('.datepicker > div').hide().filter(
|
698
|
+
'.datepicker-'+DPGlobal.modes[this.viewMode].clsName).show();
|
699
|
+
},
|
700
|
+
|
701
|
+
destroy: function() {
|
702
|
+
this._detachDatePickerEvents();
|
703
|
+
this._detachDatePickerGlobalEvents();
|
704
|
+
this.widget.remove();
|
705
|
+
this.$element.removeData('datetimepicker');
|
706
|
+
this.component.removeData('datetimepicker');
|
707
|
+
},
|
708
|
+
|
709
|
+
formatDate: function(d) {
|
710
|
+
return this.format.replace(formatReplacer, function(match) {
|
711
|
+
var methodName, property, rv, len = match.length;
|
712
|
+
if (match === 'ms')
|
713
|
+
len = 1;
|
714
|
+
property = dateFormatComponents[match].property
|
715
|
+
if (property === 'Hours12') {
|
716
|
+
rv = d.getUTCHours();
|
717
|
+
if (rv === 0) rv = 12;
|
718
|
+
else if (rv !== 12) rv = rv % 12;
|
719
|
+
} else if (property === 'Period12') {
|
720
|
+
if (d.getUTCHours() >= 12) return 'PM';
|
721
|
+
else return 'AM';
|
722
|
+
} else {
|
723
|
+
methodName = 'get' + property;
|
724
|
+
rv = d[methodName]();
|
725
|
+
}
|
726
|
+
if (methodName === 'getUTCMonth') rv = rv + 1;
|
727
|
+
if (methodName === 'getUTCYear') rv = rv + 1900 - 2000;
|
728
|
+
return padLeft(rv.toString(), len, '0');
|
729
|
+
});
|
730
|
+
},
|
731
|
+
|
732
|
+
parseDate: function(str) {
|
733
|
+
var match, i, property, methodName, value, parsed = {};
|
734
|
+
if (!(match = this._formatPattern.exec(str)))
|
735
|
+
return null;
|
736
|
+
for (i = 1; i < match.length; i++) {
|
737
|
+
property = this._propertiesByIndex[i];
|
738
|
+
if (!property)
|
739
|
+
continue;
|
740
|
+
value = match[i];
|
741
|
+
if (/^\d+$/.test(value))
|
742
|
+
value = parseInt(value, 10);
|
743
|
+
parsed[property] = value;
|
744
|
+
}
|
745
|
+
return this._finishParsingDate(parsed);
|
746
|
+
},
|
747
|
+
|
748
|
+
_resetMaskPos: function(input) {
|
749
|
+
var val = input.val();
|
750
|
+
for (var i = 0; i < this._mask.length; i++) {
|
751
|
+
if (this._mask[i].end > val.length) {
|
752
|
+
// If the mask has ended then jump to
|
753
|
+
// the next
|
754
|
+
this._maskPos = i;
|
755
|
+
break;
|
756
|
+
} else if (this._mask[i].end === val.length) {
|
757
|
+
this._maskPos = i + 1;
|
758
|
+
break;
|
759
|
+
}
|
760
|
+
}
|
761
|
+
},
|
762
|
+
|
763
|
+
_finishParsingDate: function(parsed) {
|
764
|
+
var year, month, date, hours, minutes, seconds, milliseconds;
|
765
|
+
year = parsed.UTCFullYear;
|
766
|
+
if (parsed.UTCYear) year = 2000 + parsed.UTCYear;
|
767
|
+
if (!year) year = 1970;
|
768
|
+
if (parsed.UTCMonth) month = parsed.UTCMonth - 1;
|
769
|
+
else month = 0;
|
770
|
+
date = parsed.UTCDate || 1;
|
771
|
+
hours = parsed.UTCHours || 0;
|
772
|
+
minutes = parsed.UTCMinutes || 0;
|
773
|
+
seconds = parsed.UTCSeconds || 0;
|
774
|
+
milliseconds = parsed.UTCMilliseconds || 0;
|
775
|
+
if (parsed.Hours12) {
|
776
|
+
hours = parsed.Hours12;
|
777
|
+
}
|
778
|
+
if (parsed.Period12) {
|
779
|
+
if (/pm/i.test(parsed.Period12)) {
|
780
|
+
if (hours != 12) hours = (hours + 12) % 24;
|
781
|
+
} else {
|
782
|
+
hours = hours % 12;
|
783
|
+
}
|
784
|
+
}
|
785
|
+
return UTCDate(year, month, date, hours, minutes, seconds, milliseconds);
|
786
|
+
},
|
787
|
+
|
788
|
+
_compileFormat: function () {
|
789
|
+
var match, component, components = [], mask = [],
|
790
|
+
str = this.format, propertiesByIndex = {}, i = 0, pos = 0;
|
791
|
+
while (match = formatComponent.exec(str)) {
|
792
|
+
component = match[0];
|
793
|
+
if (component in dateFormatComponents) {
|
794
|
+
i++;
|
795
|
+
propertiesByIndex[i] = dateFormatComponents[component].property;
|
796
|
+
components.push('\\s*' + dateFormatComponents[component].getPattern(
|
797
|
+
this) + '\\s*');
|
798
|
+
mask.push({
|
799
|
+
pattern: new RegExp(dateFormatComponents[component].getPattern(
|
800
|
+
this)),
|
801
|
+
property: dateFormatComponents[component].property,
|
802
|
+
start: pos,
|
803
|
+
end: pos += component.length
|
804
|
+
});
|
805
|
+
}
|
806
|
+
else {
|
807
|
+
components.push(escapeRegExp(component));
|
808
|
+
mask.push({
|
809
|
+
pattern: new RegExp(escapeRegExp(component)),
|
810
|
+
character: component,
|
811
|
+
start: pos,
|
812
|
+
end: ++pos
|
813
|
+
});
|
814
|
+
}
|
815
|
+
str = str.slice(component.length);
|
816
|
+
}
|
817
|
+
this._mask = mask;
|
818
|
+
this._maskPos = 0;
|
819
|
+
this._formatPattern = new RegExp(
|
820
|
+
'^\\s*' + components.join('') + '\\s*$');
|
821
|
+
this._propertiesByIndex = propertiesByIndex;
|
822
|
+
},
|
823
|
+
|
824
|
+
_attachDatePickerEvents: function() {
|
825
|
+
var self = this;
|
826
|
+
// this handles date picker clicks
|
827
|
+
this.widget.on('click', '.datepicker *', $.proxy(this.click, this));
|
828
|
+
// this handles time picker clicks
|
829
|
+
this.widget.on('click', '[data-action]', $.proxy(this.doAction, this));
|
830
|
+
this.widget.on('mousedown', $.proxy(this.stopEvent, this));
|
831
|
+
if (this.pickDate && this.pickTime) {
|
832
|
+
this.widget.on('click.togglePicker', '.accordion-toggle', function(e) {
|
833
|
+
e.stopPropagation();
|
834
|
+
var $this = $(this);
|
835
|
+
var $parent = $this.closest('ul');
|
836
|
+
var expanded = $parent.find('.collapse.in');
|
837
|
+
var closed = $parent.find('.collapse:not(.in)');
|
838
|
+
|
839
|
+
if (expanded && expanded.length) {
|
840
|
+
var collapseData = expanded.data('collapse');
|
841
|
+
if (collapseData && collapseData.transitioning) return;
|
842
|
+
expanded.collapse('hide');
|
843
|
+
closed.collapse('show')
|
844
|
+
$this.find('i').toggleClass(self.timeIcon + ' ' + self.dateIcon);
|
845
|
+
self.$element.find('.add-on i').toggleClass(self.timeIcon + ' ' + self.dateIcon);
|
846
|
+
}
|
847
|
+
});
|
848
|
+
}
|
849
|
+
if (this.isInput) {
|
850
|
+
this.$element.on({
|
851
|
+
'focus': $.proxy(this.show, this),
|
852
|
+
'change': $.proxy(this.change, this),
|
853
|
+
});
|
854
|
+
if (this.options.maskInput) {
|
855
|
+
this.$element.on({
|
856
|
+
'keydown': $.proxy(this.keydown, this),
|
857
|
+
'keypress': $.proxy(this.keypress, this)
|
858
|
+
});
|
859
|
+
}
|
860
|
+
} else {
|
861
|
+
this.$element.on({
|
862
|
+
'change': $.proxy(this.change, this),
|
863
|
+
}, 'input');
|
864
|
+
if (this.options.maskInput) {
|
865
|
+
this.$element.on({
|
866
|
+
'keydown': $.proxy(this.keydown, this),
|
867
|
+
'keypress': $.proxy(this.keypress, this)
|
868
|
+
}, 'input');
|
869
|
+
}
|
870
|
+
if (this.component){
|
871
|
+
this.component.on('click', $.proxy(this.show, this));
|
872
|
+
} else {
|
873
|
+
this.$element.on('click', $.proxy(this.show, this));
|
874
|
+
}
|
875
|
+
}
|
876
|
+
},
|
877
|
+
|
878
|
+
_attachDatePickerGlobalEvents: function() {
|
879
|
+
$(window).on(
|
880
|
+
'resize.datetimepicker' + this.id, $.proxy(this.place, this));
|
881
|
+
if (!this.isInput) {
|
882
|
+
$(document).on(
|
883
|
+
'mousedown.datetimepicker' + this.id, $.proxy(this.hide, this));
|
884
|
+
}
|
885
|
+
},
|
886
|
+
|
887
|
+
_detachDatePickerEvents: function() {
|
888
|
+
this.widget.off('click', '.datepicker *', this.click);
|
889
|
+
this.widget.off('click', '[data-action]');
|
890
|
+
this.widget.off('mousedown', this.stopEvent);
|
891
|
+
if (this.pickDate && this.pickTime) {
|
892
|
+
this.widget.off('click.togglePicker');
|
893
|
+
}
|
894
|
+
if (this.isInput) {
|
895
|
+
this.$element.off({
|
896
|
+
'focus': this.show,
|
897
|
+
'change': this.change,
|
898
|
+
});
|
899
|
+
if (this.options.maskInput) {
|
900
|
+
this.$element.off({
|
901
|
+
'keydown': this.keydown,
|
902
|
+
'keypress': this.keypress
|
903
|
+
});
|
904
|
+
}
|
905
|
+
} else {
|
906
|
+
this.$element.off({
|
907
|
+
'change': this.change,
|
908
|
+
}, 'input');
|
909
|
+
if (this.options.maskInput) {
|
910
|
+
this.$element.off({
|
911
|
+
'keydown': this.keydown,
|
912
|
+
'keypress': this.keypress
|
913
|
+
}, 'input');
|
914
|
+
}
|
915
|
+
if (this.component){
|
916
|
+
this.component.off('click', this.show);
|
917
|
+
} else {
|
918
|
+
this.$element.off('click', this.show);
|
919
|
+
}
|
920
|
+
}
|
921
|
+
},
|
922
|
+
|
923
|
+
_detachDatePickerGlobalEvents: function () {
|
924
|
+
$(window).off('resize.datetimepicker' + this.id);
|
925
|
+
if (!this.isInput) {
|
926
|
+
$(document).off('mousedown.datetimepicker' + this.id);
|
927
|
+
}
|
928
|
+
}
|
929
|
+
};
|
930
|
+
|
931
|
+
$.fn.datetimepicker = function ( option, val ) {
|
932
|
+
return this.each(function () {
|
933
|
+
var $this = $(this),
|
934
|
+
data = $this.data('datetimepicker'),
|
935
|
+
options = typeof option === 'object' && option;
|
936
|
+
if (!data) {
|
937
|
+
$this.data('datetimepicker', (data = new DateTimePicker(
|
938
|
+
this, $.extend({}, $.fn.datetimepicker.defaults,options))));
|
939
|
+
}
|
940
|
+
if (typeof option === 'string') data[option](val);
|
941
|
+
});
|
942
|
+
};
|
943
|
+
|
944
|
+
$.fn.datetimepicker.defaults = {
|
945
|
+
maskInput: true,
|
946
|
+
pickDate: true,
|
947
|
+
pickTime: true,
|
948
|
+
pick12HourFormat: false
|
949
|
+
};
|
950
|
+
$.fn.datetimepicker.Constructor = DateTimePicker;
|
951
|
+
var dpgId = 0;
|
952
|
+
var dates = $.fn.datetimepicker.dates = {
|
953
|
+
en: {
|
954
|
+
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
|
955
|
+
"Friday", "Saturday", "Sunday"],
|
956
|
+
daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
|
957
|
+
daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
|
958
|
+
months: ["January", "February", "March", "April", "May", "June",
|
959
|
+
"July", "August", "September", "October", "November", "December"],
|
960
|
+
monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
|
961
|
+
"Aug", "Sep", "Oct", "Nov", "Dec"]
|
962
|
+
}
|
963
|
+
};
|
964
|
+
|
965
|
+
var dateFormatComponents = {
|
966
|
+
dd: {property: 'UTCDate', getPattern: function() { return '(0?[1-9]|[1-2][0-9]|3[0-1])\\b';}},
|
967
|
+
MM: {property: 'UTCMonth', getPattern: function() {return '(0?[1-9]|1[0-2])\\b';}},
|
968
|
+
yy: {property: 'UTCYear', getPattern: function() {return '(\\d{2})\\b'}},
|
969
|
+
yyyy: {property: 'UTCFullYear', getPattern: function() {return '(\\d{4})\\b';}},
|
970
|
+
hh: {property: 'UTCHours', getPattern: function() {return '(0?[0-9]|1[0-9]|2[0-3])\\b';}},
|
971
|
+
mm: {property: 'UTCMinutes', getPattern: function() {return '(0?[0-9]|[1-5][0-9])\\b';}},
|
972
|
+
ss: {property: 'UTCSeconds', getPattern: function() {return '(0?[0-9]|[1-5][0-9])\\b';}},
|
973
|
+
ms: {property: 'UTCMilliseconds', getPattern: function() {return '([0-9]{1,3})\\b';}},
|
974
|
+
HH: {property: 'Hours12', getPattern: function() {return '(0?[1-9]|1[0-2])\\b';}},
|
975
|
+
PP: {property: 'Period12', getPattern: function() {return '(AM|PM|am|pm|Am|aM|Pm|pM)\\b';}}
|
976
|
+
};
|
977
|
+
|
978
|
+
var keys = [];
|
979
|
+
for (var k in dateFormatComponents) keys.push(k);
|
980
|
+
keys[keys.length - 1] += '\\b';
|
981
|
+
keys.push('.');
|
982
|
+
|
983
|
+
var formatComponent = new RegExp(keys.join('\\b|'));
|
984
|
+
keys.pop();
|
985
|
+
var formatReplacer = new RegExp(keys.join('\\b|'), 'g');
|
986
|
+
|
987
|
+
function escapeRegExp(str) {
|
988
|
+
// http://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
|
989
|
+
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
990
|
+
}
|
991
|
+
|
992
|
+
function padLeft(s, l, c) {
|
993
|
+
if (l < s.length) return s;
|
994
|
+
else return Array(l - s.length + 1).join(c || ' ') + s;
|
995
|
+
}
|
996
|
+
|
997
|
+
function getTemplate(timeIcon, pickDate, pickTime, is12Hours) {
|
998
|
+
if (pickDate && pickTime) {
|
999
|
+
return (
|
1000
|
+
'<div class="bootstrap-datetimepicker-widget dropdown-menu">' +
|
1001
|
+
'<ul>' +
|
1002
|
+
'<li class="collapse in">' +
|
1003
|
+
'<div class="datepicker">' +
|
1004
|
+
DPGlobal.template +
|
1005
|
+
'</div>' +
|
1006
|
+
'</li>' +
|
1007
|
+
'<li class="picker-switch"><a class="accordion-toggle"><i class="' + timeIcon + '"></i></a></li>' +
|
1008
|
+
'<li class="collapse">' +
|
1009
|
+
'<div class="timepicker">' +
|
1010
|
+
TPGlobal.getTemplate(is12Hours) +
|
1011
|
+
'</div>' +
|
1012
|
+
'</li>' +
|
1013
|
+
'</ul>' +
|
1014
|
+
'</div>'
|
1015
|
+
);
|
1016
|
+
} else if (pickTime) {
|
1017
|
+
return (
|
1018
|
+
'<div class="bootstrap-datetimepicker-widget dropdown-menu">' +
|
1019
|
+
'<div class="timepicker">' +
|
1020
|
+
TPGlobal.getTemplate(is12Hours) +
|
1021
|
+
'</div>' +
|
1022
|
+
'</div>'
|
1023
|
+
);
|
1024
|
+
} else {
|
1025
|
+
return (
|
1026
|
+
'<div class="bootstrap-datetimepicker-widget dropdown-menu">' +
|
1027
|
+
'<div class="datepicker">' +
|
1028
|
+
DPGlobal.template +
|
1029
|
+
'</div>' +
|
1030
|
+
'</div>'
|
1031
|
+
);
|
1032
|
+
}
|
1033
|
+
}
|
1034
|
+
|
1035
|
+
function UTCDate() {
|
1036
|
+
return new Date(Date.UTC.apply(Date, arguments));
|
1037
|
+
}
|
1038
|
+
|
1039
|
+
var DPGlobal = {
|
1040
|
+
modes: [
|
1041
|
+
{
|
1042
|
+
clsName: 'days',
|
1043
|
+
navFnc: 'UTCMonth',
|
1044
|
+
navStep: 1
|
1045
|
+
},
|
1046
|
+
{
|
1047
|
+
clsName: 'months',
|
1048
|
+
navFnc: 'UTCFullYear',
|
1049
|
+
navStep: 1
|
1050
|
+
},
|
1051
|
+
{
|
1052
|
+
clsName: 'years',
|
1053
|
+
navFnc: 'UTCFullYear',
|
1054
|
+
navStep: 10
|
1055
|
+
}],
|
1056
|
+
isLeapYear: function (year) {
|
1057
|
+
return (((year % 4 === 0) && (year % 100 !== 0)) || (year % 400 === 0))
|
1058
|
+
},
|
1059
|
+
getDaysInMonth: function (year, month) {
|
1060
|
+
return [31, (DPGlobal.isLeapYear(year) ? 29 : 28), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][month]
|
1061
|
+
},
|
1062
|
+
headTemplate:
|
1063
|
+
'<thead>' +
|
1064
|
+
'<tr>' +
|
1065
|
+
'<th class="prev">‹</th>' +
|
1066
|
+
'<th colspan="5" class="switch"></th>' +
|
1067
|
+
'<th class="next">›</th>' +
|
1068
|
+
'</tr>' +
|
1069
|
+
'</thead>',
|
1070
|
+
contTemplate: '<tbody><tr><td colspan="7"></td></tr></tbody>'
|
1071
|
+
};
|
1072
|
+
DPGlobal.template =
|
1073
|
+
'<div class="datepicker-days">' +
|
1074
|
+
'<table class="table-condensed">' +
|
1075
|
+
DPGlobal.headTemplate +
|
1076
|
+
'<tbody></tbody>' +
|
1077
|
+
'</table>' +
|
1078
|
+
'</div>' +
|
1079
|
+
'<div class="datepicker-months">' +
|
1080
|
+
'<table class="table-condensed">' +
|
1081
|
+
DPGlobal.headTemplate +
|
1082
|
+
DPGlobal.contTemplate+
|
1083
|
+
'</table>'+
|
1084
|
+
'</div>'+
|
1085
|
+
'<div class="datepicker-years">'+
|
1086
|
+
'<table class="table-condensed">'+
|
1087
|
+
DPGlobal.headTemplate+
|
1088
|
+
DPGlobal.contTemplate+
|
1089
|
+
'</table>'+
|
1090
|
+
'</div>';
|
1091
|
+
var TPGlobal = {
|
1092
|
+
hourTemplate: '<span data-action="showHours" data-time-component="hours" class="timepicker-hour"></span>',
|
1093
|
+
minuteTemplate: '<span data-action="showMinutes" data-time-component="minutes" class="timepicker-minute"></span>',
|
1094
|
+
secondTemplate: '<span data-action="showSeconds" data-time-component="seconds" class="timepicker-second"></span>',
|
1095
|
+
};
|
1096
|
+
TPGlobal.getTemplate = function(is12Hours) {
|
1097
|
+
return (
|
1098
|
+
'<div class="timepicker-picker">' +
|
1099
|
+
'<table class="table-condensed"' +
|
1100
|
+
(is12Hours ? ' data-hour-format="12"' : '') +
|
1101
|
+
'>' +
|
1102
|
+
'<tr>' +
|
1103
|
+
'<td><a href="#" class="btn" data-action="incrementHours"><i class="icon-chevron-up"></i></a></td>' +
|
1104
|
+
'<td class="separator"></td>' +
|
1105
|
+
'<td><a href="#" class="btn" data-action="incrementMinutes"><i class="icon-chevron-up"></i></a></td>' +
|
1106
|
+
'<td class="separator"></td>' +
|
1107
|
+
'<td><a href="#" class="btn" data-action="incrementSeconds"><i class="icon-chevron-up"></i></a></td>' +
|
1108
|
+
(is12Hours ? '<td class="separator"></td>' : '') +
|
1109
|
+
'</tr>' +
|
1110
|
+
'<tr>' +
|
1111
|
+
'<td>' + TPGlobal.hourTemplate + '</td> ' +
|
1112
|
+
'<td class="separator">:</td>' +
|
1113
|
+
'<td>' + TPGlobal.minuteTemplate + '</td> ' +
|
1114
|
+
'<td class="separator">:</td>' +
|
1115
|
+
'<td>' + TPGlobal.secondTemplate + '</td>' +
|
1116
|
+
(is12Hours ?
|
1117
|
+
'<td class="separator"></td>' +
|
1118
|
+
'<td>' +
|
1119
|
+
'<button type="button" class="btn btn-primary" data-action="togglePeriod"></button>' +
|
1120
|
+
'</td>' : '') +
|
1121
|
+
'</tr>' +
|
1122
|
+
'<tr>' +
|
1123
|
+
'<td><a href="#" class="btn" data-action="decrementHours"><i class="icon-chevron-down"></i></a></td>' +
|
1124
|
+
'<td class="separator"></td>' +
|
1125
|
+
'<td><a href="#" class="btn" data-action="decrementMinutes"><i class="icon-chevron-down"></i></a></td>' +
|
1126
|
+
'<td class="separator"></td>' +
|
1127
|
+
'<td><a href="#" class="btn" data-action="decrementSeconds"><i class="icon-chevron-down"></i></a></td>' +
|
1128
|
+
(is12Hours ? '<td class="separator"></td>' : '') +
|
1129
|
+
'</tr>' +
|
1130
|
+
'</table>' +
|
1131
|
+
'</div>' +
|
1132
|
+
'<div class="timepicker-hours" data-action="selectHour">' +
|
1133
|
+
'<table class="table-condensed">' +
|
1134
|
+
'</table>'+
|
1135
|
+
'</div>'+
|
1136
|
+
'<div class="timepicker-minutes" data-action="selectMinute">' +
|
1137
|
+
'<table class="table-condensed">' +
|
1138
|
+
'</table>'+
|
1139
|
+
'</div>'+
|
1140
|
+
'<div class="timepicker-seconds" data-action="selectSecond">' +
|
1141
|
+
'<table class="table-condensed">' +
|
1142
|
+
'</table>'+
|
1143
|
+
'</div>'
|
1144
|
+
);
|
1145
|
+
}
|
1146
|
+
|
1147
|
+
|
1148
|
+
})(window.jQuery)
|