sonarr-repo-only/packages/TelerikMvcExtensions.2011.1.../content/Scripts/2011.1.315/telerik.timepicker.min.js

1 line
7.0 KiB
JavaScript

(function(a){var b=a.telerik;b.timeView=function(c){a.extend(this,c);var d=this.dropDown=new b.dropDown({attr:this.dropDownAttr,effects:this.effects,onClick:function(f){var g=f.item;c.onChange(g.innerText||g.textContent)}});d.$element.addClass("t-time-popup").css("direction",this.isRtl?"rtl":"")};b.timeView.prototype={_ensureItems:function(){if(!this.dropDown.$items){this.bind()}},open:function(c){this._ensureItems();this.dropDown.open(c)},close:function(){this.dropDown.close()},bind:function(){var j=b.timeView.getTimeMilliseconds;var g=[];var c=this.format;var n=this.interval;var p=new b.datetime(this.minValue);var d=j(p);var f=j(this.maxValue);var l=n*b.datetime.msPerMinute;var k=parseInt(b.datetime.msPerDay/(n*b.datetime.msPerMinute));if(d!=f){var o=d<f?f-d:f+b.datetime.msPerDay-d;k=parseInt(o/l)+1}var m=b.datetime.add;var e=b.datetime.format;for(var h=0;h<k;h++){g[h]=e(p.toDate(),c);p=m(p,l)}if(j(p)-l-f!=0&&d!=f){g[k]=e(this.maxValue,c)}this.dropDown.dataBind(g)},isOpened:function(){return this.dropDown.isOpened()},value:function(c){this._ensureItems();var e=this.dropDown;if(c===undefined){return e.$items.filter(".t-state-selected").text()}var d=e.$items;if(!d){return}d.removeClass("t-state-selected");if(c){e.highlight(a.grep(d,function(f){return(f.innerText||f.textContent)==c}))}},navigate:function(i){var g=i.keyCode||i.which;if(g==38||g==40){i.preventDefault()}this._ensureItems();var d=this.dropDown;var f=d.$items;var h=f.filter(".t-state-selected");var c=h.length==0||f.length==1?f.first():(g==38)?h.prev():(g==40)?h.next():[];if(c.length){var j=c.text();d.scrollTo(c[0]);d.highlight(c[0]);if(!d.isOpened()){this.onChange(j)}else{this.onNavigateWithOpenPopup(j)}}}};a.each(["min","max"],a.proxy(function(d,c){b.timeView.prototype[c]=function(f){var e=c+"Value";if(f===undefined){return this[e]}this[e]=new Date(f.value?f.value:f);this.bind()}},this));a.extend(b.timeView,{isInRange:function(c,j,g){if(c===null){return true}var f=b.timeView.getTimeMilliseconds;var d=b.datetime.msPerDay;var i=f(c);var e=f(j);var h=f(g);i=e>i?i+d:i;h=e>h?h+d:h;return e-h==0||i>=e&&i<=h},getTimeMilliseconds:function(c){c=c.value?c:new b.datetime(c);return((c.hours()*60)+c.minutes())*b.datetime.msPerMinute+c.seconds()*1000+c.milliseconds()}});b.timepicker=function(d,e){a.extend(this,e);if(d.nodeName.toLowerCase()!=="input"&&d.type.toLowerCase()!=="text"){throw"Target element is not a INPUT"}this.element=d;var f=this.$element=a(d).addClass("t-input").attr("autocomplete","off").bind({keydown:a.proxy(this._keydown,this),focus:a.proxy(function(j){if(this.openOnFocus){this._open()}this.$element.removeClass("t-state-error")},this)});if(!f.parent().hasClass("t-picker-wrap")){f.wrap('<div class="t-widget t-timepicker"><div class="t-picker-wrap"></div></div>');if(e.showButton){var i=new b.stringBuilder(),g=e.buttonTitle;a(i.cat('<span class="t-select">').cat('<span class="t-icon t-icon-clock" ').catIf('title="',g).catIf(g,g).cat('"></span></span>').string()).insertAfter(f)}}this.timeView=new b.timeView({effects:this.effects,dropDownAttr:this.dropDownAttr,format:this.format,interval:this.interval,isRtl:f.closest(".t-rtl").length,minValue:this.minValue,maxValue:this.maxValue,onNavigateWithOpenPopup:a.proxy(function(j){this.$element.val(j)},this),onChange:a.proxy(function(j){if(j!=this.inputValue){this._update(j)}this._close()},this)});this.inputValue=f.val();var c=this.selectedValue||this.inputValue;if(c){this._value(this.parse(c))}var h=this.enabled?a.proxy(this._togglePopup,this):b.preventDefault;this.$wrapper=f.closest(".t-timepicker").find(".t-icon").bind("click",h).end();a(document.documentElement).bind("mousedown",a.proxy(function(m){var l=this.$element.val();if(l!=this.inputValue){this._update(l)}var j=this.timeView.dropDown.$element;var k=j&&j.parent().length>0;if(!k||a.contains(this.$wrapper[0],m.target)||a.contains(j.parent()[0],m.target)){return}this._close()},this));b.bind(this,{open:this.onOpen,close:this.onClose,valueChange:this.onChange,load:this.onLoad})};b.timepicker.prototype={_close:function(){var c=this.timeView.dropDown;if(!c.$element.is(":animated")&&c.isOpened()){this._trigger("close")}},_open:function(){if(!this.timeView.isOpened()){this._trigger("open")}},_trigger:function(c){if(!b.trigger(this.element,c)){this[c]()}},_togglePopup:function(){if(this.timeView.isOpened()){this._close()}else{this.element.focus();this._open()}},_update:function(f){var k=this.minValue,d=this.maxValue,i=this.parse(f),m=this.selectedValue;if(i!=null&&!b.timeView.isInRange(i,k,d)){var e=b.timeView.getTimeMilliseconds,h=e(i),j=Math.abs(e(k)-h),l=Math.abs(e(d)-h);i=new Date(j<l?k:d)}var g=m?b.datetime.format(m,this.format):"",c=i?b.datetime.format(i,this.format):"";if(c!=g){if(b.trigger(this.element,"valueChange",{previousValue:m,value:i})){i=new Date(m)}}this._value(i)},_value:function(c){var e=this.$element.val();var d=c===null;this.selectedValue=c;this.timeView.value(d?null:b.datetime.format(c,this.format));if(!d){e=b.datetime.format(c,this.format)}this.inputValue=e;this.$element.toggleClass("t-state-error",d&&e!="").val(e)},_keydown:function(d){var c=d.keyCode||d.which;if(d.altKey){if(c==40){this._open()}else{if(c==38){this._close()}}return}if(!d.shiftKey&&(c===38||c===40)){this.timeView.navigate(d);return}if(c==9||c==13||c==27){this._update(this.$element.val());this._close()}},enable:function(){this.$element.attr("disabled",false);this.$wrapper.removeClass("t-state-disabled").find(".t-icon").unbind("click").bind("click",a.proxy(this._togglePopup,this))},disable:function(c){this.$element.attr("disabled",true);this.$wrapper.addClass("t-state-disabled").find(".t-icon").unbind("click").bind("click",b.preventDefault)},value:function(c){if(c===undefined){return this.selectedValue}var d=this.parse(c);d=b.timeView.isInRange(d,this.minValue,this.maxValue)?d:null;if(d===null){this.$element.removeClass("t-state-error").val("")}this._value(d);return this},parse:function(d){if(d===null||d.getDate){return d}var c=b.datetime.parse({AM:b.cultureInfo.AM,PM:b.cultureInfo.PM,value:d,format:this.format,baseDate:this.selectedValue?new b.datetime(this.selectedValue):new b.datetime()});return c!=null?c.toDate():null},open:function(){var c=this.$element;this.timeView.open({offset:c.offset(),outerHeight:c.outerHeight(),outerWidth:c.outerWidth(),zIndex:b.getElementZIndex(c[0])})},close:function(){this.timeView.close()}};a.each(["min","max"],a.proxy(function(d,c){b.timepicker.prototype[c]=function(e){var f=c+"Value";if(e===undefined){return this[f]}var g=this.parse(e);if(g!==null){this[f]=g;this.timeView[c](g);if(!b.timeView.isInRange(this.selectedValue,this.minValue,this.maxValue)){this.value(g)}}}},this));a.fn.tTimePicker=function(c){return b.create(this,{name:"tTimePicker",init:function(d,e){return new b.timepicker(d,e)},options:c})};a.fn.tTimePicker.defaults={effects:b.fx.slide.defaults(),minValue:new b.datetime().hours(0).minutes(0).seconds(0).toDate(),maxValue:new b.datetime().hours(0).minutes(0).seconds(0).toDate(),selectedValue:null,format:b.cultureInfo.shortTime,interval:30,showButton:true,buttonTitle:"Open the calendar",enabled:true,openOnFocus:false}})(jQuery);