i||a.getMonth()>=n)}return{getFirstDateOfMonth:t,getNumberOfDaysInMonth:a,getDateInNextMonth:n,getDateInPreviousMonth:i,isInNextMonth:s,isInPreviousMonth:d,getDateMidpoint:o,isSameMonthAndYear:r,getWeekOfMonth:c,incrementDays:h,incrementMonths:u,getLastDateOfMonth:p,isSameDay:l,getMonthDistance:m,isValidDate:f,setDateTimeToMidnight:g,createDateAtMidnight:D,isDateWithinRange:C,incrementYears:v,getYearDistance:y,clampDate:$,getTimestampFromNode:b,isMonthWithinRange:M}})}(),function(){function a(t,a,i,r){return{template:function(e,a){var n=a.mdHideIcons,i=a.ariaLabel||a.mdPlaceholder,r="all"===n||"calendar"===n?"":' ',l="";return"all"!==n&&"triangle"!==n&&(l='
',e.addClass(o)),r+' '+l+'
'},require:["ngModel","mdDatepicker","?^mdInputContainer","?^form"],scope:{minDate:"=mdMinDate",maxDate:"=mdMaxDate",placeholder:"@mdPlaceholder",currentView:"@mdCurrentView",dateFilter:"=mdDateFilter",isOpen:"=?mdIsOpen",debounceInterval:"=mdDebounceInterval",dateLocale:"=mdDateLocale"},controller:n,controllerAs:"ctrl",bindToController:!0,link:function(t,n,l,o){var c=o[0],h=o[1],u=o[2],m=o[3],p=a.parseAttributeBoolean(l.mdNoAsterisk);if(h.configureNgModel(c,u,r),u){var f=n[0].querySelector(".md-errors-spacer");f&&n.after(e.element("").append(f)),u.setHasPlaceholder(l.mdPlaceholder),u.input=n,u.element.addClass(s).toggleClass(d,"calendar"!==l.mdHideIcons&&"all"!==l.mdHideIcons),u.label?p||l.$observe("required",function(t){u.label.toggleClass("md-required",!!t)}):i.expect(n,"aria-label",l.mdPlaceholder),t.$watch(u.isErrorGetter||function(){return c.$invalid&&(c.$touched||m&&m.$submitted)},u.setInvalid)}else if(m)var g=t.$watch(function(){return m.$submitted},function(t){t&&(h.updateErrorState(),g())})}}}function n(a,n,i,r,l,s,d,o,c,h,u){this.$window=r,this.dateUtil=c,this.$mdConstant=l,this.$mdUtil=d,this.$$rAF=h,this.$mdDateLocale=o,this.documentElement=e.element(document.documentElement),this.ngModelCtrl=null,this.inputElement=n[0].querySelector("input"),this.ngInputElement=e.element(this.inputElement),this.inputContainer=n[0].querySelector(".md-datepicker-input-container"),this.calendarPane=n[0].querySelector(".md-datepicker-calendar-pane"),this.calendarButton=n[0].querySelector(".md-datepicker-button"),this.inputMask=e.element(n[0].querySelector(".md-datepicker-input-mask-opaque")),this.$element=n,this.$attrs=i,this.$scope=a,this.date=null,this.isFocused=!1,this.isDisabled,this.setDisabled(n[0].disabled||e.isString(i.disabled)),this.isCalendarOpen=!1,this.openOnFocus=i.hasOwnProperty("mdOpenOnFocus"),this.mdInputContainer=null,this.calendarPaneOpenedFrom=null,this.calendarPaneId="md-date-pane-"+d.nextUid(),this.bodyClickHandler=e.bind(this,this.handleBodyClick),this.windowEventName=m.test(navigator.userAgent||navigator.vendor||t.opera)?"orientationchange":"resize",this.windowEventHandler=d.debounce(e.bind(this,this.closeCalendarPane),100),this.windowBlurHandler=e.bind(this,this.handleWindowBlur),this.ngDateFilter=u("date"),this.leftMargin=20,this.topMargin=null,i.tabindex?(this.ngInputElement.attr("tabindex",i.tabindex),i.$set("tabindex",null)):i.$set("tabindex","-1"),i.$set("aria-owns",this.calendarPaneId),s(n),s(e.element(this.calendarPane));var p=this;a.$on("$destroy",function(){p.detachCalendarPane()}),i.mdIsOpen&&a.$watch("ctrl.isOpen",function(t){t?p.openCalendarPane({target:p.inputElement}):p.closeCalendarPane()}),1===e.version.major&&e.version.minor<=4&&this.$onInit()}n.$inject=["$scope","$element","$attrs","$window","$mdConstant","$mdTheming","$mdUtil","$mdDateLocale","$$mdDateUtil","$$rAF","$filter"],a.$inject=["$$mdSvgRegistry","$mdUtil","$mdAria","inputDirective"],e.module("material.components.datepicker").directive("mdDatepicker",a);var i=3,r="md-datepicker-invalid",l="md-datepicker-open",s="_md-datepicker-floating-label",d="_md-datepicker-has-calendar-icon",o="_md-datepicker-has-triangle-icon",c=500,h=368,u=360,m=/ipad|iphone|ipod|android/i;n.prototype.$onInit=function(){this.locale=this.dateLocale?e.extend({},this.$mdDateLocale,this.dateLocale):this.$mdDateLocale,this.installPropertyInterceptors(),this.attachChangeListeners(),this.attachInteractionListeners()},n.prototype.configureNgModel=function(t,a,n){this.ngModelCtrl=t,this.mdInputContainer=a,this.$attrs.$set("type","date"),n[0].link.pre(this.$scope,{on:e.noop,val:e.noop,0:{}},this.$attrs,[t]);var i=this;i.ngModelCtrl.$formatters.push(function(t){if(t&&!(t instanceof Date))throw Error("The ng-model for md-datepicker must be a Date instance. Currently the model is a: "+typeof t);return i.onExternalChange(t),t}),t.$viewChangeListeners.unshift(e.bind(this,this.updateErrorState));var r=i.$mdUtil.getModelOption(t,"updateOn");r&&this.ngInputElement.on(r,e.bind(this.$element,this.$element.triggerHandler,r))},n.prototype.attachChangeListeners=function(){var t=this;t.$scope.$on("md-calendar-change",function(e,a){t.setModelValue(a),t.onExternalChange(a),t.closeCalendarPane()}),t.ngInputElement.on("input",e.bind(t,t.resizeInputElement));var a=e.isDefined(this.debounceInterval)?this.debounceInterval:c;t.ngInputElement.on("input",t.$mdUtil.debounce(t.handleInputEvent,a,t))},n.prototype.attachInteractionListeners=function(){var t=this,a=this.$scope,n=this.$mdConstant.KEY_CODE;t.ngInputElement.on("keydown",function(e){e.altKey&&e.keyCode==n.DOWN_ARROW&&(t.openCalendarPane(e),a.$digest())}),t.openOnFocus&&(t.ngInputElement.on("focus",e.bind(t,t.openCalendarPane)),e.element(t.$window).on("blur",t.windowBlurHandler),a.$on("$destroy",function(){e.element(t.$window).off("blur",t.windowBlurHandler)})),a.$on("md-calendar-close",function(){t.closeCalendarPane()})},n.prototype.installPropertyInterceptors=function(){var t=this;if(this.$attrs.ngDisabled){var e=this.$scope.$parent;e&&e.$watch(this.$attrs.ngDisabled,function(e){t.setDisabled(e)})}Object.defineProperty(this,"placeholder",{get:function(){return t.inputElement.placeholder},set:function(e){t.inputElement.placeholder=e||""}})},n.prototype.setDisabled=function(t){this.isDisabled=t,this.inputElement.disabled=t,this.calendarButton&&(this.calendarButton.disabled=t)},n.prototype.updateErrorState=function(t){var a=t||this.date;if(this.clearErrorState(),this.dateUtil.isValidDate(a)){if(a=this.dateUtil.createDateAtMidnight(a),this.dateUtil.isValidDate(this.minDate)){var n=this.dateUtil.createDateAtMidnight(this.minDate);this.ngModelCtrl.$setValidity("mindate",a>=n)}if(this.dateUtil.isValidDate(this.maxDate)){var i=this.dateUtil.createDateAtMidnight(this.maxDate);this.ngModelCtrl.$setValidity("maxdate",a<=i)}e.isFunction(this.dateFilter)&&this.ngModelCtrl.$setValidity("filtered",this.dateFilter(a))}else this.ngModelCtrl.$setValidity("valid",null==a);e.element(this.inputContainer).toggleClass(r,!this.ngModelCtrl.$valid)},n.prototype.clearErrorState=function(){this.inputContainer.classList.remove(r),["mindate","maxdate","filtered","valid"].forEach(function(t){this.ngModelCtrl.$setValidity(t,!0)},this)},n.prototype.resizeInputElement=function(){this.inputElement.size=this.inputElement.value.length+i},n.prototype.handleInputEvent=function(){var t=this.inputElement.value,e=t?this.locale.parseDate(t):null;this.dateUtil.setDateTimeToMidnight(e);var a=""==t||this.dateUtil.isValidDate(e)&&this.locale.isDateComplete(t)&&this.isDateEnabled(e);a&&(this.setModelValue(e),this.date=e),this.updateErrorState(e)},n.prototype.isDateEnabled=function(t){return this.dateUtil.isDateWithinRange(t,this.minDate,this.maxDate)&&(!e.isFunction(this.dateFilter)||this.dateFilter(t))},n.prototype.attachCalendarPane=function(){var t=this.calendarPane,a=document.body;t.style.transform="",this.$element.addClass(l),this.mdInputContainer&&this.mdInputContainer.element.addClass(l),e.element(a).addClass("md-datepicker-is-showing");var n=this.inputContainer.getBoundingClientRect(),i=a.getBoundingClientRect();(!this.topMargin||this.topMargin<0)&&(this.topMargin=(this.inputMask.parent().prop("clientHeight")-this.ngInputElement.prop("clientHeight"))/2);var r=n.top-i.top-this.topMargin,s=n.left-i.left-this.leftMargin,d=i.top<0&&0==document.body.scrollTop?-i.top:document.body.scrollTop,o=i.left<0&&0==document.body.scrollLeft?-i.left:document.body.scrollLeft,c=d+this.$window.innerHeight,m=o+this.$window.innerWidth;if(this.inputMask.css({position:"absolute",left:this.leftMargin+"px",top:this.topMargin+"px",width:n.width-1+"px",height:n.height-2+"px"}),s+u>m){if(m-u>0)s=m-u;else{s=o;var p=this.$window.innerWidth/u;t.style.transform="scale("+p+")"}t.classList.add("md-datepicker-pos-adjusted")}r+h>c&&c-h>d&&(r=c-h,t.classList.add("md-datepicker-pos-adjusted")),
t.style.left=s+"px",t.style.top=r+"px",document.body.appendChild(t),this.$$rAF(function(){t.classList.add("md-pane-open")})},n.prototype.detachCalendarPane=function(){this.$element.removeClass(l),this.mdInputContainer&&this.mdInputContainer.element.removeClass(l),e.element(document.body).removeClass("md-datepicker-is-showing"),this.calendarPane.classList.remove("md-pane-open"),this.calendarPane.classList.remove("md-datepicker-pos-adjusted"),this.isCalendarOpen&&this.$mdUtil.enableScrolling(),this.calendarPane.parentNode&&this.calendarPane.parentNode.removeChild(this.calendarPane)},n.prototype.openCalendarPane=function(e){if(!this.isCalendarOpen&&!this.isDisabled&&!this.inputFocusedOnWindowBlur){this.isCalendarOpen=this.isOpen=!0,this.calendarPaneOpenedFrom=e.target,this.$mdUtil.disableScrollAround(this.calendarPane),this.attachCalendarPane(),this.focusCalendar(),this.evalAttr("ngFocus");var a=this;this.$mdUtil.nextTick(function(){a.documentElement.on("click touchstart",a.bodyClickHandler)},!1),t.addEventListener(this.windowEventName,this.windowEventHandler)}},n.prototype.closeCalendarPane=function(){function e(){a.isCalendarOpen=a.isOpen=!1}if(this.isCalendarOpen){var a=this;a.detachCalendarPane(),a.ngModelCtrl.$setTouched(),a.evalAttr("ngBlur"),a.documentElement.off("click touchstart",a.bodyClickHandler),t.removeEventListener(a.windowEventName,a.windowEventHandler),a.calendarPaneOpenedFrom.focus(),a.calendarPaneOpenedFrom=null,a.openOnFocus?a.$mdUtil.nextTick(e):e()}},n.prototype.getCalendarCtrl=function(){return e.element(this.calendarPane.querySelector("md-calendar")).controller("mdCalendar")},n.prototype.focusCalendar=function(){var t=this;this.$mdUtil.nextTick(function(){t.getCalendarCtrl().focus()},!1)},n.prototype.setFocused=function(t){t||this.ngModelCtrl.$setTouched(),this.openOnFocus||this.evalAttr(t?"ngFocus":"ngBlur"),this.isFocused=t},n.prototype.handleBodyClick=function(t){if(this.isCalendarOpen){var e=this.$mdUtil.getClosest(t.target,"md-calendar");e||this.closeCalendarPane(),this.$scope.$digest()}},n.prototype.handleWindowBlur=function(){this.inputFocusedOnWindowBlur=document.activeElement===this.inputElement},n.prototype.evalAttr=function(t){this.$attrs[t]&&this.$scope.$parent.$eval(this.$attrs[t])},n.prototype.setModelValue=function(t){var e=this.$mdUtil.getModelOption(this.ngModelCtrl,"timezone");this.ngModelCtrl.$setViewValue(this.ngDateFilter(t,"yyyy-MM-dd",e))},n.prototype.onExternalChange=function(t){var e=this.$mdUtil.getModelOption(this.ngModelCtrl,"timezone");this.date=t,this.inputElement.value=this.locale.formatDate(t,e),this.mdInputContainer&&this.mdInputContainer.setHasValue(!!t),this.resizeInputElement(),this.updateErrorState()}}()}(window,window.angular);