Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make tab keydown move to next input and make setTime idiot proof

Tab keydown was switching to the next hightlighted unit but this
doesn't really make sense when entering in the full time.

Also improved the setTime method.
You can now enter 5pm, 545p, 5:30:20a and it will format the time
properly.

fixes #152
fixes #117
fixes #129
commit 0d3a1ef234a9cfab30ea308eda1c4c48abf0c70a 1 parent da8a416
@jdewit authored
View
8 _layouts/default.html
@@ -140,6 +140,14 @@
showInputs: false,
minuteStep: 5
});
+
+ setTimeout(function() {
+ $('#timeDisplay').text($('#timepicker1').val());
+ }, 100);
+
+ $('#timepicker1').on('changeTime.timepicker', function(e) {
+ $('#timeDisplay').text(e.time.value);
+ });
});
</script>
</body>
View
2  index.html
@@ -43,7 +43,7 @@
<hr>
<h1>Demos</h1>
<hr>
- <p>Default timepicker.</p>
+ <p>Default timepicker. Value = (<span id="timeDisplay"></span>)</p>
<div class="input-append bootstrap-timepicker">
<input id="timepicker1" class="input-small" type="text"/><span class="add-on"><i class="icon-time"></i></span>
</div>
View
99 js/bootstrap-timepicker.js
@@ -86,7 +86,7 @@
},
blurElement: function() {
- this.highlightedUnit = undefined;
+ this.highlightedUnit = null;
this.updateFromElementVal();
},
@@ -157,27 +157,6 @@
elementKeydown: function(e) {
switch (e.keyCode) {
case 9: //tab
- this.updateFromElementVal();
-
- switch (this.highlightedUnit) {
- case 'hour':
- e.preventDefault();
- this.highlightNextUnit();
- break;
- case 'minute':
- if (this.showMeridian || this.showSeconds) {
- e.preventDefault();
- this.highlightNextUnit();
- }
- break;
- case 'second':
- if (this.showMeridian) {
- e.preventDefault();
- this.highlightNextUnit();
- }
- break;
- }
- break;
case 27: // escape
this.updateFromElementVal();
break;
@@ -237,7 +216,7 @@
},
formatTime: function(hour, minute, second, meridian) {
- hour = hour !== null ? (hour < 10 ? '0' + hour : hour) : '';
+ hour = hour !== null ? (hour < 10 && this.showMeridian === false ? '0' + hour : hour) : '';
minute = minute !== null ? (minute < 10 ? '0' + minute : minute) : '';
second = second !== null ? (second < 10 ? '0' + second : second) : '';
@@ -678,9 +657,6 @@
},
setTime: function(time) {
- var arr,
- timeArray;
-
if (!time) {
this.clear();
return;
@@ -704,50 +680,62 @@
}
}
} else {
- if (this.showMeridian) {
- arr = time.split(' ');
- timeArray = arr[0].split(':');
- this.meridian = arr[1];
+ //
+ var timeArray,
+ hour,
+ minute,
+ second = 0;
+
+ if (time.match(/p/i) !== null) {
+ this.meridian = 'PM';
} else {
- timeArray = time.split(':');
+ this.meridian = 'AM';
}
- this.hour = parseInt(timeArray[0], 10);
- this.minute = parseInt(timeArray[1], 10);
- this.second = parseInt(timeArray[2], 10);
+ time = time.replace(/[^0-9\:]/g, '');
- if (isNaN(this.hour)) {
- this.hour = 0;
+ timeArray = time.split(':');
+
+ hour = timeArray[0] ? timeArray[0].toString() : timeArray.toString();
+ minute = timeArray[1] ? timeArray[1].toString() : '';
+ second = timeArray[2] ? timeArray[2].toString() : '';
+
+ // idiot proofing
+ if (hour.length > 4) {
+ second = hour.substr(4, 2);
}
- if (isNaN(this.minute)) {
- this.minute = 0;
+ if (hour.length > 2) {
+ minute = hour.substr(2, 2);
+ hour = hour.substr(0, 2);
+ }
+ if (minute.length > 2) {
+ second = minute.substr(2, 2);
+ minute = minute.substr(0, 2);
}
+ if (second.length > 2) {
+ second = second.substr(2, 2);
+ }
+
+ this.hour = parseInt(hour, 10);
+ this.minute = parseInt(minute, 10);
+ this.second = parseInt(second, 10);
if (this.showMeridian) {
- if (this.hour > 12) {
- this.hour = 12;
- } else if (this.hour < 1) {
+ if (this.hour < 1 || this.hour > 12) {
this.hour = 12;
}
-
- if (this.meridian === 'am' || this.meridian === 'a') {
- this.meridian = 'AM';
- } else if (this.meridian === 'pm' || this.meridian === 'p') {
- this.meridian = 'PM';
- }
-
- if (this.meridian !== 'AM' && this.meridian !== 'PM') {
- this.meridian = 'AM';
- }
} else {
if (this.hour >= 24) {
this.hour = 23;
} else if (this.hour < 0) {
this.hour = 0;
}
+ if (this.hour < 13 && this.meridian === 'PM') {
+ this.hour = this.hour + 12;
+ }
}
- if (this.minute < 0) {
+ if (!this.minute || this.minute < 0) {
this.minute = 0;
} else if (this.minute >= 60) {
this.minute = 59;
@@ -838,11 +826,7 @@
},
updateFromElementVal: function() {
- var val = this.$element.val();
-
- if (val) {
- this.setTime(val);
- }
+ this.setTime(this.$element.val());
},
updateWidget: function() {
@@ -964,7 +948,6 @@
}
};
-
//TIMEPICKER PLUGIN DEFINITION
$.fn.timepicker = function(option) {
var args = Array.apply(null, arguments);
View
6 js/bootstrap-timepicker.min.js
@@ -2,8 +2,4 @@
* http://jdewit.github.com/bootstrap-timepicker
* Copyright (c) 2013 Joris de Wit
* MIT License
-<<<<<<< HEAD
-*/!function(a,b,c,d){"use strict";var e=function(b,c){this.widget="",this.$element=a(b),this.defaultTime=c.defaultTime,this.disableFocus=c.disableFocus,this.disableMousewheel=c.disableMousewheel,this.isOpen=c.isOpen,this.minuteStep=c.minuteStep,this.modalBackdrop=c.modalBackdrop,this.secondStep=c.secondStep,this.showInputs=c.showInputs,this.showMeridian=c.showMeridian,this.showSeconds=c.showSeconds,this.template=c.template,this.appendWidgetTo=c.appendWidgetTo,this._init()};e.prototype={constructor:e,_init:function(){var b=this;this.$element.parent().hasClass("input-append")||this.$element.parent().hasClass("input-prepend")?(this.$element.parent(".input-append, .input-prepend").find(".add-on").on({"click.timepicker":a.proxy(this.showWidget,this)}),this.$element.on({"focus.timepicker":a.proxy(this.highlightUnit,this),"click.timepicker":a.proxy(this.highlightUnit,this),"keydown.timepicker":a.proxy(this.elementKeydown,this),"blur.timepicker":a.proxy(this.blurElement,this),"mousewheel.timepicker DOMMouseScroll.timepicker":a.proxy(this.mousewheel,this)})):this.template?this.$element.on({"focus.timepicker":a.proxy(this.showWidget,this),"click.timepicker":a.proxy(this.showWidget,this),"blur.timepicker":a.proxy(this.blurElement,this),"mousewheel.timepicker DOMMouseScroll.timepicker":a.proxy(this.mousewheel,this)}):this.$element.on({"focus.timepicker":a.proxy(this.highlightUnit,this),"click.timepicker":a.proxy(this.highlightUnit,this),"keydown.timepicker":a.proxy(this.elementKeydown,this),"blur.timepicker":a.proxy(this.blurElement,this),"mousewheel.timepicker DOMMouseScroll.timepicker":a.proxy(this.mousewheel,this)}),this.$widget=this.template!==!1?a(this.getTemplate()).prependTo(this.$element.parents(this.appendWidgetTo)).on("click",a.proxy(this.widgetClick,this)):!1,this.showInputs&&this.$widget!==!1&&this.$widget.find("input").each(function(){a(this).on({"click.timepicker":function(){a(this).select()},"keydown.timepicker":a.proxy(b.widgetKeydown,b)})}),this.setDefaultTime(this.defaultTime)},blurElement:function(){this.highlightedUnit=d,this.updateFromElementVal()},decrementHour:function(){if(this.showMeridian)if(1===this.hour)this.hour=12;else{if(12===this.hour)return this.hour--,this.toggleMeridian();if(0===this.hour)return this.hour=11,this.toggleMeridian();this.hour--}else 0===this.hour?this.hour=23:this.hour--;this.update()},decrementMinute:function(a){var b;b=a?this.minute-a:this.minute-this.minuteStep,0>b?(this.decrementHour(),this.minute=b+60):this.minute=b,this.update()},decrementSecond:function(){var a=this.second-this.secondStep;0>a?(this.decrementMinute(!0),this.second=a+60):this.second=a,this.update()},elementKeydown:function(a){switch(a.keyCode){case 9:switch(this.updateFromElementVal(),this.highlightedUnit){case"hour":a.preventDefault(),this.highlightNextUnit();break;case"minute":(this.showMeridian||this.showSeconds)&&(a.preventDefault(),this.highlightNextUnit());break;case"second":this.showMeridian&&(a.preventDefault(),this.highlightNextUnit())}break;case 27:this.updateFromElementVal();break;case 37:a.preventDefault(),this.highlightPrevUnit(),this.updateFromElementVal();break;case 38:switch(a.preventDefault(),this.highlightedUnit){case"hour":this.incrementHour(),this.highlightHour();break;case"minute":this.incrementMinute(),this.highlightMinute();break;case"second":this.incrementSecond(),this.highlightSecond();break;case"meridian":this.toggleMeridian(),this.highlightMeridian()}break;case 39:a.preventDefault(),this.updateFromElementVal(),this.highlightNextUnit();break;case 40:switch(a.preventDefault(),this.highlightedUnit){case"hour":this.decrementHour(),this.highlightHour();break;case"minute":this.decrementMinute(),this.highlightMinute();break;case"second":this.decrementSecond(),this.highlightSecond();break;case"meridian":this.toggleMeridian(),this.highlightMeridian()}}},formatTime:function(a,b,c,d){return a=10>a?"0"+a:a,b=10>b?"0"+b:b,c=10>c?"0"+c:c,a+":"+b+(this.showSeconds?":"+c:"")+(this.showMeridian?" "+d:"")},getCursorPosition:function(){var a=this.$element.get(0);if("selectionStart"in a)return a.selectionStart;if(c.selection){a.focus();var b=c.selection.createRange(),d=c.selection.createRange().text.length;return b.moveStart("character",-a.value.length),b.text.length-d}},getTemplate:function(){var a,b,c,d,e,f;switch(this.showInputs?(b='<input type="text" name="hour" class="bootstrap-timepicker-hour" maxlength="2"/>',c='<input type="text" name="minute" class="bootstrap-timepicker-minute" maxlength="2"/>',d='<input type="text" name="second" class="bootstrap-timepicker-second" maxlength="2"/>',e='<input type="text" name="meridian" class="bootstrap-timepicker-meridian" maxlength="2"/>'):(b='<span class="bootstrap-timepicker-hour"></span>',c='<span class="bootstrap-timepicker-minute"></span>',d='<span class="bootstrap-timepicker-second"></span>',e='<span class="bootstrap-timepicker-meridian"></span>'),f='<table><tr><td><a href="#" data-action="incrementHour"><i class="icon-chevron-up"></i></a></td><td class="separator">&nbsp;</td><td><a href="#" data-action="incrementMinute"><i class="icon-chevron-up"></i></a></td>'+(this.showSeconds?'<td class="separator">&nbsp;</td><td><a href="#" data-action="incrementSecond"><i class="icon-chevron-up"></i></a></td>':"")+(this.showMeridian?'<td class="separator">&nbsp;</td><td class="meridian-column"><a href="#" data-action="toggleMeridian"><i class="icon-chevron-up"></i></a></td>':"")+"</tr>"+"<tr>"+"<td>"+b+"</td> "+'<td class="separator">:</td>'+"<td>"+c+"</td> "+(this.showSeconds?'<td class="separator">:</td><td>'+d+"</td>":"")+(this.showMeridian?'<td class="separator">&nbsp;</td><td>'+e+"</td>":"")+"</tr>"+"<tr>"+'<td><a href="#" data-action="decrementHour"><i class="icon-chevron-down"></i></a></td>'+'<td class="separator"></td>'+'<td><a href="#" data-action="decrementMinute"><i class="icon-chevron-down"></i></a></td>'+(this.showSeconds?'<td class="separator">&nbsp;</td><td><a href="#" data-action="decrementSecond"><i class="icon-chevron-down"></i></a></td>':"")+(this.showMeridian?'<td class="separator">&nbsp;</td><td><a href="#" data-action="toggleMeridian"><i class="icon-chevron-down"></i></a></td>':"")+"</tr>"+"</table>",this.template){case"modal":a='<div class="bootstrap-timepicker-widget modal hide fade in" data-backdrop="'+(this.modalBackdrop?"true":"false")+'">'+'<div class="modal-header">'+'<a href="#" class="close" data-dismiss="modal">×</a>'+"<h3>Pick a Time</h3>"+"</div>"+'<div class="modal-content">'+f+"</div>"+'<div class="modal-footer">'+'<a href="#" class="btn btn-primary" data-dismiss="modal">OK</a>'+"</div>"+"</div>";break;case"dropdown":a='<div class="bootstrap-timepicker-widget dropdown-menu">'+f+"</div>"}return a},getTime:function(){return this.formatTime(this.hour,this.minute,this.second,this.meridian)},hideWidget:function(){this.isOpen!==!1&&(this.showInputs&&this.updateFromWidgetInputs(),this.$element.trigger({type:"hide.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),"modal"===this.template&&this.$widget.modal?this.$widget.modal("hide"):this.$widget.removeClass("open"),a(c).off("mousedown.timepicker"),this.isOpen=!1)},highlightUnit:function(){this.position=this.getCursorPosition(),this.position>=0&&this.position<=2?this.highlightHour():this.position>=3&&this.position<=5?this.highlightMinute():this.position>=6&&this.position<=8?this.showSeconds?this.highlightSecond():this.highlightMeridian():this.position>=9&&this.position<=11&&this.highlightMeridian()},highlightNextUnit:function(){switch(this.highlightedUnit){case"hour":this.highlightMinute();break;case"minute":this.showSeconds?this.highlightSecond():this.showMeridian?this.highlightMeridian():this.highlightHour();break;case"second":this.showMeridian?this.highlightMeridian():this.highlightHour();break;case"meridian":this.highlightHour()}},highlightPrevUnit:function(){switch(this.highlightedUnit){case"hour":this.highlightMeridian();break;case"minute":this.highlightHour();break;case"second":this.highlightMinute();break;case"meridian":this.showSeconds?this.highlightSecond():this.highlightMinute()}},highlightHour:function(){var a=this.$element.get(0);this.highlightedUnit="hour",a.setSelectionRange&&setTimeout(function(){a.setSelectionRange(0,2)},0)},highlightMinute:function(){var a=this.$element.get(0);this.highlightedUnit="minute",a.setSelectionRange&&setTimeout(function(){a.setSelectionRange(3,5)},0)},highlightSecond:function(){var a=this.$element.get(0);this.highlightedUnit="second",a.setSelectionRange&&setTimeout(function(){a.setSelectionRange(6,8)},0)},highlightMeridian:function(){var a=this.$element.get(0);this.highlightedUnit="meridian",a.setSelectionRange&&(this.showSeconds?setTimeout(function(){a.setSelectionRange(9,11)},0):setTimeout(function(){a.setSelectionRange(6,8)},0))},incrementHour:function(){if(this.showMeridian){if(11===this.hour)return this.hour++,this.toggleMeridian();12===this.hour&&(this.hour=0)}return 23===this.hour?(this.hour=0,void 0):(this.hour++,this.update(),void 0)},incrementMinute:function(a){var b;b=a?this.minute+a:this.minute+this.minuteStep-this.minute%this.minuteStep,b>59?(this.incrementHour(),this.minute=b-60):(this.minute=b,this.update())},incrementSecond:function(){var a=this.second+this.secondStep-this.second%this.secondStep;a>59?(this.incrementMinute(!0),this.second=a-60):this.second=a,this.update()},mousewheel:function(b){if(!this.disableMousewheel){b.preventDefault(),b.stopPropagation();var c=b.originalEvent.wheelDelta||-b.originalEvent.detail,d=null;switch("mousewheel"===b.type?d=-1*b.originalEvent.wheelDelta:"DOMMouseScroll"===b.type&&(d=40*b.originalEvent.detail),d&&(b.preventDefault(),a(this).scrollTop(d+a(this).scrollTop())),this.highlightedUnit){case"minute":c>0?this.incrementMinute():this.decrementMinute(),this.highlightMinute();break;case"second":c>0?this.incrementSecond():this.decrementSecond(),this.highlightSecond();break;case"meridian":this.toggleMeridian(),this.highlightMeridian();break;default:c>0?this.incrementHour():this.decrementHour(),this.highlightHour()}return!1}},remove:function(){a("document").off(".timepicker"),this.$widget&&this.$widget.remove(),delete this.$element.data().timepicker},setDefaultTime:function(a){if(this.$element.val())this.updateFromElementVal();else if("current"===a){var b=new Date,c=b.getHours(),d=b.getMinutes(),e=b.getSeconds(),f="AM";0!==e&&(e=Math.ceil(b.getSeconds()/this.secondStep)*this.secondStep,60===e&&(d+=1,e=0)),0!==d&&(d=Math.ceil(b.getMinutes()/this.minuteStep)*this.minuteStep,60===d&&(c+=1,d=0)),this.showMeridian&&(0===c?c=12:c>=12?(c>12&&(c-=12),f="PM"):f="AM"),this.hour=c,this.minute=d,this.second=e,this.meridian=f,this.update()}else a===!1?(this.hour=0,this.minute=0,this.second=0,this.meridian="AM"):this.setTime(a)},setTime:function(a){var b,c;this.showMeridian?(b=a.split(" "),c=b[0].split(":"),this.meridian=b[1]):c=a.split(":"),this.hour=parseInt(c[0],10),this.minute=parseInt(c[1],10),this.second=parseInt(c[2],10),isNaN(this.hour)&&(this.hour=0),isNaN(this.minute)&&(this.minute=0),this.showMeridian?(this.hour>12?this.hour=12:this.hour<1&&(this.hour=12),"am"===this.meridian||"a"===this.meridian?this.meridian="AM":("pm"===this.meridian||"p"===this.meridian)&&(this.meridian="PM"),"AM"!==this.meridian&&"PM"!==this.meridian&&(this.meridian="AM")):this.hour>=24?this.hour=23:this.hour<0&&(this.hour=0),this.minute<0?this.minute=0:this.minute>=60&&(this.minute=59),this.showSeconds&&(isNaN(this.second)?this.second=0:this.second<0?this.second=0:this.second>=60&&(this.second=59)),this.update()},showWidget:function(){if(!this.isOpen&&!this.$element.is(":disabled")){var b=this;a(c).on("mousedown.timepicker",function(c){0===a(c.target).closest(".bootstrap-timepicker-widget").length&&b.hideWidget()}),this.$element.trigger({type:"show.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),this.disableFocus&&this.$element.blur(),this.updateFromElementVal(),"modal"===this.template&&this.$widget.modal?this.$widget.modal("show").on("hidden",a.proxy(this.hideWidget,this)):this.isOpen===!1&&this.$widget.addClass("open"),this.isOpen=!0}},toggleMeridian:function(){this.meridian="AM"===this.meridian?"PM":"AM",this.update()},update:function(){this.$element.trigger({type:"changeTime.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),this.updateElement(),this.updateWidget()},updateElement:function(){this.$element.val(this.getTime()).change()},updateFromElementVal:function(){var a=this.$element.val();a&&this.setTime(a)},updateWidget:function(){if(this.$widget!==!1){var a=this.hour<10?"0"+this.hour:this.hour,b=this.minute<10?"0"+this.minute:this.minute,c=this.second<10?"0"+this.second:this.second;this.showInputs?(this.$widget.find("input.bootstrap-timepicker-hour").val(a),this.$widget.find("input.bootstrap-timepicker-minute").val(b),this.showSeconds&&this.$widget.find("input.bootstrap-timepicker-second").val(c),this.showMeridian&&this.$widget.find("input.bootstrap-timepicker-meridian").val(this.meridian)):(this.$widget.find("span.bootstrap-timepicker-hour").text(a),this.$widget.find("span.bootstrap-timepicker-minute").text(b),this.showSeconds&&this.$widget.find("span.bootstrap-timepicker-second").text(c),this.showMeridian&&this.$widget.find("span.bootstrap-timepicker-meridian").text(this.meridian))}},updateFromWidgetInputs:function(){if(this.$widget!==!1){var b=a("input.bootstrap-timepicker-hour",this.$widget).val()+":"+a("input.bootstrap-timepicker-minute",this.$widget).val()+(this.showSeconds?":"+a("input.bootstrap-timepicker-second",this.$widget).val():"")+(this.showMeridian?" "+a("input.bootstrap-timepicker-meridian",this.$widget).val():"");this.setTime(b)}},widgetClick:function(b){b.stopPropagation(),b.preventDefault();var c=a(b.target).closest("a").data("action");c&&this[c]()},widgetKeydown:function(b){var c=a(b.target).closest("input"),d=c.attr("name");switch(b.keyCode){case 9:if(this.showMeridian){if("meridian"===d)return this.hideWidget()}else if(this.showSeconds){if("second"===d)return this.hideWidget()}else if("minute"===d)return this.hideWidget();this.updateFromWidgetInputs();break;case 27:this.hideWidget();break;case 38:switch(b.preventDefault(),d){case"hour":this.incrementHour();break;case"minute":this.incrementMinute();break;case"second":this.incrementSecond();break;case"meridian":this.toggleMeridian()}break;case 40:switch(b.preventDefault(),d){case"hour":this.decrementHour();break;case"minute":this.decrementMinute();break;case"second":this.decrementSecond();break;case"meridian":this.toggleMeridian()}}}},a.fn.timepicker=function(b){var c=Array.apply(null,arguments);return c.shift(),this.each(function(){var d=a(this),f=d.data("timepicker"),g="object"==typeof b&&b;f||d.data("timepicker",f=new e(this,a.extend({},a.fn.timepicker.defaults,g,a(this).data()))),"string"==typeof b&&f[b].apply(f,c)})},a.fn.timepicker.defaults={defaultTime:"current",disableFocus:!1,disableMousewheel:!1,isOpen:!1,minuteStep:15,modalBackdrop:!1,secondStep:15,showSeconds:!1,showInputs:!0,showMeridian:!0,template:"dropdown",appendWidgetTo:".bootstrap-timepicker"},a.fn.timepicker.Constructor=e}(jQuery,window,document);
-=======
-*/(function(e,t,n,r){"use strict";var i=function(t,n){this.widget="";this.$element=e(t);this.defaultTime=n.defaultTime;this.disableFocus=n.disableFocus;this.isOpen=n.isOpen;this.minuteStep=n.minuteStep;this.modalBackdrop=n.modalBackdrop;this.secondStep=n.secondStep;this.showInputs=n.showInputs;this.showMeridian=n.showMeridian;this.showSeconds=n.showSeconds;this.template=n.template;this.appendWidgetTo=n.appendWidgetTo;this._init()};i.prototype={constructor:i,_init:function(){var t=this;if(this.$element.parent().hasClass("input-append")||this.$element.parent().hasClass("input-prepend")){this.$element.parent(".input-append, .input-prepend").find(".add-on").on({"click.timepicker":e.proxy(this.showWidget,this)});this.$element.on({"focus.timepicker":e.proxy(this.highlightUnit,this),"click.timepicker":e.proxy(this.highlightUnit,this),"keydown.timepicker":e.proxy(this.elementKeydown,this),"blur.timepicker":e.proxy(this.blurElement,this)})}else{if(this.template){this.$element.on({"focus.timepicker":e.proxy(this.showWidget,this),"click.timepicker":e.proxy(this.showWidget,this),"blur.timepicker":e.proxy(this.blurElement,this)})}else{this.$element.on({"focus.timepicker":e.proxy(this.highlightUnit,this),"click.timepicker":e.proxy(this.highlightUnit,this),"keydown.timepicker":e.proxy(this.elementKeydown,this),"blur.timepicker":e.proxy(this.blurElement,this)})}}if(this.template!==false){this.$widget=e(this.getTemplate()).prependTo(this.$element.parents(this.appendWidgetTo)).on("click",e.proxy(this.widgetClick,this))}else{this.$widget=false}if(this.showInputs&&this.$widget!==false){this.$widget.find("input").each(function(){e(this).on({"click.timepicker":function(){e(this).select()},"keydown.timepicker":e.proxy(t.widgetKeydown,t)})})}this.setDefaultTime(this.defaultTime)},blurElement:function(){this.highlightedUnit=r;this.updateFromElementVal()},decrementHour:function(){if(this.showMeridian){if(this.hour===1){this.hour=12}else if(this.hour===12){this.hour--;return this.toggleMeridian()}else if(this.hour===0){this.hour=11;return this.toggleMeridian()}else{this.hour--}}else{if(this.hour===0){this.hour=23}else{this.hour--}}this.update()},decrementMinute:function(e){var t;if(e){t=this.minute-e}else{t=this.minute-this.minuteStep}if(t<0){this.decrementHour();this.minute=t+60}else{this.minute=t}this.update()},decrementSecond:function(){var e=this.second-this.secondStep;if(e<0){this.decrementMinute(true);this.second=e+60}else{this.second=e}this.update()},elementKeydown:function(e){switch(e.keyCode){case 9:this.updateFromElementVal();switch(this.highlightedUnit){case"hour":e.preventDefault();this.highlightNextUnit();break;case"minute":if(this.showMeridian||this.showSeconds){e.preventDefault();this.highlightNextUnit()}break;case"second":if(this.showMeridian){e.preventDefault();this.highlightNextUnit()}break}break;case 27:this.updateFromElementVal();break;case 37:e.preventDefault();this.highlightPrevUnit();this.updateFromElementVal();break;case 38:e.preventDefault();switch(this.highlightedUnit){case"hour":this.incrementHour();this.highlightHour();break;case"minute":this.incrementMinute();this.highlightMinute();break;case"second":this.incrementSecond();this.highlightSecond();break;case"meridian":this.toggleMeridian();this.highlightMeridian();break}break;case 39:e.preventDefault();this.updateFromElementVal();this.highlightNextUnit();break;case 40:e.preventDefault();switch(this.highlightedUnit){case"hour":this.decrementHour();this.highlightHour();break;case"minute":this.decrementMinute();this.highlightMinute();break;case"second":this.decrementSecond();this.highlightSecond();break;case"meridian":this.toggleMeridian();this.highlightMeridian();break}break}},formatTime:function(e,t,n,r){e=e<10?"0"+e:e;t=t<10?"0"+t:t;n=n<10?"0"+n:n;return e+":"+t+(this.showSeconds?":"+n:"")+(this.showMeridian?" "+r:"")},getCursorPosition:function(){var e=this.$element.get(0);if("selectionStart"in e){return e.selectionStart}else if(n.selection){e.focus();var t=n.selection.createRange(),r=n.selection.createRange().text.length;t.moveStart("character",-e.value.length);return t.text.length-r}},getTemplate:function(){var e,t,n,r,i,s;if(this.showInputs){t='<input type="text" name="hour" class="bootstrap-timepicker-hour" maxlength="2"/>';n='<input type="text" name="minute" class="bootstrap-timepicker-minute" maxlength="2"/>';r='<input type="text" name="second" class="bootstrap-timepicker-second" maxlength="2"/>';i='<input type="text" name="meridian" class="bootstrap-timepicker-meridian" maxlength="2"/>'}else{t='<span class="bootstrap-timepicker-hour"></span>';n='<span class="bootstrap-timepicker-minute"></span>';r='<span class="bootstrap-timepicker-second"></span>';i='<span class="bootstrap-timepicker-meridian"></span>'}s="<table>"+"<tr>"+'<td><a href="#" data-action="incrementHour"><i class="icon-chevron-up"></i></a></td>'+'<td class="separator"> </td>'+'<td><a href="#" data-action="incrementMinute"><i class="icon-chevron-up"></i></a></td>'+(this.showSeconds?'<td class="separator"> </td>'+'<td><a href="#" data-action="incrementSecond"><i class="icon-chevron-up"></i></a></td>':"")+(this.showMeridian?'<td class="separator"> </td>'+'<td class="meridian-column"><a href="#" data-action="toggleMeridian"><i class="icon-chevron-up"></i></a></td>':"")+"</tr>"+"<tr>"+"<td>"+t+"</td> "+'<td class="separator">:</td>'+"<td>"+n+"</td> "+(this.showSeconds?'<td class="separator">:</td>'+"<td>"+r+"</td>":"")+(this.showMeridian?'<td class="separator"> </td>'+"<td>"+i+"</td>":"")+"</tr>"+"<tr>"+'<td><a href="#" data-action="decrementHour"><i class="icon-chevron-down"></i></a></td>'+'<td class="separator"></td>'+'<td><a href="#" data-action="decrementMinute"><i class="icon-chevron-down"></i></a></td>'+(this.showSeconds?'<td class="separator"> </td>'+'<td><a href="#" data-action="decrementSecond"><i class="icon-chevron-down"></i></a></td>':"")+(this.showMeridian?'<td class="separator"> </td>'+'<td><a href="#" data-action="toggleMeridian"><i class="icon-chevron-down"></i></a></td>':"")+"</tr>"+"</table>";switch(this.template){case"modal":e='<div class="bootstrap-timepicker-widget modal hide fade in" data-backdrop="'+(this.modalBackdrop?"true":"false")+'">'+'<div class="modal-header">'+'<a href="#" class="close" data-dismiss="modal">×</a>'+"<h3>Pick a Time</h3>"+"</div>"+'<div class="modal-content">'+s+"</div>"+'<div class="modal-footer">'+'<a href="#" class="btn btn-primary" data-dismiss="modal">OK</a>'+"</div>"+"</div>";break;case"dropdown":e='<div class="bootstrap-timepicker-widget dropdown-menu">'+s+"</div>";break}return e},getTime:function(){return this.formatTime(this.hour,this.minute,this.second,this.meridian)},hideWidget:function(){if(this.isOpen===false){return}if(this.showInputs){this.updateFromWidgetInputs()}this.$element.trigger({type:"hide.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}});if(this.template==="modal"&&this.$widget.modal){this.$widget.modal("hide")}else{this.$widget.removeClass("open")}e(n).off("mousedown.timepicker");this.isOpen=false},highlightUnit:function(){this.position=this.getCursorPosition();if(this.position>=0&&this.position<=2){this.highlightHour()}else if(this.position>=3&&this.position<=5){this.highlightMinute()}else if(this.position>=6&&this.position<=8){if(this.showSeconds){this.highlightSecond()}else{this.highlightMeridian()}}else if(this.position>=9&&this.position<=11){this.highlightMeridian()}},highlightNextUnit:function(){switch(this.highlightedUnit){case"hour":this.highlightMinute();break;case"minute":if(this.showSeconds){this.highlightSecond()}else if(this.showMeridian){this.highlightMeridian()}else{this.highlightHour()}break;case"second":if(this.showMeridian){this.highlightMeridian()}else{this.highlightHour()}break;case"meridian":this.highlightHour();break}},highlightPrevUnit:function(){switch(this.highlightedUnit){case"hour":this.highlightMeridian();break;case"minute":this.highlightHour();break;case"second":this.highlightMinute();break;case"meridian":if(this.showSeconds){this.highlightSecond()}else{this.highlightMinute()}break}},highlightHour:function(){var e=this.$element.get(0);this.highlightedUnit="hour";if(e.setSelectionRange){setTimeout(function(){e.setSelectionRange(0,2)},0)}},highlightMinute:function(){var e=this.$element.get(0);this.highlightedUnit="minute";if(e.setSelectionRange){setTimeout(function(){e.setSelectionRange(3,5)},0)}},highlightSecond:function(){var e=this.$element.get(0);this.highlightedUnit="second";if(e.setSelectionRange){setTimeout(function(){e.setSelectionRange(6,8)},0)}},highlightMeridian:function(){var e=this.$element.get(0);this.highlightedUnit="meridian";if(e.setSelectionRange){if(this.showSeconds){setTimeout(function(){e.setSelectionRange(9,11)},0)}else{setTimeout(function(){e.setSelectionRange(6,8)},0)}}},incrementHour:function(){if(this.showMeridian){if(this.hour===11){this.hour++;return this.toggleMeridian()}else if(this.hour===12){this.hour=0}}if(this.hour===23){this.hour=0;return}this.hour++;this.update()},incrementMinute:function(e){var t;if(e){t=this.minute+e}else{t=this.minute+this.minuteStep-this.minute%this.minuteStep}if(t>59){this.incrementHour();this.minute=t-60}else{this.minute=t}this.update()},incrementSecond:function(){var e=this.second+this.secondStep-this.second%this.secondStep;if(e>59){this.incrementMinute(true);this.second=e-60}else{this.second=e}this.update()},remove:function(){e("document").off(".timepicker");if(this.$widget){this.$widget.remove()}delete this.$element.data().timepicker},setDefaultTime:function(e){if(!this.$element.val()){if(e==="current"){var t=new Date,n=t.getHours(),r=Math.floor(t.getMinutes()/this.minuteStep)*this.minuteStep,i=Math.floor(t.getSeconds()/this.secondStep)*this.secondStep,s="AM";if(this.showMeridian){if(n===0){n=12}else if(n>=12){if(n>12){n=n-12}s="PM"}else{s="AM"}}this.hour=n;this.minute=r;this.second=i;this.meridian=s;this.update()}else if(e===false){this.hour=0;this.minute=0;this.second=0;this.meridian="AM"}else{this.setTime(e)}}else{this.updateFromElementVal()}},setTime:function(e){var t,n;if(typeof e==="object"&&e.getMonth){this.hour=e.getHours();this.minute=e.getMinutes();this.second=e.getSeconds();if(this.showMeridian){this.meridian="AM";if(this.hour>12){this.meridian="PM";this.hour=this.hour%12}if(this.hour===12){this.meridian="PM"}}}else{if(this.showMeridian){t=e.split(" ");n=t[0].split(":");this.meridian=t[1]}else{n=e.split(":")}this.hour=parseInt(n[0],10);this.minute=parseInt(n[1],10);this.second=parseInt(n[2],10);if(isNaN(this.hour)){this.hour=0}if(isNaN(this.minute)){this.minute=0}if(this.showMeridian){if(this.hour>12){this.hour=12}else if(this.hour<1){this.hour=12}if(this.meridian==="am"||this.meridian==="a"){this.meridian="AM"}else if(this.meridian==="pm"||this.meridian==="p"){this.meridian="PM"}if(this.meridian!=="AM"&&this.meridian!=="PM"){this.meridian="AM"}}else{if(this.hour>=24){this.hour=23}else if(this.hour<0){this.hour=0}}if(this.minute<0){this.minute=0}else if(this.minute>=60){this.minute=59}if(this.showSeconds){if(isNaN(this.second)){this.second=0}else if(this.second<0){this.second=0}else if(this.second>=60){this.second=59}}}this.update()},showWidget:function(){if(this.isOpen){return}if(this.$element.is(":disabled")){return}var t=this;e(n).on("mousedown.timepicker",function(n){if(e(n.target).closest(".bootstrap-timepicker-widget").length===0){t.hideWidget()}});this.$element.trigger({type:"show.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}});if(this.disableFocus){this.$element.blur()}this.updateFromElementVal();if(this.template==="modal"&&this.$widget.modal){this.$widget.modal("show").on("hidden",e.proxy(this.hideWidget,this))}else{if(this.isOpen===false){this.$widget.addClass("open")}}this.isOpen=true},toggleMeridian:function(){this.meridian=this.meridian==="AM"?"PM":"AM";this.update()},update:function(){this.$element.trigger({type:"changeTime.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}});this.updateElement();this.updateWidget()},updateElement:function(){this.$element.val(this.getTime()).change()},updateFromElementVal:function(){var e=this.$element.val();if(e){this.setTime(e)}},updateWidget:function(){if(this.$widget===false){return}var e=this.hour<10?"0"+this.hour:this.hour,t=this.minute<10?"0"+this.minute:this.minute,n=this.second<10?"0"+this.second:this.second;if(this.showInputs){this.$widget.find("input.bootstrap-timepicker-hour").val(e);this.$widget.find("input.bootstrap-timepicker-minute").val(t);if(this.showSeconds){this.$widget.find("input.bootstrap-timepicker-second").val(n)}if(this.showMeridian){this.$widget.find("input.bootstrap-timepicker-meridian").val(this.meridian)}}else{this.$widget.find("span.bootstrap-timepicker-hour").text(e);this.$widget.find("span.bootstrap-timepicker-minute").text(t);if(this.showSeconds){this.$widget.find("span.bootstrap-timepicker-second").text(n)}if(this.showMeridian){this.$widget.find("span.bootstrap-timepicker-meridian").text(this.meridian)}}},updateFromWidgetInputs:function(){if(this.$widget===false){return}var t=e("input.bootstrap-timepicker-hour",this.$widget).val()+":"+e("input.bootstrap-timepicker-minute",this.$widget).val()+(this.showSeconds?":"+e("input.bootstrap-timepicker-second",this.$widget).val():"")+(this.showMeridian?" "+e("input.bootstrap-timepicker-meridian",this.$widget).val():"");this.setTime(t)},widgetClick:function(t){t.stopPropagation();t.preventDefault();var n=e(t.target).closest("a").data("action");if(n){this[n]()}},widgetKeydown:function(t){var n=e(t.target).closest("input"),r=n.attr("name");switch(t.keyCode){case 9:if(this.showMeridian){if(r==="meridian"){return this.hideWidget()}}else{if(this.showSeconds){if(r==="second"){return this.hideWidget()}}else{if(r==="minute"){return this.hideWidget()}}}this.updateFromWidgetInputs();break;case 27:this.hideWidget();break;case 38:t.preventDefault();switch(r){case"hour":this.incrementHour();break;case"minute":this.incrementMinute();break;case"second":this.incrementSecond();break;case"meridian":this.toggleMeridian();break}break;case 40:t.preventDefault();switch(r){case"hour":this.decrementHour();break;case"minute":this.decrementMinute();break;case"second":this.decrementSecond();break;case"meridian":this.toggleMeridian();break}break}}};e.fn.timepicker=function(t){var n=Array.apply(null,arguments);n.shift();return this.each(function(){var r=e(this),s=r.data("timepicker"),o=typeof t==="object"&&t;if(!s){r.data("timepicker",s=new i(this,e.extend({},e.fn.timepicker.defaults,o,e(this).data())))}if(typeof t==="string"){s[t].apply(s,n)}})};e.fn.timepicker.defaults={defaultTime:"current",disableFocus:false,isOpen:false,minuteStep:15,modalBackdrop:false,secondStep:15,showSeconds:false,showInputs:true,showMeridian:true,template:"dropdown",appendWidgetTo:".bootstrap-timepicker"};e.fn.timepicker.Constructor=i})(jQuery,window,document)
->>>>>>> 838c86829f90b851fb36c4d2fcbeb4a318d72263
+*/!function(a,b,c){"use strict";var d=function(b,c){this.widget="",this.$element=a(b),this.defaultTime=c.defaultTime,this.disableFocus=c.disableFocus,this.disableMousewheel=c.disableMousewheel,this.isOpen=c.isOpen,this.minuteStep=c.minuteStep,this.modalBackdrop=c.modalBackdrop,this.secondStep=c.secondStep,this.showInputs=c.showInputs,this.showMeridian=c.showMeridian,this.showSeconds=c.showSeconds,this.template=c.template,this.appendWidgetTo=c.appendWidgetTo,this._init()};d.prototype={constructor:d,_init:function(){var b=this;this.$element.parent().hasClass("input-append")||this.$element.parent().hasClass("input-prepend")?(this.$element.parent(".input-append, .input-prepend").find(".add-on").on({"click.timepicker":a.proxy(this.showWidget,this)}),this.$element.on({"focus.timepicker":a.proxy(this.highlightUnit,this),"click.timepicker":a.proxy(this.highlightUnit,this),"keydown.timepicker":a.proxy(this.elementKeydown,this),"blur.timepicker":a.proxy(this.blurElement,this),"mousewheel.timepicker DOMMouseScroll.timepicker":a.proxy(this.mousewheel,this)})):this.template?this.$element.on({"focus.timepicker":a.proxy(this.showWidget,this),"click.timepicker":a.proxy(this.showWidget,this),"blur.timepicker":a.proxy(this.blurElement,this),"mousewheel.timepicker DOMMouseScroll.timepicker":a.proxy(this.mousewheel,this)}):this.$element.on({"focus.timepicker":a.proxy(this.highlightUnit,this),"click.timepicker":a.proxy(this.highlightUnit,this),"keydown.timepicker":a.proxy(this.elementKeydown,this),"blur.timepicker":a.proxy(this.blurElement,this),"mousewheel.timepicker DOMMouseScroll.timepicker":a.proxy(this.mousewheel,this)}),this.$widget=this.template!==!1?a(this.getTemplate()).prependTo(this.$element.parents(this.appendWidgetTo)).on("click",a.proxy(this.widgetClick,this)):!1,this.showInputs&&this.$widget!==!1&&this.$widget.find("input").each(function(){a(this).on({"click.timepicker":function(){a(this).select()},"keydown.timepicker":a.proxy(b.widgetKeydown,b)})}),this.setDefaultTime(this.defaultTime)},blurElement:function(){this.highlightedUnit=null,this.updateFromElementVal()},clear:function(){this.hour=null,this.minute=null,this.second=null,this.meridian=null,this.$element.val("")},decrementHour:function(){if(this.showMeridian)if(1===this.hour)this.hour=12;else{if(12===this.hour)return this.hour--,this.toggleMeridian();if(0===this.hour)return this.hour=11,this.toggleMeridian();this.hour--}else 0===this.hour?this.hour=23:this.hour--;this.update()},decrementMinute:function(a){var b;b=a?this.minute-a:this.minute-this.minuteStep,0>b?(this.decrementHour(),this.minute=b+60):this.minute=b,this.update()},decrementSecond:function(){var a=this.second-this.secondStep;0>a?(this.decrementMinute(!0),this.second=a+60):this.second=a,this.update()},elementKeydown:function(a){switch(a.keyCode){case 9:case 27:this.updateFromElementVal();break;case 37:a.preventDefault(),this.highlightPrevUnit(),this.updateFromElementVal();break;case 38:switch(a.preventDefault(),this.highlightedUnit){case"hour":this.incrementHour(),this.highlightHour();break;case"minute":this.incrementMinute(),this.highlightMinute();break;case"second":this.incrementSecond(),this.highlightSecond();break;case"meridian":this.toggleMeridian(),this.highlightMeridian()}break;case 39:a.preventDefault(),this.updateFromElementVal(),this.highlightNextUnit();break;case 40:switch(a.preventDefault(),this.highlightedUnit){case"hour":this.decrementHour(),this.highlightHour();break;case"minute":this.decrementMinute(),this.highlightMinute();break;case"second":this.decrementSecond(),this.highlightSecond();break;case"meridian":this.toggleMeridian(),this.highlightMeridian()}}},formatTime:function(a,b,c,d){return a=null!==a?10>a&&this.showMeridian===!1?"0"+a:a:"",b=null!==b?10>b?"0"+b:b:"",c=null!==c?10>c?"0"+c:c:"",a+(""!==a?":":"")+b+(this.showSeconds&&""!==c?":"+c:"")+(this.showMeridian&&null!==d?" "+d:"")},getCursorPosition:function(){var a=this.$element.get(0);if("selectionStart"in a)return a.selectionStart;if(c.selection){a.focus();var b=c.selection.createRange(),d=c.selection.createRange().text.length;return b.moveStart("character",-a.value.length),b.text.length-d}},getTemplate:function(){var a,b,c,d,e,f;switch(this.showInputs?(b='<input type="text" name="timepicker_hour" class="bootstrap-timepicker-hour" maxlength="2"/>',c='<input type="text" name="timepicker_minute" class="bootstrap-timepicker-minute" maxlength="2"/>',d='<input type="text" name="timepicker_second" class="bootstrap-timepicker-second" maxlength="2"/>',e='<input type="text" name="timepicker_meridian" class="bootstrap-timepicker-meridian" maxlength="2"/>'):(b='<span class="bootstrap-timepicker-hour"></span>',c='<span class="bootstrap-timepicker-minute"></span>',d='<span class="bootstrap-timepicker-second"></span>',e='<span class="bootstrap-timepicker-meridian"></span>'),f='<table><tr><td><a href="#" data-action="incrementHour"><i class="icon-chevron-up"></i></a></td><td class="separator">&nbsp;</td><td><a href="#" data-action="incrementMinute"><i class="icon-chevron-up"></i></a></td>'+(this.showSeconds?'<td class="separator">&nbsp;</td><td><a href="#" data-action="incrementSecond"><i class="icon-chevron-up"></i></a></td>':"")+(this.showMeridian?'<td class="separator">&nbsp;</td><td class="meridian-column"><a href="#" data-action="toggleMeridian"><i class="icon-chevron-up"></i></a></td>':"")+"</tr>"+"<tr>"+"<td>"+b+"</td> "+'<td class="separator">:</td>'+"<td>"+c+"</td> "+(this.showSeconds?'<td class="separator">:</td><td>'+d+"</td>":"")+(this.showMeridian?'<td class="separator">&nbsp;</td><td>'+e+"</td>":"")+"</tr>"+"<tr>"+'<td><a href="#" data-action="decrementHour"><i class="icon-chevron-down"></i></a></td>'+'<td class="separator"></td>'+'<td><a href="#" data-action="decrementMinute"><i class="icon-chevron-down"></i></a></td>'+(this.showSeconds?'<td class="separator">&nbsp;</td><td><a href="#" data-action="decrementSecond"><i class="icon-chevron-down"></i></a></td>':"")+(this.showMeridian?'<td class="separator">&nbsp;</td><td><a href="#" data-action="toggleMeridian"><i class="icon-chevron-down"></i></a></td>':"")+"</tr>"+"</table>",this.template){case"modal":a='<div class="bootstrap-timepicker-widget modal hide fade in" data-backdrop="'+(this.modalBackdrop?"true":"false")+'">'+'<div class="modal-header">'+'<a href="#" class="close" data-dismiss="modal">×</a>'+"<h3>Pick a Time</h3>"+"</div>"+'<div class="modal-content">'+f+"</div>"+'<div class="modal-footer">'+'<a href="#" class="btn btn-primary" data-dismiss="modal">OK</a>'+"</div>"+"</div>";break;case"dropdown":a='<div class="bootstrap-timepicker-widget dropdown-menu">'+f+"</div>"}return a},getTime:function(){return this.formatTime(this.hour,this.minute,this.second,this.meridian)},hideWidget:function(){this.isOpen!==!1&&(this.showInputs&&this.updateFromWidgetInputs(),this.$element.trigger({type:"hide.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),"modal"===this.template&&this.$widget.modal?this.$widget.modal("hide"):this.$widget.removeClass("open"),a(c).off("mousedown.timepicker, touchend.timepicker"),this.isOpen=!1)},highlightUnit:function(){this.position=this.getCursorPosition(),this.position>=0&&this.position<=2?this.highlightHour():this.position>=3&&this.position<=5?this.highlightMinute():this.position>=6&&this.position<=8?this.showSeconds?this.highlightSecond():this.highlightMeridian():this.position>=9&&this.position<=11&&this.highlightMeridian()},highlightNextUnit:function(){switch(this.highlightedUnit){case"hour":this.highlightMinute();break;case"minute":this.showSeconds?this.highlightSecond():this.showMeridian?this.highlightMeridian():this.highlightHour();break;case"second":this.showMeridian?this.highlightMeridian():this.highlightHour();break;case"meridian":this.highlightHour()}},highlightPrevUnit:function(){switch(this.highlightedUnit){case"hour":this.showMeridian?this.highlightMeridian():this.showSeconds?this.highlightSecond():this.highlightMinute();break;case"minute":this.highlightHour();break;case"second":this.highlightMinute();break;case"meridian":this.showSeconds?this.highlightSecond():this.highlightMinute()}},highlightHour:function(){var a=this.$element.get(0);this.highlightedUnit="hour",a.setSelectionRange&&setTimeout(function(){a.setSelectionRange(0,2)},0)},highlightMinute:function(){var a=this.$element.get(0);this.highlightedUnit="minute",a.setSelectionRange&&setTimeout(function(){a.setSelectionRange(3,5)},0)},highlightSecond:function(){var a=this.$element.get(0);this.highlightedUnit="second",a.setSelectionRange&&setTimeout(function(){a.setSelectionRange(6,8)},0)},highlightMeridian:function(){var a=this.$element.get(0);this.highlightedUnit="meridian",a.setSelectionRange&&(this.showSeconds?setTimeout(function(){a.setSelectionRange(9,11)},0):setTimeout(function(){a.setSelectionRange(6,8)},0))},incrementHour:function(){if(this.showMeridian){if(11===this.hour)return this.hour++,this.toggleMeridian();12===this.hour&&(this.hour=0)}return 23===this.hour?(this.hour=0,void 0):(this.hour++,this.update(),void 0)},incrementMinute:function(a){var b;b=a?this.minute+a:this.minute+this.minuteStep-this.minute%this.minuteStep,b>59?(this.incrementHour(),this.minute=b-60):(this.minute=b,this.update())},incrementSecond:function(){var a=this.second+this.secondStep-this.second%this.secondStep;a>59?(this.incrementMinute(!0),this.second=a-60):this.second=a,this.update()},mousewheel:function(b){if(!this.disableMousewheel){b.preventDefault(),b.stopPropagation();var c=b.originalEvent.wheelDelta||-b.originalEvent.detail,d=null;switch("mousewheel"===b.type?d=-1*b.originalEvent.wheelDelta:"DOMMouseScroll"===b.type&&(d=40*b.originalEvent.detail),d&&(b.preventDefault(),a(this).scrollTop(d+a(this).scrollTop())),this.highlightedUnit){case"minute":c>0?this.incrementMinute():this.decrementMinute(),this.highlightMinute();break;case"second":c>0?this.incrementSecond():this.decrementSecond(),this.highlightSecond();break;case"meridian":this.toggleMeridian(),this.highlightMeridian();break;default:c>0?this.incrementHour():this.decrementHour(),this.highlightHour()}return!1}},remove:function(){a("document").off(".timepicker"),this.$widget&&this.$widget.remove(),delete this.$element.data().timepicker},setDefaultTime:function(a){if(this.$element.val())this.updateFromElementVal();else if("current"===a){var b=new Date,c=b.getHours(),d=b.getMinutes(),e=b.getSeconds(),f="AM";0!==e&&(e=Math.ceil(b.getSeconds()/this.secondStep)*this.secondStep,60===e&&(d+=1,e=0)),0!==d&&(d=Math.ceil(b.getMinutes()/this.minuteStep)*this.minuteStep,60===d&&(c+=1,d=0)),this.showMeridian&&(0===c?c=12:c>=12?(c>12&&(c-=12),f="PM"):f="AM"),this.hour=c,this.minute=d,this.second=e,this.meridian=f,this.update()}else a===!1?(this.hour=0,this.minute=0,this.second=0,this.meridian="AM"):this.setTime(a)},setTime:function(a){if(!a)return this.clear(),void 0;if("object"==typeof a&&a.getMonth)this.hour=a.getHours(),this.minute=a.getMinutes(),this.second=a.getSeconds(),this.showMeridian&&(this.meridian="AM",this.hour>12&&(this.meridian="PM",this.hour=this.hour%12),12===this.hour&&(this.meridian="PM"));else{var b,c,d,e=0;this.meridian=null!==a.match(/p/i)?"PM":"AM",a=a.replace(/[^0-9\:]/g,""),b=a.split(":"),c=b[0]?b[0].toString():b.toString(),d=b[1]?b[1].toString():"",e=b[2]?b[2].toString():"",c.length>4&&(e=c.substr(4,2)),c.length>2&&(d=c.substr(2,2),c=c.substr(0,2)),d.length>2&&(e=d.substr(2,2),d=d.substr(0,2)),e.length>2&&(e=e.substr(2,2)),this.hour=parseInt(c,10),this.minute=parseInt(d,10),this.second=parseInt(e,10),this.showMeridian?(this.hour<1||this.hour>12)&&(this.hour=12):(this.hour>=24?this.hour=23:this.hour<0&&(this.hour=0),this.hour<13&&"PM"===this.meridian&&(this.hour=this.hour+12)),!this.minute||this.minute<0?this.minute=0:this.minute>=60&&(this.minute=59),this.showSeconds&&(isNaN(this.second)?this.second=0:this.second<0?this.second=0:this.second>=60&&(this.second=59))}this.update()},showWidget:function(){if(!this.isOpen&&!this.$element.is(":disabled")){var b=this;a(c).on("mousedown.timepicker, touchend.timepicker",function(c){0===a(c.target).closest(".bootstrap-timepicker-widget").length&&b.hideWidget()}),this.$element.trigger({type:"show.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),this.disableFocus&&this.$element.blur(),this.updateFromElementVal(),"modal"===this.template&&this.$widget.modal?this.$widget.modal("show").on("hidden",a.proxy(this.hideWidget,this)):this.isOpen===!1&&this.$widget.addClass("open"),this.isOpen=!0}},toggleMeridian:function(){this.meridian="AM"===this.meridian?"PM":"AM",this.update()},update:function(){this.$element.trigger({type:"changeTime.timepicker",time:{value:this.getTime(),hours:this.hour,minutes:this.minute,seconds:this.second,meridian:this.meridian}}),this.updateElement(),this.updateWidget()},updateElement:function(){this.$element.val(this.getTime()).change()},updateFromElementVal:function(){this.setTime(this.$element.val())},updateWidget:function(){if(this.$widget!==!1){var a=this.hour<10?"0"+this.hour:this.hour,b=this.minute<10?"0"+this.minute:this.minute,c=this.second<10?"0"+this.second:this.second;this.showInputs?(this.$widget.find("input.bootstrap-timepicker-hour").val(a),this.$widget.find("input.bootstrap-timepicker-minute").val(b),this.showSeconds&&this.$widget.find("input.bootstrap-timepicker-second").val(c),this.showMeridian&&this.$widget.find("input.bootstrap-timepicker-meridian").val(this.meridian)):(this.$widget.find("span.bootstrap-timepicker-hour").text(a),this.$widget.find("span.bootstrap-timepicker-minute").text(b),this.showSeconds&&this.$widget.find("span.bootstrap-timepicker-second").text(c),this.showMeridian&&this.$widget.find("span.bootstrap-timepicker-meridian").text(this.meridian))}},updateFromWidgetInputs:function(){if(this.$widget!==!1){var b=a("input.bootstrap-timepicker-hour",this.$widget).val()+":"+a("input.bootstrap-timepicker-minute",this.$widget).val()+(this.showSeconds?":"+a("input.bootstrap-timepicker-second",this.$widget).val():"")+(this.showMeridian?" "+a("input.bootstrap-timepicker-meridian",this.$widget).val():"");this.setTime(b)}},widgetClick:function(b){b.stopPropagation(),b.preventDefault();var c=a(b.target).closest("a").data("action");c&&this[c]()},widgetKeydown:function(b){var c=a(b.target).closest("input"),d=c.attr("name");switch(b.keyCode){case 9:if(this.showMeridian){if("meridian"===d)return this.hideWidget()}else if(this.showSeconds){if("second"===d)return this.hideWidget()}else if("minute"===d)return this.hideWidget();this.updateFromWidgetInputs();break;case 27:this.hideWidget();break;case 38:switch(b.preventDefault(),d){case"hour":this.incrementHour();break;case"minute":this.incrementMinute();break;case"second":this.incrementSecond();break;case"meridian":this.toggleMeridian()}break;case 40:switch(b.preventDefault(),d){case"hour":this.decrementHour();break;case"minute":this.decrementMinute();break;case"second":this.decrementSecond();break;case"meridian":this.toggleMeridian()}}}},a.fn.timepicker=function(b){var c=Array.apply(null,arguments);return c.shift(),this.each(function(){var e=a(this),f=e.data("timepicker"),g="object"==typeof b&&b;f||e.data("timepicker",f=new d(this,a.extend({},a.fn.timepicker.defaults,g,a(this).data()))),"string"==typeof b&&f[b].apply(f,c)})},a.fn.timepicker.defaults={defaultTime:"current",disableFocus:!1,disableMousewheel:!1,isOpen:!1,minuteStep:15,modalBackdrop:!1,secondStep:15,showSeconds:!1,showInputs:!0,showMeridian:!0,template:"dropdown",appendWidgetTo:".bootstrap-timepicker"},a.fn.timepicker.Constructor=d}(jQuery,window,document);
View
33 spec/js/KeyboardEventsSpec.js
@@ -53,7 +53,7 @@ describe('Keyboard events feature', function() {
$input1.autotype('{{back}}{{back}}{{back}}{{back}}{{back}}{{back}}{{back}}{{back}}9:45a{{tab}}');
expect(tp1.highlightedUnit).not.toBe('minute');
- expect(tp1.getTime()).toBe('09:45 AM');
+ expect(tp1.getTime()).toBe('9:45 AM');
expect($input1.is(':focus')).toBe(false);
});
@@ -223,7 +223,7 @@ describe('Keyboard events feature', function() {
'keyCode': 9 //tab
});
- expect(tp2.getTime()).toBe('02:30:00 AM');
+ expect(tp2.getTime()).toBe('2:30:00 AM');
$minuteInput.autotype('{{back}}{{back}}0');
@@ -232,7 +232,7 @@ describe('Keyboard events feature', function() {
'keyCode': 9 //tab
});
- expect(tp2.getTime()).toBe('02:00:00 AM');
+ expect(tp2.getTime()).toBe('2:00:00 AM');
$secondInput.autotype('{{back}}{{back}}30');
$secondInput.trigger({
@@ -240,7 +240,7 @@ describe('Keyboard events feature', function() {
'keyCode': 9 //tab
});
- expect(tp2.getTime()).toBe('02:00:30 AM');
+ expect(tp2.getTime()).toBe('2:00:30 AM');
$meridianInput.autotype('{{back}}{{back}}p');
$meridianInput.trigger({
@@ -248,7 +248,7 @@ describe('Keyboard events feature', function() {
'keyCode': 9 //tab
});
- expect(tp2.getTime()).toBe('02:00:30 PM');
+ expect(tp2.getTime()).toBe('2:00:30 PM');
});
it('should be 12:00 AM if 00:00 AM is entered', function() {
@@ -270,24 +270,19 @@ describe('Keyboard events feature', function() {
tp1.setTime('11:30 AM');
tp1.update();
- $hourInput.autotype('{{back}}{{back}}13');
- tp1.updateFromWidgetInputs();
- expect(tp1.getTime()).toBe('12:30 AM');
+ $hourInput.autotype('{{back}}{{back}}10{{tab}}');
+ expect(tp1.getTime()).toBe('10:30 AM');
- $minuteInput.autotype('{{back}}{{back}}60');
- tp1.updateFromWidgetInputs();
- expect(tp1.getTime()).toBe('12:59 AM');
+ $minuteInput.autotype('{{back}}{{back}}60{{tab}}');
+ expect(tp1.getTime()).toBe('10:59 AM');
- $meridianInput.autotype('{{back}}{{back}}dk');
- tp1.updateFromWidgetInputs();
- expect(tp1.getTime()).toBe('12:59 AM');
+ $meridianInput.autotype('{{back}}{{back}}dk{{tab}}');
+ expect(tp1.getTime()).toBe('10:59 AM');
- $meridianInput.autotype('{{back}}{{back}}p');
- tp1.updateFromWidgetInputs();
- expect(tp1.getTime()).toBe('12:59 PM');
+ $meridianInput.autotype('{{back}}{{back}}p{{tab}}');
+ expect(tp1.getTime()).toBe('10:59 PM');
- $input3.autotype('{{back}}{{back}}{{back}}{{back}}{{back}}{{back}}{{back}}{{back}}25:60:60');
- tp3.updateFromElementVal();
+ $input3.autotype('{{back}}{{back}}{{back}}{{back}}{{back}}{{back}}{{back}}{{back}}25:60:60{{tab}}');
expect(tp3.getTime()).toBe('23:59:59');
});
});
View
8 spec/js/MouseEventsSpec.js
@@ -112,7 +112,7 @@ describe('Mouse events feature', function() {
expect(count).toBe(1);
tp2.$widget.find('a[data-action="incrementHour"]').trigger('click');
- expect(tp2.getTime()).toBe('01:00:00 AM');
+ expect(tp2.getTime()).toBe('1:00:00 AM');
});
it('should decrement hour on button click and fire 1 changeTime event', function() {
@@ -132,7 +132,7 @@ describe('Mouse events feature', function() {
tp2.$widget.find('a[data-action="incrementHour"]').trigger('click');
tp2.$widget.find('a[data-action="incrementHour"]').trigger('click');
tp2.$widget.find('a[data-action="decrementHour"]').trigger('click');
- expect(tp2.getTime()).toBe('01:00:00 AM');
+ expect(tp2.getTime()).toBe('1:00:00 AM');
});
it('should increment minute on button click and fire 1 changeTime event', function() {
@@ -150,7 +150,7 @@ describe('Mouse events feature', function() {
expect(tp1.getTime()).toBe('11:45 AM');
tp2.$widget.find('a[data-action="incrementMinute"]').trigger('click');
- expect(tp2.getTime()).toBe('00:30:00 AM');
+ expect(tp2.getTime()).toBe('0:30:00 AM');
expect(count).toBe(1);
@@ -187,7 +187,7 @@ describe('Mouse events feature', function() {
tp1.$widget.find('a[data-action="incrementHour"]').trigger('click');
tp1.$widget.find('a[data-action="incrementHour"]').trigger('click');
- expect(tp1.getTime()).toBe('01:00 PM');
+ expect(tp1.getTime()).toBe('1:00 PM');
expect(count).toBe(2);
});
View
61 spec/js/TimepickerSpec.js
@@ -147,13 +147,13 @@ describe('Timepicker feature', function() {
});
it('should update the element and widget with the setTime method', function() {
- tp2.setTime('09:15:20 AM');
+ tp2.setTime('9:15:20 AM');
expect(tp2.hour).toBe(9);
expect(tp2.minute).toBe(15);
expect(tp2.second).toBe(20);
expect(tp2.meridian).toBe('AM');
- expect($input2.val()).toBe('09:15:20 AM');
+ expect($input2.val()).toBe('9:15:20 AM');
expect(tp2.$widget.find('.bootstrap-timepicker-hour').val()).toBe('09');
expect(tp2.$widget.find('.bootstrap-timepicker-minute').val()).toBe('15');
expect(tp2.$widget.find('.bootstrap-timepicker-second').val()).toBe('20');
@@ -161,12 +161,65 @@ describe('Timepicker feature', function() {
});
it('should be able to format time values into a string', function() {
- expect(tp2.formatTime(3, 15, 45, 'PM')).toBe('03:15:45 PM');
+ expect(tp2.formatTime(3, 15, 45, 'PM')).toBe('3:15:45 PM');
});
it('should be able get & set the pickers time', function() {
+ tp1.setTime('11:15 PM');
+ expect(tp1.getTime()).toBe('11:15 PM');
tp3.setTime('23:15:20');
expect(tp3.getTime()).toBe('23:15:20');
+
+ tp1.setTime('11pm');
+ expect(tp1.getTime()).toBe('11:00 PM');
+ tp3.setTime('11pm');
+ expect(tp3.getTime()).toBe('23:00:00');
+
+ tp1.setTime('11a');
+ expect(tp1.getTime()).toBe('11:00 AM');
+ tp3.setTime('11a');
+ expect(tp3.getTime()).toBe('11:00:00');
+
+ tp1.setTime('1');
+ expect(tp1.getTime()).toBe('1:00 AM');
+ tp3.setTime('1');
+ expect(tp3.getTime()).toBe('01:00:00');
+
+ tp1.setTime('13');
+ expect(tp1.getTime()).toBe('12:00 AM');
+ tp3.setTime('13');
+ expect(tp3.getTime()).toBe('13:00:00');
+
+ tp1.setTime('10:20p');
+ expect(tp1.getTime()).toBe('10:20 PM');
+ tp3.setTime('10:20p');
+ expect(tp3.getTime()).toBe('22:20:00');
+
+ tp1.setTime('10:20 p.m.');
+ expect(tp1.getTime()).toBe('10:20 PM');
+ tp3.setTime('10:20 p.m.');
+ expect(tp3.getTime()).toBe('22:20:00');
+
+ tp1.setTime('10:20a');
+ expect(tp1.getTime()).toBe('10:20 AM');
+ tp3.setTime('10:20a');
+ expect(tp3.getTime()).toBe('10:20:00');
+
+ tp1.setTime('10:2010');
+ expect(tp1.getTime()).toBe('10:20 AM', 'setTime with 10:2010 on tp1');
+ tp3.setTime('10:2010');
+ expect(tp3.getTime()).toBe('10:20:10', 'setTime with 10:2010 on tp3');
+
+ tp1.setTime('102010');
+ expect(tp1.getTime()).toBe('10:20 AM', 'setTime with 102010 on tp1');
+ tp3.setTime('102010');
+ expect(tp3.getTime()).toBe('10:20:10', 'setTime with 102010 on tp3');
+
+ tp1.setTime('2320');
+ expect(tp1.getTime()).toBe('12:20 AM', 'setTime with 2320 on tp1');
+ tp3.setTime('2320');
+ expect(tp3.getTime()).toBe('23:20:00', 'setTime with 2320 on tp3');
+
});
it('should update picker on blur', function() {
@@ -286,7 +339,7 @@ describe('Timepicker feature', function() {
tp1.incrementHour();
tp1.incrementHour();
- expect(tp1.getTime()).toBe('01:15 AM');
+ expect(tp1.getTime()).toBe('1:15 AM');
});
it('should set hour to 0 if hour increments on 23 for 24h clock', function() {
Please sign in to comment.
Something went wrong with that request. Please try again.