Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<div pickadate ng-model="date" special-dates="specialDatesFn(formattedDate)"></div>
```

```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
<div pickadate ng-model="date" special-dates="specialDatesFn(date)"></div>
```

```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.
Expand Down
2 changes: 2 additions & 0 deletions dist/angular-pickadate.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 11 additions & 3 deletions dist/angular-pickadate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -163,6 +165,7 @@
formattedDate: formattedDate,
today: formattedDate === dateFilter(new Date(), format),
disabled: disabled,
special: special,
outOfMinRange: outOfMinRange,
outOfMaxRange: outOfMaxRange,
monthOffset: monthOffset,
Expand Down Expand Up @@ -250,7 +253,8 @@
minDate: '=',
maxDate: '=',
disabledDates: '&',
weekStartsOn: '='
weekStartsOn: '=',
specialDates: '&'
},

link: function(scope, element, attrs, ngModel) {
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
});
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-pickadate.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions src/angular-pickadate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -163,6 +165,7 @@
formattedDate: formattedDate,
today: formattedDate === dateFilter(new Date(), format),
disabled: disabled,
special: special,
outOfMinRange: outOfMinRange,
outOfMaxRange: outOfMaxRange,
monthOffset: monthOffset,
Expand Down Expand Up @@ -250,7 +253,8 @@
minDate: '=',
maxDate: '=',
disabledDates: '&',
weekStartsOn: '='
weekStartsOn: '=',
specialDates: '&'
},

link: function(scope, element, attrs, ngModel) {
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
});
Expand Down
3 changes: 3 additions & 0 deletions src/angular-pickadate.scss
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
border-left: 1px solid #DCDCDC;
}
}
.pickadate-special {
text-decoration: underline
}
.pickadate-disabled {
color: #DCDCDC;
a {
Expand Down
Loading