diff --git a/README.md b/README.md index 6e347ea..07a418c 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,36 @@ function MyAppController($scope) { } ``` +#### special-dates + +You can specify a function that will determine if a date is special or not. You can pass `formattedDate` as an argument to receive the date formatted in the current locale, or `date` to receive the date object. You can pass both of them if you need. + +```html +
+``` + +```javascript +function MyAppController($scope) { + $scope.specialDatesFn = function(formattedDate) { + return ['2013-11-10', '2013-11-15', '2013-11-19'].indexOf(formattedDate) > -1; + } +} +``` + +This is handy if you want to disable dates programatically. + +```html + +``` + +```javascript +function MyAppController($scope) { + $scope.specialDatesFn = function(date) { + return date.getDay() === 6; // Disable every Sunday + } +} +``` + #### default-date Allows you to preset the calendar to a particular month without setting the chosen date. diff --git a/dist/angular-pickadate.css b/dist/angular-pickadate.css index f54b8b9..fe12389 100644 --- a/dist/angular-pickadate.css +++ b/dist/angular-pickadate.css @@ -34,6 +34,8 @@ border-right: 1px solid #DCDCDC; } .pickadate-cell li:nth-child(1), .pickadate-cell li:nth-child(8), .pickadate-cell li:nth-child(15), .pickadate-cell li:nth-child(22), .pickadate-cell li:nth-child(29), .pickadate-cell li:nth-child(36) { border-left: 1px solid #DCDCDC; } + .pickadate-cell .pickadate-special { + text-decoration: underline; } .pickadate-cell .pickadate-disabled { color: #DCDCDC; } .pickadate-cell .pickadate-disabled a { diff --git a/dist/angular-pickadate.js b/dist/angular-pickadate.js index ad93618..15424a1 100755 --- a/dist/angular-pickadate.js +++ b/dist/angular-pickadate.js @@ -98,13 +98,14 @@ } return function(format, options) { - var minDate, maxDate, disabledDates, currentDate, weekStartsOn, noExtraRows; + var minDate, maxDate, disabledDates, specialDates, currentDate, weekStartsOn, noExtraRows; options = options || {}; format = format || 'yyyy-MM-dd'; weekStartsOn = options.weekStartsOn; noExtraRows = options.noExtraRows; disabledDates = options.disabledDates || angular.noop; + specialDates = options.specialDates || angular.noop; if (!angular.isNumber(weekStartsOn) || weekStartsOn < 0 || weekStartsOn > 6) weekStartsOn = 0; @@ -152,6 +153,7 @@ var localDate = angular.copy(date), formattedDate = dateFilter(localDate, format), disabled = disabledDates({date: localDate, formattedDate: formattedDate}), + special = specialDates({date: localDate, formattedDate: formattedDate}), monthOffset = this.getMonthOffset(localDate, currentDate), outOfMinRange = localDate < minDate, outOfMaxRange = localDate > maxDate, @@ -163,6 +165,7 @@ formattedDate: formattedDate, today: formattedDate === dateFilter(new Date(), format), disabled: disabled, + special: special, outOfMinRange: outOfMinRange, outOfMaxRange: outOfMaxRange, monthOffset: monthOffset, @@ -250,7 +253,8 @@ minDate: '=', maxDate: '=', disabledDates: '&', - weekStartsOn: '=' + weekStartsOn: '=', + specialDates: '&' }, link: function(scope, element, attrs, ngModel) { @@ -265,7 +269,8 @@ nextMonthSelectable: /^(next|both)$/.test(attrs.selectOtherMonths), weekStartsOn: scope.weekStartsOn, noExtraRows: attrs.hasOwnProperty('noExtraRows'), - disabledDates: scope.disabledDates + disabledDates: scope.disabledDates, + specialDates: scope.specialDates }); scope.displayPicker = !wantsModal; @@ -282,6 +287,8 @@ }; var $render = ngModel.$render = function(options) { + if (!ngModel.$viewValue) return; + if (angular.isArray(ngModel.$viewValue)) { selectedDates = ngModel.$viewValue; } else if (ngModel.$viewValue) { @@ -360,6 +367,7 @@ if (date.today) date.classNames.push('pickadate-today'); if (date.disabled) date.classNames.push('pickadate-unavailable'); + if (date.special) date.classNames.push('pickadate-special'); return date; }); diff --git a/dist/angular-pickadate.min.js b/dist/angular-pickadate.min.js index 09f19e5..aa01d39 100755 --- a/dist/angular-pickadate.min.js +++ b/dist/angular-pickadate.min.js @@ -1 +1 @@ -!function(e){"use strict";function t(t,a){var n=[];return e.forEach(t,function(t){n.push(e.isFunction(a)?a(t):t[a])}),n}var a=[].indexOf||function(e){for(var t=0,a=this.length;t=300?l.left=r+a.getBoundingClientRect().left+"px":l.right=s-a.getBoundingClientRect().right-r+"px",l},o=function(e,t){for(var a=t.parentNode;null!==a;){if(a===e)return!0;a=a.parentNode}return!1};return function(e,n,i){var s=function(t){e.displayPicker=t,e.$apply()};n.on("focus",function(){e.modalStyles=r(n[0]),s(!0)}),n.on("keydown",function(e){a.call([9,13,27],e.keyCode)>=0&&s(!1)}),t.on("click",function(e){o(i,e.target)||e.target===n[0]||s(!1)})}}]).factory("pickadateDateHelper",["$locale","dateFilter",function(t,a){function n(e){switch(e){case"dd":return"day";case"MM":return"month";case"yyyy":return"year"}}return function(i,r){var o,s,l,c,d,u;return r=r||{},i=i||"yyyy-MM-dd",d=r.weekStartsOn,u=r.noExtraRows,l=r.disabledDates||e.noop,(!e.isNumber(d)||d<0||d>6)&&(d=0),{parseDate:function(t){if(t){if(e.isDate(t))return new Date(t);var a="(dd|MM|yyyy)",r=i.match(/[-|\/]/)[0],o=t.split(r),s=new RegExp([a,a,a].join(r)),l=i.match(s),c={};if(l.shift(),e.forEach(l,function(e,t){c[n(e)]=parseInt(o[t],10)}),!(isNaN(c.year)||isNaN(c.month)||isNaN(c.day)))return new Date(c.year,c.month-1,c.day,3)}},setRestrictions:function(e){o=this.parseDate(e.minDate)||new Date(0),s=this.parseDate(e.maxDate)||new Date(99999999999999),c=e.currentDate},allowPrevMonth:function(){return c>o},allowNextMonth:function(){var t=e.copy(c);return t.setMonth(t.getMonth()+1),t<=s},buildDateObject:function(t){var n=e.copy(t),d=a(n,i),u=l({date:n,formattedDate:d}),f=this.getMonthOffset(n,c),p=n