sonarr-repo-only/NzbDrone.Web/Scripts/2010.3.1318/telerik.datepicker.min.js

1 line
11 KiB
JavaScript

(function(d){var b=d.telerik;var a=null;b.datetime.parseByToken=function(g,i){if(g===null||g===""){return null}i=i||new b.datetime();var e=null;var m=null;var k=null;var n=0;var f=function(o){var p=null;if(o&&g.substring(n,n+o.length).toLowerCase()==o.toLowerCase()){p=o}return p};var j=function(){var o=null;d.each(["days","abbrDays","months","abbrMonths"],function(q,p){if(o!==null){return}d.each(b.cultureInfo[p],function(s,r){if(o!==null){return}o=f(r)});k=p});return o};var h=function(){var o;var p=function(r,s){i[s?"date":"month"](i[s?"date":"month"]()+(o!=0?((o+((o>0?1:-1)*r))%r):0)+(m?(e==b.cultureInfo.next?1:-1)*r:0))};var q=d.inArray(m||e,b.cultureInfo[k]);if(k.toLowerCase().indexOf("day")>-1){o=(q==0?7:q)-i.day();p(7,true)}else{o=q-i.month();p(12,false)}};var l=function(){var p=function(q){var r;switch(m){case"year":r=q==1?1:0;break;case"month":r=q==2?1:0;break;case"week":r=q==3?7:0;break;case"day":r=q==3?1:0;break}return r};var o=(e==b.cultureInfo.next?1:-1);i.year(i.year()+p(1)*o,i.month()+p(2)*o,i.date()+p(3)*o)};d.each(["today","tomorrow","yesterday","next","last"],function(p,o){if(e!==null){return}e=f(b.cultureInfo[o])});if(e!==null){n+=e.length;if(/[^\s\d]\s+[^\s\d]/i.test(g)){n++;d.each(["year","month","week","day"],function(p,o){if(m!==null){return}m=f(b.cultureInfo[o])});k=null;if(m===null){m=j()}if(m===null){return null}}else{switch(e){case b.cultureInfo.today:break;case b.cultureInfo.tomorrow:i.date(i.date()+1);break;case b.cultureInfo.yesterday:i.date(i.date()-1);break;default:i=null;break}return i}}else{e=j();if(e!=null){h();return i}else{return null}}if(k!==null){h()}else{l()}return i};function c(h,g,f,e){if(g){h=new b.datetime(g.toDate())}if(f.value>h.value){h=new b.datetime(f.value)}else{if(e.value<h.value){h=new b.datetime(e.value)}}return h}b.dateView=function(e){d.extend(this,e);this.isValueChanged=false;this.focusedValue=c(new b.datetime(),this.selectedValue,this.minValue,this.maxValue);this.$calendar=this._createSharedCalendar()};b.dateView.prototype={_createSharedCalendar:function(){if(!a){a=d(b.calendar.html(this.focusedValue,this.selectedValue,this.minValue,this.maxValue)).hide().addClass("t-datepicker-calendar").bind("click",function(f){f.stopPropagation()}).appendTo(document.body).tCalendar({selectedValue:this.selectedValue,minDate:this.minValue,maxDate:this.maxValue});b.fx._wrap(a).css("display","none");if(d.browser.msie&&d.browser.version<=6){d('<iframe class="t-iframe-overlay" src="javascript:false;"></iframe>').prependTo(a).height(a.height())}}return a},_getCalendar:function(){return a.data("tCalendar")},_reassignSharedCalendar:function(){var e=this._getCalendar();if(a.data("associatedDateView")!=this){a.stop(true,true);this.focusedValue=c(this.focusedValue,this.selectedValue,this.minValue,this.maxValue);e.minDate=this.minValue;e.maxDate=this.maxValue;e.selectedValue=this.selectedValue;e.goToView(0,this.focusedValue);a.unbind("change").bind("change",d.proxy(function(h){var g=this.selectedValue;var f=new b.datetime(h.date);if(g!==null){f.hours(g.hours()).minutes(g.minutes()).seconds(g.seconds()).milliseconds(g.milliseconds())}this.onChange(f)},this)).unbind("navigate").bind("navigate",d.proxy(function(i){var h=this.focusedValue;var f=e.viewedMonth;var g=e.currentView.index;if(g==0){h=this.selectedValue?new b.datetime(this.selectedValue.toDate()):h}else{h.year(f.year(),f.month(),h.date())}b.calendar.focusDate(h,g,a,i.direction)},this)).data("associatedDateView",this);if(this.selectedValue){e.value(this.selectedValue)}b.calendar.focusDate(this.focusedValue,e.currentView.index,a)}},open:function(e){if(this.isOpened()){return}this._reassignSharedCalendar();var i=this.isRtl;var h=this.$calendar;elementPosition=e.offset;elementPosition.top+=e.outerHeight;if(i){elementPosition.left-=(a.outerWidth()||a.parent().outerWidth())-e.outerWidth}b.fx._wrap(a).css(d.extend({position:"absolute",direction:i?"rtl":"",display:a.is(":visible")?"":"none"},elementPosition));var f=this._getCalendar();var g=f.currentView.index;if(!a.is(":visible")&&f.viewedMonth.value-this.focusedValue.value!=0){f.goToView(g,this.focusedValue).value(this.selectedValue)}b.calendar.focusDate(this.focusedValue,f.currentView.index,a);b.fx._wrap(h).css("zIndex",e.zIndex).show();b.fx.play(this.effects,h,{direction:"bottom"})},close:function(){if(this.isOpened()){b.fx.rewind(this.effects,this.$calendar,{direction:"bottom"},function(){if(a){b.fx._wrap(a).hide()}})}},isOpened:function(){return a&&a.data("associatedDateView")==this&&a.is(":visible")},value:function(e){if(e===undefined){return this.selectedValue.toDate()}var g=e===null;var f=this._getCalendar();if(!g){e=e.value?e:new b.datetime(e)}f.value(e);this.selectedValue=e;if(g){e=new b.datetime()}this.focusedValue=new b.datetime(e.toDate());b.calendar.focusDate(e,f.currentView.index,a)},navigate:function(p){if(this.isOpened()&&d(".t-overlay",a).length>0){return}var m;var k=false;var o=this.$calendar;var l=this._getCalendar();var n=l.viewedMonth;var h=l.currentView;var f=h.index;var q=new b.datetime(this.focusedValue.value);var r=function(e,t,s){if(!d(e,o).hasClass("t-state-disabled")){if("navigateUp"==t){f+=1}m=s||false;l[t]();return true}else{return false}};var g=function(){var e=b.calendar.findTarget(q,f,o,false)[0];l.navigateDown(p,e,f);f=f==0?0:f-1;m=true};var i=function(e,u,s){var t=!s?-1:1;if(!r(e,u,s)){return false}if(f==0){q.addMonth(t)}else{q.addYear(t*(f==1?1:f==2?10:100))}return true};var j=b.datepicker.adjustDate;if(o.is(":visible")&&!p.shiftKey){k=true;switch(p.keyCode){case 37:if(p.ctrlKey){if(!i(".t-nav-prev","navigateToPast")){return}}else{j(f,q,-1,-1);if(h.navCheck(q,n,false)){if(!r(".t-nav-prev","navigateToPast")){return}}}break;case 38:if(p.ctrlKey){r(".t-nav-fast","navigateUp")}else{j(f,q,-7,-4);if(h.navCheck(q,n,false)){if(!r(".t-nav-prev","navigateToPast")){return}}}break;case 39:if(p.ctrlKey){if(!i(".t-nav-next","navigateToFuture",true)){return}}else{j(f,q,1,1);if(h.navCheck(q,n,true)){if(!r(".t-nav-next","navigateToFuture",true)){return}}}break;case 40:if(p.ctrlKey){g()}else{j(f,q,7,4);if(h.navCheck(q,n,true)){if(!r(".t-nav-next","navigateToFuture",true)){return}}}break;case 33:if(!i(".t-nav-prev","navigateToPast")){return}break;case 34:if(!i(".t-nav-next","navigateToFuture",true)){return}break;case 35:q=b.calendar.views[f].firstLastDay(q,false,l);break;case 36:q=b.calendar.views[f].firstLastDay(q,true,l);break;case 13:p.stopPropagation();if(f==0){this.onChange(this.focusedValue)}else{g()}break;default:k=false;break}}if(k){p.preventDefault();q=b.calendar.fitDateToRange(q,this.minValue,this.maxValue);b.calendar.focusDate(q,f,o,m);this.focusedValue=q}}};d.each(["min","max"],d.proxy(function(f,e){b.dateView.prototype[e]=function(h){var g=e+"Value";if(h===undefined){return this[g].toDate()}this[g]=h.value?h:new b.datetime(h);a.data("associatedDateView",null);this._reassignSharedCalendar()}},this));b.datepicker=function(f,g){this.element=f;d.extend(this,g);var h=this.$input=d(".t-input",f).attr("autocomplete","off").bind({change:function(i){i.stopPropagation()},keydown:d.proxy(this._keydown,this),focus:d.proxy(function(i){this._change(h.val());this._open();this.$input.removeClass("t-state-error")},this)});this.dateView=new b.dateView({selectedValue:this.selectedValue,minValue:this.minDate,maxValue:this.maxDate,effects:this.effects,isRtl:h.closest(".t-rtl").length,onChange:d.proxy(function(i){this._change(i);this._close()},this)});this.inputValue=h.val();var e=this.selectedValue||this.inputValue;if(e){this._value(this.parse(e))}d(".t-icon-calendar",f).bind("click",this.enabled?d.proxy(this._togglePopup,this):b.preventDefault);d(document.documentElement).bind("mousedown",d.proxy(function(i){if(!a){return}var j=a.data("associatedDateView");if(j&&j==this.dateView){if(d.contains(f,i.target)||d.contains(a[0],i.target)){return}this._change(this.$input.val());this._close()}},this));b.bind(this,{open:this.onOpen,close:this.onClose,change:this.onChange,load:this.onLoad})};b.datepicker.prototype={_togglePopup:function(){var e=this.$input;if(this.dateView.isOpened()){this._change(e.val());this._close()}else{e[0].focus()}},_close:function(){if(!a.is(":animated")&&this.dateView.isOpened()){this._trigger("close")}},_open:function(){if(!this.dateView.isOpened()){this._trigger("open")}},_trigger:function(e){if(!b.trigger(this.element,e)){this[e]()}},_change:function(e){var g=this.selectedValue;var f=this.parse(e);if(f!=null){if(f.value-this.minDate.value<=0){f=this.minDate}else{if(f.value-this.maxDate.value>=0){f=this.maxDate}}}if(f==null||this.inputValue!=e){this._value(f);if((g===null&&f!==null)||(g!==null&&f===null)||(g&&f&&(g.value>f.value||f.value>g.value))){b.trigger(this.element,"change",{previousValue:g===null?null:g.toDate(),value:f===null?null:f.toDate(),previousDate:g===null?null:g.toDate(),date:f===null?null:f.toDate()})}}},_keydown:function(h){var g=h.keyCode;var f=h.target.value;if(g==9){this._change(f);this._close()}else{if(g==27){this._close()}else{if(g==13&&(this.inputValue!=f||!this.dateView.isOpened())){this._change(f);this._close()}else{if(h.altKey){if(g==40){this._open()}else{if(g==38){this._close()}}}else{this.dateView.navigate(h)}}}}},enable:function(){this.$input.attr("disabled",false);d(this.element).removeClass("t-state-disabled").find(".t-icon").unbind("click").bind("click",d.proxy(this._togglePopup,this))},disable:function(f){this.$input.attr("disabled",true);d(this.element).addClass("t-state-disabled").find(".t-icon").unbind("click").bind("click",b.preventDefault)},_value:function(e){var g=this.$input.val();var f=e===null;this.selectedValue=e;this.dateView.value(e);if(!f){g=b.datetime.format(e.toDate(),this.format)}this.inputValue=g;this.$input.toggleClass("t-state-error",f&&g!="").val(g)},value:function(e){if(e===undefined){return this.selectedValue===null?null:this.selectedValue.toDate()}var f=this.parse(e);f=b.calendar.isInRange(f,this.minDate,this.maxDate)?f:null;if(f===null){this.$input.removeClass("t-state-error").val("")}this._value(f);return this},showPopup:function(){this.open()},hidePopup:function(){this.close()},open:function(){var e=this.$input;this.dateView.open({offset:e.offset(),outerHeight:e.outerHeight(),outerWidth:e.outerWidth(),zIndex:b.getElementZIndex(e[0])})},close:function(){this.dateView.close()},parse:function(f,e){if(f===null||f.value){return f}return f.getDate?new b.datetime(f):b.datetime.parse({value:f,format:e||this.format,shortYearCutOff:this.shortYearCutOff})}};d.each(["min","max"],d.proxy(function(f,e){b.datepicker.prototype[e]=function(g){var i=e+"Date";if(g===undefined){return this[i].toDate()}var j=this.parse(g);if(j!==null){var h=this[i];this[i]=j;if(this.minDate.value>this.maxDate.value){this[i]=h;return}this.dateView[e](j);if(!b.calendar.isInRange(this.selectedValue,this.minDate,this.maxDate)){this.value(j)}}}},this));d.extend(b.datepicker,{adjustDate:function(e,h,g,f){if(e==0){b.datetime.modify(h,b.datetime.msPerDay*g)}else{if(e==1){h.addMonth(f)}else{h.addYear((e==2?f:10*f))}}}});d.fn.tDatePicker=function(e){return b.create(this,{name:"tDatePicker",init:function(f,g){return new b.datepicker(f,g)},options:e})};d.fn.tDatePicker.defaults={effects:b.fx.slide.defaults(),selectedValue:null,format:b.cultureInfo.shortDate,minDate:new b.datetime(1899,11,31),maxDate:new b.datetime(2100,0,1),shortYearCutOff:30,enabled:true}})(jQuery);