You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3 lines
7.7 KiB
3 lines
7.7 KiB
/*! UIkit 2.5.0 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
|
|
|
|
(function(t){"function"==typeof define&&define.amd&&define("uikit-timepicker",["uikit"],function(){return jQuery.UIkit.timepicker||t(window,window.jQuery,window.jQuery.UIkit)}),window&&window.jQuery&&window.jQuery.UIkit&&t(window,window.jQuery,window.jQuery.UIkit)})(function(t,e,i){var n=function(t,i){var s=e(t);s.data("timepicker")||(this.$element=s,this.element=this.$element[0],this.options=e.extend({},n.defaults,i),this.$element.on({"focus.timepicker.uikit":e.proxy(this.highlightUnit,this),"click.timepicker.uikit":e.proxy(this.highlightUnit,this),"keydown.timepicker.uikit":e.proxy(this.onKeydown,this),"blur.timepicker.uikit":e.proxy(this.blurElement,this)}),this.setDefaultTime(this.options.defaultTime),this.$element.data("timepicker",this))};return n.defaults={defaultTime:"current",disableFocus:!1,minuteStep:15,secondStep:15,showSeconds:!1,showMeridian:!1},e.extend(n.prototype,{setDefaultTime:function(t){if(this.element.value)this.updateFromElementVal();else if("current"===t){var e=new Date;this.hour=e.getHours(),this.minute=Math.floor(e.getMinutes()/this.options.minuteStep)*this.options.minuteStep,this.second=Math.floor(e.getSeconds()/this.options.secondStep)*this.options.secondStep,this.meridian="AM",this.options.showMeridian&&(0===this.hour?this.hour=12:this.hour>=12?(this.hour>12&&(this.hour=this.hour-12),this.meridian="PM"):this.meridian="AM"),this.update()}else t===!1?(this.hour=0,this.minute=0,this.second=0,this.meridian="AM"):this.setTime(t)},setTime:function(t){var e,i;this.options.showMeridian?(e=t.split(" "),i=e[0].split(":"),this.meridian=e[1]):i=t.split(":"),this.hour=parseInt(i[0],10),this.minute=parseInt(i[1],10),this.second=parseInt(i[2],10),isNaN(this.hour)&&(this.hour=0),isNaN(this.minute)&&(this.minute=0),this.options.showMeridian?(this.hour>12?this.hour=12:1>this.hour&&(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:0>this.hour&&(this.hour=0),0>this.minute?this.minute=0:this.minute>=60&&(this.minute=59),this.options.showSeconds&&(isNaN(this.second)?this.second=0:0>this.second?this.second=0:this.second>=60&&(this.second=59)),this.update()},blurElement:function(){this.highlightedUnit=void 0,this.updateFromElementVal()},decrementHour:function(t){if(this.options.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--;t||this.update()},decrementMinute:function(t){var e=t?this.minute-t:this.minute-this.options.minuteStep;0>e?(this.decrementHour(!0),this.minute=e+60):this.minute=e,this.update()},decrementSecond:function(){var t=this.second-this.options.secondStep;0>t?(this.decrementMinute(!0),this.second=t+60):this.second=t,this.update()},onKeydown:function(t){switch(t.keyCode){case 9:switch(this.updateFromElementVal(),this.highlightedUnit){case"hour":t.preventDefault(),this.highlightNextUnit();break;case"minute":(this.options.showMeridian||this.options.showSeconds)&&(t.preventDefault(),this.highlightNextUnit());break;case"second":this.options.showMeridian&&(t.preventDefault(),this.highlightNextUnit())}break;case 27:this.updateFromElementVal();break;case 37:t.preventDefault(),this.highlightPrevUnit(),this.updateFromElementVal();break;case 38:switch(t.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:t.preventDefault(),this.updateFromElementVal(),this.highlightNextUnit();break;case 40:switch(t.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(t,e,i,n){return t=10>t?"0"+t:t,e=10>e?"0"+e:e,i=10>i?"0"+i:i,t+":"+e+(this.options.showSeconds?":"+i:"")+(this.options.showMeridian?" "+n:"")},getCursorPosition:function(){if("selectionStart"in this.element)return this.element.selectionStart;if(document.selection){this.element.focus();var t=document.selection.createRange(),e=document.selection.createRange().text.length;return t.moveStart("character",-this.element.value.length),t.text.length-e}},getTime:function(){return this.formatTime(this.hour,this.minute,this.second,this.meridian)},highlightUnit:function(){this.position=this.getCursorPosition(),this.position>=0&&2>=this.position?this.highlightHour():this.position>=3&&5>=this.position?this.highlightMinute():this.position>=6&&8>=this.position?this.options.showSeconds?this.highlightSecond():this.highlightMeridian():this.position>=9&&11>=this.position&&this.highlightMeridian()},highlightNextUnit:function(){switch(this.highlightedUnit){case"hour":this.highlightMinute();break;case"minute":this.options.showSeconds?this.highlightSecond():this.options.showMeridian?this.highlightMeridian():this.highlightHour();break;case"second":this.options.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.options.showSeconds?this.highlightSecond():this.highlightMinute()}},highlightHour:function(){var t=this.element;this.highlightedUnit="hour",t.setSelectionRange&&setTimeout(function(){t.setSelectionRange(0,2)},0)},highlightMinute:function(){var t=this.element;this.highlightedUnit="minute",t.setSelectionRange&&setTimeout(function(){t.setSelectionRange(3,5)},0)},highlightSecond:function(){var t=this.element;this.highlightedUnit="second",t.setSelectionRange&&setTimeout(function(){t.setSelectionRange(6,8)},0)},highlightMeridian:function(){var t=this.element;this.highlightedUnit="meridian",t.setSelectionRange&&(this.options.showSeconds?setTimeout(function(){t.setSelectionRange(9,11)},0):setTimeout(function(){t.setSelectionRange(6,8)},0))},incrementHour:function(t){if(this.options.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++,t||this.update(),void 0)},incrementMinute:function(t){var e=t?this.minute+t:this.minute+this.options.minuteStep-this.minute%this.options.minuteStep;e>59?(this.incrementHour(!0),this.minute=e-60):this.minute=e,this.update()},incrementSecond:function(){var t=this.second+this.options.secondStep-this.second%this.options.secondStep;t>59?(this.incrementMinute(!0),this.second=t-60):this.second=t,this.update()},remove:function(){e("document").off(".timepicker.uikit"),delete this.$element.data().timepicker},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()},updateElement:function(){this.$element.val(this.getTime()).trigger("change")},updateFromElementVal:function(){this.element.value&&this.setTime(this.element.value)}}),e(document).on("focus.timepicker.uikit","[data-uk-timepicker]",function(t){var s=e(this);s.data("timepicker")||(t.preventDefault(),new n(s,i.Utils.options(s.attr("data-uk-timepicker"))),s.trigger("focus"))}),i.timepicker=n,n});
|