datetimepicker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,800 @@
1
+ /* =========================================================
2
+ * bootstrap-timepicker.js
3
+ * http://www.github.com/jdewit/bootstrap-timepicker
4
+ * =========================================================
5
+ * Copyright 2012
6
+ *
7
+ * Created By:
8
+ * Joris de Wit @joris_dewit
9
+ *
10
+ * Contributions By:
11
+ * Gilbert @mindeavor
12
+ * Koen Punt info@koenpunt.nl
13
+ * Nek
14
+ * Chris Martin
15
+ * Dominic Barnes contact@dominicbarnes.us
16
+ *
17
+ * Licensed under the Apache License, Version 2.0 (the "License");
18
+ * you may not use this file except in compliance with the License.
19
+ * You may obtain a copy of the License at
20
+ *
21
+ * http://www.apache.org/licenses/LICENSE-2.0
22
+ *
23
+ * Unless required by applicable law or agreed to in writing, software
24
+ * distributed under the License is distributed on an "AS IS" BASIS,
25
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26
+ * See the License for the specific language governing permissions and
27
+ * limitations under the License.
28
+ * ========================================================= */
29
+
30
+ !function($) {
31
+
32
+ "use strict"; // jshint ;_;
33
+
34
+ /* TIMEPICKER PUBLIC CLASS DEFINITION
35
+ * ================================== */
36
+ var Timepicker = function(element, options) {
37
+ this.$element = $(element);
38
+ this.options = $.extend({}, $.fn.timepicker.defaults, options, this.$element.data());
39
+ this.minuteStep = this.options.minuteStep || this.minuteStep;
40
+ this.secondStep = this.options.secondStep || this.secondStep;
41
+ this.showMeridian = this.options.showMeridian || this.showMeridian;
42
+ this.showSeconds = this.options.showSeconds || this.showSeconds;
43
+ this.showInputs = this.options.showInputs || this.showInputs;
44
+ this.disableFocus = this.options.disableFocus || this.disableFocus;
45
+ this.template = this.options.template || this.template;
46
+ this.modalBackdrop = this.options.modalBackdrop || this.modalBackdrop;
47
+ this.defaultTime = this.options.defaultTime || this.defaultTime;
48
+ this.open = false;
49
+ this.init();
50
+ };
51
+
52
+ Timepicker.prototype = {
53
+
54
+ constructor: Timepicker
55
+
56
+ , init: function () {
57
+ if (this.$element.parent().hasClass('input-append')) {
58
+ this.$element.parent('.input-append').find('.add-on').on('click', $.proxy(this.showWidget, this));
59
+ this.$element.on({
60
+ focus: $.proxy(this.highlightUnit, this),
61
+ click: $.proxy(this.highlightUnit, this),
62
+ keypress: $.proxy(this.elementKeypress, this),
63
+ blur: $.proxy(this.blurElement, this)
64
+ });
65
+
66
+ } else {
67
+ if (this.template) {
68
+ this.$element.on({
69
+ focus: $.proxy(this.showWidget, this),
70
+ click: $.proxy(this.showWidget, this),
71
+ blur: $.proxy(this.blurElement, this)
72
+ });
73
+ } else {
74
+ this.$element.on({
75
+ focus: $.proxy(this.highlightUnit, this),
76
+ click: $.proxy(this.highlightUnit, this),
77
+ keypress: $.proxy(this.elementKeypress, this),
78
+ blur: $.proxy(this.blurElement, this)
79
+ });
80
+ }
81
+ }
82
+
83
+
84
+ this.$widget = $(this.getTemplate()).appendTo('body');
85
+
86
+ this.$widget.on('click', $.proxy(this.widgetClick, this));
87
+
88
+ if (this.showInputs) {
89
+ this.$widget.find('input').on({
90
+ click: function() { this.select(); },
91
+ keypress: $.proxy(this.widgetKeypress, this),
92
+ change: $.proxy(this.updateFromWidgetInputs, this)
93
+ });
94
+ }
95
+
96
+ this.setDefaultTime(this.defaultTime);
97
+ }
98
+
99
+ , showWidget: function(e) {
100
+ e.stopPropagation();
101
+ e.preventDefault();
102
+
103
+ if (this.open) {
104
+ return;
105
+ }
106
+
107
+ this.$element.trigger('show');
108
+
109
+ if (this.disableFocus) {
110
+ this.$element.blur();
111
+ }
112
+
113
+ var pos = $.extend({}, this.$element.offset(), {
114
+ height: this.$element[0].offsetHeight
115
+ });
116
+
117
+ this.updateFromElementVal();
118
+
119
+ $('html')
120
+ .trigger('click.timepicker.data-api')
121
+ .one('click.timepicker.data-api', $.proxy(this.hideWidget, this));
122
+
123
+ if (this.template === 'modal') {
124
+ this.$widget.modal('show').on('hidden', $.proxy(this.hideWidget, this));
125
+ } else {
126
+ this.$widget.css({
127
+ top: pos.top + pos.height
128
+ , left: pos.left
129
+ })
130
+
131
+ if (!this.open) {
132
+ this.$widget.addClass('open');
133
+ }
134
+ }
135
+
136
+ this.open = true;
137
+ this.$element.trigger('shown');
138
+ }
139
+
140
+ , hideWidget: function(){
141
+ this.$element.trigger('hide');
142
+
143
+ if (this.template === 'modal') {
144
+ this.$widget.modal('hide');
145
+ } else {
146
+ this.$widget.removeClass('open');
147
+ }
148
+ this.open = false;
149
+ this.$element.trigger('hidden');
150
+ }
151
+
152
+ , widgetClick: function(e) {
153
+ e.stopPropagation();
154
+ e.preventDefault();
155
+
156
+ var action = $(e.target).closest('a').data('action');
157
+ if (action) {
158
+ this[action]();
159
+ this.update();
160
+ }
161
+ }
162
+
163
+ , widgetKeypress: function(e) {
164
+ var input = $(e.target).closest('input').attr('name');
165
+
166
+ switch (e.keyCode) {
167
+ case 9: //tab
168
+ if (this.showMeridian) {
169
+ if (input == 'meridian') {
170
+ this.hideWidget();
171
+ }
172
+ } else {
173
+ if (this.showSeconds) {
174
+ if (input == 'second') {
175
+ this.hideWidget();
176
+ }
177
+ } else {
178
+ if (input == 'minute') {
179
+ this.hideWidget();
180
+ }
181
+ }
182
+ }
183
+ break;
184
+ case 27: // escape
185
+ this.hideWidget();
186
+ break;
187
+ case 38: // up arrow
188
+ switch (input) {
189
+ case 'hour':
190
+ this.incrementHour();
191
+ break;
192
+ case 'minute':
193
+ this.incrementMinute();
194
+ break;
195
+ case 'second':
196
+ this.incrementSecond();
197
+ break;
198
+ case 'meridian':
199
+ this.toggleMeridian();
200
+ break;
201
+ }
202
+ this.update();
203
+ break;
204
+ case 40: // down arrow
205
+ switch (input) {
206
+ case 'hour':
207
+ this.decrementHour();
208
+ break;
209
+ case 'minute':
210
+ this.decrementMinute();
211
+ break;
212
+ case 'second':
213
+ this.decrementSecond();
214
+ break;
215
+ case 'meridian':
216
+ this.toggleMeridian();
217
+ break;
218
+ }
219
+ this.update();
220
+ break;
221
+ }
222
+ }
223
+
224
+ , elementKeypress: function(e) {
225
+ var input = this.$element.get(0);
226
+ switch (e.keyCode) {
227
+ case 0: //input
228
+ break;
229
+ case 9: //tab
230
+ this.updateFromElementVal();
231
+ if (this.showMeridian) {
232
+ if (this.highlightedUnit != 'meridian') {
233
+ e.preventDefault();
234
+ this.highlightNextUnit();
235
+ }
236
+ } else {
237
+ if (this.showSeconds) {
238
+ if (this.highlightedUnit != 'second') {
239
+ e.preventDefault();
240
+ this.highlightNextUnit();
241
+ }
242
+ } else {
243
+ if (this.highlightedUnit != 'minute') {
244
+ e.preventDefault();
245
+ this.highlightNextUnit();
246
+ }
247
+ }
248
+ }
249
+ break;
250
+ case 27: // escape
251
+ this.updateFromElementVal();
252
+ break;
253
+ case 37: // left arrow
254
+ this.updateFromElementVal();
255
+ this.highlightPrevUnit();
256
+ break;
257
+ case 38: // up arrow
258
+ switch (this.highlightedUnit) {
259
+ case 'hour':
260
+ this.incrementHour();
261
+ break;
262
+ case 'minute':
263
+ this.incrementMinute();
264
+ break;
265
+ case 'second':
266
+ this.incrementSecond();
267
+ break;
268
+ case 'meridian':
269
+ this.toggleMeridian();
270
+ break;
271
+ }
272
+ this.updateElement();
273
+ break;
274
+ case 39: // right arrow
275
+ this.updateFromElementVal();
276
+ this.highlightNextUnit();
277
+ break;
278
+ case 40: // down arrow
279
+ switch (this.highlightedUnit) {
280
+ case 'hour':
281
+ this.decrementHour();
282
+ break;
283
+ case 'minute':
284
+ this.decrementMinute();
285
+ break;
286
+ case 'second':
287
+ this.decrementSecond();
288
+ break;
289
+ case 'meridian':
290
+ this.toggleMeridian();
291
+ break;
292
+ }
293
+ this.updateElement();
294
+ break;
295
+ }
296
+
297
+ if (e.keyCode !== 0 && e.keyCode !== 8 && e.keyCode !== 9 && e.keyCode !== 46) {
298
+ e.preventDefault();
299
+ }
300
+ }
301
+
302
+ , setValues: function(time) {
303
+ if (this.showMeridian) {
304
+ var arr = time.split(' ');
305
+ var timeArray = arr[0].split(':');
306
+ this.meridian = arr[1];
307
+ } else {
308
+ var timeArray = time.split(':');
309
+ }
310
+
311
+ this.hour = parseInt(timeArray[0], 10);
312
+ this.minute = parseInt(timeArray[1], 10);
313
+ this.second = parseInt(timeArray[2], 10);
314
+
315
+ if (isNaN(this.hour)) {
316
+ this.hour = 0;
317
+ }
318
+ if (isNaN(this.minute)) {
319
+ this.minute = 0;
320
+ }
321
+
322
+ if (this.showMeridian) {
323
+ if (this.hour > 12) {
324
+ this.hour = 12;
325
+ } else if (this.hour < 1) {
326
+ this.hour = 1;
327
+ }
328
+
329
+ if (this.meridian == 'am' || this.meridian == 'a') {
330
+ this.meridian = 'AM';
331
+ } else if (this.meridian == 'pm' || this.meridian == 'p') {
332
+ this.meridian = 'PM';
333
+ }
334
+
335
+ if (this.meridian != 'AM' && this.meridian != 'PM') {
336
+ this.meridian = 'AM';
337
+ }
338
+ } else {
339
+ if (this.hour >= 24) {
340
+ this.hour = 23;
341
+ } else if (this.hour < 0) {
342
+ this.hour = 0;
343
+ }
344
+ }
345
+
346
+ if (this.minute < 0) {
347
+ this.minute = 0;
348
+ } else if (this.minute >= 60) {
349
+ this.minute = 59;
350
+ }
351
+
352
+ if (this.showSeconds) {
353
+ if (isNaN(this.second)) {
354
+ this.second = 0;
355
+ } else if (this.second < 0) {
356
+ this.second = 0;
357
+ } else if (this.second >= 60) {
358
+ this.second = 59;
359
+ }
360
+ }
361
+
362
+ this.updateElement();
363
+ this.updateWidget();
364
+ }
365
+
366
+ , setMeridian: function(meridian) {
367
+ if (meridian == 'a' || meridian == 'am' || meridian == 'AM' ) {
368
+ this.meridian = 'AM';
369
+ } else if (meridian == 'p' || meridian == 'pm' || meridian == 'PM' ) {
370
+ this.meridian = 'PM';
371
+ } else {
372
+ this.updateWidget();
373
+ }
374
+
375
+ this.updateElement();
376
+ }
377
+
378
+ , setDefaultTime: function(defaultTime){
379
+ if (defaultTime) {
380
+ if (defaultTime === 'current') {
381
+ var dTime = new Date();
382
+ var hours = dTime.getHours();
383
+ var minutes = Math.floor(dTime.getMinutes() / this.minuteStep) * this.minuteStep;
384
+ var seconds = Math.floor(dTime.getSeconds() / this.secondStep) * this.secondStep;
385
+ var meridian = "AM";
386
+ if (this.showMeridian) {
387
+ if (hours === 0) {
388
+ hours = 12;
389
+ } else if (hours >= 12) {
390
+ if (hours > 12) {
391
+ hours = hours - 12;
392
+ }
393
+ meridian = "PM";
394
+ } else {
395
+ meridian = "AM";
396
+ }
397
+ }
398
+ this.hour = hours;
399
+ this.minute = minutes;
400
+ this.second = seconds;
401
+ this.meridian = meridian;
402
+ } else if (defaultTime === 'value') {
403
+ this.setValues(this.$element.val());
404
+ } else {
405
+ this.setValues(defaultTime);
406
+ }
407
+ this.update();
408
+ } else {
409
+ this.hour = 0;
410
+ this.minute = 0;
411
+ this.second = 0;
412
+ }
413
+ }
414
+
415
+ , formatTime: function(hour, minute, second, meridian) {
416
+ hour = hour < 10 ? '0' + hour : hour;
417
+ minute = minute < 10 ? '0' + minute : minute;
418
+ second = second < 10 ? '0' + second : second;
419
+
420
+ return hour + ':' + minute + (this.showSeconds ? ':' + second : '') + (this.showMeridian ? ' ' + meridian : '');
421
+ }
422
+
423
+ , getTime: function() {
424
+ return this.formatTime(this.hour, this.minute, this.second, this.meridian);
425
+ }
426
+
427
+ , setTime: function(time) {
428
+ this.setValues(time);
429
+ this.update();
430
+ }
431
+
432
+ , update: function() {
433
+ this.updateElement();
434
+ this.updateWidget();
435
+ }
436
+
437
+ , blurElement: function() {
438
+ this.highlightedUnit = undefined;
439
+ this.updateFromElementVal();
440
+ }
441
+
442
+ , updateElement: function() {
443
+ var time = this.getTime();
444
+
445
+ this.$element.val(time).change();
446
+
447
+ switch (this.highlightedUnit) {
448
+ case 'hour':
449
+ this.highlightHour();
450
+ break;
451
+ case 'minute':
452
+ this.highlightMinute();
453
+ break;
454
+ case 'second':
455
+ this.highlightSecond();
456
+ break;
457
+ case 'meridian':
458
+ this.highlightMeridian();
459
+ break;
460
+ }
461
+ }
462
+
463
+ , updateWidget: function() {
464
+ if (this.showInputs) {
465
+ this.$widget.find('input.bootstrap-timepicker-hour').val(this.hour < 10 ? '0' + this.hour : this.hour);
466
+ this.$widget.find('input.bootstrap-timepicker-minute').val(this.minute < 10 ? '0' + this.minute : this.minute);
467
+ if (this.showSeconds) {
468
+ this.$widget.find('input.bootstrap-timepicker-second').val(this.second < 10 ? '0' + this.second : this.second);
469
+ }
470
+ if (this.showMeridian) {
471
+ this.$widget.find('input.bootstrap-timepicker-meridian').val(this.meridian);
472
+ }
473
+ } else {
474
+ this.$widget.find('span.bootstrap-timepicker-hour').text(this.hour);
475
+ this.$widget.find('span.bootstrap-timepicker-minute').text(this.minute < 10 ? '0' + this.minute : this.minute);
476
+ if (this.showSeconds) {
477
+ this.$widget.find('span.bootstrap-timepicker-second').text(this.second < 10 ? '0' + this.second : this.second);
478
+ }
479
+ if (this.showMeridian) {
480
+ this.$widget.find('span.bootstrap-timepicker-meridian').text(this.meridian);
481
+ }
482
+ }
483
+ }
484
+
485
+ , updateFromElementVal: function (e) {
486
+ var time = this.$element.val();
487
+ if (time) {
488
+ this.setValues(time);
489
+ this.updateWidget();
490
+ }
491
+ }
492
+
493
+ , updateFromWidgetInputs: function () {
494
+ var time = $('input.bootstrap-timepicker-hour', this.$widget).val() + ':' +
495
+ $('input.bootstrap-timepicker-minute', this.$widget).val() +
496
+ (this.showSeconds ?
497
+ ':' + $('input.bootstrap-timepicker-second', this.$widget).val()
498
+ : '') +
499
+ (this.showMeridian ?
500
+ ' ' + $('input.bootstrap-timepicker-meridian', this.$widget).val()
501
+ : '');
502
+
503
+ this.setValues(time);
504
+ }
505
+
506
+ , getCursorPosition: function() {
507
+ var input = this.$element.get(0);
508
+
509
+ if ('selectionStart' in input) {
510
+ // Standard-compliant browsers
511
+ return input.selectionStart;
512
+ } else if (document.selection) {
513
+ // IE fix
514
+ input.focus();
515
+ var sel = document.selection.createRange();
516
+ var selLen = document.selection.createRange().text.length;
517
+ sel.moveStart('character', - input.value.length);
518
+
519
+ return sel.text.length - selLen;
520
+ }
521
+ }
522
+
523
+ , highlightUnit: function () {
524
+ var input = this.$element.get(0);
525
+
526
+ this.position = this.getCursorPosition();
527
+ if (this.position >= 0 && this.position <= 2) {
528
+ this.highlightHour();
529
+ } else if (this.position >= 3 && this.position <= 5) {
530
+ this.highlightMinute();
531
+ } else if (this.position >= 6 && this.position <= 8) {
532
+ if (this.showSeconds) {
533
+ this.highlightSecond();
534
+ } else {
535
+ this.highlightMeridian();
536
+ }
537
+ } else if (this.position >= 9 && this.position <= 11) {
538
+ this.highlightMeridian();
539
+ }
540
+ }
541
+
542
+ , highlightNextUnit: function() {
543
+ switch (this.highlightedUnit) {
544
+ case 'hour':
545
+ this.highlightMinute();
546
+ break;
547
+ case 'minute':
548
+ if (this.showSeconds) {
549
+ this.highlightSecond();
550
+ } else {
551
+ this.highlightMeridian();
552
+ }
553
+ break;
554
+ case 'second':
555
+ this.highlightMeridian();
556
+ break;
557
+ case 'meridian':
558
+ this.highlightHour();
559
+ break;
560
+ }
561
+ }
562
+
563
+ , highlightPrevUnit: function() {
564
+ switch (this.highlightedUnit) {
565
+ case 'hour':
566
+ this.highlightMeridian();
567
+ break;
568
+ case 'minute':
569
+ this.highlightHour();
570
+ break;
571
+ case 'second':
572
+ this.highlightMinute();
573
+ break;
574
+ case 'meridian':
575
+ if (this.showSeconds) {
576
+ this.highlightSecond();
577
+ } else {
578
+ this.highlightMinute();
579
+ }
580
+ break;
581
+ }
582
+ }
583
+
584
+ , highlightHour: function() {
585
+ this.highlightedUnit = 'hour';
586
+ this.$element.get(0).setSelectionRange(0,2);
587
+ }
588
+
589
+ , highlightMinute: function() {
590
+ this.highlightedUnit = 'minute';
591
+ this.$element.get(0).setSelectionRange(3,5);
592
+ }
593
+
594
+ , highlightSecond: function() {
595
+ this.highlightedUnit = 'second';
596
+ this.$element.get(0).setSelectionRange(6,8);
597
+ }
598
+
599
+ , highlightMeridian: function() {
600
+ this.highlightedUnit = 'meridian';
601
+ if (this.showSeconds) {
602
+ this.$element.get(0).setSelectionRange(9,11);
603
+ } else {
604
+ this.$element.get(0).setSelectionRange(6,8);
605
+ }
606
+ }
607
+
608
+ , incrementHour: function() {
609
+ if (this.showMeridian) {
610
+ if (this.hour === 11) {
611
+ this.toggleMeridian();
612
+ } else if (this.hour === 12) {
613
+ return this.hour = 1;
614
+ }
615
+ }
616
+ if (this.hour === 23) {
617
+ return this.hour = 0;
618
+ }
619
+ this.hour = this.hour + 1;
620
+ }
621
+
622
+ , decrementHour: function() {
623
+ if (this.showMeridian) {
624
+ if (this.hour === 1) {
625
+ return this.hour = 12;
626
+ }
627
+ else if (this.hour === 12) {
628
+ this.toggleMeridian();
629
+ }
630
+ }
631
+ if (this.hour === 0) {
632
+ return this.hour = 23;
633
+ }
634
+ this.hour = this.hour - 1;
635
+ }
636
+
637
+ , incrementMinute: function() {
638
+ var newVal = this.minute + this.minuteStep - (this.minute % this.minuteStep);
639
+ if (newVal > 59) {
640
+ this.incrementHour();
641
+ this.minute = newVal - 60;
642
+ } else {
643
+ this.minute = newVal;
644
+ }
645
+ }
646
+
647
+ , decrementMinute: function() {
648
+ var newVal = this.minute - this.minuteStep;
649
+ if (newVal < 0) {
650
+ this.decrementHour();
651
+ this.minute = newVal + 60;
652
+ } else {
653
+ this.minute = newVal;
654
+ }
655
+ }
656
+
657
+ , incrementSecond: function() {
658
+ var newVal = this.second + this.secondStep - (this.second % this.secondStep);
659
+ if (newVal > 59) {
660
+ this.incrementMinute();
661
+ this.second = newVal - 60;
662
+ } else {
663
+ this.second = newVal;
664
+ }
665
+ }
666
+
667
+ , decrementSecond: function() {
668
+ var newVal = this.second - this.secondStep;
669
+ if (newVal < 0) {
670
+ this.decrementMinute();
671
+ this.second = newVal + 60;
672
+ } else {
673
+ this.second = newVal;
674
+ }
675
+ }
676
+
677
+ , toggleMeridian: function() {
678
+ this.meridian = this.meridian === 'AM' ? 'PM' : 'AM';
679
+
680
+ this.update();
681
+ }
682
+
683
+ , getTemplate: function() {
684
+ if (this.options.templates[this.options.template]) {
685
+ return this.options.templates[this.options.template];
686
+ }
687
+ if (this.showInputs) {
688
+ var hourTemplate = '<input type="text" name="hour" class="bootstrap-timepicker-hour" maxlength="2"/>';
689
+ var minuteTemplate = '<input type="text" name="minute" class="bootstrap-timepicker-minute" maxlength="2"/>';
690
+ var secondTemplate = '<input type="text" name="second" class="bootstrap-timepicker-second" maxlength="2"/>';
691
+ var meridianTemplate = '<input type="text" name="meridian" class="bootstrap-timepicker-meridian" maxlength="2"/>';
692
+ } else {
693
+ var hourTemplate = '<span class="bootstrap-timepicker-hour"></span>';
694
+ var minuteTemplate = '<span class="bootstrap-timepicker-minute"></span>';
695
+ var secondTemplate = '<span class="bootstrap-timepicker-second"></span>';
696
+ var meridianTemplate = '<span class="bootstrap-timepicker-meridian"></span>';
697
+ }
698
+ var templateContent = '<table class="'+ (this.showSeconds ? 'show-seconds' : '') +' '+ (this.showMeridian ? 'show-meridian' : '') +'">'+
699
+ '<tr>'+
700
+ '<td><a href="#" data-action="incrementHour"><i class="icon-chevron-up"></i></a></td>'+
701
+ '<td class="separator">&nbsp;</td>'+
702
+ '<td><a href="#" data-action="incrementMinute"><i class="icon-chevron-up"></i></a></td>'+
703
+ (this.showSeconds ?
704
+ '<td class="separator">&nbsp;</td>'+
705
+ '<td><a href="#" data-action="incrementSecond"><i class="icon-chevron-up"></i></a></td>'
706
+ : '') +
707
+ (this.showMeridian ?
708
+ '<td class="separator">&nbsp;</td>'+
709
+ '<td class="meridian-column"><a href="#" data-action="toggleMeridian"><i class="icon-chevron-up"></i></a></td>'
710
+ : '') +
711
+ '</tr>'+
712
+ '<tr>'+
713
+ '<td>'+ hourTemplate +'</td> '+
714
+ '<td class="separator">:</td>'+
715
+ '<td>'+ minuteTemplate +'</td> '+
716
+ (this.showSeconds ?
717
+ '<td class="separator">:</td>'+
718
+ '<td>'+ secondTemplate +'</td>'
719
+ : '') +
720
+ (this.showMeridian ?
721
+ '<td class="separator">&nbsp;</td>'+
722
+ '<td>'+ meridianTemplate +'</td>'
723
+ : '') +
724
+ '</tr>'+
725
+ '<tr>'+
726
+ '<td><a href="#" data-action="decrementHour"><i class="icon-chevron-down"></i></a></td>'+
727
+ '<td class="separator"></td>'+
728
+ '<td><a href="#" data-action="decrementMinute"><i class="icon-chevron-down"></i></a></td>'+
729
+ (this.showSeconds ?
730
+ '<td class="separator">&nbsp;</td>'+
731
+ '<td><a href="#" data-action="decrementSecond"><i class="icon-chevron-down"></i></a></td>'
732
+ : '') +
733
+ (this.showMeridian ?
734
+ '<td class="separator">&nbsp;</td>'+
735
+ '<td><a href="#" data-action="toggleMeridian"><i class="icon-chevron-down"></i></a></td>'
736
+ : '') +
737
+ '</tr>'+
738
+ '</table>';
739
+
740
+ var template;
741
+ switch(this.options.template) {
742
+ case 'modal':
743
+ template = '<div class="bootstrap-timepicker modal hide fade in" style="top: 30%; margin-top: 0; width: 200px; margin-left: -100px;" data-backdrop="'+ (this.modalBackdrop ? 'true' : 'false') +'">'+
744
+ '<div class="modal-header">'+
745
+ '<a href="#" class="close" data-dismiss="modal">×</a>'+
746
+ '<h3>Pick a Time</h3>'+
747
+ '</div>'+
748
+ '<div class="modal-content">'+
749
+ templateContent +
750
+ '</div>'+
751
+ '<div class="modal-footer">'+
752
+ '<a href="#" class="btn btn-primary" data-dismiss="modal">Ok</a>'+
753
+ '</div>'+
754
+ '</div>';
755
+
756
+ break;
757
+ case 'dropdown':
758
+ template = '<div class="bootstrap-timepicker dropdown-menu">'+
759
+ templateContent +
760
+ '</div>';
761
+ break;
762
+
763
+ }
764
+ return template;
765
+ }
766
+ };
767
+
768
+
769
+ /* TIMEPICKER PLUGIN DEFINITION
770
+ * =========================== */
771
+
772
+ $.fn.timepicker = function (option) {
773
+ return this.each(function () {
774
+ var $this = $(this)
775
+ , data = $this.data('timepicker')
776
+ , options = typeof option == 'object' && option;
777
+ if (!data) {
778
+ $this.data('timepicker', (data = new Timepicker(this, options)));
779
+ }
780
+ if (typeof option == 'string') {
781
+ data[option]();
782
+ }
783
+ })
784
+ }
785
+
786
+ $.fn.timepicker.defaults = {
787
+ minuteStep: 15
788
+ , secondStep: 15
789
+ , disableFocus: false
790
+ , defaultTime: 'current'
791
+ , showSeconds: false
792
+ , showInputs: true
793
+ , showMeridian: true
794
+ , template: 'dropdown'
795
+ , modalBackdrop: false
796
+ , templates: {} // set custom templates
797
+ }
798
+
799
+ $.fn.timepicker.Constructor = Timepicker
800
+ }(window.jQuery);