forked from mgcrea/angular-strap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatepicker.min.js
More file actions
9 lines (9 loc) · 11.2 KB
/
datepicker.min.js
File metadata and controls
9 lines (9 loc) · 11.2 KB
1
2
3
4
5
6
7
8
9
/**
* angular-strap
* @version v2.3.8 - 2016-03-31
* @link http://mgcrea.github.io/angular-strap
* @author Olivier Louvignes <olivier@mg-crea.com> (https://github.com/mgcrea)
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
'use strict';angular.module('mgcrea.ngStrap.datepicker',['mgcrea.ngStrap.helpers.dateParser','mgcrea.ngStrap.helpers.dateFormatter','mgcrea.ngStrap.tooltip']).provider('$datepicker',function(){var e=this.defaults={animation:'am-fade',prefixClass:'datepicker',placement:'bottom-left',templateUrl:'datepicker/datepicker.tpl.html',trigger:'focus',container:!1,keyboard:!0,html:!1,delay:0,useNative:!1,dateType:'date',dateFormat:'shortDate',timezone:null,modelDateFormat:null,dayFormat:'dd',monthFormat:'MMM',yearFormat:'yyyy',monthTitleFormat:'MMMM yyyy',yearTitleFormat:'yyyy',strictFormat:!1,autoclose:!1,minDate:-(1/0),maxDate:+(1/0),startView:0,minView:0,startWeek:0,daysOfWeekDisabled:'',iconLeft:'glyphicon glyphicon-chevron-left',iconRight:'glyphicon glyphicon-chevron-right'};this.$get=['$window','$document','$rootScope','$sce','$dateFormatter','datepickerViews','$tooltip','$timeout',function(t,a,n,i,o,r,s,d){function l(t,a,n){function i(e){e.selected=l.$isSelected(e.date)}function o(){t[0].focus()}var l=s(t,angular.extend({},e,n)),g=n.scope,m=l.$options,f=l.$scope;m.startView&&(m.startView-=m.minView);var $=r(l);l.$views=$.views;var h=$.viewDate;f.$mode=m.startView,f.$iconLeft=m.iconLeft,f.$iconRight=m.iconRight;var D=l.$views[f.$mode];f.$select=function(e){l.select(e)},f.$selectPane=function(e){l.$selectPane(e)},f.$toggleMode=function(){l.setMode((f.$mode+1)%l.$views.length)},l.update=function(e){angular.isDate(e)&&!isNaN(e.getTime())&&(l.$date=e,D.update.call(D,e)),l.$build(!0)},l.updateDisabledDates=function(e){m.disabledDateRanges=e;for(var t=0,a=f.rows.length;a>t;t++)angular.forEach(f.rows[t],l.$setDisabledEl)},l.select=function(e,t){angular.isDate(a.$dateValue)||(a.$dateValue=new Date(e)),!f.$mode||t?(a.$setViewValue(angular.copy(e)),a.$render(),m.autoclose&&!t&&d(function(){l.hide(!0)})):(angular.extend(h,{year:e.getFullYear(),month:e.getMonth(),date:e.getDate()}),l.setMode(f.$mode-1),l.$build())},l.setMode=function(e){f.$mode=e,D=l.$views[f.$mode],l.$build()},l.$build=function(e){e===!0&&D.built||(e!==!1||D.built)&&D.build.call(D)},l.$updateSelected=function(){for(var e=0,t=f.rows.length;t>e;e++)angular.forEach(f.rows[e],i)},l.$isSelected=function(e){return D.isSelected(e)},l.$setDisabledEl=function(e){e.disabled=D.isDisabled(e.date)},l.$selectPane=function(e){var t=D.steps,a=new Date(Date.UTC(h.year+(t.year||0)*e,h.month+(t.month||0)*e,1));angular.extend(h,{year:a.getUTCFullYear(),month:a.getUTCMonth(),date:a.getUTCDate()}),l.$build()},l.$onMouseDown=function(e){if(e.preventDefault(),e.stopPropagation(),c){var t=angular.element(e.target);'button'!==t[0].nodeName.toLowerCase()&&(t=t.parent()),t.triggerHandler('click')}},l.$onKeyDown=function(e){if(/(38|37|39|40|13)/.test(e.keyCode)&&!e.shiftKey&&!e.altKey){if(e.preventDefault(),e.stopPropagation(),13===e.keyCode)return void(f.$mode?f.$apply(function(){l.setMode(f.$mode-1)}):l.hide(!0));D.onKeyDown(e),g.$digest()}};var p=l.init;l.init=function(){return u&&m.useNative?(t.prop('type','date'),void t.css('-webkit-appearance','textfield')):(c&&(t.prop('type','text'),t.attr('readonly','true'),t.on('click',o)),void p())};var y=l.destroy;l.destroy=function(){u&&m.useNative&&t.off('click',o),y()};var w=l.show;l.show=function(){!c&&t.attr('readonly')||t.attr('disabled')||(w(),d(function(){l.$isShown&&(l.$element.on(c?'touchstart':'mousedown',l.$onMouseDown),m.keyboard&&t.on('keydown',l.$onKeyDown))},0,!1))};var b=l.hide;return l.hide=function(e){l.$isShown&&(l.$element.off(c?'touchstart':'mousedown',l.$onMouseDown),m.keyboard&&t.off('keydown',l.$onKeyDown),b(e))},l}var u=/(ip[ao]d|iphone|android)/gi.test(t.navigator.userAgent),c='createTouch'in t.document&&u;return e.lang||(e.lang=o.getDefaultLocale()),l.defaults=e,l}]}).directive('bsDatepicker',['$window','$parse','$q','$dateFormatter','$dateParser','$datepicker',function(e,t,a,n,i,o){var r=/(ip[ao]d|iphone|android)/gi.test(e.navigator.userAgent);return{restrict:'EAC',require:'ngModel',link:function(e,t,a,s){function d(e){return e&&e.length?e:null}function l(e){if(angular.isDate(e)){var t=isNaN(m.$options.minDate)||e.getTime()>=m.$options.minDate,a=isNaN(m.$options.maxDate)||e.getTime()<=m.$options.maxDate,n=t&&a;s.$setValidity('date',n),s.$setValidity('min',t),s.$setValidity('max',a),n&&(s.$dateValue=e)}}function u(){return!s.$dateValue||isNaN(s.$dateValue.getTime())?'':$(s.$dateValue,c.dateFormat)}var c={scope:e};angular.forEach(['template','templateUrl','controller','controllerAs','placement','container','delay','trigger','html','animation','autoclose','dateType','dateFormat','timezone','modelDateFormat','dayFormat','strictFormat','startWeek','startDate','useNative','lang','startView','minView','iconLeft','iconRight','daysOfWeekDisabled','id','prefixClass','prefixEvent'],function(e){angular.isDefined(a[e])&&(c[e]=a[e])});var g=/^(false|0|)$/i;angular.forEach(['html','container','autoclose','useNative'],function(e){angular.isDefined(a[e])&&g.test(a[e])&&(c[e]=!1)});var m=o(t,s,c);c=m.$options,r&&c.useNative&&(c.dateFormat='yyyy-MM-dd');var f=c.lang,$=function(e,t){return n.formatDate(e,t,f)},h=i({format:c.dateFormat,lang:f,strict:c.strictFormat});a.bsShow&&e.$watch(a.bsShow,function(e,t){m&&angular.isDefined(e)&&(angular.isString(e)&&(e=!!e.match(/true|,?(datepicker),?/i)),e===!0?m.show():m.hide())}),angular.forEach(['minDate','maxDate'],function(e){angular.isDefined(a[e])&&a.$observe(e,function(t){m.$options[e]=h.getDateForAttribute(e,t),isNaN(m.$options[e])||m.$build(!1),l(s.$dateValue)})}),angular.isDefined(a.dateFormat)&&a.$observe('dateFormat',function(e){m.$options.dateFormat=e}),e.$watch(a.ngModel,function(e,t){m.update(s.$dateValue)},!0),angular.isDefined(a.disabledDates)&&e.$watch(a.disabledDates,function(e,t){e=d(e),t=d(t),e&&m.updateDisabledDates(e)}),s.$parsers.unshift(function(e){var t;if(!e)return s.$setValidity('date',!0),null;var a=h.parse(e,s.$dateValue);return!a||isNaN(a.getTime())?void s.$setValidity('date',!1):(l(a),'string'===c.dateType?(t=h.timezoneOffsetAdjust(a,c.timezone,!0),$(t,c.modelDateFormat||c.dateFormat)):(t=h.timezoneOffsetAdjust(s.$dateValue,c.timezone,!0),'number'===c.dateType?t.getTime():'unix'===c.dateType?t.getTime()/1e3:'iso'===c.dateType?t.toISOString():new Date(t)))}),s.$formatters.push(function(e){var t;return t=angular.isUndefined(e)||null===e?NaN:angular.isDate(e)?e:'string'===c.dateType?h.parse(e,null,c.modelDateFormat):'unix'===c.dateType?new Date(1e3*e):new Date(e),s.$dateValue=h.timezoneOffsetAdjust(t,c.timezone),u()}),s.$render=function(){t.val(u())},e.$on('$destroy',function(){m&&m.destroy(),c=null,m=null})}}}]).provider('datepickerViews',function(){function e(e,t){for(var a=[];e.length>0;)a.push(e.splice(0,t));return a}function t(e,t){return(e%t+t)%t}this.$get=['$dateFormatter','$dateParser','$sce',function(a,n,i){return function(o){var r=o.$scope,s=o.$options,d=s.lang,l=function(e,t){return a.formatDate(e,t,d)},u=n({format:s.dateFormat,lang:d,strict:s.strictFormat}),c=a.weekdaysShort(d),g=c.slice(s.startWeek).concat(c.slice(0,s.startWeek)),m=i.trustAsHtml('<th class="dow text-center">'+g.join('</th><th class="dow text-center">')+'</th>'),f=o.$date||(s.startDate?u.getDateForAttribute('startDate',s.startDate):new Date),$={year:f.getFullYear(),month:f.getMonth(),date:f.getDate()},h=[{format:s.dayFormat,split:7,steps:{month:1},update:function(e,t){!this.built||t||e.getFullYear()!==$.year||e.getMonth()!==$.month?(angular.extend($,{year:o.$date.getFullYear(),month:o.$date.getMonth(),date:o.$date.getDate()}),o.$build()):(e.getDate()!==$.date||1===e.getDate())&&($.date=o.$date.getDate(),o.$updateSelected())},build:function(){var a=new Date($.year,$.month,1),n=a.getTimezoneOffset(),i=new Date(+a-864e5*t(a.getDay()-s.startWeek,7)),d=i.getTimezoneOffset(),c=u.timezoneOffsetAdjust(new Date,s.timezone).toDateString();d!==n&&(i=new Date(+i+6e4*(d-n)));for(var g,f=[],h=0;42>h;h++)g=u.daylightSavingAdjust(new Date(i.getFullYear(),i.getMonth(),i.getDate()+h)),f.push({date:g,isToday:g.toDateString()===c,label:l(g,this.format),selected:o.$date&&this.isSelected(g),muted:g.getMonth()!==$.month,disabled:this.isDisabled(g)});r.title=l(a,s.monthTitleFormat),r.showLabels=!0,r.labels=m,r.rows=e(f,this.split),this.built=!0},isSelected:function(e){return o.$date&&e.getFullYear()===o.$date.getFullYear()&&e.getMonth()===o.$date.getMonth()&&e.getDate()===o.$date.getDate()},isDisabled:function(e){var t=e.getTime();if(t<s.minDate||t>s.maxDate)return!0;if(-1!==s.daysOfWeekDisabled.indexOf(e.getDay()))return!0;if(s.disabledDateRanges)for(var a=0;a<s.disabledDateRanges.length;a++)if(t>=s.disabledDateRanges[a].start&&t<=s.disabledDateRanges[a].end)return!0;return!1},onKeyDown:function(e){if(o.$date){var t,a=o.$date.getTime();37===e.keyCode?t=new Date(a-864e5):38===e.keyCode?t=new Date(a-6048e5):39===e.keyCode?t=new Date(a+864e5):40===e.keyCode&&(t=new Date(a+6048e5)),this.isDisabled(t)||o.select(t,!0)}}},{name:'month',format:s.monthFormat,split:4,steps:{year:1},update:function(e,t){this.built&&e.getFullYear()===$.year?e.getMonth()!==$.month&&(angular.extend($,{month:o.$date.getMonth(),date:o.$date.getDate()}),o.$updateSelected()):(angular.extend($,{year:o.$date.getFullYear(),month:o.$date.getMonth(),date:o.$date.getDate()}),o.$build())},build:function(){for(var t,a=[],n=0;12>n;n++)t=new Date($.year,n,1),a.push({date:t,label:l(t,this.format),selected:o.$isSelected(t),disabled:this.isDisabled(t)});r.title=l(t,s.yearTitleFormat),r.showLabels=!1,r.rows=e(a,this.split),this.built=!0},isSelected:function(e){return o.$date&&e.getFullYear()===o.$date.getFullYear()&&e.getMonth()===o.$date.getMonth()},isDisabled:function(e){var t=+new Date(e.getFullYear(),e.getMonth()+1,0);return t<s.minDate||e.getTime()>s.maxDate},onKeyDown:function(e){if(o.$date){var t=o.$date.getMonth(),a=new Date(o.$date);37===e.keyCode?a.setMonth(t-1):38===e.keyCode?a.setMonth(t-4):39===e.keyCode?a.setMonth(t+1):40===e.keyCode&&a.setMonth(t+4),this.isDisabled(a)||o.select(a,!0)}}},{name:'year',format:s.yearFormat,split:4,steps:{year:12},update:function(e,t){!this.built||t||parseInt(e.getFullYear()/20,10)!==parseInt($.year/20,10)?(angular.extend($,{year:o.$date.getFullYear(),month:o.$date.getMonth(),date:o.$date.getDate()}),o.$build()):e.getFullYear()!==$.year&&(angular.extend($,{year:o.$date.getFullYear(),month:o.$date.getMonth(),date:o.$date.getDate()}),o.$updateSelected())},build:function(){for(var t,a=$.year-$.year%(3*this.split),n=[],i=0;12>i;i++)t=new Date(a+i,0,1),n.push({date:t,label:l(t,this.format),selected:o.$isSelected(t),disabled:this.isDisabled(t)});r.title=n[0].label+'-'+n[n.length-1].label,r.showLabels=!1,r.rows=e(n,this.split),this.built=!0},isSelected:function(e){return o.$date&&e.getFullYear()===o.$date.getFullYear()},isDisabled:function(e){var t=+new Date(e.getFullYear()+1,0,0);return t<s.minDate||e.getTime()>s.maxDate},onKeyDown:function(e){if(o.$date){var t=o.$date.getFullYear(),a=new Date(o.$date);37===e.keyCode?a.setYear(t-1):38===e.keyCode?a.setYear(t-4):39===e.keyCode?a.setYear(t+1):40===e.keyCode&&a.setYear(t+4),this.isDisabled(a)||o.select(a,!0)}}}];return{views:s.minView?Array.prototype.slice.call(h,s.minView):h,viewDate:$}}}]});
//# sourceMappingURL=datepicker.min.js.map