/* * jQuery timepicker addon * By: Trent Richardson [http://trentrichardson.com] * Version 1.0.0 * Last Modified: 02/05/2012 * * Copyright 2012 Trent Richardson * Dual licensed under the MIT and GPL licenses. * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt */ ;(function($){function Timepicker(){this.regional=[],this.regional[""]={currentText:"Now",closeText:"Done",ampm:!1,amNames:["AM","A"],pmNames:["PM","P"],timeFormat:"hh:mm tt",timeSuffix:"",timeOnlyTitle:"Choose Time",timeText:"Time",hourText:"Hour",minuteText:"Minute",secondText:"Second",millisecText:"Millisecond",timezoneText:"Time Zone"},this._defaults={showButtonPanel:!0,timeOnly:!1,showHour:!0,showMinute:!0,showSecond:!1,showMillisec:!1,showTimezone:!1,showTime:!0,stepHour:1,stepMinute:1,stepSecond:1,stepMillisec:1,hour:0,minute:0,second:0,millisec:0,timezone:"+0000",hourMin:0,minuteMin:0,secondMin:0,millisecMin:0,hourMax:23,minuteMax:59,secondMax:59,millisecMax:999,minDateTime:null,maxDateTime:null,onSelect:null,hourGrid:0,minuteGrid:0,secondGrid:0,millisecGrid:0,alwaysSetTime:!0,separator:" ",altFieldTimeOnly:!0,showTimepicker:!0,timezoneIso8609:!1,timezoneList:null,addSliderAccess:!1,sliderAccessArgs:null},$.extend(this._defaults,this.regional[""])}function extendRemove(a,b){$.extend(a,b);for(var c in b)if(b[c]===null||b[c]===undefined)a[c]=b[c];return a}$.ui.timepicker=$.ui.timepicker||{};if($.ui.timepicker.version)return;$.extend($.ui,{timepicker:{version:"1.0.0"}}),$.extend(Timepicker.prototype,{$input:null,$altInput:null,$timeObj:null,inst:null,hour_slider:null,minute_slider:null,second_slider:null,millisec_slider:null,timezone_select:null,hour:0,minute:0,second:0,millisec:0,timezone:"+0000",hourMinOriginal:null,minuteMinOriginal:null,secondMinOriginal:null,millisecMinOriginal:null,hourMaxOriginal:null,minuteMaxOriginal:null,secondMaxOriginal:null,millisecMaxOriginal:null,ampm:"",formattedDate:"",formattedTime:"",formattedDateTime:"",timezoneList:null,setDefaults:function(a){return extendRemove(this._defaults,a||{}),this},_newInst:function($input,o){var tp_inst=new Timepicker,inlineSettings={};for(var attrName in this._defaults){var attrValue=$input.attr("time:"+attrName);if(attrValue)try{inlineSettings[attrName]=eval(attrValue)}catch(err){inlineSettings[attrName]=attrValue}}tp_inst._defaults=$.extend({},this._defaults,inlineSettings,o,{beforeShow:function(a,b){if($.isFunction(o.beforeShow))return o.beforeShow(a,b,tp_inst)},onChangeMonthYear:function(a,b,c){tp_inst._updateDateTime(c),$.isFunction(o.onChangeMonthYear)&&o.onChangeMonthYear.call($input[0],a,b,c,tp_inst)},onClose:function(a,b){tp_inst.timeDefined===!0&&$input.val()!=""&&tp_inst._updateDateTime(b),$.isFunction(o.onClose)&&o.onClose.call($input[0],a,b,tp_inst)},timepicker:tp_inst}),tp_inst.amNames=$.map(tp_inst._defaults.amNames,function(a){return a.toUpperCase()}),tp_inst.pmNames=$.map(tp_inst._defaults.pmNames,function(a){return a.toUpperCase()});if(tp_inst._defaults.timezoneList===null){var timezoneList=[];for(var i=-11;i<=12;i++)timezoneList.push((i>=0?"+":"-")+("0"+Math.abs(i).toString()).slice(-2)+"00");tp_inst._defaults.timezoneIso8609&&(timezoneList=$.map(timezoneList,function(a){return a=="+0000"?"Z":a.substring(0,3)+":"+a.substring(3)})),tp_inst._defaults.timezoneList=timezoneList}tp_inst.hour=tp_inst._defaults.hour,tp_inst.minute=tp_inst._defaults.minute,tp_inst.second=tp_inst._defaults.second,tp_inst.millisec=tp_inst._defaults.millisec,tp_inst.ampm="",tp_inst.$input=$input,o.altField&&(tp_inst.$altInput=$(o.altField).css({cursor:"pointer"}).focus(function(){$input.trigger("focus")}));if(tp_inst._defaults.minDate==0||tp_inst._defaults.minDateTime==0)tp_inst._defaults.minDate=new Date;if(tp_inst._defaults.maxDate==0||tp_inst._defaults.maxDateTime==0)tp_inst._defaults.maxDate=new Date;return tp_inst._defaults.minDate!==undefined&&tp_inst._defaults.minDate instanceof Date&&(tp_inst._defaults.minDateTime=new Date(tp_inst._defaults.minDate.getTime())),tp_inst._defaults.minDateTime!==undefined&&tp_inst._defaults.minDateTime instanceof Date&&(tp_inst._defaults.minDate=new Date(tp_inst._defaults.minDateTime.getTime())),tp_inst._defaults.maxDate!==undefined&&tp_inst._defaults.maxDate instanceof Date&&(tp_inst._defaults.maxDateTime=new Date(tp_inst._defaults.maxDate.getTime())),tp_inst._defaults.maxDateTime!==undefined&&tp_inst._defaults.maxDateTime instanceof Date&&(tp_inst._defaults.maxDate=new Date(tp_inst._defaults.maxDateTime.getTime())),tp_inst},_addTimePicker:function(a){var b=this.$altInput&&this._defaults.altFieldTimeOnly?this.$input.val()+" "+this.$altInput.val():this.$input.val();this.timeDefined=this._parseTime(b),this._limitMinMaxDateTime(a,!1),this._injectTimePicker()},_parseTime:function(a,b){var c=this._defaults.timeFormat.toString().replace(/h{1,2}/ig,"(\\d?\\d)").replace(/m{1,2}/ig,"(\\d?\\d)").replace(/s{1,2}/ig,"(\\d?\\d)").replace(/l{1}/ig,"(\\d?\\d?\\d)").replace(/t{1,2}/ig,this._getPatternAmpm()).replace(/z{1}/ig,"(z|[-+]\\d\\d:?\\d\\d)?").replace(/\s/g,"\\s?")+this._defaults.timeSuffix+"$",d=this._getFormatPositions(),e="",f;this.inst||(this.inst=$.datepicker._getInst(this.$input[0]));if(b||!this._defaults.timeOnly){var g=$.datepicker._get(this.inst,"dateFormat"),h=new RegExp("[.*+?|()\\[\\]{}\\\\]","g");c="^.{"+g.length+",}?"+this._defaults.separator.replace(h,"\\$&")+c}f=a.match(new RegExp(c,"i"));if(f){d.t!==-1&&(f[d.t]===undefined||f[d.t].length===0?(e="",this.ampm=""):(e=$.inArray(f[d.t].toUpperCase(),this.amNames)!==-1?"AM":"PM",this.ampm=this._defaults[e=="AM"?"amNames":"pmNames"][0])),d.h!==-1&&(e=="AM"&&f[d.h]=="12"?this.hour=0:e=="PM"&&f[d.h]!="12"?this.hour=(parseFloat(f[d.h])+12).toFixed(0):this.hour=Number(f[d.h])),d.m!==-1&&(this.minute=Number(f[d.m])),d.s!==-1&&(this.second=Number(f[d.s])),d.l!==-1&&(this.millisec=Number(f[d.l]));if(d.z!==-1&&f[d.z]!==undefined){var i=f[d.z].toUpperCase();switch(i.length){case 1:i=this._defaults.timezoneIso8609?"Z":"+0000";break;case 5:this._defaults.timezoneIso8609&&(i=i.substring(1)=="0000"?"Z":i.substring(0,3)+":"+i.substring(3));break;case 6:this._defaults.timezoneIso8609?i.substring(1)=="00:00"&&(i="Z"):i=i=="Z"||i.substring(1)=="00:00"?"+0000":i.replace(/:/,"")}this.timezone=i}return!0}return!1},_getPatternAmpm:function(){var a=[],b=this._defaults;return b.amNames&&$.merge(a,b.amNames),b.pmNames&&$.merge(a,b.pmNames),a=$.map(a,function(a){return a.replace(/[.*+?|()\[\]{}\\]/g,"\\$&")}),"("+a.join("|")+")?"},_getFormatPositions:function(){var a=this._defaults.timeFormat.toLowerCase().match(/(h{1,2}|m{1,2}|s{1,2}|l{1}|t{1,2}|z)/g),b={h:-1,m:-1,s:-1,l:-1,t:-1,z:-1};if(a)for(var c=0;c
'+'
"+b.timeText+"
"+'
"+'
"+b.hourText+"
",k=0,l=0,m=0,n=0,o=null;j+='
";if(b.showHour&&b.hourGrid>0){j+='
';for(var p=b.hourMin;p<=d;p+=parseInt(b.hourGrid,10)){k++;var q=b.ampm&&p>12?p-12:p;q<10&&(q="0"+q),b.ampm&&(p==0?q="12a":p<12?q+="a":q+="p"),j+=""}j+="
"+q+"
"}j+="
",j+='
"+b.minuteText+"
"+'
";if(b.showMinute&&b.minuteGrid>0){j+='
';for(var r=b.minuteMin;r<=e;r+=parseInt(b.minuteGrid,10))l++,j+="";j+="
"+(r<10?"0":"")+r+"
"}j+="
",j+='
"+b.secondText+"
"+'
";if(b.showSecond&&b.secondGrid>0){j+='
';for(var s=b.secondMin;s<=f;s+=parseInt(b.secondGrid,10))m++,j+="";j+="
"+(s<10?"0":"")+s+"
"}j+="
",j+='
"+b.millisecText+"
"+'
";if(b.showMillisec&&b.millisecGrid>0){j+='
';for(var t=b.millisecMin;t<=g;t+=parseInt(b.millisecGrid,10))n++,j+="";j+="
"+(t<10?"0":"")+t+"
"}j+="
",j+='
"+b.timezoneText+"
",j+='
",j+="
",$tp=$(j),b.timeOnly===!0&&($tp.prepend('
'+b.timeOnlyTitle+"
"+"
"),a.find(".ui-datepicker-header, .ui-datepicker-calendar").hide()),this.hour_slider=$tp.find("#ui_tpicker_hour_"+h).slider({orientation:"horizontal",value:this.hour,min:b.hourMin,max:d,step:b.stepHour,slide:function(a,b){c.hour_slider.slider("option","value",b.value),c._onTimeChange()}}),this.minute_slider=$tp.find("#ui_tpicker_minute_"+h).slider({orientation:"horizontal",value:this.minute,min:b.minuteMin,max:e,step:b.stepMinute,slide:function(a,b){c.minute_slider.slider("option","value",b.value),c._onTimeChange()}}),this.second_slider=$tp.find("#ui_tpicker_second_"+h).slider({orientation:"horizontal",value:this.second,min:b.secondMin,max:f,step:b.stepSecond,slide:function(a,b){c.second_slider.slider("option","value",b.value),c._onTimeChange()}}),this.millisec_slider=$tp.find("#ui_tpicker_millisec_"+h).slider({orientation:"horizontal",value:this.millisec,min:b.millisecMin,max:g,step:b.stepMillisec,slide:function(a,b){c.millisec_slider.slider("option","value",b.value),c._onTimeChange()}}),this.timezone_select=$tp.find("#ui_tpicker_timezone_"+h).append("").find("select"),$.fn.append.apply(this.timezone_select,$.map(b.timezoneList,function(a,b){return $("