Sonarr/NzbDrone.Web/Scripts/2010.2.825/telerik.datepicker.min.js

1 line
11 KiB
JavaScript

(function(d){var b=d.telerik;var a=null;var c=/\d/;d.extend(b.datetime,{parse:function(e,g,f,h,i){g=b.calendar.standardFormat(g)?b.calendar.standardFormat(g):g;if(c.test(e)){return b.datetime.parseMachineDate(e,g,h,i)}return b.datetime.parseByToken(e,f,h,i)},parseMachineDate:function(i,l,E,u){var q=-1;var x=-1;var r=-1;var h=0;var o=0;var s=0;var k="+10";var A;var m=false;var D=function(G){var F=0;while(p(G)){F++;t++}return F};var f=function(){var F=p("'");if(F){t++}return F};var p=function(F){return(t+1<l.length&&l.charAt(t+1)==F)};var v=function(G){var H=new RegExp("^\\d{1,"+G+"}");var F=i.substr(y).match(H);if(F){y+=F[0].length;return parseInt(F[0],10)}else{return -1}};var j=function(F){for(var G=0;G<F.length;G++){if(i.substr(y,F[G].length)==F[G]){y+=F[G].length;return G+1}}return -1};var B=function(){if(i.charAt(y)==l.charAt(t)){y++}};var z=0;var y=0;var e=i.length;for(var t=0,n=l.length;t<n;t++){if(y==e){break}if(m){B();if(l.charAt(t)=="'"){m=false}}else{switch(l.charAt(t)){case"d":z=D("d");r=z<=1?v(2):j(b.cultureInfo[z==3?"days":"abbrDays"]);break;case"M":z=D("M");x=z<=1?v(2):j(b.cultureInfo[z==3?"months":"abbrMonths"]);break;case"y":z=D("y");q=v(z<=1?2:4);break;case"H":h=v(D("H")+1);break;case"h":h=v(D("h")+1);break;case"m":o=v(D("m")+1);break;case"s":s=v(D("s")+1);break;case"t":z=D("t");var C=i.substr(y,z+1).toLowerCase();A=C=="pm"||C=="p";case"'":B();m=true;break;default:B()}}}var g=new b.datetime();if(q==-1){q=g.year()}else{if(q<100){q+=g.year()-g.year()%100+(q<=k?0:-100)}}var w=new b.datetime(q,x-1,r,A?h+12:h,o,s);if(q==-1||x==-1||r==-1){return null}if(E&&u){w=b.calendar.isInRange(w,E,u)?w:null}return w},parseByToken:function(i,k,g,m){k=k||new b.datetime();var e=null;var o=null;var h=null;var p=0;var f=function(q){var r=null;if(q&&i.substring(p,p+q.length).toLowerCase()==q.toLowerCase()){r=q}return r};var l=function(){var q=null;d.each(["days","abbrDays","months","abbrMonths"],function(s,r){if(q!==null){return}d.each(b.cultureInfo[r],function(u,t){if(q!==null){return}q=f(t)});h=r});return q};var j=function(){var q;var r=function(t,u){k[u?"date":"month"](k[u?"date":"month"]()+(q!=0?((q+((q>0?1:-1)*t))%t):0)+(o?(e==b.cultureInfo.next?1:-1)*t:0))};var s=d.inArray(o||e,b.cultureInfo[h]);if(h.toLowerCase().indexOf("day")>-1){q=(s==0?7:s)-k.day();r(7,true)}else{q=s-k.month();r(12,false)}};var n=function(){var r=function(s){var t;switch(o){case"year":t=s==1?1:0;break;case"month":t=s==2?1:0;break;case"week":t=s==3?7:0;break;case"day":t=s==3?1:0;break}return t};var q=(e==b.cultureInfo.next?1:-1);k.year(k.year()+r(1)*q,k.month()+r(2)*q,k.date()+r(3)*q)};d.each(["today","tomorrow","yesterday","next","last"],function(r,q){if(e!==null){return}e=f(b.cultureInfo[q])});if(e!==null){p+=e.length;if(/[^\s\d]\s+[^\s\d]/i.test(i)){p++;d.each(["year","month","week","day"],function(r,q){if(o!==null){return}o=f(b.cultureInfo[q])});h=null;if(o===null){o=l()}if(o===null){return null}}else{switch(e){case b.cultureInfo.today:break;case b.cultureInfo.tomorrow:k.date(k.date()+1);break;case b.cultureInfo.yesterday:k.date(k.date()-1);break;default:k=null;break}if(g&&m){k=b.calendar.isInRange(k,g,m)?k:null}return k}}else{e=l();if(e!=null){j();if(g&&m){k=b.calendar.isInRange(k,g,m)?k:null}return k}else{return null}}if(h!==null){j()}else{n()}if(g&&m){k=b.calendar.isInRange(k,g,m)?k:null}return k}});b.datepicker=function(e,f){this.element=e;this.isValueChanged=false;d.extend(this,f);d("> .t-icon",e).bind("click",b.delegate(this,this.togglePopup));this.$input=d(".t-input",e).keydown(b.delegate(this,this.keyDown)).focus(b.delegate(this,this.show)).attr("autocomplete","off");this.focusedDate=this.selectedDate||(b.calendar.isInRange(this.focusedDate,this.minDate,this.maxDate)?this.focusedDate:new b.datetime(this.minDate.value));b.bind(this,{open:this.onOpen,close:this.onClose,change:this.onChange,load:this.onLoad})};d.extend(b.datepicker,{hideSharedCalendar:function(h){var f=a.data("associatedDatePicker");if(f){if(d.contains(f,h.target)||d.contains(a[0],h.target)){return}var g=d(f).data("tDatePicker");if(!g){g=d(f).tDatePicker().data("tDatePicker")}g.parseDate(d(".t-input",f).val());g.hide()}},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))}}}});b.datepicker.prototype={enable:function(){this.$input.attr("disabled",false);d(".t-icon",this.element).unbind("click").bind("click",b.delegate(this,this.togglePopup))},disable:function(f){this.$input.attr("disabled",true);d(".t-icon",this.element).unbind("click").bind("click",b.preventDefault)},$calendar:function(){if(!a){a=d(b.calendar.html(this.focusedDate,this.selectedDate,this.minDate,this.maxDate)).hide().addClass("t-datepicker-calendar").bind("click",function(i){i.stopPropagation()}).appendTo(document.body).tCalendar({selectedDate:this.selectedDate,minDate:this.minDate,maxDate:this.maxDate});d(document).bind("mousedown",b.datepicker.hideSharedCalendar)}var g=d(this.element).offset();g.top+=d(this.element).height();var h=b.fx._wrap(a);h.css(d.extend({position:"absolute"},g));var e=a.data("tCalendar");if(a.data("associatedDatePicker")!=this.element){e.minDate=this.minDate;e.maxDate=this.maxDate;e.selectedDate=this.selectedDate;e.goToView(0,this.focusedDate);a.unbind("change").bind("change",d.proxy(this.calendarChange,this)).unbind("navigate").bind("navigate",d.proxy(this.viewedMonthChanged,this)).data("associatedDatePicker",this.element);if(this.selectedDate){this.value(this.focusedDate)}}var f=e.currentView.index;if(!a.is(":visible")&&e.viewedMonth.value-this.focusedDate.value!=0){e.goToView(f,this.focusedDate).value(this.selectedDate)}b.calendar.focusDate(this.focusedDate,f,a);return a},isOpened:function(){return a&&a.data("associatedDatePicker")==this.element&&a.is(":visible")},viewedMonthChanged:function(i){var h=a.data("tCalendar");var f=h.viewedMonth;var g=h.currentView.index;if(g==0){this.focusedDate=this.selectedDate||this.focusedDate}else{this.focusedDate.year(f.year(),f.month(),this.focusedDate.date())}b.calendar.focusDate(this.focusedDate,g,a,i.direction)},value:function(g){if(arguments.length==0){return this.selectedDate===null?null:this.selectedDate.toDate()}var f=g===null?null:g.getDate||g.value?g:this.parse(g);var e=f===null;this.selectedDate=e?null:f.value?f:new b.datetime(f);if(!e){this.focusedDate=this.selectedDate}this.$input.val(e?"":b.calendar.formatDate(this.selectedDate.toDate(),this.format));if(this.isOpened()){this.$calendar().data("tCalendar").value(this.selectedDate)}return this},calendarChange:function(f){var g=new b.datetime(f.date);if(this.checkSelectedDate(this.selectedDate,g)){return this}this.$input.removeClass("t-state-error");this.hide()},checkSelectedDate:function(e,f){if(!e||(e.value>f.value||f.value>e.value)){this.value(f);return b.trigger(this.element,"change",{previousDate:e===null?null:e.toDate(),date:f.toDate()})}},togglePopup:function(f){f.preventDefault();var g=this.$input;if(this.isOpened()){this.parseDate(g.val());g.blur();this.hide()}else{g[0].focus()}},showPopup:function(){var f=this.parse(d(":input",this.element).val());this.selectedDate=f;if(f!==null){this.focusedDate=new b.datetime(f.value)}var g=this.$calendar();if(g){var e="auto";d(this.element).parents().andSelf().each(function(){e=d(this).css("zIndex");if(Number(e)){e=Number(e)+1;return false}});b.fx._wrap(g).css("zIndex",e).show();b.fx.play(this.effects,g,{direction:"bottom"})}},hidePopup:function(){if(this.isOpened()){b.fx.rewind(this.effects,this.$calendar(),{direction:"bottom"},function(){if(a){b.fx._wrap(a).hide()}})}},show:function(){this.showPopup();b.trigger(this.element,"open")},hide:function(){if(this.isOpened()){b.trigger(this.element,"close")}this.hidePopup()},keyDown:function(s){var k=d(s.target).val();if(s.keyCode==9){this.parseDate(k);this.hide()}if(s.keyCode==27){this.hide()}if(this.isOpened()&&d(".t-overlay",a).length>0){return}var o;var l=false;var q=this.$calendar();var n=q.data("tCalendar");var p=n.viewedMonth;var h=n.currentView;var i=n.currentView.index;var t=new b.datetime(this.focusedDate.value);var u=function(e,w,v){if(!d(e,q).hasClass("t-state-disabled")){if("navigateUp"==w){i+=1}o=v||false;n[w]();return true}else{return false}};var g=function(){var e=b.calendar.findTarget(t,i,q,false)[0];n.navigateDown(s,e,i);i=i==0?0:i-1;o=true};var m=function(e,x,v){var w=!v?-1:1;if(!u(e,x,v)){return false}if(i==0){t.addMonth(w)}else{t.addYear(w*(i==1?1:i==2?10:100))}return true};if(q.is(":visible")&&!s.shiftKey){switch(s.keyCode){case 37:l=true;if(s.ctrlKey){if(!m(".t-nav-prev","navigateToPast")){return}}else{b.datepicker.adjustDate(i,t,-1,-1);if(h.navCheck(t,p,false)){if(!u(".t-nav-prev","navigateToPast")){return}}}break;case 38:l=true;if(s.ctrlKey){u(".t-nav-fast","navigateUp")}else{b.datepicker.adjustDate(i,t,-7,-4);if(h.navCheck(t,p,false)){if(!u(".t-nav-prev","navigateToPast")){return}}}break;case 39:l=true;if(s.ctrlKey){if(!m(".t-nav-next","navigateToFuture",true)){return}}else{b.datepicker.adjustDate(i,t,1,1);if(h.navCheck(t,p,true)){if(!u(".t-nav-next","navigateToFuture",true)){return}}}break;case 40:l=true;if(s.ctrlKey){g()}else{b.datepicker.adjustDate(i,t,7,4);if(h.navCheck(t,p,true)){if(!u(".t-nav-next","navigateToFuture",true)){return}}}break;case 33:if(!m(".t-nav-prev","navigateToPast")){return}l=true;break;case 34:if(!m(".t-nav-next","navigateToFuture",true)){return}l=true;break;case 35:t=b.calendar.views[i].firstLastDay(t,false,n);l=true;break;case 36:t=b.calendar.views[i].firstLastDay(t,true,n);l=true;break;case 13:if(this.isValueChanged){this.parseDate(k);this.isValueChanged=false;break}l=true;if(i==0){d(s.target).removeClass("t-state-error");if(this.checkSelectedDate(this.selectedDate,this.focusedDate)){return}this.hide()}else{g()}break}}else{if(s.altKey&&s.keyCode==40){this.show();var r=this.parseDate(k);if(k!=""&&r===null){l=true}}else{if(s.keyCode==13){this.parseDate(k)}}}if(l){s.preventDefault();t=b.calendar.fitDateToRange(t,this.minDate,this.maxDate);b.calendar.focusDate(t,i,q,o);this.focusedDate=t}else{var j=s.keyCode;var f=function(v,e,w){return v>e&&v<w};if(f(j,47,57)||f(j,65,90)||f(j,95,105)||j==8||j==32||j==47){this.isValueChanged=true}}},parseDate:function(e){var f=null;var g=function(){this.selectedDate=null;if(this.isOpened()){this.$calendar().data("tCalendar").selectedDate=null;d(".t-state-selected",this.$calendar()).removeClass("t-state-selected")}};if(e!=""){f=this.parse(e,this.format);var h=f===null;if(!h){this.focusedDate=f;if(this.checkSelectedDate(this.selectedDate,f)){return}}else{d.proxy(g,this)()}this.$input.toggleClass("t-state-error",h).val(h?e:b.calendar.formatDate(f.toDate(),this.format))}else{this.$input.removeClass("t-state-error");d.proxy(g,this)()}return f},parse:function(e,g,f){return b.datetime.parse(e,g||this.format,f,this.minDate,this.maxDate)}};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(),selectedDate:null,format:b.cultureInfo.shortDate,focusedDate:new b.datetime(),minDate:new b.datetime(1899,11,31),maxDate:new b.datetime(2100,0,1)}})(jQuery);