-
Notifications
You must be signed in to change notification settings - Fork 371
/
angular-daterangepicker.min.js
2 lines (2 loc) · 5.6 KB
/
angular-daterangepicker.min.js
1
2
(function(){var a;a=angular.module("daterangepicker",[]),a.constant("dateRangePickerConfig",{cancelOnOutsideClick:!0,locale:{separator:" - ",format:"YYYY-MM-DD",clearLabel:"Clear"}}),a.directive("dateRangePicker",["$compile","$timeout","$parse","dateRangePickerConfig",function(a,b,c,d){return{require:"ngModel",restrict:"A",scope:{min:"=",max:"=",picker:"=?",model:"=ngModel",opts:"=options",clearable:"="},link:function(a,c,e,f){var g,h,i,j,k,l,m,n,o,p,q,r,s,t;return j=function(){var a,b;return b=angular.extend.apply(angular,Array.prototype.slice.call(arguments).map(function(a){return null!=a?a.locale:void 0}).filter(function(a){return!!a})),a=angular.extend.apply(angular,arguments),a.locale=b,a},r=$(c),r.attr("ng-trim","false"),e.ngTrim="false",p=!1,function(){var a,b;if(f.$options&&"function"==typeof f.$options.getOption?(b=f.$options.getOption("updateOn"),p=!!f.$options.getOption("allowInvalid")):(b=f.$options&&f.$options.updateOn||"",p=!(!f.$options||!f.$options.allowInvalid)),!b.includes("change"))return"function"==typeof f.$overrideModelOptions?(b+=" change",f.$overrideModelOptions({"*":"$inherit",updateOn:b})):(b+=" change",b.replace(/default/g," "),a=angular.copy(f.$options)||{},a.updateOn=b,a.updateOnDefault=!1,f.$options=a)}(),q=a.opts,t=j({},angular.copy(d),q),k=null,g=function(){if(k)return k.setStartDate(),k.setEndDate()},l=function(a){return function(b){if(b&&(!moment.isMoment(b)||b.isValid()))return b=moment(b),k?a(b):void 0}},n=l(function(a){return a&&k.endDate<a&&k.setEndDate(a),k.setStartDate(a),t.startDate=k.startDate}),m=l(function(a){return a&&k.startDate>a?(k.setEndDate(k.startDate),t.endDate=k.endDate,k.setStartDate(a),t.startDate=k.startDate):(k.setEndDate(a),t.endDate=k.endDate)}),s=function(a){var b;return b=function(a){return moment.isMoment(a)?a.format(t.locale.format):moment(a).format(t.locale.format)},t.singleDatePicker&&a?b(a):a&&(a.startDate||a.endDate)?[b(a.startDate),b(a.endDate)].join(t.locale.separator):""},f.$formatters.push(function(a){return s(a)}),f.$renderOriginal=f.$render,f.$render=function(){if(f.$modelValue&&t.singleDatePicker?(n(f.$modelValue),m(f.$modelValue)):f.$modelValue&&(f.$modelValue.startDate||f.$modelValue.endDate)?(n(f.$modelValue.startDate),m(f.$modelValue.endDate)):g(),f.$valid)return f.$renderOriginal()},f.$parsers.push(function(a){var b,c,d;return b=function(a){var b;return b=moment(a,t.locale.format),b.isValid()&&b||null},c=t.singleDatePicker?null:{startDate:null,endDate:null},angular.isString(a)&&a.length>0&&(t.singleDatePicker?c=b(a):(d=a.split(t.locale.separator).map(b),c.startDate=d[0]?d[0].startOf("day"):null,c.endDate=d[1]?d[1].endOf("day"):null)),c}),f.$isEmpty=function(a){return!(angular.isString(a)&&a.length>0)},h=function(){var b;r.daterangepicker(angular.extend(t,{autoUpdateInput:!1}),function(b,c,d){return a.$apply(function(){if("function"==typeof t.changeCallback)return t.changeCallback.apply(this,arguments)})}),k=r.data("daterangepicker"),a.picker=k,k.container.hide(),k.container.addClass((t.pickerClasses||"")+" "+(e.pickerClasses||"")),r.on("show.daterangepicker",function(b,c){return r.addClass("picker-open"),a.$apply(function(){t.singleDatePicker?c.startDate.isSame(a.model)||(n(a.model),m(a.model)):(a.model&&!c.startDate.isSame(a.model.startDate)&&n(a.model.startDate),a.model&&!c.endDate.isSame(a.model.endDate)&&m(a.model.endDate)),c.updateView()})}),r.on("hide.daterangepicker",function(a,b){return r.removeClass("picker-open")}),r.on("apply.daterangepicker",function(b,c){return a.$apply(function(){t.singleDatePicker?c.startDate?c.startDate.isSame(a.model)||(a.model=c.startDate):a.model=null:c.startDate.isSame(c.oldStartDate)&&c.endDate.isSame(c.oldEndDate)&&a.model&&c.startDate.isSame(a.model.startDate)&&c.endDate.isSame(a.model.endDate)||(a.model={startDate:c.startDate,endDate:c.endDate,label:c.chosenLabel})})}),r.on("outsideClick.daterangepicker",function(b,c){return t.cancelOnOutsideClick?a.$apply(function(){return c.cancelingClick=!0,c.clickCancel()}):c.clickApply()});for(b in t.eventHandlers)r.on(b,function(b,c){var d;return d=b.type+"."+b.namespace,a.$evalAsync(t.eventHandlers[d])});if(f.$validate(),!a.model)return r.trigger("change")},a.$watch(function(){return s(a.model)},function(a){return"function"==typeof f.$processModelValue?(f.$processModelValue(),f.$render()):("function"==typeof f.$$updateEmptyClasses&&f.$$updateEmptyClasses(a),f.$viewValue=f.$$lastCommittedViewValue=a,f.$render())}),f.$validators.invalid=function(a,b){var c,d;return c=e.required&&!f.$isEmpty(b),d=t.singleDatePicker?a&&a.isValid():a&&a.startDate&&a.startDate.isValid()&&a.endDate&&a.endDate.isValid(),!c||!!d},o=function(a,b,c){var d;return!a||!b&&!c||(d=[a,b,c].map(function(a){return a?moment(a):a}),a=d[0],b=d[1],c=d[2],(!b||b.isBefore(a)||b.isSame(a,"day"))&&(!c||c.isSame(a,"day")||c.isAfter(a)))},i=function(c,d,g,h){if(f.$validators[c]=function(a){return!t[h]||(t.singleDatePicker?"min"===c?!a||d(a,t.minDate,a):"max"===c?!a||d(a,a,t.maxDate):void 0:a&&d(a[g],t.minDate,t.maxDate))},e[c])return a.$watch(c,function(a){if(t[h]=!!a&&moment(a),k)return k[h]=t[h],b(function(){return f.$validate()})})},i("min",o,"startDate","minDate"),i("max",o,"endDate","maxDate"),a.$watch("opts",function(a){return null==a&&(a={}),t=j(t,a),h()},!0),e.clearable&&a.$watch("clearable",function(c){if(c&&(t=j(t,{locale:{cancelLabel:t.locale.clearLabel}})),h(),c)return r.on("cancel.daterangepicker",function(c,d){return d.cancelingClick||(a.model=t.singleDatePicker?null:{startDate:null,endDate:null},r.val("")),d.cancelingClick=null,b(function(){return a.$apply()})})}),a.$on("$destroy",function(){return null!=k?k.remove():void 0})}}}])}).call(this);
//# sourceMappingURL=angular-daterangepicker.min.js.map