Skip to content
This repository has been archived by the owner on Feb 18, 2022. It is now read-only.

Commit

Permalink
PR number #264, new option disable-weekdays thanks to @fabianoroberto
Browse files Browse the repository at this point in the history
  • Loading branch information
45kb committed May 5, 2017
1 parent 33fb171 commit 5d7573e
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angularjs-datepicker",
"version": "2.1.18",
"version": "2.1.19",
"description": "A datepicker directive for angularjs.",
"authors": [
"Filippo Oretti <filippo.oretti@gmail.com",
Expand Down
38 changes: 34 additions & 4 deletions dist/angular-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
'<div class="_720kb-datepicker-calendar-header">',
'<div class="_720kb-datepicker-calendar-header-middle _720kb-datepicker-mobile-item _720kb-datepicker-calendar-month">',
'<select ng-model="month" title="{{ dateMonthTitle }}" ng-change="selectedMonthHandle(month)">',
'<option ng-repeat="item in months" ng-selected="item === month" ng-disabled=\'!isSelectableMaxDate($index + 1 + " " + day + ", " + year) || !isSelectableMinDate($index + 1 + " " + day + ", " + year)\' ng-value="$index + 1" value="$index + 1">',
'<option ng-repeat="item in months" ng-selected="item === month" ng-disabled=\'!isSelectableMaxDate(item + " " + day + ", " + year) || !isSelectableMinDate(item + " " + day + ", " + year)\' ng-value="$index + 1" value="$index + 1">',
'{{ item }}',
'</option>',
'</select>',
Expand Down Expand Up @@ -110,7 +110,7 @@
'<a href="javascript:void(0)" ng-repeat="px in prevMonthDays" class="_720kb-datepicker-calendar-day _720kb-datepicker-disabled">',
'{{px}}',
'</a>',
'<a href="javascript:void(0)" ng-repeat="item in days" ng-click="setDatepickerDay(item)" ng-class="{\'_720kb-datepicker-active\': selectedDay === item && selectedMonth === monthNumber && selectedYear === year, \'_720kb-datepicker-disabled\': !isSelectableMinDate(year + \'/\' + monthNumber + \'/\' + item ) || !isSelectableMaxDate(year + \'/\' + monthNumber + \'/\' + item) || !isSelectableDate(monthNumber, year, item),\'_720kb-datepicker-today\': item === today.getDate() && monthNumber === (today.getMonth() + 1) && year === today.getFullYear() && !selectedDay}" class="_720kb-datepicker-calendar-day">',
'<a href="javascript:void(0)" ng-repeat="item in days" ng-click="setDatepickerDay(item)" ng-class="{\'_720kb-datepicker-active\': selectedDay === item && selectedMonth === monthNumber && selectedYear === year, \'_720kb-datepicker-disabled\': !isSelectableMinDate(year + \'/\' + monthNumber + \'/\' + item ) || !isSelectableMaxDate(year + \'/\' + monthNumber + \'/\' + item) || !isSelectableDate(monthNumber, year, item) || !isSelectableDay(monthNumber, year, item),\'_720kb-datepicker-today\': item === today.getDate() && monthNumber === (today.getMonth() + 1) && year === today.getFullYear() && !selectedDay}" class="_720kb-datepicker-calendar-day">',
'{{item}}',
'</a>',
'<a href="javascript:void(0)" ng-repeat="nx in nextMonthDays" class="_720kb-datepicker-calendar-day _720kb-datepicker-disabled">',
Expand Down Expand Up @@ -157,6 +157,7 @@
//, dateMinLimit
//, dateMaxLimit
, dateDisabledDates = $scope.$eval($scope.dateDisabledDates)
, dateDisabledWeekdays = $scope.$eval($scope.dateDisabledWeekdays)
, date = new Date()
, isMouseOn = false
, isMouseOnInput = false
Expand Down Expand Up @@ -477,6 +478,17 @@
if (newValue) {
setInputValue();
}
})
, unregisterDateDisabledDatesWatcher = $scope.$watch('dateDisabledDates', function dateDisabledDatesWatcher(newValue) {
if (newValue) {
dateDisabledDates = $scope.$eval(newValue);

if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) {
thisInput.val('');
thisInput.triggerHandler('input');
thisInput.triggerHandler('change');//just to be sure;
}
}
});

$scope.nextMonth = function nextMonth() {
Expand Down Expand Up @@ -631,7 +643,8 @@

$scope.setDatepickerDay = function setDatepickerDay(day) {

if ($scope.isSelectableDate($scope.monthNumber, $scope.year, day) &&
if ($scope.isSelectableDay($scope.monthNumber, $scope.year, day) &&
$scope.isSelectableDate($scope.monthNumber, $scope.year, day) &&
$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + day) &&
$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + day)) {

Expand Down Expand Up @@ -697,7 +710,8 @@
if (date.getFullYear() &&
!isNaN(date.getDay()) &&
!isNaN(date.getMonth()) &&
$scope.isSelectableDate(date) &&
$scope.isSelectableDay(date.getMonth(), date.getFullYear(), date.getDay()) &&
$scope.isSelectableDate(date.getMonth(), date.getFullYear(), date.getDay()) &&
$scope.isSelectableMaxDate(date) &&
$scope.isSelectableMinDate(date)) {

Expand Down Expand Up @@ -746,6 +760,20 @@
$scope.paginationYears = theNewYears;
};

$scope.isSelectableDay = function isSelectableDay(monthNumber, year, day) {
var i = 0;

if (dateDisabledWeekdays && dateDisabledWeekdays.length > 0) {
for (i; i <= dateDisabledWeekdays.length; i += 1) {
if (dateDisabledWeekdays[i] === new Date(monthNumber + '/' + day + '/' + year).getDay()) {
return false;
}
}
}

return true;
};

$scope.isSelectableDate = function isSelectableDate(monthNumber, year, day) {
var i = 0;

Expand Down Expand Up @@ -944,6 +972,7 @@
unregisterDateMinLimitWatcher();
unregisterDateMaxLimitWatcher();
unregisterDateFormatWatcher();
unregisterDateDisabledDatesWatcher();
thisInput.off('focus click focusout blur');
angular.element(theCalendar).off('mouseenter mouseleave focusin');
angular.element($window).off('click focus focusin', onClickOnWindow);
Expand All @@ -961,6 +990,7 @@
'buttonNextTitle': '@',
'buttonPrevTitle': '@',
'dateDisabledDates': '@',
'dateDisabledWeekdays': '@',
'dateSetHidden': '@',
'dateTyper': '@',
'dateWeekStartDay': '@',
Expand Down
Loading

0 comments on commit 5d7573e

Please sign in to comment.