-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatepicker.min.js
1 lines (1 loc) · 5.97 KB
/
datepicker.min.js
1
!function(a,t,e){"use strict";t.datepicker&&!t.datepicker.modifiedSetDate&&(t.datepicker._setDate=function(){var a=t.datepicker._setDate;return function(t){a.apply(this,arguments),t.input.trigger("change")}}(),t.datepicker.modifiedSetDate=!0),a.Datepicker=a.Datepicker||function(){var n="mm/dd/yy",d=".date-picker",r="date-picker-container",i="input[name]"+d,p="dp-pan",s="span.dp-pan",c=!1,o=function(a){var n=t(a).length&&t(a)||t(i),d=t("<div>").addClass(r+" pan-inputs"),s=t("<span>").addClass(p);n.each(function(){var a,n=t(this),r=l(n),i=t("<input>").attr({type:"hidden"}),p=0!==n.siblings(".hasDatepicker").length,c=t("<a>").attr("title","Clear the set date").addClass("clear-icon").on("click",function(){return i.datepicker("setDate",""),!1}),o=s.clone().addClass("left"),D=s.clone().addClass("right"),m=function(a,t){var e,n=864e5;return a=new Date(a),t=new Date(t),e=Math.round(Math.abs((a.getTime()-t.getTime())/n))},h=function(a,t){return""!=a&&(a=new Date(a),a.setDate(a.getDate()+t)),a},g=function(){c.toggle(r.clearIcon&&!r.disabled&&null!==i.datepicker("getDate"))},k=function(){r.disabled||!r.showPans||null===i.datepicker("getDate")?(o.hide(),D.hide()):(o.show(),D.show())},y=function(){var a,n,d,p;n=i.val(),null!==r.dateSpanStart&&""!=n&&(n=new Date(n),a=t("#"+r.dateSpanStart),a.length>0&&(d=a.val(),""!==d&&(d=new Date(d),null!==r.maxDaySpan&&(p=m(n,d),p>r.maxDaySpan&&(d=h(n,-r.maxDaySpan))),d>n&&(d=n),d.getTime()!=new Date(a.val()).getTime()&&(a.data("datepicker_ID")!==e?t("#"+a.data("datepicker_ID")).datepicker("setDate",d):a.val(d))))),null!==r.dateSpanEnd&&""!=n&&(n=new Date(n),a=t("#"+r.dateSpanEnd),a.length>0&&(d=a.val(),""!=d&&(d=new Date(d),null!==r.maxDaySpan&&(p=m(n,d),p>r.maxDaySpan&&(d=h(n,r.maxDaySpan))),n>d&&(d=n),d.getTime()!=new Date(a.val()).getTime()&&(a.data("datepicker_ID")!==e?t("#"+a.data("datepicker_ID")).datepicker("setDate",d):a.val(d)))))};n.attr("placeholder","Select Date").addClass("form-control").destroy=function(){var a=t("#"+t(this).data("datepicker_ID"));t(this).prop({readonly:!1,disabled:!1}),t(this).val(a.val()),a.datepicker("destroy"),t(this).siblings().remove(),t(this).unwrap(),t(this).attr("name",n.data("name"))},p&&n.destroy(),r.altField=n,i.data(n.data()),i.val(n.val()),i.attr("name",n.attr("name")),n.attr("id")!==e&&i.attr("id","dp_"+n.attr("id")),i.datepicker(r).on("change",g).on("change",k).on("change",y),a=i.datepicker("getDate"),"date"!==t.type(a)&&r.disabled?i.datepicker("setDate",u(new Date,i)):"date"===t.type(a)&&i.datepicker("setDate",u(a,i)),n.wrap(d.clone()).before(i).before(o).after(D).after(c).data("name",n.attr("name")).removeAttr("name").data("datepicker_ID",i.attr("id")).addClass("inset").prop({readonly:!0,disabled:r.disabled}),y(),g(),k(),n.trigger("dpinit")})},l=function(a){var d={altField:null,altFormat:D(a.data("pan")).altFormat,firstDay:1,dateFormat:D(a.data("pan")).displayFormat,onSelect:function(a,e){a!==e.lastVal&&t(this).trigger("change",[a,e])},disabled:"month"===a.data("pan")||"year"===a.data("pan")||a.prop("disabled"),showWeek:"week"===a.data("pan"),clearIcon:a.data("clearicon")!==e&&""!==t.trim(a.data("clearicon"))&&a.data("clearicon"),maxDaySpan:null,dateSpanStart:null,dateSpanEnd:null,showPans:a.data("showpans")!==!1,changeMonth:a.data("changemonth")!==e&&""!==t.trim(a.data("changemonth"))&&a.data("changemonth"),changeYear:a.data("changeyear")!==e&&""!==t.trim(a.data("changeyear"))&&a.data("changeyear")};return a.data("mindate")!==e&&""!==t.trim(a.data("mindate"))&&(d.minDate=t.datepicker.parseDate(n,a.data("mindate"))),a.data("maxdate")!==e&&""!==t.trim(a.data("maxdate"))&&(d.maxDate=t.datepicker.parseDate(n,a.data("maxdate"))),a.data("maxdayspan")!==e&&""!==t.trim(a.data("maxdayspan"))&&a.data("maxdayspan")>=0&&(d.maxDaySpan=a.data("maxdayspan")),a.data("datespanstart")!==e&&""!==t.trim(a.data("datespanstart"))&&t("#"+a.data("datespanstart")).length>0&&(d.dateSpanStart=a.data("datespanstart")),a.data("datespanend")!==e&&""!==t.trim(a.data("datespanend"))&&t("#"+a.data("datespanend")).length>0&&(d.dateSpanEnd=a.data("datespanend")),d},D=function(a){switch(a){case"month":return{altFormat:"M, yy",displayFormat:n};case"year":return{altFormat:"yy",displayFormat:n};default:return{altFormat:"D, M d, yy",displayFormat:n}}},m=function(){var e,n="."+r+" "+s;c||(t(a.document.body).on("click.date-picker",d,function(a){a.preventDefault();var e=t(this),n=e.parent().children(".hasDatepicker");return n.datepicker("widget").is(":visible")?!1:(n.datepicker("show"),void n.datepicker("widget").position({my:"top",at:"bottom",of:e}))}),t(a.document.body).on({"mousedown.date-picker-pan":function(a){if(a.preventDefault(),1===a.which){var n=t(this),d=500,r=75,i=function(a){var p,s=n.parent().children(".hasDatepicker"),c=s.data("pan")||"day",o=s.datepicker("getDate"),l=n.hasClass("right"),D=s.datepicker("option","minDate"),m=s.datepicker("option","maxDate");if("date"===t.type(o))switch(c.toLowerCase()){case"week":var h=(o.getDay()+6)%7;o.setDate(o.getDate()-h),p=new Date(o),l?(o.setDate(o.getDate()+7),m&&o>m&&(o=p)):(o.setDate(o.getDate()-7),D&&D>o&&(o=p));break;case"month":o.setMonth(l?o.getMonth()+1:o.getMonth()-1);break;case"year":o.setFullYear(l?o.getFullYear()+1:o.getFullYear()-1);break;default:o.setDate(l?o.getDate()+1:o.getDate()-1)}o=u(o,n),o&&(s.datepicker("setDate",o),e=setTimeout(i,a||d)),d>r&&(d+=d/7*-1)};i(500)}},"mouseup.date-picker-pan":function(a){a.preventDefault(),clearTimeout(e)},"mouseleave.date-picker-pan":function(a){a.preventDefault(),clearTimeout(e)}},n),c=!0)},u=function(a,e){var n,d,r,i,p,s=e.data("pan")||"",c=e.datepicker("option","minDate"),o=e.datepicker("option","maxDate");if("date"===t.type(a))switch(s){case"month":a.setDate(1);break;case"year":a.setMonth(0,1);break;case"week":c&&(d=new Date(c),r=(c.getDay()+6)%7,d.setDate(d.getDate()-r),c>d&&d.setDate(d.getDate()+7)),o&&(i=new Date(o),p=(o.getDay()+6)%7,i.setDate(i.getDate()-p),i>o&&i.setDate(i.getDate()-7)),n=(a.getDay()+6)%7,a.setDate(a.getDate()-n),c&&d>a?a=d:o&&a>i&&(a=i)}return a};return{init:function(a){o(a),m()}}}(),t(function(){a.Datepicker.init()})}(window,jQuery);