Razique Mahroua
2019-11-28 1759c24ad2d2b35ec5c756e3dd3a60185fe944b7
commit | author | age
1759c2 1 /**
RM 2  * angular-strap
3  * @version v2.0.3 - 2014-05-30
4  * @link http://mgcrea.github.io/angular-strap
5  * @author Olivier Louvignes (olivier@mg-crea.com)
6  * @license MIT License, http://www.opensource.org/licenses/MIT
7  */
8 "use strict";angular.module("mgcrea.ngStrap.datepicker",["mgcrea.ngStrap.helpers.dateParser","mgcrea.ngStrap.tooltip"]).provider("$datepicker",function(){var e=this.defaults={animation:"am-fade",prefixClass:"datepicker",placement:"bottom-left",template:"datepicker/datepicker.tpl.html",trigger:"focus",container:!1,keyboard:!0,html:!1,delay:0,useNative:!1,dateType:"date",dateFormat:"shortDate",modelDateFormat:null,dayFormat:"dd",strictFormat:!1,autoclose:!1,minDate:-1/0,maxDate:+1/0,startView:0,minView:0,startWeek:0,iconLeft:"glyphicon glyphicon-chevron-left",iconRight:"glyphicon glyphicon-chevron-right"};this.$get=["$window","$document","$rootScope","$sce","$locale","dateFilter","datepickerViews","$tooltip",function(t,a,n,i,o,r,l,d){function s(t,a,n){function i(e){e.selected=r.$isSelected(e.date)}function o(){t[0].focus()}var r=d(t,angular.extend({},e,n)),s=n.scope,g=r.$options,$=r.$scope;g.startView&&(g.startView-=g.minView);var m=l(r);r.$views=m.views;var h=m.viewDate;$.$mode=g.startView,$.$iconLeft=g.iconLeft,$.$iconRight=g.iconRight;var f=r.$views[$.$mode];$.$select=function(e){r.select(e)},$.$selectPane=function(e){r.$selectPane(e)},$.$toggleMode=function(){r.setMode(($.$mode+1)%r.$views.length)},r.update=function(e){angular.isDate(e)&&!isNaN(e.getTime())&&(r.$date=e,f.update.call(f,e)),r.$build(!0)},r.select=function(e,t){angular.isDate(a.$dateValue)||(a.$dateValue=new Date(e)),a.$dateValue.setFullYear(e.getFullYear(),e.getMonth(),e.getDate()),!$.$mode||t?(a.$setViewValue(a.$dateValue),a.$render(),g.autoclose&&!t&&r.hide(!0)):(angular.extend(h,{year:e.getFullYear(),month:e.getMonth(),date:e.getDate()}),r.setMode($.$mode-1),r.$build())},r.setMode=function(e){$.$mode=e,f=r.$views[$.$mode],r.$build()},r.$build=function(e){e===!0&&f.built||(e!==!1||f.built)&&f.build.call(f)},r.$updateSelected=function(){for(var e=0,t=$.rows.length;t>e;e++)angular.forEach($.rows[e],i)},r.$isSelected=function(e){return f.isSelected(e)},r.$selectPane=function(e){var t=f.steps,a=new Date(Date.UTC(h.year+(t.year||0)*e,h.month+(t.month||0)*e,h.date+(t.day||0)*e));angular.extend(h,{year:a.getUTCFullYear(),month:a.getUTCMonth(),date:a.getUTCDate()}),r.$build()},r.$onMouseDown=function(e){if(e.preventDefault(),e.stopPropagation(),u){var t=angular.element(e.target);"button"!==t[0].nodeName.toLowerCase()&&(t=t.parent()),t.triggerHandler("click")}},r.$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 $.$mode?$.$apply(function(){r.setMode($.$mode-1)}):r.hide(!0);f.onKeyDown(e),s.$digest()}};var p=r.init;r.init=function(){return c&&g.useNative?(t.prop("type","date"),void t.css("-webkit-appearance","textfield")):(u&&(t.prop("type","text"),t.attr("readonly","true"),t.on("click",o)),void p())};var y=r.destroy;r.destroy=function(){c&&g.useNative&&t.off("click",o),y()};var D=r.show;r.show=function(){D(),setTimeout(function(){r.$element.on(u?"touchstart":"mousedown",r.$onMouseDown),g.keyboard&&t.on("keydown",r.$onKeyDown)})};var w=r.hide;return r.hide=function(e){r.$element.off(u?"touchstart":"mousedown",r.$onMouseDown),g.keyboard&&t.off("keydown",r.$onKeyDown),w(e)},r}var u=(angular.element(t.document.body),"createTouch"in t.document),c=/(ip(a|o)d|iphone|android)/gi.test(t.navigator.userAgent);return e.lang||(e.lang=o.id),s.defaults=e,s}]}).directive("bsDatepicker",["$window","$parse","$q","$locale","dateFilter","$datepicker","$dateParser","$timeout",function(e,t,a,n,i,o,r){var l=(o.defaults,/(ip(a|o)d|iphone|android)/gi.test(e.navigator.userAgent)),d=function(e){return!isNaN(parseFloat(e))&&isFinite(e)};return{restrict:"EAC",require:"ngModel",link:function(e,t,a,n){var s={scope:e,controller:n};angular.forEach(["placement","container","delay","trigger","keyboard","html","animation","template","autoclose","dateType","dateFormat","modelDateFormat","dayFormat","strictFormat","startWeek","useNative","lang","startView","minView"],function(e){angular.isDefined(a[e])&&(s[e]=a[e])}),l&&s.useNative&&(s.dateFormat="yyyy-MM-dd");var u=o(t,n,s);s=u.$options,angular.forEach(["minDate","maxDate"],function(e){angular.isDefined(a[e])&&a.$observe(e,function(t){if("today"===t){var a=new Date;u.$options[e]=+new Date(a.getFullYear(),a.getMonth(),a.getDate()+("maxDate"===e?1:0),0,0,0,"minDate"===e?0:-1)}else u.$options[e]=angular.isString(t)&&t.match(/^".+"$/)?+new Date(t.substr(1,t.length-2)):d(t)?+new Date(parseInt(t,10)):+new Date(t);!isNaN(u.$options[e])&&u.$build(!1)})}),e.$watch(a.ngModel,function(){u.update(n.$dateValue)},!0);var c=r({format:s.dateFormat,lang:s.lang,strict:s.strictFormat});n.$parsers.unshift(function(e){if(!e)return void n.$setValidity("date",!0);var t=c.parse(e,n.$dateValue);if(!t||isNaN(t.getTime()))return void n.$setValidity("date",!1);var a=isNaN(u.$options.minDate)||t.getTime()>=u.$options.minDate,o=isNaN(u.$options.maxDate)||t.getTime()<=u.$options.maxDate,r=a&&o;return n.$setValidity("date",r),n.$setValidity("min",a),n.$setValidity("max",o),r&&(n.$dateValue=t),"string"===s.dateType?i(t,s.modelDateFormat||s.dateFormat):"number"===s.dateType?n.$dateValue.getTime():"iso"===s.dateType?n.$dateValue.toISOString():new Date(n.$dateValue)}),n.$formatters.push(function(e){var t;return t=angular.isUndefined(e)||null===e?0/0:angular.isDate(e)?e:"string"===s.dateType?c.parse(e,null,s.modelDateFormat):new Date(e),n.$dateValue=t,n.$dateValue}),n.$render=function(){t.val(!n.$dateValue||isNaN(n.$dateValue.getTime())?"":i(n.$dateValue,s.dateFormat))},e.$on("$destroy",function(){u.destroy(),s=null,u=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.defaults={dayFormat:"dd",daySplit:7};this.$get=["$locale","$sce","dateFilter",function(a,n,i){return function(o){var r=o.$scope,l=o.$options,d=a.DATETIME_FORMATS.SHORTDAY,s=d.slice(l.startWeek).concat(d.slice(0,l.startWeek)),u=n.trustAsHtml('<th class="dow text-center">'+s.join('</th><th class="dow text-center">')+"</th>"),c=o.$date||new Date,g={year:c.getFullYear(),month:c.getMonth(),date:c.getDate()},$=(6e4*c.getTimezoneOffset(),[{format:l.dayFormat,split:7,steps:{month:1},update:function(e,t){!this.built||t||e.getFullYear()!==g.year||e.getMonth()!==g.month?(angular.extend(g,{year:o.$date.getFullYear(),month:o.$date.getMonth(),date:o.$date.getDate()}),o.$build()):e.getDate()!==g.date&&(g.date=o.$date.getDate(),o.$updateSelected())},build:function(){var a=new Date(g.year,g.month,1),n=a.getTimezoneOffset(),d=new Date(+a-864e5*t(a.getDay()-l.startWeek,7)),s=d.getTimezoneOffset();s!==n&&(d=new Date(+d+6e4*(s-n)));for(var c,$=[],m=0;42>m;m++)c=new Date(d.getFullYear(),d.getMonth(),d.getDate()+m),$.push({date:c,label:i(c,this.format),selected:o.$date&&this.isSelected(c),muted:c.getMonth()!==g.month,disabled:this.isDisabled(c)});r.title=i(a,"MMMM yyyy"),r.showLabels=!0,r.labels=u,r.rows=e($,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){return e.getTime()<l.minDate||e.getTime()>l.maxDate},onKeyDown:function(e){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:"MMM",split:4,steps:{year:1},update:function(e){this.built&&e.getFullYear()===g.year?e.getMonth()!==g.month&&(angular.extend(g,{month:o.$date.getMonth(),date:o.$date.getDate()}),o.$updateSelected()):(angular.extend(g,{year:o.$date.getFullYear(),month:o.$date.getMonth(),date:o.$date.getDate()}),o.$build())},build:function(){for(var t,a=(new Date(g.year,0,1),[]),n=0;12>n;n++)t=new Date(g.year,n,1),a.push({date:t,label:i(t,this.format),selected:o.$isSelected(t),disabled:this.isDisabled(t)});r.title=i(t,"yyyy"),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<l.minDate||e.getTime()>l.maxDate},onKeyDown:function(e){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:"yyyy",split:4,steps:{year:12},update:function(e,t){!this.built||t||parseInt(e.getFullYear()/20,10)!==parseInt(g.year/20,10)?(angular.extend(g,{year:o.$date.getFullYear(),month:o.$date.getMonth(),date:o.$date.getDate()}),o.$build()):e.getFullYear()!==g.year&&(angular.extend(g,{year:o.$date.getFullYear(),month:o.$date.getMonth(),date:o.$date.getDate()}),o.$updateSelected())},build:function(){for(var t,a=g.year-g.year%(3*this.split),n=[],l=0;12>l;l++)t=new Date(a+l,0,1),n.push({date:t,label:i(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<l.minDate||e.getTime()>l.maxDate},onKeyDown:function(e){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:l.minView?Array.prototype.slice.call($,l.minView):$,viewDate:g}}}]});