-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-date-binder.min.js
1 lines (1 loc) · 1.41 KB
/
angular-date-binder.min.js
1
"use strict";angular.module("angularDateBinder",[]).directive("bindDate",["$parse",function(e){return{restrict:"A",scope:!0,link:function(t,n,a){var r=function(e,t){var n=null==e||"undefined"==typeof e||e.constructor===Date;if(t&&!n)throw new Error("Expected `"+a.bindDate+"` to be a date");return n},u=function(e,t){return!!e&&!!t&&r(e)&&r(t)&&e.getTime()===t.getTime()},o=null,i=e(a.bindDate),c=e(a.bindDate).assign,s=function(){var e=i(t.$parent);return r(e,!0),e},l=function(e){c(t.$parent,e),c(t,e)},$=function(e){null!=o?(null!=e||e||(o=new Date(o.getTime())),t.$year=o.getFullYear(),t.$month=o.getMonth()+1,t.$date=o.getDate(),t.$hour=o.getHours(),t.$minute=o.getMinutes(),t.$second=o.getSeconds(),t.$lastDate=new Date(o.getFullYear(),o.getMonth()+1,0).getDate(),l(o)):t.$year=t.$month=t.$date=t.$hour=t.$minute=t.$second=t.$lastDate=null},d=function(e,t){(null==e||r(e,!0)&&!u(e,t))&&(o=e,$())};t.$parent.$watch(a.bindDate,d),t.$watch(a.bindDate,d);var D=[{key:"$year",setFunc:Date.prototype.setFullYear},{key:"$month",setFunc:function(e){this.setMonth(e-1)}},{key:"$date",setFunc:Date.prototype.setDate},{key:"$hour",setFunc:Date.prototype.setHours},{key:"$minute",setFunc:Date.prototype.setMinutes},{key:"$second",setFunc:Date.prototype.setSeconds},{key:"$year",setFunc:Date.prototype.setFullYear}];for(var p in D)!function(){var e=D[p].key,n=D[p].setFunc;t.$watch(e,function(e,t){e&&e!==t&&(n.call(o,e),$())})}();o=s(!1),$()}}}]);