diff --git a/dist/angular-datepicker.js b/dist/angular-datepicker.js
index 971dbc9..1c85cef 100644
--- a/dist/angular-datepicker.js
+++ b/dist/angular-datepicker.js
@@ -6,8 +6,8 @@
var A_DAY_IN_MILLISECONDS = 86400000
, isMobile = (function isMobile() {
- if (navigator.userAgent &&
- (navigator.userAgent.match(/Android/i) ||
+ if (navigator.userAgent &&
+ (navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
@@ -15,435 +15,392 @@
navigator.userAgent.match(/BlackBerry/i) ||
navigator.userAgent.match(/Windows Phone/i))) {
- return true;
- }
- }())
+ return true;
+ }
+ }())
, generateMonthAndYearHeader = function generateMonthAndYearHeader(prevButton, nextButton, preventMobile) {
- if (preventMobile) {
+ if (preventMobile) {
- isMobile = false;
- }
+ isMobile = false;
+ }
- if (isMobile) {
-
- return [
- '
',
- ''
- ];
- }
+ if (isMobile) {
return [
'',
+ ''
];
}
+
+ return [
+ '",
+ '",
+ ''
+ ];
+ }
, generateYearsPaginationHeader = function generateYearsPaginationHeader(prevButton, nextButton) {
- return [
- ''
- ];
- }
+ return ['"];
+ }
+
+ , generateMonthsPaginationHeader = function generateMonthsPaginationHeader() {
+
+ return ['"];
+
+ }
, generateDaysColumns = function generateDaysColumns() {
- return [
+ return [
''
- ];
- }
+ ];
+ }
, generateDays = function generateDays() {
-
- return [
- '',
- '
',
- '{{px}}',
- '',
- '
',
- '{{item}}',
- '',
- '
',
- '{{nx}}',
- '',
- '
'
- ];
- }
+ return [
+ '',
+ '
',
+ '{{px}}',
+ '',
+ '
',
+ '{{item}}',
+ '',
+ '
',
+ '{{nx}}',
+ '',
+ '
'
+ ];
+ }
, generateHtmlTemplate = function generateHtmlTemplate(prevButton, nextButton, preventMobile) {
- var toReturn = [
- '',
- '
'
- ]
+ var toReturn = [
+ '',
+ '
'
+ ]
, monthAndYearHeader = generateMonthAndYearHeader(prevButton, nextButton, preventMobile)
, yearsPaginationHeader = generateYearsPaginationHeader(prevButton, nextButton)
+ , monthsPaginationHeader = generateMonthsPaginationHeader()
, daysColumns = generateDaysColumns()
, days = generateDays()
, iterator = function iterator(aRow) {
- toReturn.splice(toReturn.length - 1, 0, aRow);
- };
+ toReturn.splice(toReturn.length - 1, 0, aRow);
+ };
- monthAndYearHeader.forEach(iterator);
- yearsPaginationHeader.forEach(iterator);
- daysColumns.forEach(iterator);
- days.forEach(iterator);
+ monthAndYearHeader.forEach(iterator);
+ yearsPaginationHeader.forEach(iterator);
+ monthsPaginationHeader.forEach(iterator);
+ daysColumns.forEach(iterator);
+ days.forEach(iterator);
- return toReturn.join('');
- }
+ return toReturn.join('');
+ }
, datepickerDirective = function datepickerDirective($window, $compile, $locale, $filter, $interpolate, $timeout) {
- var linkingFunction = function linkingFunction($scope, element, attr) {
-
- //get child input
- var selector = attr.selector
- , thisInput = angular.element(selector ? element[0].querySelector('.' + selector) : element[0].children[0])
- , theCalendar
- , defaultPrevButton = '〈'
- , defaultNextButton = '〉'
- , prevButton = attr.buttonPrev || defaultPrevButton
- , nextButton = attr.buttonNext || defaultNextButton
- , dateFormat = attr.dateFormat
- //, dateMinLimit
- //, dateMaxLimit
- , dateDisabledDates = $scope.$eval($scope.dateDisabledDates)
- , dateEnabledDates = $scope.$eval($scope.dateEnabledDates)
- , dateDisabledWeekdays = $scope.$eval($scope.dateDisabledWeekdays)
- , date = new Date()
- , isMouseOn = false
- , isMouseOnInput = false
- , preventMobile = typeof attr.datepickerMobile !== 'undefined' && attr.datepickerMobile !== 'false'
- , datetime = $locale.DATETIME_FORMATS
- , pageDatepickers
- , hours24h = 86400000
- , htmlTemplate = generateHtmlTemplate(prevButton, nextButton, preventMobile)
- , n
- , onClickOnWindow = function onClickOnWindow() {
-
- if (!isMouseOn &&
- !isMouseOnInput && theCalendar) {
-
- $scope.hideCalendar();
- }
+ var linkingFunction = function linkingFunction($scope, element, attr) {
+
+ //get child input
+ var selector = attr.selector
+ , thisInput = angular.element(selector ? element[0].querySelector('.' + selector) : element[0].children[0])
+ , theCalendar
+ , defaultPrevButton = '〈'
+ , defaultNextButton = '〉'
+ , prevButton = attr.buttonPrev || defaultPrevButton
+ , nextButton = attr.buttonNext || defaultNextButton
+ , dateFormat = attr.dateFormat
+ //, dateMinLimit
+ //, dateMaxLimit
+ , dateDisabledDates = $scope.$eval($scope.dateDisabledDates)
+ , dateEnabledDates = $scope.$eval($scope.dateEnabledDates)
+ , dateDisabledWeekdays = $scope.$eval($scope.dateDisabledWeekdays)
+ , date = new Date()
+ , isMouseOn = false
+ , isMouseOnInput = false
+ , preventMobile = typeof attr.datepickerMobile !== 'undefined' && attr.datepickerMobile !== 'false'
+ , datetime = $locale.DATETIME_FORMATS
+ , pageDatepickers
+ , hours24h = 86400000
+ , htmlTemplate = generateHtmlTemplate(prevButton, nextButton, preventMobile)
+ , n
+ , onClickOnWindow = function onClickOnWindow() {
+
+ if (!isMouseOn &&
+ !isMouseOnInput && theCalendar) {
+
+ $scope.hideCalendar();
}
- , setDaysInMonth = function setDaysInMonth(month, year) {
+ }
+ , setDaysInMonth = function setDaysInMonth(month, year) {
- var i
- , limitDate = new Date(year, month, 0).getDate()
- , firstDayMonthNumber = new Date(year + '/' + month + '/' + 1).getDay()
- , lastDayMonthNumber = new Date(year + '/' + month + '/' + limitDate).getDay()
- , prevMonthDays = []
- , nextMonthDays = []
- , howManyNextDays
- , howManyPreviousDays
- , monthAlias
- , dateWeekEndDay;
-
- $scope.days = [];
- $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay);
- dateWeekEndDay = ($scope.dateWeekStartDay + 6) % 7;
-
- for (i = 1; i <= limitDate; i += 1) {
-
- $scope.days.push(i);
- }
+ var i
+ , limitDate = new Date(year, month, 0).getDate()
+ , firstDayMonthNumber = new Date(year + '/' + month + '/' + 1).getDay()
+ , lastDayMonthNumber = new Date(year + '/' + month + '/' + limitDate).getDay()
+ , prevMonthDays = []
+ , nextMonthDays = []
+ , howManyNextDays
+ , howManyPreviousDays
+ , monthAlias
+ , dateWeekEndDay;
+
+ $scope.days = [];
+ $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay);
+ dateWeekEndDay = ($scope.dateWeekStartDay + 6) % 7;
+
+ for (i = 1; i <= limitDate; i += 1) {
+
+ $scope.days.push(i);
+ }
- //get previous month days if first day in month is not first day in week
- if (firstDayMonthNumber === $scope.dateWeekStartDay) {
+ //get previous month days if first day in month is not first day in week
+ if (firstDayMonthNumber === $scope.dateWeekStartDay) {
- //no need for it
- $scope.prevMonthDays = [];
- } else {
+ //no need for it
+ $scope.prevMonthDays = [];
+ } else {
- howManyPreviousDays = firstDayMonthNumber - $scope.dateWeekStartDay;
+ howManyPreviousDays = firstDayMonthNumber - $scope.dateWeekStartDay;
- if (firstDayMonthNumber < $scope.dateWeekStartDay) {
+ if (firstDayMonthNumber < $scope.dateWeekStartDay) {
- howManyPreviousDays += 7;
- }
+ howManyPreviousDays += 7;
+ }
- //get previous month
- if (Number(month) === 1) {
+ //get previous month
+ if (Number(month) === 1) {
- monthAlias = 12;
- } else {
+ monthAlias = 12;
+ } else {
- monthAlias = month - 1;
- }
- //return previous month days
- for (i = 1; i <= new Date(year, monthAlias, 0).getDate(); i += 1) {
+ monthAlias = month - 1;
+ }
+ //return previous month days
+ for (i = 1; i <= new Date(year, monthAlias, 0).getDate(); i += 1) {
- prevMonthDays.push(i);
- }
- //attach previous month days
- $scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays);
+ prevMonthDays.push(i);
}
+ //attach previous month days
+ $scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays);
+ }
- //get next month days if last day in month is not last day in week
- if (lastDayMonthNumber === dateWeekEndDay) {
- //no need for it
- $scope.nextMonthDays = [];
- } else {
- howManyNextDays = 6 - lastDayMonthNumber + $scope.dateWeekStartDay;
+ //get next month days if last day in month is not last day in week
+ if (lastDayMonthNumber === dateWeekEndDay) {
+ //no need for it
+ $scope.nextMonthDays = [];
+ } else {
+ howManyNextDays = 6 - lastDayMonthNumber + $scope.dateWeekStartDay;
- if (lastDayMonthNumber < $scope.dateWeekStartDay) {
+ if (lastDayMonthNumber < $scope.dateWeekStartDay) {
- howManyNextDays -= 7;
- }
- //get previous month
+ howManyNextDays -= 7;
+ }
+ //get previous month
- //return next month days
- for (i = 1; i <= howManyNextDays; i += 1) {
+ //return next month days
+ for (i = 1; i <= howManyNextDays; i += 1) {
- nextMonthDays.push(i);
- }
- //attach previous month days
- $scope.nextMonthDays = nextMonthDays;
+ nextMonthDays.push(i);
}
+ //attach previous month days
+ $scope.nextMonthDays = nextMonthDays;
}
- , resetToMinDate = function resetToMinDate() {
+ }
+ , resetToMinDate = function resetToMinDate() {
- $scope.month = $filter('date')(new Date($scope.dateMinLimit), 'MMMM');
- $scope.monthNumber = Number($filter('date')(new Date($scope.dateMinLimit), 'MM'));
- $scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd'));
- $scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy'));
+ $scope.month = $filter('date')(new Date($scope.dateMinLimit), 'MMMM');
+ $scope.monthNumber = Number($filter('date')(new Date($scope.dateMinLimit), 'MM'));
+ $scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd'));
+ $scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy'));
- setDaysInMonth($scope.monthNumber, $scope.year);
- }
- , resetToMaxDate = function resetToMaxDate() {
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ }
+ , resetToMaxDate = function resetToMaxDate() {
- $scope.month = $filter('date')(new Date($scope.dateMaxLimit), 'MMMM');
- $scope.monthNumber = Number($filter('date')(new Date($scope.dateMaxLimit), 'MM'));
- $scope.day = Number($filter('date')(new Date($scope.dateMaxLimit), 'dd'));
- $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));
+ $scope.month = $filter('date')(new Date($scope.dateMaxLimit), 'MMMM');
+ $scope.monthNumber = Number($filter('date')(new Date($scope.dateMaxLimit), 'MM'));
+ $scope.day = Number($filter('date')(new Date($scope.dateMaxLimit), 'dd'));
+ $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));
- setDaysInMonth($scope.monthNumber, $scope.year);
- }
- , prevYear = function prevYear() {
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ }
+ , prevYear = function prevYear() {
- $scope.year = Number($scope.year) - 1;
- }
- , nextYear = function nextYear() {
+ $scope.year = Number($scope.year) - 1;
+ }
+ , nextYear = function nextYear() {
- $scope.year = Number($scope.year) + 1;
- }
- , localDateTimestamp = function localDateTimestamp(rawDate, dateFormatDefinition) {
-
- var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|MMMM|MMM|MM|M|dd?d?|yy?yy?y?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g
+ $scope.year = Number($scope.year) + 1;
+ }
+ , localDateTimestamp = function localDateTimestamp(rawDate, dateFormatDefinition) {
+
+ var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|MMMM|MMM|MM|M|dd?d?|yy?yy?y?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g
,formatDate,dateSplit, m, d, y, index, el, longName, shortName;
- for (index = 0; index < datetime.MONTH.length; index += 1) {
- longName = datetime.MONTH[index];
- shortName = datetime.SHORTMONTH[index];
+ for (index = 0; index < datetime.MONTH.length; index += 1) {
+ longName = datetime.MONTH[index];
+ shortName = datetime.SHORTMONTH[index];
- if (rawDate.indexOf(longName) !== -1) {
- rawDate = rawDate.replace(longName, index + 1);
- break;
- }
+ if (rawDate.indexOf(longName) !== -1) {
+ rawDate = rawDate.replace(longName, index + 1);
+ break;
+ }
- if (rawDate.indexOf(shortName) !== -1) {
- rawDate = rawDate.replace(shortName, index + 1);
- break;
- }
+ if (rawDate.indexOf(shortName) !== -1) {
+ rawDate = rawDate.replace(shortName, index + 1);
+ break;
}
+ }
- dateSplit = rawDate
- .split(/\D/)
- .filter(function dateSplitFilter(item) {
- return item.length > 0;
- });
-
- formatDate = dateFormatDefinition
- .match(formattingTokens)
- .filter(function fromatDateFilter(item) {
- return item.match(/^[a-zA-Z]+$/i) !== null;
- });
-
- for (index = 0; index < formatDate.length; index += 1) {
- el = formatDate[index];
-
- switch (true) {
- case el.indexOf('d') !== -1: {
- d = dateSplit[index - (formatDate.length - dateSplit.length)];
- break;
- }
- case el.indexOf('M') !== -1: {
- m = dateSplit[index - (formatDate.length - dateSplit.length)];
- break;
- }
- case el.indexOf('y') !== -1: {
- y = dateSplit[index - (formatDate.length - dateSplit.length)];
- break;
- }
- default: {
- break;
- }
+ dateSplit = rawDate
+ .split(/\D/)
+ .filter(function dateSplitFilter(item) {
+ return item.length > 0;
+ });
+
+ formatDate = dateFormatDefinition
+ .match(formattingTokens)
+ .filter(function fromatDateFilter(item) {
+ return item.match(/^[a-zA-Z]+$/i) !== null;
+ });
+
+ for (index = 0; index < formatDate.length; index += 1) {
+ el = formatDate[index];
+
+ switch (true) {
+ case el.indexOf('d') !== -1: {
+ d = dateSplit[index - (formatDate.length - dateSplit.length)];
+ break;
+ }
+ case el.indexOf('M') !== -1: {
+ m = dateSplit[index - (formatDate.length - dateSplit.length)];
+ break;
+ }
+ case el.indexOf('y') !== -1: {
+ y = dateSplit[index - (formatDate.length - dateSplit.length)];
+ break;
+ }
+ default: {
+ break;
}
}
-
- return new Date(y + '/' + m + '/' + d);
}
- , setInputValue = function setInputValue() {
- if ($scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day) &&
- $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
-
- var modelDate = new Date($scope.year + '/' + $scope.monthNumber + '/' + $scope.day);
+ return new Date(y + '/' + m + '/' + d);
+ }
+ , setInputValue = function setInputValue() {
- if (attr.dateFormat) {
+ if ($scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day) &&
+ $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
- thisInput.val($filter('date')(modelDate, dateFormat));
- } else {
+ var modelDate = new Date($scope.year + '/' + $scope.monthNumber + '/' + $scope.day);
- thisInput.val(modelDate);
- }
+ if (attr.dateFormat) {
- thisInput.triggerHandler('input');
- thisInput.triggerHandler('change');//just to be sure;
+ thisInput.val($filter('date')(modelDate, dateFormat));
} else {
- return false;
+ thisInput.val(modelDate);
}
- }
- , classHelper = {
- 'add': function add(ele, klass) {
- var classes;
-
- if (ele.className.indexOf(klass) > -1) {
- return;
- }
+ thisInput.triggerHandler('input');
+ thisInput.triggerHandler('change');//just to be sure;
+ } else {
- classes = ele.className.split(' ');
- classes.push(klass);
- ele.className = classes.join(' ');
- },
- 'remove': function remove(ele, klass) {
- var i
- , classes;
+ return false;
+ }
+ }
+ , classHelper = {
+ 'add': function add(ele, klass) {
+ var classes;
- if (ele.className.indexOf(klass) === -1) {
+ if (ele.className.indexOf(klass) > -1) {
- return;
- }
+ return;
+ }
- classes = ele.className.split(' ');
- for (i = 0; i < classes.length; i += 1) {
+ classes = ele.className.split(' ');
+ classes.push(klass);
+ ele.className = classes.join(' ');
+ },
+ 'remove': function remove(ele, klass) {
+ var i
+ , classes;
- if (classes[i] === klass) {
+ if (ele.className.indexOf(klass) === -1) {
- classes = classes.slice(0, i).concat(classes.slice(i + 1));
- break;
- }
- }
- ele.className = classes.join(' ');
+ return;
}
- }
- , showCalendar = function showCalendar() {
- //lets hide all the latest instances of datepicker
- pageDatepickers = $window.document.getElementsByClassName('_720kb-datepicker-calendar');
- angular.forEach(pageDatepickers, function forEachDatepickerPages(value, key) {
- if (pageDatepickers[key].classList) {
+ classes = ele.className.split(' ');
+ for (i = 0; i < classes.length; i += 1) {
- pageDatepickers[key].classList.remove('_720kb-datepicker-open');
- } else {
+ if (classes[i] === klass) {
- classHelper.remove(pageDatepickers[key], '_720kb-datepicker-open');
+ classes = classes.slice(0, i).concat(classes.slice(i + 1));
+ break;
}
- });
+ }
+ ele.className = classes.join(' ');
+ }
+ }
+ , showCalendar = function showCalendar() {
+ //lets hide all the latest instances of datepicker
+ pageDatepickers = $window.document.getElementsByClassName('_720kb-datepicker-calendar');
- if (theCalendar.classList) {
+ angular.forEach(pageDatepickers, function forEachDatepickerPages(value, key) {
+ if (pageDatepickers[key].classList) {
- theCalendar.classList.add('_720kb-datepicker-open');
- if (dateFormat) {
- date = localDateTimestamp(thisInput[0].value.toString(), dateFormat);
- } else {
- date = new Date(thisInput[0].value.toString());
- }
- $scope.selectedMonth = Number($filter('date')(date, 'MM'));
- $scope.selectedDay = Number($filter('date')(date, 'dd'));
- $scope.selectedYear = Number($filter('date')(date, 'yyyy'));
+ pageDatepickers[key].classList.remove('_720kb-datepicker-open');
} else {
- classHelper.add(theCalendar, '_720kb-datepicker-open');
- }
- $scope.today = new Date();
- $timeout(function timeoutForYears() {
- if ($scope.selectedDay) {
- $scope.year = $scope.selectedYear;
- $scope.monthNumber = $scope.selectedMonth;
- } else {
- $scope.year = $scope.today.getFullYear();
- $scope.monthNumber = $scope.today.getMonth() + 1;
- }
- $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM');
- setDaysInMonth($scope.monthNumber, $scope.year);
- }, 0);
- }
- , checkToggle = function checkToggle() {
- if (!$scope.datepickerToggle) {
-
- return true;
+ classHelper.remove(pageDatepickers[key], '_720kb-datepicker-open');
}
+ });
- return $scope.$eval($scope.datepickerToggle);
- }
- , checkVisibility = function checkVisibility() {
- if (!$scope.datepickerShow) {
+ if (theCalendar.classList) {
- return false;
- }
+ theCalendar.classList.add('_720kb-datepicker-open');
if (dateFormat) {
date = localDateTimestamp(thisInput[0].value.toString(), dateFormat);
} else {
@@ -452,593 +409,664 @@
$scope.selectedMonth = Number($filter('date')(date, 'MM'));
$scope.selectedDay = Number($filter('date')(date, 'dd'));
$scope.selectedYear = Number($filter('date')(date, 'yyyy'));
- return $scope.$eval($scope.datepickerShow);
+ } else {
+
+ classHelper.add(theCalendar, '_720kb-datepicker-open');
}
- , unregisterDataSetWatcher = $scope.$watch('dateSet', function dateSetWatcher(newValue) {
+ $scope.today = new Date();
+ $timeout(function timeoutForYears() {
+ if ($scope.selectedDay) {
+ $scope.year = $scope.selectedYear;
+ $scope.monthNumber = $scope.selectedMonth;
+ } else {
+ $scope.year = $scope.today.getFullYear();
+ $scope.monthNumber = $scope.today.getMonth() + 1;
+ }
+ $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM');
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ }, 0);
+ }
+ , checkToggle = function checkToggle() {
+ if (!$scope.datepickerToggle) {
- if (newValue && !isNaN(Date.parse(newValue))) {
+ return true;
+ }
- date = new Date(newValue);
+ return $scope.$eval($scope.datepickerToggle);
+ }
+ , checkVisibility = function checkVisibility() {
+ if (!$scope.datepickerShow) {
- $scope.month = $filter('date')(date, 'MMMM');//december-November like
- $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
- $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
- $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
+ return false;
+ }
+ if (dateFormat) {
+ date = localDateTimestamp(thisInput[0].value.toString(), dateFormat);
+ } else {
+ date = new Date(thisInput[0].value.toString());
+ }
+ $scope.selectedMonth = Number($filter('date')(date, 'MM'));
+ $scope.selectedDay = Number($filter('date')(date, 'dd'));
+ $scope.selectedYear = Number($filter('date')(date, 'yyyy'));
+ return $scope.$eval($scope.datepickerShow);
+ }
+ , unregisterDataSetWatcher = $scope.$watch('dateSet', function dateSetWatcher(newValue) {
- setDaysInMonth($scope.monthNumber, $scope.year);
+ if (newValue && !isNaN(Date.parse(newValue))) {
- if ($scope.dateSetHidden !== 'true') {
+ date = new Date(newValue);
+
+ $scope.month = $filter('date')(date, 'MMMM');//december-November like
+ $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
+ $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
+ $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
+
+ setDaysInMonth($scope.monthNumber, $scope.year);
+
+ if ($scope.dateSetHidden !== 'true') {
- setInputValue();
- }
- }
- })
- , unregisterDateMinLimitWatcher = $scope.$watch('dateMinLimit', function dateMinLimitWatcher(newValue) {
- if (newValue) {
- resetToMinDate();
- }
- })
- , unregisterDateMaxLimitWatcher = $scope.$watch('dateMaxLimit', function dateMaxLimitWatcher(newValue) {
- if (newValue) {
- resetToMaxDate();
- }
- })
- , unregisterDateFormatWatcher = $scope.$watch('dateFormat', function dateFormatWatcher(newValue) {
- 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;
- }
+ }
+ })
+ , unregisterDateMinLimitWatcher = $scope.$watch('dateMinLimit', function dateMinLimitWatcher(newValue) {
+ if (newValue) {
+ resetToMinDate();
+ }
+ })
+ , unregisterDateMaxLimitWatcher = $scope.$watch('dateMaxLimit', function dateMaxLimitWatcher(newValue) {
+ if (newValue) {
+ resetToMaxDate();
+ }
+ })
+ , unregisterDateFormatWatcher = $scope.$watch('dateFormat', function dateFormatWatcher(newValue) {
+ 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;
}
- })
- , unregisterDateEnabledDatesWatcher = $scope.$watch('dateEnabledDates', function dateEnabledDatesWatcher(newValue) {
- if (newValue) {
- dateEnabledDates = $scope.$eval(newValue);
-
- if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) {
- thisInput.val('');
- thisInput.triggerHandler('input');
- thisInput.triggerHandler('change');//just to be sure;
- }
+ }
+ })
+ , unregisterDateEnabledDatesWatcher = $scope.$watch('dateEnabledDates', function dateEnabledDatesWatcher(newValue) {
+ if (newValue) {
+ dateEnabledDates = $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() {
+ $scope.nextMonth = function nextMonth() {
- if ($scope.monthNumber === 12) {
+ if ($scope.monthNumber === 12) {
- $scope.monthNumber = 1;
- //its happy new year
- nextYear();
- } else {
+ $scope.monthNumber = 1;
+ //its happy new year
+ nextYear();
+ } else {
- $scope.monthNumber += 1;
- }
+ $scope.monthNumber += 1;
+ }
- //check if max date is ok
- if ($scope.dateMaxLimit) {
+ //check if max date is ok
+ if ($scope.dateMaxLimit) {
- if (!$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[0])) {
+ if (!$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[0])) {
- resetToMaxDate();
- }
+ resetToMaxDate();
}
+ }
- //set next month
- $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM');
- //reinit days
- setDaysInMonth($scope.monthNumber, $scope.year);
- //deactivate selected day
- $scope.day = undefined;
- };
+ //set next month
+ $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM');
+ //reinit days
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ //deactivate selected day
+ $scope.day = undefined;
+ };
- $scope.willPrevMonthBeSelectable = function willPrevMonthBeSelectable() {
- var monthNumber = $scope.monthNumber
- , year = $scope.year
- , prevDay = $filter('date')(new Date(new Date(year + '/' + monthNumber + '/01').getTime() - hours24h), 'dd'); //get last day in previous month
+ $scope.willPrevMonthBeSelectable = function willPrevMonthBeSelectable() {
+ var monthNumber = $scope.monthNumber
+ , year = $scope.year
+ , prevDay = $filter('date')(new Date(new Date(year + '/' + monthNumber + '/01').getTime() - hours24h), 'dd'); //get last day in previous month
- if (monthNumber === 1) {
+ if (monthNumber === 1) {
- monthNumber = 12;
- year = year - 1;
- } else {
+ monthNumber = 12;
+ year = year - 1;
+ } else {
- monthNumber -= 1;
- }
+ monthNumber -= 1;
+ }
- if ($scope.dateMinLimit) {
- if (!$scope.isSelectableMinDate(year + '/' + monthNumber + '/' + prevDay)) {
+ if ($scope.dateMinLimit) {
+ if (!$scope.isSelectableMinDate(year + '/' + monthNumber + '/' + prevDay)) {
- return false;
- }
+ return false;
}
+ }
- return true;
- };
+ return true;
+ };
- $scope.willNextMonthBeSelectable = function willNextMonthBeSelectable() {
- var monthNumber = $scope.monthNumber
- , year = $scope.year;
+ $scope.willNextMonthBeSelectable = function willNextMonthBeSelectable() {
+ var monthNumber = $scope.monthNumber
+ , year = $scope.year;
- if (monthNumber === 12) {
+ if (monthNumber === 12) {
- monthNumber = 1;
- year += 1;
- } else {
+ monthNumber = 1;
+ year += 1;
+ } else {
- monthNumber += 1;
- }
+ monthNumber += 1;
+ }
- if ($scope.dateMaxLimit) {
- if (!$scope.isSelectableMaxDate(year + '/' + monthNumber + '/01')) {
+ if ($scope.dateMaxLimit) {
+ if (!$scope.isSelectableMaxDate(year + '/' + monthNumber + '/01')) {
- return false;
- }
+ return false;
}
+ }
- return true;
- };
+ return true;
+ };
- $scope.prevMonth = function managePrevMonth() {
+ $scope.prevMonth = function managePrevMonth() {
- if ($scope.monthNumber === 1) {
+ if ($scope.monthNumber === 1) {
- $scope.monthNumber = 12;
- //its happy new year
- prevYear();
- } else {
+ $scope.monthNumber = 12;
+ //its happy new year
+ prevYear();
+ } else {
- $scope.monthNumber -= 1;
- }
- //check if min date is ok
- if ($scope.dateMinLimit) {
+ $scope.monthNumber -= 1;
+ }
+ //check if min date is ok
+ if ($scope.dateMinLimit) {
- if (!$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[$scope.days.length - 1])) {
+ if (!$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[$scope.days.length - 1])) {
- resetToMinDate();
- }
+ resetToMinDate();
}
- //set next month
- $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM');
- //reinit days
- setDaysInMonth($scope.monthNumber, $scope.year);
- //deactivate selected day
+ }
+ //set next month
+ $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM');
+ //reinit days
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ //deactivate selected day
+ $scope.day = undefined;
+ };
+
+ $scope.selectedMonthHandle = function manageSelectedMonthHandle(selectedMonthNumber) {
+
+ $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM'));
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ setInputValue();
+ };
+
+ $scope.setMonth = function setMonth(selectedMonthNumber) {
+ $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM'));
+ $scope.showMonthPagination = false;
+ $scope.month = selectedMonthNumber;
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ };
+
+ $scope.setNewYear = function setNewYear(year) {
+
+ //deactivate selected day
+ if (!isMobile) {
$scope.day = undefined;
- };
+ }
- $scope.selectedMonthHandle = function manageSelectedMonthHandle(selectedMonthNumber) {
+ if ($scope.dateMaxLimit &&
+ $scope.year < Number(year)) {
- $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM'));
- setDaysInMonth($scope.monthNumber, $scope.year);
- setInputValue();
- };
+ if (!$scope.isSelectableMaxYear(year)) {
- $scope.setNewYear = function setNewYear(year) {
+ return;
+ }
+ } else if ($scope.dateMinLimit &&
+ $scope.year > Number(year)) {
+
+ if (!$scope.isSelectableMinYear(year)) {
- //deactivate selected day
- if (!isMobile) {
- $scope.day = undefined;
+ return;
}
+ }
- if ($scope.dateMaxLimit &&
- $scope.year < Number(year)) {
+ $scope.paginateYears(year);
+ $scope.showYearsPagination = false;
+ $timeout(function timeoutForYears() {
+ $scope.year = Number(year);
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ }, 0);
+ };
- if (!$scope.isSelectableMaxYear(year)) {
+ $scope.showMPagination = function showMPagination() {
+ $scope.showYearsPagination = false;
+ $scope.showMonthPagination = !$scope.showMonthPagination;
+ };
- return;
- }
- } else if ($scope.dateMinLimit &&
- $scope.year > Number(year)) {
+ $scope.showYPagination = function showYPagination() {
+ $scope.showMonthPagination = false;
+ $scope.showYearsPagination = !$scope.showYearsPagination;
+ };
- if (!$scope.isSelectableMinYear(year)) {
+ $scope.hideCalendar = function hideCalendar() {
+ if (theCalendar.classList) {
+ theCalendar.classList.remove('_720kb-datepicker-open');
+ } else {
- return;
+ classHelper.remove(theCalendar, '_720kb-datepicker-open');
+ }
+ };
+
+ $scope.setDatepickerDay = function setDatepickerDay(day, type) {
+ 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)) {
+
+ if (type === 'previous') {
+ if ($scope.monthNumber !== 1) {
+ $scope.monthNumber -= 1;
+ } else {
+ $scope.monthNumber = 12;
+ $scope.year -= 1;
+ }
+ } else if (type === 'next') {
+ if ($scope.monthNumber !== 12) {
+ $scope.monthNumber += 1;
+ } else {
+ $scope.monthNumber = 1;
+ $scope.year += 1;
}
}
- $scope.paginateYears(year);
- $scope.showYearsPagination = false;
- $timeout(function timeoutForYears() {
- $scope.year = Number(year);
- setDaysInMonth($scope.monthNumber, $scope.year);
- }, 0);
- };
+ $scope.day = Number(day);
+ $scope.selectedDay = $scope.day;
+ $scope.selectedMonth = $scope.monthNumber;
+ $scope.selectedYear = $scope.year;
- $scope.hideCalendar = function hideCalendar() {
- if (theCalendar.classList) {
- theCalendar.classList.remove('_720kb-datepicker-open');
- } else {
+ setInputValue();
- classHelper.remove(theCalendar, '_720kb-datepicker-open');
+ if (attr.hasOwnProperty('dateRefocus')) {
+ thisInput[0].focus();
}
- };
- $scope.setDatepickerDay = function setDatepickerDay(day) {
+ $scope.hideCalendar();
+ }
+ };
- 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)) {
+ $scope.paginateYears = function paginateYears(startingYear) {
+ var i
+ , theNewYears = []
+ , daysToPrepend = 10
+ , daysToAppend = 10;
- $scope.day = Number(day);
- $scope.selectedDay = $scope.day;
- $scope.selectedMonth = $scope.monthNumber;
- $scope.selectedYear = $scope.year;
+ $scope.paginationYears = [];
+ if (isMobile) {
- setInputValue();
+ daysToPrepend = 50;
+ daysToAppend = 50;
+ if ( $scope.dateMinLimit && $scope.dateMaxLimit) {
- if (attr.hasOwnProperty('dateRefocus')) {
- thisInput[0].focus();
- }
-
- $scope.hideCalendar();
+ startingYear = new Date($scope.dateMaxLimit).getFullYear();
+ daysToPrepend = startingYear - new Date($scope.dateMinLimit).getFullYear();
+ daysToAppend = 1;
}
- };
+ }
- $scope.paginateYears = function paginateYears(startingYear) {
- var i
- , theNewYears = []
- , daysToPrepend = 10
- , daysToAppend = 10;
+ for (i = daysToPrepend; i > 0; i -= 1) {
- $scope.paginationYears = [];
- if (isMobile) {
+ theNewYears.push(Number(startingYear) - i);
+ }
- daysToPrepend = 50;
- daysToAppend = 50;
- if ( $scope.dateMinLimit && $scope.dateMaxLimit) {
+ for (i = 0; i < daysToAppend; i += 1) {
- startingYear = new Date($scope.dateMaxLimit).getFullYear();
- daysToPrepend = startingYear - new Date($scope.dateMinLimit).getFullYear();
- daysToAppend = 1;
- }
- }
+ theNewYears.push(Number(startingYear) + i);
+ }
+ //date typing in input date-typer
+ if ($scope.dateTyper === 'true') {
- for (i = daysToPrepend; i > 0; i -= 1) {
+ thisInput.on('keyup blur', function onTyping() {
- theNewYears.push(Number(startingYear) - i);
- }
+ if (thisInput[0].value &&
+ thisInput[0].value.length &&
+ thisInput[0].value.length > 0) {
- for (i = 0; i < daysToAppend; i += 1) {
+ try {
+ if (dateFormat) {
+ date = localDateTimestamp(thisInput[0].value.toString(), dateFormat);
+ } else {
+ date = new Date(thisInput[0].value.toString());
+ }
- theNewYears.push(Number(startingYear) + i);
- }
- //date typing in input date-typer
- if ($scope.dateTyper === 'true') {
-
- thisInput.on('keyup blur', function onTyping() {
-
- if (thisInput[0].value &&
- thisInput[0].value.length &&
- thisInput[0].value.length > 0) {
-
- try {
- if (dateFormat) {
- date = localDateTimestamp(thisInput[0].value.toString(), dateFormat);
- } else {
- date = new Date(thisInput[0].value.toString());
- }
-
- if (date.getFullYear() &&
- !isNaN(date.getDay()) &&
- !isNaN(date.getMonth()) &&
- $scope.isSelectableDay(date.getMonth(), date.getFullYear(), date.getDay()) &&
- $scope.isSelectableDate(date.getMonth(), date.getFullYear(), date.getDay()) &&
- $scope.isSelectableMaxDate(date) &&
- $scope.isSelectableMinDate(date)) {
-
- $scope.$apply(function applyTyping() {
-
- $scope.month = $filter('date')(date, 'MMMM');//december-November like
- $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
- $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
-
- if (date.getFullYear().toString().length === 4) {
- $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
- }
- setDaysInMonth($scope.monthNumber, $scope.year);
- });
- }
- } catch (e) {
-
- return e;
+ if (date.getFullYear() &&
+ !isNaN(date.getDay()) &&
+ !isNaN(date.getMonth()) &&
+ $scope.isSelectableDay(date.getMonth(), date.getFullYear(), date.getDay()) &&
+ $scope.isSelectableDate(date.getMonth(), date.getFullYear(), date.getDay()) &&
+ $scope.isSelectableMaxDate(date) &&
+ $scope.isSelectableMinDate(date)) {
+
+ $scope.$apply(function applyTyping() {
+
+ $scope.month = $filter('date')(date, 'MMMM');//december-November like
+ $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
+ $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
+
+ if (date.getFullYear().toString().length === 4) {
+ $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
+ }
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ });
}
+ } catch (e) {
+
+ return e;
}
- });
- }
- //check range dates
- if ($scope.dateMaxLimit &&
- theNewYears &&
- theNewYears.length &&
- !$scope.isSelectableMaxYear(Number(theNewYears[theNewYears.length - 1]) + 1)) {
+ }
+ });
+ }
+ //check range dates
+ if ($scope.dateMaxLimit &&
+ theNewYears &&
+ theNewYears.length &&
+ !$scope.isSelectableMaxYear(Number(theNewYears[theNewYears.length - 1]) + 1)) {
- $scope.paginationYearsNextDisabled = true;
- } else {
+ $scope.paginationYearsNextDisabled = true;
+ } else {
- $scope.paginationYearsNextDisabled = false;
- }
+ $scope.paginationYearsNextDisabled = false;
+ }
- if ($scope.dateMinLimit &&
- theNewYears &&
- theNewYears.length &&
- !$scope.isSelectableMinYear(Number(theNewYears[0]) - 1)) {
+ if ($scope.dateMinLimit &&
+ theNewYears &&
+ theNewYears.length &&
+ !$scope.isSelectableMinYear(Number(theNewYears[0]) - 1)) {
- $scope.paginationYearsPrevDisabled = true;
- } else {
+ $scope.paginationYearsPrevDisabled = true;
+ } else {
- $scope.paginationYearsPrevDisabled = false;
- }
+ $scope.paginationYearsPrevDisabled = false;
+ }
- $scope.paginationYears = theNewYears;
- };
+ $scope.paginationYears = theNewYears;
+ };
- $scope.isSelectableDay = function isSelectableDay(monthNumber, year, day) {
- var i = 0;
+ $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;
- }
+ 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;
- };
+ return true;
+ };
- $scope.isSelectableDate = function isSelectableDate(monthNumber, year, day) {
- var i = 0;
+ $scope.isSelectableDate = function isSelectableDate(monthNumber, year, day) {
+ var i = 0;
- if (dateDisabledDates &&
- dateDisabledDates.length > 0) {
+ if (dateDisabledDates &&
+ dateDisabledDates.length > 0) {
- for (i; i <= dateDisabledDates.length; i += 1) {
+ for (i; i <= dateDisabledDates.length; i += 1) {
- if (new Date(dateDisabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) {
+ if (new Date(dateDisabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) {
- return false;
- }
+ return false;
}
}
+ }
- if (dateEnabledDates) {
+ if (dateEnabledDates) {
- for (i; i <= dateEnabledDates.length; i += 1) {
+ for (i; i <= dateEnabledDates.length; i += 1) {
- if (new Date(dateEnabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) {
+ if (new Date(dateEnabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) {
- return true;
- }
+ return true;
}
-
- return false;
}
- return true;
- };
+ return false;
+ }
- $scope.isSelectableMinDate = function isSelectableMinDate(aDate) {
- //if current date
- if (!!$scope.dateMinLimit &&
- !!new Date($scope.dateMinLimit) &&
- new Date(aDate).getTime() < new Date($scope.dateMinLimit).getTime()) {
+ return true;
+ };
- return false;
- }
+ $scope.isSelectableMinDate = function isSelectableMinDate(aDate) {
+ //if current date
+ if (!!$scope.dateMinLimit &&
+ !!new Date($scope.dateMinLimit) &&
+ new Date(aDate).getTime() < new Date($scope.dateMinLimit).getTime()) {
- return true;
- };
+ return false;
+ }
- $scope.isSelectableMaxDate = function isSelectableMaxDate(aDate) {
- //if current date
- if (!!$scope.dateMaxLimit &&
- !!new Date($scope.dateMaxLimit) &&
- new Date(aDate).getTime() > new Date($scope.dateMaxLimit).getTime()) {
+ return true;
+ };
- return false;
- }
+ $scope.isSelectableMaxDate = function isSelectableMaxDate(aDate) {
+ //if current date
+ if (!!$scope.dateMaxLimit &&
+ !!new Date($scope.dateMaxLimit) &&
+ new Date(aDate).getTime() > new Date($scope.dateMaxLimit).getTime()) {
- return true;
- };
+ return false;
+ }
- $scope.isSelectableMaxYear = function isSelectableMaxYear(year) {
- if (!!$scope.dateMaxLimit &&
- year > new Date($scope.dateMaxLimit).getFullYear()) {
+ return true;
+ };
- return false;
- }
+ $scope.isSelectableMaxYear = function isSelectableMaxYear(year) {
+ if (!!$scope.dateMaxLimit &&
+ year > new Date($scope.dateMaxLimit).getFullYear()) {
- return true;
- };
+ return false;
+ }
- $scope.isSelectableMinYear = function isSelectableMinYear(year) {
- if (!!$scope.dateMinLimit &&
- year < new Date($scope.dateMinLimit).getFullYear()) {
+ return true;
+ };
- return false;
- }
+ $scope.isSelectableMinYear = function isSelectableMinYear(year) {
+ if (!!$scope.dateMinLimit &&
+ year < new Date($scope.dateMinLimit).getFullYear()) {
- return true;
- };
+ return false;
+ }
- $scope.validateWeekDay = function isValidWeekDay(weekDay) {
- var validWeekDay = Number(weekDay, 10);
- // making sure that the given option is valid
- if (!validWeekDay || validWeekDay < 0 || validWeekDay > 6) {
+ return true;
+ };
- validWeekDay = 0;
- }
- return validWeekDay;
- };
-
- // respect previously configured interpolation symbols.
- htmlTemplate = htmlTemplate.replace(/{{/g, $interpolate.startSymbol()).replace(/}}/g, $interpolate.endSymbol());
- $scope.dateMonthTitle = $scope.dateMonthTitle || 'Select month';
- $scope.dateYearTitle = $scope.dateYearTitle || 'Select year';
- $scope.buttonNextTitle = $scope.buttonNextTitle || 'Next';
- $scope.buttonPrevTitle = $scope.buttonPrevTitle || 'Prev';
- $scope.month = $filter('date')(date, 'MMMM');//december-November like
- $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
- $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
- $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay);
+ $scope.validateWeekDay = function isValidWeekDay(weekDay) {
+ var validWeekDay = Number(weekDay, 10);
+ // making sure that the given option is valid
+ if (!validWeekDay || validWeekDay < 0 || validWeekDay > 6) {
- if ($scope.dateMaxLimit) {
+ validWeekDay = 0;
+ }
+ return validWeekDay;
+ };
- $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like
- } else {
+ // respect previously configured interpolation symbols.
+ htmlTemplate = htmlTemplate.replace(/{{/g, $interpolate.startSymbol()).replace(/}}/g, $interpolate.endSymbol());
+ $scope.dateMonthTitle = $scope.dateMonthTitle || 'Select month';
+ $scope.dateYearTitle = $scope.dateYearTitle || 'Select year';
+ $scope.buttonNextTitle = $scope.buttonNextTitle || 'Next';
+ $scope.buttonPrevTitle = $scope.buttonPrevTitle || 'Prev';
+ $scope.month = $filter('date')(date, 'MMMM');//december-November like
+ $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
+ $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
+ $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay);
- $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
- }
- $scope.months = datetime.MONTH;
+ if ($scope.dateMaxLimit) {
- $scope.daysInString = [];
- for (n = $scope.dateWeekStartDay; n <= $scope.dateWeekStartDay + 6; n += 1) {
+ $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like
+ } else {
- $scope.daysInString.push(n % 7);
- }
- $scope.daysInString = $scope.daysInString.map(function mappingFunc(el) {
+ $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
+ }
+ $scope.months = datetime.MONTH;
- return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE');
- });
+ $scope.daysInString = [];
+ for (n = $scope.dateWeekStartDay; n <= $scope.dateWeekStartDay + 6; n += 1) {
- //create the calendar holder and append where needed
- if ($scope.datepickerAppendTo &&
- $scope.datepickerAppendTo.indexOf('.') !== -1) {
+ $scope.daysInString.push(n % 7);
+ }
+ $scope.daysInString = $scope.daysInString.map(function mappingFunc(el) {
- $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8);
- angular.element(document.getElementsByClassName($scope.datepickerAppendTo.replace('.', ''))[0]).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) {
+ return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE');
+ });
- theCalendar = angular.element(el)[0];
- }));
- } else if ($scope.datepickerAppendTo &&
- $scope.datepickerAppendTo.indexOf('#') !== -1) {
+ //create the calendar holder and append where needed
+ if ($scope.datepickerAppendTo &&
+ $scope.datepickerAppendTo.indexOf('.') !== -1) {
- $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8);
- angular.element(document.getElementById($scope.datepickerAppendTo.replace('#', ''))).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) {
+ $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8);
+ angular.element(document.getElementsByClassName($scope.datepickerAppendTo.replace('.', ''))[0]).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) {
- theCalendar = angular.element(el)[0];
- }));
- } else if ($scope.datepickerAppendTo &&
- $scope.datepickerAppendTo === 'body') {
- $scope.datepickerID = 'datepicker-id-' + (new Date().getTime() + (Math.floor(Math.random() * 6) + 8));
- angular.element(document).find('body').append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) {
+ theCalendar = angular.element(el)[0];
+ }));
+ } else if ($scope.datepickerAppendTo &&
+ $scope.datepickerAppendTo.indexOf('#') !== -1) {
- theCalendar = angular.element(el)[0];
- }));
- } else {
+ $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8);
+ angular.element(document.getElementById($scope.datepickerAppendTo.replace('#', ''))).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) {
- thisInput.after($compile(angular.element(htmlTemplate))($scope));
- //get the calendar as element
- theCalendar = element[0].querySelector('._720kb-datepicker-calendar');
- }
- //if datepicker-toggle="" is not present or true by default
- if (checkToggle()) {
+ theCalendar = angular.element(el)[0];
+ }));
+ } else if ($scope.datepickerAppendTo &&
+ $scope.datepickerAppendTo === 'body') {
+ $scope.datepickerID = 'datepicker-id-' + (new Date().getTime() + (Math.floor(Math.random() * 6) + 8));
+ angular.element(document).find('body').append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) {
- thisInput.on('focus click focusin', function onFocusAndClick() {
+ theCalendar = angular.element(el)[0];
+ }));
+ } else {
- isMouseOnInput = true;
+ thisInput.after($compile(angular.element(htmlTemplate))($scope));
+ //get the calendar as element
+ theCalendar = element[0].querySelector('._720kb-datepicker-calendar');
+ }
+ //if datepicker-toggle="" is not present or true by default
+ if (checkToggle()) {
- if (!isMouseOn &&
- !isMouseOnInput && theCalendar) {
+ thisInput.on('focus click focusin', function onFocusAndClick() {
- $scope.hideCalendar();
- } else {
+ isMouseOnInput = true;
- showCalendar();
- }
- });
- }
+ if (!isMouseOn &&
+ !isMouseOnInput && theCalendar) {
- thisInput.on('focusout blur', function onBlurAndFocusOut() {
+ $scope.hideCalendar();
+ } else {
- isMouseOnInput = false;
+ showCalendar();
+ }
});
- //some tricky dirty events to fire if click is outside of the calendar and show/hide calendar when needed
- angular.element(theCalendar).on('mouseenter', function onMouseEnter() {
+ }
- isMouseOn = true;
- });
+ thisInput.on('focusout blur', function onBlurAndFocusOut() {
- angular.element(theCalendar).on('mouseleave', function onMouseLeave() {
+ isMouseOnInput = false;
+ });
+ //some tricky dirty events to fire if click is outside of the calendar and show/hide calendar when needed
+ angular.element(theCalendar).on('mouseenter', function onMouseEnter() {
- isMouseOn = false;
- });
+ isMouseOn = true;
+ });
- angular.element(theCalendar).on('focusin', function onCalendarFocus() {
+ angular.element(theCalendar).on('mouseleave', function onMouseLeave() {
- isMouseOn = true;
- });
+ isMouseOn = false;
+ });
- angular.element($window).on('click focus focusin', onClickOnWindow);
+ angular.element(theCalendar).on('focusin', function onCalendarFocus() {
- //check always if given range of dates is ok
- if ($scope.dateMinLimit &&
- !$scope.isSelectableMinYear($scope.year) ||
- !$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
+ isMouseOn = true;
+ });
- resetToMinDate();
- }
+ angular.element($window).on('click focus focusin', onClickOnWindow);
- if ($scope.dateMaxLimit &&
- !$scope.isSelectableMaxYear($scope.year) ||
- !$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
+ //check always if given range of dates is ok
+ if ($scope.dateMinLimit &&
+ !$scope.isSelectableMinYear($scope.year) ||
+ !$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
- resetToMaxDate();
- }
+ resetToMinDate();
+ }
- //datepicker boot start
- $scope.paginateYears($scope.year);
+ if ($scope.dateMaxLimit &&
+ !$scope.isSelectableMaxYear($scope.year) ||
+ !$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
- setDaysInMonth($scope.monthNumber, $scope.year);
- $scope.checkVisibility = checkVisibility;
-
- $scope.$on('$destroy', function unregisterListener() {
-
- unregisterDataSetWatcher();
- unregisterDateMinLimitWatcher();
- unregisterDateMaxLimitWatcher();
- unregisterDateFormatWatcher();
- unregisterDateDisabledDatesWatcher();
- unregisterDateEnabledDatesWatcher();
- thisInput.off('focus click focusout blur');
- angular.element(theCalendar).off('mouseenter mouseleave focusin');
- angular.element($window).off('click focus focusin', onClickOnWindow);
- });
- };
+ resetToMaxDate();
+ }
- return {
- 'restrict': 'AEC',
- 'scope': {
- 'dateSet': '@',
- 'dateMinLimit': '@',
- 'dateMaxLimit': '@',
- 'dateMonthTitle': '@',
- 'dateYearTitle': '@',
- 'buttonNextTitle': '@',
- 'buttonPrevTitle': '@',
- 'dateDisabledDates': '@',
- 'dateEnabledDates': '@',
- 'dateDisabledWeekdays': '@',
- 'dateSetHidden': '@',
- 'dateTyper': '@',
- 'dateWeekStartDay': '@',
- 'datepickerAppendTo': '@',
- 'datepickerToggle': '@',
- 'datepickerClass': '@',
- 'datepickerShow': '@'
- },
- 'link': linkingFunction
- };
+ //datepicker boot start
+ $scope.paginateYears($scope.year);
+
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ $scope.checkVisibility = checkVisibility;
+
+ $scope.$on('$destroy', function unregisterListener() {
+
+ unregisterDataSetWatcher();
+ unregisterDateMinLimitWatcher();
+ unregisterDateMaxLimitWatcher();
+ unregisterDateFormatWatcher();
+ unregisterDateDisabledDatesWatcher();
+ unregisterDateEnabledDatesWatcher();
+ thisInput.off('focus click focusout blur');
+ angular.element(theCalendar).off('mouseenter mouseleave focusin');
+ angular.element($window).off('click focus focusin', onClickOnWindow);
+ });
+ };
+
+ return {
+ 'restrict': 'AEC',
+ 'scope': {
+ 'dateSet': '@',
+ 'dateMinLimit': '@',
+ 'dateMaxLimit': '@',
+ 'dateMonthTitle': '@',
+ 'dateYearTitle': '@',
+ 'buttonNextTitle': '@',
+ 'buttonPrevTitle': '@',
+ 'dateDisabledDates': '@',
+ 'dateEnabledDates': '@',
+ 'dateDisabledWeekdays': '@',
+ 'dateSetHidden': '@',
+ 'dateTyper': '@',
+ 'dateWeekStartDay': '@',
+ 'datepickerAppendTo': '@',
+ 'datepickerToggle': '@',
+ 'datepickerClass': '@',
+ 'datepickerShow': '@',
+ 'anyDay': '@'
+ },
+ 'link': linkingFunction
};
+ };
angular.module('720kb.datepicker', [])
- .directive('datepicker', ['$window', '$compile', '$locale', '$filter', '$interpolate', '$timeout', datepickerDirective]);
+ .directive('datepicker', ['$window', '$compile', '$locale', '$filter', '$interpolate', '$timeout', datepickerDirective]);
}(angular, navigator));
diff --git a/dist/angular-datepicker.min.js b/dist/angular-datepicker.min.js
index 13c53aa..051c793 100644
--- a/dist/angular-datepicker.min.js
+++ b/dist/angular-datepicker.min.js
@@ -4,9 +4,9 @@
* Released by 720kb.net under the MIT license
* www.opensource.org/licenses/MIT
*
- * 2017-06-28
+ * 2018-03-13
*/
-!function(e,a){"use strict";var t=function(){if(a.userAgent&&(a.userAgent.match(/Android/i)||a.userAgent.match(/webOS/i)||a.userAgent.match(/iPhone/i)||a.userAgent.match(/iPad/i)||a.userAgent.match(/iPod/i)||a.userAgent.match(/BlackBerry/i)||a.userAgent.match(/Windows Phone/i)))return!0}(),n=function(e,a,n){return n&&(t=!1),t?['",'"]:['"]},i=function(e,a){return['"]},r=function(e,a,t){var r=['',"
"],d=n(e,a,t),l=i(e,a),c=['"],o=['','
',"{{px}}","","
","{{item}}","",'
',"{{nx}}","","
"],s=function(e){r.splice(r.length-1,0,e)};return d.forEach(s),l.forEach(s),c.forEach(s),o.forEach(s),r.join("")},d=function(a,n,i,d,l,c){return{restrict:"AEC",scope:{dateSet:"@",dateMinLimit:"@",dateMaxLimit:"@",dateMonthTitle:"@",dateYearTitle:"@",buttonNextTitle:"@",buttonPrevTitle:"@",dateDisabledDates:"@",dateEnabledDates:"@",dateDisabledWeekdays:"@",dateSetHidden:"@",dateTyper:"@",dateWeekStartDay:"@",datepickerAppendTo:"@",datepickerToggle:"@",datepickerClass:"@",datepickerShow:"@"},link:function(o,s,m){var u,b,h,y=m.selector,p=e.element(y?s[0].querySelector("."+y):s[0].children[0]),g=m.buttonPrev||'〈',M=m.buttonNext||'〉',k=m.dateFormat,f=o.$eval(o.dateDisabledDates),D=o.$eval(o.dateEnabledDates),v=o.$eval(o.dateDisabledWeekdays),N=new Date,S=!1,w=!1,x=void 0!==m.datepickerMobile&&"false"!==m.datepickerMobile,Y=i.DATETIME_FORMATS,T=r(g,M,x),_=function(){S||w||!u||o.hideCalendar()},L=function(e,a){var t,n,i,r,d,l=new Date(a,e,0).getDate(),c=new Date(a+"/"+e+"/1").getDay(),s=new Date(a+"/"+e+"/"+l).getDay(),m=[],u=[];for(o.days=[],o.dateWeekStartDay=o.validateWeekDay(o.dateWeekStartDay),d=(o.dateWeekStartDay+6)%7,t=1;t<=l;t+=1)o.days.push(t);if(c===o.dateWeekStartDay)o.prevMonthDays=[];else{for(i=c-o.dateWeekStartDay,c0}),t=a.match(m).filter(function(e){return null!==e.match(/^[a-zA-Z]+$/i)}),l=0;l-1||((t=e.className.split(" ")).push(a),e.className=t.join(" "))},remove:function(e,a){var t,n;if(-1!==e.className.indexOf(a)){for(n=e.className.split(" "),t=0;tNumber(e)&&!o.isSelectableMinYear(e))return;o.paginateYears(e),o.showYearsPagination=!1,c(function(){o.year=Number(e),L(o.monthNumber,o.year)},0)},o.hideCalendar=function(){u.classList?u.classList.remove("_720kb-datepicker-open"):O.remove(u,"_720kb-datepicker-open")},o.setDatepickerDay=function(e){o.isSelectableDay(o.monthNumber,o.year,e)&&o.isSelectableDate(o.monthNumber,o.year,e)&&o.isSelectableMaxDate(o.year+"/"+o.monthNumber+"/"+e)&&o.isSelectableMinDate(o.year+"/"+o.monthNumber+"/"+e)&&(o.day=Number(e),o.selectedDay=o.day,o.selectedMonth=o.monthNumber,o.selectedYear=o.year,H(),m.hasOwnProperty("dateRefocus")&&p[0].focus(),o.hideCalendar())},o.paginateYears=function(e){var a,n=[],i=10,r=10;for(o.paginationYears=[],t&&(i=50,r=50,o.dateMinLimit&&o.dateMaxLimit&&(i=(e=new Date(o.dateMaxLimit).getFullYear())-new Date(o.dateMinLimit).getFullYear(),r=1)),a=i;a>0;a-=1)n.push(Number(e)-a);for(a=0;a0)try{(N=k?E(p[0].value.toString(),k):new Date(p[0].value.toString())).getFullYear()&&!isNaN(N.getDay())&&!isNaN(N.getMonth())&&o.isSelectableDay(N.getMonth(),N.getFullYear(),N.getDay())&&o.isSelectableDate(N.getMonth(),N.getFullYear(),N.getDay())&&o.isSelectableMaxDate(N)&&o.isSelectableMinDate(N)&&o.$apply(function(){o.month=d("date")(N,"MMMM"),o.monthNumber=Number(d("date")(N,"MM")),o.day=Number(d("date")(N,"dd")),4===N.getFullYear().toString().length&&(o.year=Number(d("date")(N,"yyyy"))),L(o.monthNumber,o.year)})}catch(e){return e}}),o.dateMaxLimit&&n&&n.length&&!o.isSelectableMaxYear(Number(n[n.length-1])+1)?o.paginationYearsNextDisabled=!0:o.paginationYearsNextDisabled=!1,o.dateMinLimit&&n&&n.length&&!o.isSelectableMinYear(Number(n[0])-1)?o.paginationYearsPrevDisabled=!0:o.paginationYearsPrevDisabled=!1,o.paginationYears=n},o.isSelectableDay=function(e,a,t){var n=0;if(v&&v.length>0)for(n;n<=v.length;n+=1)if(v[n]===new Date(e+"/"+t+"/"+a).getDay())return!1;return!0},o.isSelectableDate=function(e,a,t){var n=0;if(f&&f.length>0)for(n;n<=f.length;n+=1)if(new Date(f[n]).getTime()===new Date(e+"/"+t+"/"+a).getTime())return!1;if(D){for(n;n<=D.length;n+=1)if(new Date(D[n]).getTime()===new Date(e+"/"+t+"/"+a).getTime())return!0;return!1}return!0},o.isSelectableMinDate=function(e){return!(o.dateMinLimit&&new Date(o.dateMinLimit)&&new Date(e).getTime()new Date(o.dateMaxLimit).getTime())},o.isSelectableMaxYear=function(e){return!(o.dateMaxLimit&&e>new Date(o.dateMaxLimit).getFullYear())},o.isSelectableMinYear=function(e){return!(o.dateMinLimit&&e6)&&(a=0),a},T=T.replace(/{{/g,l.startSymbol()).replace(/}}/g,l.endSymbol()),o.dateMonthTitle=o.dateMonthTitle||"Select month",o.dateYearTitle=o.dateYearTitle||"Select year",o.buttonNextTitle=o.buttonNextTitle||"Next",o.buttonPrevTitle=o.buttonPrevTitle||"Prev",o.month=d("date")(N,"MMMM"),o.monthNumber=Number(d("date")(N,"MM")),o.day=Number(d("date")(N,"dd")),o.dateWeekStartDay=o.validateWeekDay(o.dateWeekStartDay),o.dateMaxLimit?o.year=Number(d("date")(new Date(o.dateMaxLimit),"yyyy")):o.year=Number(d("date")(N,"yyyy")),o.months=Y.MONTH,o.daysInString=[],h=o.dateWeekStartDay;h<=o.dateWeekStartDay+6;h+=1)o.daysInString.push(h%7);o.daysInString=o.daysInString.map(function(e){return d("date")(new Date(new Date("06/08/2014").valueOf()+864e5*e),"EEE")}),o.datepickerAppendTo&&-1!==o.datepickerAppendTo.indexOf(".")?(o.datepickerID="datepicker-id-"+(new Date).getTime()+(Math.floor(6*Math.random())+8),e.element(document.getElementsByClassName(o.datepickerAppendTo.replace(".",""))[0]).append(n(e.element(T))(o,function(a){u=e.element(a)[0]}))):o.datepickerAppendTo&&-1!==o.datepickerAppendTo.indexOf("#")?(o.datepickerID="datepicker-id-"+(new Date).getTime()+(Math.floor(6*Math.random())+8),e.element(document.getElementById(o.datepickerAppendTo.replace("#",""))).append(n(e.element(T))(o,function(a){u=e.element(a)[0]}))):o.datepickerAppendTo&&"body"===o.datepickerAppendTo?(o.datepickerID="datepicker-id-"+((new Date).getTime()+(Math.floor(6*Math.random())+8)),e.element(document).find("body").append(n(e.element(T))(o,function(a){u=e.element(a)[0]}))):(p.after(n(e.element(T))(o)),u=s[0].querySelector("._720kb-datepicker-calendar")),function(){return!o.datepickerToggle||o.$eval(o.datepickerToggle)}()&&p.on("focus click focusin",function(){w=!0,S||w||!u?F():o.hideCalendar()}),p.on("focusout blur",function(){w=!1}),e.element(u).on("mouseenter",function(){S=!0}),e.element(u).on("mouseleave",function(){S=!1}),e.element(u).on("focusin",function(){S=!0}),e.element(a).on("click focus focusin",_),(o.dateMinLimit&&!o.isSelectableMinYear(o.year)||!o.isSelectableMinDate(o.year+"/"+o.monthNumber+"/"+o.day))&&$(),(o.dateMaxLimit&&!o.isSelectableMaxYear(o.year)||!o.isSelectableMaxDate(o.year+"/"+o.monthNumber+"/"+o.day))&&A(),o.paginateYears(o.year),L(o.monthNumber,o.year),o.checkVisibility=j,o.$on("$destroy",function(){I(),C(),B(),G(),z(),R(),p.off("focus click focusout blur"),e.element(u).off("mouseenter mouseleave focusin"),e.element(a).off("click focus focusin",_)})}}};e.module("720kb.datepicker",[]).directive("datepicker",["$window","$compile","$locale","$filter","$interpolate","$timeout",d])}(angular,navigator);
+!function(I,e){"use strict";var C=function(){if(e.userAgent&&(e.userAgent.match(/Android/i)||e.userAgent.match(/webOS/i)||e.userAgent.match(/iPhone/i)||e.userAgent.match(/iPad/i)||e.userAgent.match(/iPod/i)||e.userAgent.match(/BlackBerry/i)||e.userAgent.match(/Windows Phone/i)))return!0}(),B=function(e,a,t){var i,n,r=['',"
"],d=(i=e,n=a,t&&(C=!1),C?['",'"]:['",'",'"]),l=['"],c=['"],o=['"],s=['','
',"{{px}}","","
","{{item}}","",'
',"{{nx}}","","
"],m=function(e){r.splice(r.length-1,0,e)};return d.forEach(m),l.forEach(m),c.forEach(m),o.forEach(m),s.forEach(m),r.join("")};I.module("720kb.datepicker",[]).directive("datepicker",["$window","$compile","$locale","$filter","$interpolate","$timeout",function(E,W,O,H,j,F){return{restrict:"AEC",scope:{dateSet:"@",dateMinLimit:"@",dateMaxLimit:"@",dateMonthTitle:"@",dateYearTitle:"@",buttonNextTitle:"@",buttonPrevTitle:"@",dateDisabledDates:"@",dateEnabledDates:"@",dateDisabledWeekdays:"@",dateSetHidden:"@",dateTyper:"@",dateWeekStartDay:"@",datepickerAppendTo:"@",datepickerToggle:"@",datepickerClass:"@",datepickerShow:"@",anyDay:"@"},link:function(u,e,t){var a,i,n,r=t.selector,d=I.element(r?e[0].querySelector("."+r):e[0].children[0]),l=t.buttonPrev||'〈',c=t.buttonNext||'〉',o=t.dateFormat,s=u.$eval(u.dateDisabledDates),m=u.$eval(u.dateEnabledDates),b=u.$eval(u.dateDisabledWeekdays),h=new Date,y=!1,p=!1,k=void 0!==t.datepickerMobile&&"false"!==t.datepickerMobile,g=O.DATETIME_FORMATS,M=B(l,c,k),D=function(){y||p||!a||u.hideCalendar()},f=function(e,a){var t,i,n,r,d,l=new Date(a,e,0).getDate(),c=new Date(a+"/"+e+"/1").getDay(),o=new Date(a+"/"+e+"/"+l).getDay(),s=[],m=[];for(u.days=[],u.dateWeekStartDay=u.validateWeekDay(u.dateWeekStartDay),d=(u.dateWeekStartDay+6)%7,t=1;t<=l;t+=1)u.days.push(t);if(c===u.dateWeekStartDay)u.prevMonthDays=[];else{for(n=c-u.dateWeekStartDay,cNumber(e)&&!u.isSelectableMinYear(e))return;u.paginateYears(e),u.showYearsPagination=!1,F(function(){u.year=Number(e),f(u.monthNumber,u.year)},0)},u.showMPagination=function(){u.showYearsPagination=!1,u.showMonthPagination=!u.showMonthPagination},u.showYPagination=function(){u.showMonthPagination=!1,u.showYearsPagination=!u.showYearsPagination},u.hideCalendar=function(){a.classList?a.classList.remove("_720kb-datepicker-open"):_(a,"_720kb-datepicker-open")},u.setDatepickerDay=function(e,a){u.isSelectableDay(u.monthNumber,u.year,e)&&u.isSelectableDate(u.monthNumber,u.year,e)&&u.isSelectableMaxDate(u.year+"/"+u.monthNumber+"/"+e)&&u.isSelectableMinDate(u.year+"/"+u.monthNumber+"/"+e)&&("previous"===a?1!==u.monthNumber?u.monthNumber-=1:(u.monthNumber=12,u.year-=1):"next"===a&&(12!==u.monthNumber?u.monthNumber+=1:(u.monthNumber=1,u.year+=1)),u.day=Number(e),u.selectedDay=u.day,u.selectedMonth=u.monthNumber,u.selectedYear=u.year,S(),t.hasOwnProperty("dateRefocus")&&d[0].focus(),u.hideCalendar())},u.paginateYears=function(e){var a,t=[],i=10,n=10;for(u.paginationYears=[],C&&(n=i=50,u.dateMinLimit&&u.dateMaxLimit&&(i=(e=new Date(u.dateMaxLimit).getFullYear())-new Date(u.dateMinLimit).getFullYear(),n=1)),a=i;0new Date(u.dateMaxLimit).getTime())},u.isSelectableMaxYear=function(e){return!(u.dateMaxLimit&&e>new Date(u.dateMaxLimit).getFullYear())},u.isSelectableMinYear=function(e){return!(u.dateMinLimit&&ea,
+._720kb-datepicker-calendar-years-pagination>a:hover {
+ border: 1px solid #EAEAEA;
+ border-radius: 3px;
+ font-size: 12px;
+ line-height: 14px;
+ padding: 7px 10px;
+ font-family: Montserrat, sans-serif!important
}
+
+._720kb-datepicker-calendar-years-pagination>a {
+ background-color: #F5F6FA!important;
+ color: #202020!important;
+ font-family: Montserrat, sans-serif!important
+}
+
+._720kb-datepicker-calendar-years-pagination>a:hover {
+ background-color: #F95A4F!important;
+ color: #fff!important
+}
+
+._720kb-datepicker-calendar-years-pagination>a._720kb-datepicker-active {
+ background-color: #FE3429!important;
+ color: #fff!important;
+ font-family: Montserrat, sans-serif!important
+}
+
+._720kb-datepicker-calendar-month span {
+ font-size: 16px;
+ color: #000;
+ font-weight: 700;
+ font-family: Montserrat, sans-serif!important
+}
+
+._720kb-datepicker-calendar-header-left>a,
+._720kb-datepicker-calendar-header-right>a {
+ font-size: 9px!important;
+ font-family: Montserrat, sans-serif!important
+}
+
+._720kb-datepicker-calendar-days-header {
+ background: 0 0!important;
+ border-bottom: none!important;
+ font-family: Montserrat, sans-serif!important
+}
+
+._720kb-datepicker-calendar-days-header>div {
+ color: #2C3135!important;
+ font-size: 14px;
+ font-family: Montserrat, sans-serif!important
+}
+
+._720kb-datepicker-calendar-day {
+ font-family: Montserrat, sans-serif!important;
+ font-size: 14px!important;
+ color: #2C3135!important;
+ border-radius: 3px!important
+}
+
+._720kb-datepicker-calendar-day: hover {
+ background: #F1F4F8!important;
+ border-radius: 3px!important
+}
+
+._720kb-datepicker-active {
+ background: #FE3429!important;
+ color: #fff!important
+}
+
+._720kb-datepicker-today {
+ border-radius: 3px!important;
+ color: #F95A4F!important;
+ background: #fff!important
+}
\ No newline at end of file
diff --git a/src/js/angular-datepicker.js b/src/js/angular-datepicker.js
index 971dbc9..24a5e8c 100644
--- a/src/js/angular-datepicker.js
+++ b/src/js/angular-datepicker.js
@@ -6,8 +6,8 @@
var A_DAY_IN_MILLISECONDS = 86400000
, isMobile = (function isMobile() {
- if (navigator.userAgent &&
- (navigator.userAgent.match(/Android/i) ||
+ if (navigator.userAgent &&
+ (navigator.userAgent.match(/Android/i) ||
navigator.userAgent.match(/webOS/i) ||
navigator.userAgent.match(/iPhone/i) ||
navigator.userAgent.match(/iPad/i) ||
@@ -15,435 +15,386 @@
navigator.userAgent.match(/BlackBerry/i) ||
navigator.userAgent.match(/Windows Phone/i))) {
- return true;
- }
- }())
+ return true;
+ }
+ }())
, generateMonthAndYearHeader = function generateMonthAndYearHeader(prevButton, nextButton, preventMobile) {
- if (preventMobile) {
+ if (preventMobile) {
- isMobile = false;
- }
+ isMobile = false;
+ }
- if (isMobile) {
-
- return [
- '',
- ''
- ];
- }
+ if (isMobile) {
return [
'',
+ ''
];
}
+
+ return [
+ '",
+ '",
+ ''
+ ];
+ }
, generateYearsPaginationHeader = function generateYearsPaginationHeader(prevButton, nextButton) {
- return [
- ''
- ];
- }
+ return [
+ '"
+ ];
+ }
, generateDaysColumns = function generateDaysColumns() {
- return [
+ return [
''
- ];
- }
+ ];
+ }
, generateDays = function generateDays() {
-
- return [
- '',
- '
',
- '{{px}}',
- '',
- '
',
- '{{item}}',
- '',
- '
',
- '{{nx}}',
- '',
- '
'
- ];
- }
+ return [
+ '',
+ '
',
+ '{{px}}',
+ '',
+ '
',
+ '{{item}}',
+ '',
+ '
',
+ '{{nx}}',
+ '',
+ '
'
+ ];
+ }
, generateHtmlTemplate = function generateHtmlTemplate(prevButton, nextButton, preventMobile) {
- var toReturn = [
- '',
- '
'
- ]
- , monthAndYearHeader = generateMonthAndYearHeader(prevButton, nextButton, preventMobile)
+ var toReturn = [
+ '',
+ '
'
+ ]
, yearsPaginationHeader = generateYearsPaginationHeader(prevButton, nextButton)
+ , monthAndYearHeader = generateMonthAndYearHeader(prevButton, nextButton, preventMobile)
, daysColumns = generateDaysColumns()
, days = generateDays()
, iterator = function iterator(aRow) {
- toReturn.splice(toReturn.length - 1, 0, aRow);
- };
-
- monthAndYearHeader.forEach(iterator);
- yearsPaginationHeader.forEach(iterator);
- daysColumns.forEach(iterator);
- days.forEach(iterator);
+ toReturn.splice(toReturn.length - 1, 0, aRow);
+ };
+ yearsPaginationHeader.forEach(iterator);
+ monthAndYearHeader.forEach(iterator);
+ daysColumns.forEach(iterator);
+ days.forEach(iterator);
- return toReturn.join('');
- }
+ return toReturn.join('');
+ }
, datepickerDirective = function datepickerDirective($window, $compile, $locale, $filter, $interpolate, $timeout) {
- var linkingFunction = function linkingFunction($scope, element, attr) {
-
- //get child input
- var selector = attr.selector
- , thisInput = angular.element(selector ? element[0].querySelector('.' + selector) : element[0].children[0])
- , theCalendar
- , defaultPrevButton = '〈'
- , defaultNextButton = '〉'
- , prevButton = attr.buttonPrev || defaultPrevButton
- , nextButton = attr.buttonNext || defaultNextButton
- , dateFormat = attr.dateFormat
- //, dateMinLimit
- //, dateMaxLimit
- , dateDisabledDates = $scope.$eval($scope.dateDisabledDates)
- , dateEnabledDates = $scope.$eval($scope.dateEnabledDates)
- , dateDisabledWeekdays = $scope.$eval($scope.dateDisabledWeekdays)
- , date = new Date()
- , isMouseOn = false
- , isMouseOnInput = false
- , preventMobile = typeof attr.datepickerMobile !== 'undefined' && attr.datepickerMobile !== 'false'
- , datetime = $locale.DATETIME_FORMATS
- , pageDatepickers
- , hours24h = 86400000
- , htmlTemplate = generateHtmlTemplate(prevButton, nextButton, preventMobile)
- , n
- , onClickOnWindow = function onClickOnWindow() {
-
- if (!isMouseOn &&
- !isMouseOnInput && theCalendar) {
-
- $scope.hideCalendar();
- }
+ var linkingFunction = function linkingFunction($scope, element, attr) {
+
+ //get child input
+ var selector = attr.selector
+ , thisInput = angular.element(selector ? element[0].querySelector('.' + selector) : element[0].children[0])
+ , theCalendar
+ , defaultPrevButton = '〈'
+ , defaultNextButton = '〉'
+ , prevButton = attr.buttonPrev || defaultPrevButton
+ , nextButton = attr.buttonNext || defaultNextButton
+ , dateFormat = attr.dateFormat
+ //, dateMinLimit
+ //, dateMaxLimit
+ , dateDisabledDates = $scope.$eval($scope.dateDisabledDates)
+ , dateEnabledDates = $scope.$eval($scope.dateEnabledDates)
+ , dateDisabledWeekdays = $scope.$eval($scope.dateDisabledWeekdays)
+ , date = new Date()
+ , isMouseOn = false
+ , isMouseOnInput = false
+ , preventMobile = typeof attr.datepickerMobile !== 'undefined' && attr.datepickerMobile !== 'false'
+ , datetime = $locale.DATETIME_FORMATS
+ , pageDatepickers
+ , hours24h = 86400000
+ , htmlTemplate = generateHtmlTemplate(prevButton, nextButton, preventMobile)
+ , n
+ , onClickOnWindow = function onClickOnWindow() {
+
+ if (!isMouseOn &&
+ !isMouseOnInput && theCalendar) {
+
+ $scope.hideCalendar();
}
- , setDaysInMonth = function setDaysInMonth(month, year) {
+ }
+ , setDaysInMonth = function setDaysInMonth(month, year) {
- var i
- , limitDate = new Date(year, month, 0).getDate()
- , firstDayMonthNumber = new Date(year + '/' + month + '/' + 1).getDay()
- , lastDayMonthNumber = new Date(year + '/' + month + '/' + limitDate).getDay()
- , prevMonthDays = []
- , nextMonthDays = []
- , howManyNextDays
- , howManyPreviousDays
- , monthAlias
- , dateWeekEndDay;
-
- $scope.days = [];
- $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay);
- dateWeekEndDay = ($scope.dateWeekStartDay + 6) % 7;
-
- for (i = 1; i <= limitDate; i += 1) {
-
- $scope.days.push(i);
- }
+ var i
+ , limitDate = new Date(year, month, 0).getDate()
+ , firstDayMonthNumber = new Date(year + '/' + month + '/' + 1).getDay()
+ , lastDayMonthNumber = new Date(year + '/' + month + '/' + limitDate).getDay()
+ , prevMonthDays = []
+ , nextMonthDays = []
+ , howManyNextDays
+ , howManyPreviousDays
+ , monthAlias
+ , dateWeekEndDay;
+
+ $scope.days = [];
+ $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay);
+ dateWeekEndDay = ($scope.dateWeekStartDay + 6) % 7;
+
+ for (i = 1; i <= limitDate; i += 1) {
+
+ $scope.days.push(i);
+ }
- //get previous month days if first day in month is not first day in week
- if (firstDayMonthNumber === $scope.dateWeekStartDay) {
+ //get previous month days if first day in month is not first day in week
+ if (firstDayMonthNumber === $scope.dateWeekStartDay) {
- //no need for it
- $scope.prevMonthDays = [];
- } else {
+ //no need for it
+ $scope.prevMonthDays = [];
+ } else {
- howManyPreviousDays = firstDayMonthNumber - $scope.dateWeekStartDay;
+ howManyPreviousDays = firstDayMonthNumber - $scope.dateWeekStartDay;
- if (firstDayMonthNumber < $scope.dateWeekStartDay) {
+ if (firstDayMonthNumber < $scope.dateWeekStartDay) {
- howManyPreviousDays += 7;
- }
+ howManyPreviousDays += 7;
+ }
- //get previous month
- if (Number(month) === 1) {
+ //get previous month
+ if (Number(month) === 1) {
- monthAlias = 12;
- } else {
+ monthAlias = 12;
+ } else {
- monthAlias = month - 1;
- }
- //return previous month days
- for (i = 1; i <= new Date(year, monthAlias, 0).getDate(); i += 1) {
+ monthAlias = month - 1;
+ }
+ //return previous month days
+ for (i = 1; i <= new Date(year, monthAlias, 0).getDate(); i += 1) {
- prevMonthDays.push(i);
- }
- //attach previous month days
- $scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays);
+ prevMonthDays.push(i);
}
+ //attach previous month days
+ $scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays);
+ }
- //get next month days if last day in month is not last day in week
- if (lastDayMonthNumber === dateWeekEndDay) {
- //no need for it
- $scope.nextMonthDays = [];
- } else {
- howManyNextDays = 6 - lastDayMonthNumber + $scope.dateWeekStartDay;
+ //get next month days if last day in month is not last day in week
+ if (lastDayMonthNumber === dateWeekEndDay) {
+ //no need for it
+ $scope.nextMonthDays = [];
+ } else {
+ howManyNextDays = 6 - lastDayMonthNumber + $scope.dateWeekStartDay;
- if (lastDayMonthNumber < $scope.dateWeekStartDay) {
+ if (lastDayMonthNumber < $scope.dateWeekStartDay) {
- howManyNextDays -= 7;
- }
- //get previous month
+ howManyNextDays -= 7;
+ }
+ //get previous month
- //return next month days
- for (i = 1; i <= howManyNextDays; i += 1) {
+ //return next month days
+ for (i = 1; i <= howManyNextDays; i += 1) {
- nextMonthDays.push(i);
- }
- //attach previous month days
- $scope.nextMonthDays = nextMonthDays;
+ nextMonthDays.push(i);
}
+ //attach previous month days
+ $scope.nextMonthDays = nextMonthDays;
}
- , resetToMinDate = function resetToMinDate() {
+ }
+ , resetToMinDate = function resetToMinDate() {
- $scope.month = $filter('date')(new Date($scope.dateMinLimit), 'MMMM');
- $scope.monthNumber = Number($filter('date')(new Date($scope.dateMinLimit), 'MM'));
- $scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd'));
- $scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy'));
+ $scope.month = $filter('date')(new Date($scope.dateMinLimit), 'MMMM');
+ $scope.monthNumber = Number($filter('date')(new Date($scope.dateMinLimit), 'MM'));
+ $scope.day = Number($filter('date')(new Date($scope.dateMinLimit), 'dd'));
+ $scope.year = Number($filter('date')(new Date($scope.dateMinLimit), 'yyyy'));
- setDaysInMonth($scope.monthNumber, $scope.year);
- }
- , resetToMaxDate = function resetToMaxDate() {
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ }
+ , resetToMaxDate = function resetToMaxDate() {
- $scope.month = $filter('date')(new Date($scope.dateMaxLimit), 'MMMM');
- $scope.monthNumber = Number($filter('date')(new Date($scope.dateMaxLimit), 'MM'));
- $scope.day = Number($filter('date')(new Date($scope.dateMaxLimit), 'dd'));
- $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));
+ $scope.month = $filter('date')(new Date($scope.dateMaxLimit), 'MMMM');
+ $scope.monthNumber = Number($filter('date')(new Date($scope.dateMaxLimit), 'MM'));
+ $scope.day = Number($filter('date')(new Date($scope.dateMaxLimit), 'dd'));
+ $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));
- setDaysInMonth($scope.monthNumber, $scope.year);
- }
- , prevYear = function prevYear() {
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ }
+ , prevYear = function prevYear() {
- $scope.year = Number($scope.year) - 1;
- }
- , nextYear = function nextYear() {
+ $scope.year = $scope.setNewYear(Number($scope.year) - 1);
+ }
+ , nextYear = function nextYear() {
- $scope.year = Number($scope.year) + 1;
- }
- , localDateTimestamp = function localDateTimestamp(rawDate, dateFormatDefinition) {
-
- var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|MMMM|MMM|MM|M|dd?d?|yy?yy?y?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g
+ $scope.year = $scope.setNewYear(Number($scope.year) + 1);
+ }
+ , localDateTimestamp = function localDateTimestamp(rawDate, dateFormatDefinition) {
+
+ var formattingTokens = /(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|MMMM|MMM|MM|M|dd?d?|yy?yy?y?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g
,formatDate,dateSplit, m, d, y, index, el, longName, shortName;
- for (index = 0; index < datetime.MONTH.length; index += 1) {
- longName = datetime.MONTH[index];
- shortName = datetime.SHORTMONTH[index];
+ for (index = 0; index < datetime.MONTH.length; index += 1) {
+ longName = datetime.MONTH[index];
+ shortName = datetime.SHORTMONTH[index];
- if (rawDate.indexOf(longName) !== -1) {
- rawDate = rawDate.replace(longName, index + 1);
- break;
- }
+ if (rawDate.indexOf(longName) !== -1) {
+ rawDate = rawDate.replace(longName, index + 1);
+ break;
+ }
- if (rawDate.indexOf(shortName) !== -1) {
- rawDate = rawDate.replace(shortName, index + 1);
- break;
- }
+ if (rawDate.indexOf(shortName) !== -1) {
+ rawDate = rawDate.replace(shortName, index + 1);
+ break;
}
+ }
- dateSplit = rawDate
- .split(/\D/)
- .filter(function dateSplitFilter(item) {
- return item.length > 0;
- });
-
- formatDate = dateFormatDefinition
- .match(formattingTokens)
- .filter(function fromatDateFilter(item) {
- return item.match(/^[a-zA-Z]+$/i) !== null;
- });
-
- for (index = 0; index < formatDate.length; index += 1) {
- el = formatDate[index];
-
- switch (true) {
- case el.indexOf('d') !== -1: {
- d = dateSplit[index - (formatDate.length - dateSplit.length)];
- break;
- }
- case el.indexOf('M') !== -1: {
- m = dateSplit[index - (formatDate.length - dateSplit.length)];
- break;
- }
- case el.indexOf('y') !== -1: {
- y = dateSplit[index - (formatDate.length - dateSplit.length)];
- break;
- }
- default: {
- break;
- }
+ dateSplit = rawDate
+ .split(/\D/)
+ .filter(function dateSplitFilter(item) {
+ return item.length > 0;
+ });
+
+ formatDate = dateFormatDefinition
+ .match(formattingTokens)
+ .filter(function fromatDateFilter(item) {
+ return item.match(/^[a-zA-Z]+$/i) !== null;
+ });
+
+ for (index = 0; index < formatDate.length; index += 1) {
+ el = formatDate[index];
+
+ switch (true) {
+ case el.indexOf('d') !== -1: {
+ d = dateSplit[index - (formatDate.length - dateSplit.length)];
+ break;
+ }
+ case el.indexOf('M') !== -1: {
+ m = dateSplit[index - (formatDate.length - dateSplit.length)];
+ break;
+ }
+ case el.indexOf('y') !== -1: {
+ y = dateSplit[index - (formatDate.length - dateSplit.length)];
+ break;
+ }
+ default: {
+ break;
}
}
-
- return new Date(y + '/' + m + '/' + d);
}
- , setInputValue = function setInputValue() {
-
- if ($scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day) &&
- $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
- var modelDate = new Date($scope.year + '/' + $scope.monthNumber + '/' + $scope.day);
+ return new Date(y + '/' + m + '/' + d);
+ }
+ , setInputValue = function setInputValue() {
- if (attr.dateFormat) {
+ if ($scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day) &&
+ $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
- thisInput.val($filter('date')(modelDate, dateFormat));
- } else {
+ var modelDate = new Date($scope.year + '/' + $scope.monthNumber + '/' + $scope.day);
- thisInput.val(modelDate);
- }
+ if (attr.dateFormat) {
- thisInput.triggerHandler('input');
- thisInput.triggerHandler('change');//just to be sure;
+ thisInput.val($filter('date')(modelDate, dateFormat));
} else {
- return false;
+ thisInput.val(modelDate);
}
- }
- , classHelper = {
- 'add': function add(ele, klass) {
- var classes;
-
- if (ele.className.indexOf(klass) > -1) {
- return;
- }
+ thisInput.triggerHandler('input');
+ thisInput.triggerHandler('change');//just to be sure;
+ } else {
- classes = ele.className.split(' ');
- classes.push(klass);
- ele.className = classes.join(' ');
- },
- 'remove': function remove(ele, klass) {
- var i
- , classes;
+ return false;
+ }
+ }
+ , classHelper = {
+ 'add': function add(ele, klass) {
+ var classes;
- if (ele.className.indexOf(klass) === -1) {
+ if (ele.className.indexOf(klass) > -1) {
- return;
- }
+ return;
+ }
- classes = ele.className.split(' ');
- for (i = 0; i < classes.length; i += 1) {
+ classes = ele.className.split(' ');
+ classes.push(klass);
+ ele.className = classes.join(' ');
+ },
+ 'remove': function remove(ele, klass) {
+ var i
+ , classes;
- if (classes[i] === klass) {
+ if (ele.className.indexOf(klass) === -1) {
- classes = classes.slice(0, i).concat(classes.slice(i + 1));
- break;
- }
- }
- ele.className = classes.join(' ');
+ return;
}
- }
- , showCalendar = function showCalendar() {
- //lets hide all the latest instances of datepicker
- pageDatepickers = $window.document.getElementsByClassName('_720kb-datepicker-calendar');
- angular.forEach(pageDatepickers, function forEachDatepickerPages(value, key) {
- if (pageDatepickers[key].classList) {
+ classes = ele.className.split(' ');
+ for (i = 0; i < classes.length; i += 1) {
- pageDatepickers[key].classList.remove('_720kb-datepicker-open');
- } else {
+ if (classes[i] === klass) {
- classHelper.remove(pageDatepickers[key], '_720kb-datepicker-open');
+ classes = classes.slice(0, i).concat(classes.slice(i + 1));
+ break;
}
- });
+ }
+ ele.className = classes.join(' ');
+ }
+ }
+ , showCalendar = function showCalendar() {
+ //lets hide all the latest instances of datepicker
+ pageDatepickers = $window.document.getElementsByClassName('_720kb-datepicker-calendar');
- if (theCalendar.classList) {
+ angular.forEach(pageDatepickers, function forEachDatepickerPages(value, key) {
+ if (pageDatepickers[key].classList) {
- theCalendar.classList.add('_720kb-datepicker-open');
- if (dateFormat) {
- date = localDateTimestamp(thisInput[0].value.toString(), dateFormat);
- } else {
- date = new Date(thisInput[0].value.toString());
- }
- $scope.selectedMonth = Number($filter('date')(date, 'MM'));
- $scope.selectedDay = Number($filter('date')(date, 'dd'));
- $scope.selectedYear = Number($filter('date')(date, 'yyyy'));
+ pageDatepickers[key].classList.remove('_720kb-datepicker-open');
} else {
- classHelper.add(theCalendar, '_720kb-datepicker-open');
- }
- $scope.today = new Date();
- $timeout(function timeoutForYears() {
- if ($scope.selectedDay) {
- $scope.year = $scope.selectedYear;
- $scope.monthNumber = $scope.selectedMonth;
- } else {
- $scope.year = $scope.today.getFullYear();
- $scope.monthNumber = $scope.today.getMonth() + 1;
- }
- $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM');
- setDaysInMonth($scope.monthNumber, $scope.year);
- }, 0);
- }
- , checkToggle = function checkToggle() {
- if (!$scope.datepickerToggle) {
-
- return true;
+ classHelper.remove(pageDatepickers[key], '_720kb-datepicker-open');
}
+ });
- return $scope.$eval($scope.datepickerToggle);
- }
- , checkVisibility = function checkVisibility() {
- if (!$scope.datepickerShow) {
+ if (theCalendar.classList) {
- return false;
- }
+ theCalendar.classList.add('_720kb-datepicker-open');
if (dateFormat) {
date = localDateTimestamp(thisInput[0].value.toString(), dateFormat);
} else {
@@ -452,593 +403,664 @@
$scope.selectedMonth = Number($filter('date')(date, 'MM'));
$scope.selectedDay = Number($filter('date')(date, 'dd'));
$scope.selectedYear = Number($filter('date')(date, 'yyyy'));
- return $scope.$eval($scope.datepickerShow);
+ } else {
+
+ classHelper.add(theCalendar, '_720kb-datepicker-open');
}
- , unregisterDataSetWatcher = $scope.$watch('dateSet', function dateSetWatcher(newValue) {
+ $scope.today = new Date();
+ $timeout(function timeoutForYears() {
+ if ($scope.selectedDay) {
+ $scope.year = $scope.selectedYear;
+ $scope.monthNumber = $scope.selectedMonth;
+ } else {
+ $scope.year = $scope.today.getFullYear();
+ $scope.monthNumber = $scope.today.getMonth() + 1;
+ }
+ $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM');
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ }, 0);
+ }
+ , checkToggle = function checkToggle() {
+ if (!$scope.datepickerToggle) {
+
+ return true;
+ }
+
+ return $scope.$eval($scope.datepickerToggle);
+ }
+ , checkVisibility = function checkVisibility() {
+ if (!$scope.datepickerShow) {
+
+ return false;
+ }
+ if (dateFormat) {
+ date = localDateTimestamp(thisInput[0].value.toString(), dateFormat);
+ } else {
+ date = new Date(thisInput[0].value.toString());
+ }
+ $scope.selectedMonth = Number($filter('date')(date, 'MM'));
+ $scope.selectedDay = Number($filter('date')(date, 'dd'));
+ $scope.selectedYear = Number($filter('date')(date, 'yyyy'));
+ return $scope.$eval($scope.datepickerShow);
+ }
+ , unregisterDataSetWatcher = $scope.$watch('dateSet', function dateSetWatcher(newValue) {
- if (newValue && !isNaN(Date.parse(newValue))) {
+ if (newValue && !isNaN(Date.parse(newValue))) {
- date = new Date(newValue);
+ date = new Date(newValue);
- $scope.month = $filter('date')(date, 'MMMM');//december-November like
- $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
- $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
- $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
+ $scope.month = $filter('date')(date, 'MMMM');//december-November like
+ $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
+ $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
+ $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
- setDaysInMonth($scope.monthNumber, $scope.year);
+ setDaysInMonth($scope.monthNumber, $scope.year);
- if ($scope.dateSetHidden !== 'true') {
+ if ($scope.dateSetHidden !== 'true') {
- setInputValue();
- }
- }
- })
- , unregisterDateMinLimitWatcher = $scope.$watch('dateMinLimit', function dateMinLimitWatcher(newValue) {
- if (newValue) {
- resetToMinDate();
- }
- })
- , unregisterDateMaxLimitWatcher = $scope.$watch('dateMaxLimit', function dateMaxLimitWatcher(newValue) {
- if (newValue) {
- resetToMaxDate();
- }
- })
- , unregisterDateFormatWatcher = $scope.$watch('dateFormat', function dateFormatWatcher(newValue) {
- 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;
- }
+ }
+ })
+ , unregisterDateMinLimitWatcher = $scope.$watch('dateMinLimit', function dateMinLimitWatcher(newValue) {
+ if (newValue) {
+ resetToMinDate();
+ }
+ })
+ , unregisterDateMaxLimitWatcher = $scope.$watch('dateMaxLimit', function dateMaxLimitWatcher(newValue) {
+ if (newValue) {
+ resetToMaxDate();
+ }
+ })
+ , unregisterDateFormatWatcher = $scope.$watch('dateFormat', function dateFormatWatcher(newValue) {
+ 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;
}
- })
- , unregisterDateEnabledDatesWatcher = $scope.$watch('dateEnabledDates', function dateEnabledDatesWatcher(newValue) {
- if (newValue) {
- dateEnabledDates = $scope.$eval(newValue);
-
- if (!$scope.isSelectableDate($scope.monthNumber, $scope.year, $scope.day)) {
- thisInput.val('');
- thisInput.triggerHandler('input');
- thisInput.triggerHandler('change');//just to be sure;
- }
+ }
+ })
+ , unregisterDateEnabledDatesWatcher = $scope.$watch('dateEnabledDates', function dateEnabledDatesWatcher(newValue) {
+ if (newValue) {
+ dateEnabledDates = $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() {
+ $scope.nextMonth = function nextMonth() {
- if ($scope.monthNumber === 12) {
+ if ($scope.monthNumber === 12) {
- $scope.monthNumber = 1;
- //its happy new year
- nextYear();
- } else {
+ $scope.monthNumber = 1;
+ //its happy new year
+ nextYear();
+ } else {
- $scope.monthNumber += 1;
- }
+ $scope.monthNumber += 1;
+ }
- //check if max date is ok
- if ($scope.dateMaxLimit) {
+ //check if max date is ok
+ if ($scope.dateMaxLimit) {
- if (!$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[0])) {
+ if (!$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[0])) {
- resetToMaxDate();
- }
+ resetToMaxDate();
}
+ }
- //set next month
- $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM');
- //reinit days
- setDaysInMonth($scope.monthNumber, $scope.year);
- //deactivate selected day
- $scope.day = undefined;
- };
+ //set next month
+ $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM');
+ //reinit days
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ //deactivate selected day
+ $scope.day = undefined;
+ };
- $scope.willPrevMonthBeSelectable = function willPrevMonthBeSelectable() {
- var monthNumber = $scope.monthNumber
- , year = $scope.year
- , prevDay = $filter('date')(new Date(new Date(year + '/' + monthNumber + '/01').getTime() - hours24h), 'dd'); //get last day in previous month
+ $scope.willPrevMonthBeSelectable = function willPrevMonthBeSelectable() {
+ var monthNumber = $scope.monthNumber
+ , year = $scope.year
+ , prevDay = $filter('date')(new Date(new Date(year + '/' + monthNumber + '/01').getTime() - hours24h), 'dd'); //get last day in previous month
- if (monthNumber === 1) {
+ if (monthNumber === 1) {
- monthNumber = 12;
- year = year - 1;
- } else {
+ monthNumber = 12;
+ year = year - 1;
+ } else {
- monthNumber -= 1;
- }
+ monthNumber -= 1;
+ }
- if ($scope.dateMinLimit) {
- if (!$scope.isSelectableMinDate(year + '/' + monthNumber + '/' + prevDay)) {
+ if ($scope.dateMinLimit) {
+ if (!$scope.isSelectableMinDate(year + '/' + monthNumber + '/' + prevDay)) {
- return false;
- }
+ return false;
}
+ }
- return true;
- };
+ return true;
+ };
- $scope.willNextMonthBeSelectable = function willNextMonthBeSelectable() {
- var monthNumber = $scope.monthNumber
- , year = $scope.year;
+ $scope.willNextMonthBeSelectable = function willNextMonthBeSelectable() {
+ var monthNumber = $scope.monthNumber
+ , year = $scope.year;
- if (monthNumber === 12) {
+ if (monthNumber === 12) {
- monthNumber = 1;
- year += 1;
- } else {
+ monthNumber = 1;
+ year += 1;
+ } else {
- monthNumber += 1;
- }
+ monthNumber += 1;
+ }
- if ($scope.dateMaxLimit) {
- if (!$scope.isSelectableMaxDate(year + '/' + monthNumber + '/01')) {
+ if ($scope.dateMaxLimit) {
+ if (!$scope.isSelectableMaxDate(year + '/' + monthNumber + '/01')) {
- return false;
- }
+ return false;
}
+ }
- return true;
- };
+ return true;
+ };
- $scope.prevMonth = function managePrevMonth() {
+ $scope.prevMonth = function managePrevMonth() {
- if ($scope.monthNumber === 1) {
+ if ($scope.monthNumber === 1) {
- $scope.monthNumber = 12;
- //its happy new year
- prevYear();
- } else {
+ $scope.monthNumber = 12;
+ //its happy new year
+ prevYear();
+ } else {
- $scope.monthNumber -= 1;
- }
- //check if min date is ok
- if ($scope.dateMinLimit) {
+ $scope.monthNumber -= 1;
+ }
+ //check if min date is ok
+ if ($scope.dateMinLimit) {
- if (!$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[$scope.days.length - 1])) {
+ if (!$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[$scope.days.length - 1])) {
- resetToMinDate();
- }
+ resetToMinDate();
}
- //set next month
- $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM');
- //reinit days
- setDaysInMonth($scope.monthNumber, $scope.year);
- //deactivate selected day
+ }
+ //set next month
+ $scope.month = $filter('date')(new Date($scope.year, $scope.monthNumber - 1), 'MMMM');
+ //reinit days
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ //deactivate selected day
+ $scope.day = undefined;
+ };
+
+ $scope.selectedMonthHandle = function manageSelectedMonthHandle(selectedMonthNumber) {
+
+ $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM'));
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ setInputValue();
+ };
+
+ $scope.setMonth = function setMonth(selectedMonthNumber) {
+ $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM'));
+ $scope.showMonthPagination = false;
+ $scope.month = selectedMonthNumber;
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ };
+
+ $scope.setNewYear = function setNewYear(year) {
+
+ //deactivate selected day
+ if (!isMobile) {
$scope.day = undefined;
- };
+ }
- $scope.selectedMonthHandle = function manageSelectedMonthHandle(selectedMonthNumber) {
+ if ($scope.dateMaxLimit &&
+ $scope.year < Number(year)) {
- $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM'));
- setDaysInMonth($scope.monthNumber, $scope.year);
- setInputValue();
- };
+ if (!$scope.isSelectableMaxYear(year)) {
+
+ return;
+ }
+ } else if ($scope.dateMinLimit &&
+ $scope.year > Number(year)) {
- $scope.setNewYear = function setNewYear(year) {
+ if (!$scope.isSelectableMinYear(year)) {
- //deactivate selected day
- if (!isMobile) {
- $scope.day = undefined;
+ return;
}
+ }
- if ($scope.dateMaxLimit &&
- $scope.year < Number(year)) {
+ $scope.paginateYears(year);
+ $scope.showYearsPagination = false;
+ $timeout(function timeoutForYears() {
+ $scope.year = Number(year);
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ }, 0);
+ };
- if (!$scope.isSelectableMaxYear(year)) {
+ $scope.showMPagination = function showMPagination() {
+ $scope.showYearsPagination = false;
+ $scope.showMonthPagination = !$scope.showMonthPagination;
+ };
- return;
- }
- } else if ($scope.dateMinLimit &&
- $scope.year > Number(year)) {
+ $scope.showYPagination = function showYPagination() {
+ $scope.showMonthPagination = false;
+ $scope.showYearsPagination = !$scope.showYearsPagination;
+ };
+
+ $scope.hideCalendar = function hideCalendar() {
+ if (theCalendar.classList) {
+ theCalendar.classList.remove('_720kb-datepicker-open');
+ } else {
+
+ classHelper.remove(theCalendar, '_720kb-datepicker-open');
+ }
+ };
- if (!$scope.isSelectableMinYear(year)) {
+ $scope.setDatepickerDay = function setDatepickerDay(day, type) {
+ 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)) {
- return;
+ if (type === 'previous') {
+ if ($scope.monthNumber !== 1) {
+ $scope.monthNumber -= 1;
+ } else {
+ $scope.monthNumber = 12;
+ $scope.year -= 1;
+ }
+ } else if (type === 'next') {
+ if ($scope.monthNumber !== 12) {
+ $scope.monthNumber += 1;
+ } else {
+ $scope.monthNumber = 1;
+ $scope.year += 1;
}
}
- $scope.paginateYears(year);
- $scope.showYearsPagination = false;
- $timeout(function timeoutForYears() {
- $scope.year = Number(year);
- setDaysInMonth($scope.monthNumber, $scope.year);
- }, 0);
- };
+ $scope.day = Number(day);
+ $scope.selectedDay = $scope.day;
+ $scope.selectedMonth = $scope.monthNumber;
+ $scope.selectedYear = $scope.year;
- $scope.hideCalendar = function hideCalendar() {
- if (theCalendar.classList) {
- theCalendar.classList.remove('_720kb-datepicker-open');
- } else {
+ setInputValue();
- classHelper.remove(theCalendar, '_720kb-datepicker-open');
+ if (attr.hasOwnProperty('dateRefocus')) {
+ thisInput[0].focus();
}
- };
- $scope.setDatepickerDay = function setDatepickerDay(day) {
+ $scope.hideCalendar();
+ }
+ };
- 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)) {
+ $scope.paginateYears = function paginateYears(startingYear) {
+ var i
+ , theNewYears = []
+ , daysToPrepend = 1
+ , daysToAppend = 4;
- $scope.day = Number(day);
- $scope.selectedDay = $scope.day;
- $scope.selectedMonth = $scope.monthNumber;
- $scope.selectedYear = $scope.year;
+ $scope.paginationYears = [];
+ if (isMobile) {
- setInputValue();
+ daysToPrepend = 50;
+ daysToAppend = 50;
+ if ( $scope.dateMinLimit && $scope.dateMaxLimit) {
- if (attr.hasOwnProperty('dateRefocus')) {
- thisInput[0].focus();
- }
-
- $scope.hideCalendar();
+ startingYear = new Date($scope.dateMaxLimit).getFullYear();
+ daysToPrepend = startingYear - new Date($scope.dateMinLimit).getFullYear();
+ daysToAppend = 1;
}
- };
+ }
- $scope.paginateYears = function paginateYears(startingYear) {
- var i
- , theNewYears = []
- , daysToPrepend = 10
- , daysToAppend = 10;
+ for (i = daysToPrepend; i > 0; i -= 1) {
- $scope.paginationYears = [];
- if (isMobile) {
+ theNewYears.push(Number(startingYear) - i);
+ }
- daysToPrepend = 50;
- daysToAppend = 50;
- if ( $scope.dateMinLimit && $scope.dateMaxLimit) {
+ for (i = 0; i < daysToAppend; i += 1) {
- startingYear = new Date($scope.dateMaxLimit).getFullYear();
- daysToPrepend = startingYear - new Date($scope.dateMinLimit).getFullYear();
- daysToAppend = 1;
- }
- }
+ theNewYears.push(Number(startingYear) + i);
+ }
+ //date typing in input date-typer
+ if ($scope.dateTyper === 'true') {
- for (i = daysToPrepend; i > 0; i -= 1) {
+ thisInput.on('keyup blur', function onTyping() {
- theNewYears.push(Number(startingYear) - i);
- }
+ if (thisInput[0].value &&
+ thisInput[0].value.length &&
+ thisInput[0].value.length > 0) {
- for (i = 0; i < daysToAppend; i += 1) {
+ try {
+ if (dateFormat) {
+ date = localDateTimestamp(thisInput[0].value.toString(), dateFormat);
+ } else {
+ date = new Date(thisInput[0].value.toString());
+ }
- theNewYears.push(Number(startingYear) + i);
- }
- //date typing in input date-typer
- if ($scope.dateTyper === 'true') {
-
- thisInput.on('keyup blur', function onTyping() {
-
- if (thisInput[0].value &&
- thisInput[0].value.length &&
- thisInput[0].value.length > 0) {
-
- try {
- if (dateFormat) {
- date = localDateTimestamp(thisInput[0].value.toString(), dateFormat);
- } else {
- date = new Date(thisInput[0].value.toString());
- }
-
- if (date.getFullYear() &&
- !isNaN(date.getDay()) &&
- !isNaN(date.getMonth()) &&
- $scope.isSelectableDay(date.getMonth(), date.getFullYear(), date.getDay()) &&
- $scope.isSelectableDate(date.getMonth(), date.getFullYear(), date.getDay()) &&
- $scope.isSelectableMaxDate(date) &&
- $scope.isSelectableMinDate(date)) {
-
- $scope.$apply(function applyTyping() {
-
- $scope.month = $filter('date')(date, 'MMMM');//december-November like
- $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
- $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
-
- if (date.getFullYear().toString().length === 4) {
- $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
- }
- setDaysInMonth($scope.monthNumber, $scope.year);
- });
- }
- } catch (e) {
-
- return e;
+ if (date.getFullYear() &&
+ !isNaN(date.getDay()) &&
+ !isNaN(date.getMonth()) &&
+ $scope.isSelectableDay(date.getMonth(), date.getFullYear(), date.getDay()) &&
+ $scope.isSelectableDate(date.getMonth(), date.getFullYear(), date.getDay()) &&
+ $scope.isSelectableMaxDate(date) &&
+ $scope.isSelectableMinDate(date)) {
+
+ $scope.$apply(function applyTyping() {
+
+ $scope.month = $filter('date')(date, 'MMMM');//december-November like
+ $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
+ $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
+
+ if (date.getFullYear().toString().length === 4) {
+ $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
+ }
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ });
}
+ } catch (e) {
+
+ return e;
}
- });
- }
- //check range dates
- if ($scope.dateMaxLimit &&
- theNewYears &&
- theNewYears.length &&
- !$scope.isSelectableMaxYear(Number(theNewYears[theNewYears.length - 1]) + 1)) {
+ }
+ });
+ }
+ //check range dates
+ if ($scope.dateMaxLimit &&
+ theNewYears &&
+ theNewYears.length &&
+ !$scope.isSelectableMaxYear(Number(theNewYears[theNewYears.length - 1]) + 1)) {
- $scope.paginationYearsNextDisabled = true;
- } else {
+ $scope.paginationYearsNextDisabled = true;
+ } else {
- $scope.paginationYearsNextDisabled = false;
- }
+ $scope.paginationYearsNextDisabled = false;
+ }
- if ($scope.dateMinLimit &&
- theNewYears &&
- theNewYears.length &&
- !$scope.isSelectableMinYear(Number(theNewYears[0]) - 1)) {
+ if ($scope.dateMinLimit &&
+ theNewYears &&
+ theNewYears.length &&
+ !$scope.isSelectableMinYear(Number(theNewYears[0]) - 1)) {
- $scope.paginationYearsPrevDisabled = true;
- } else {
+ $scope.paginationYearsPrevDisabled = true;
+ } else {
- $scope.paginationYearsPrevDisabled = false;
- }
+ $scope.paginationYearsPrevDisabled = false;
+ }
- $scope.paginationYears = theNewYears;
- };
+ $scope.paginationYears = theNewYears;
+ };
- $scope.isSelectableDay = function isSelectableDay(monthNumber, year, day) {
- var i = 0;
+ $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;
- }
+ 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;
- };
+ return true;
+ };
- $scope.isSelectableDate = function isSelectableDate(monthNumber, year, day) {
- var i = 0;
+ $scope.isSelectableDate = function isSelectableDate(monthNumber, year, day) {
+ var i = 0;
- if (dateDisabledDates &&
- dateDisabledDates.length > 0) {
+ if (dateDisabledDates &&
+ dateDisabledDates.length > 0) {
- for (i; i <= dateDisabledDates.length; i += 1) {
+ for (i; i <= dateDisabledDates.length; i += 1) {
- if (new Date(dateDisabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) {
+ if (new Date(dateDisabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) {
- return false;
- }
+ return false;
}
}
+ }
- if (dateEnabledDates) {
+ if (dateEnabledDates) {
- for (i; i <= dateEnabledDates.length; i += 1) {
+ for (i; i <= dateEnabledDates.length; i += 1) {
- if (new Date(dateEnabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) {
+ if (new Date(dateEnabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) {
- return true;
- }
+ return true;
}
-
- return false;
}
- return true;
- };
+ return false;
+ }
- $scope.isSelectableMinDate = function isSelectableMinDate(aDate) {
- //if current date
- if (!!$scope.dateMinLimit &&
- !!new Date($scope.dateMinLimit) &&
- new Date(aDate).getTime() < new Date($scope.dateMinLimit).getTime()) {
+ return true;
+ };
- return false;
- }
+ $scope.isSelectableMinDate = function isSelectableMinDate(aDate) {
+ //if current date
+ if (!!$scope.dateMinLimit &&
+ !!new Date($scope.dateMinLimit) &&
+ new Date(aDate).getTime() < new Date($scope.dateMinLimit).getTime()) {
- return true;
- };
+ return false;
+ }
- $scope.isSelectableMaxDate = function isSelectableMaxDate(aDate) {
- //if current date
- if (!!$scope.dateMaxLimit &&
- !!new Date($scope.dateMaxLimit) &&
- new Date(aDate).getTime() > new Date($scope.dateMaxLimit).getTime()) {
+ return true;
+ };
- return false;
- }
+ $scope.isSelectableMaxDate = function isSelectableMaxDate(aDate) {
+ //if current date
+ if (!!$scope.dateMaxLimit &&
+ !!new Date($scope.dateMaxLimit) &&
+ new Date(aDate).getTime() > new Date($scope.dateMaxLimit).getTime()) {
- return true;
- };
+ return false;
+ }
- $scope.isSelectableMaxYear = function isSelectableMaxYear(year) {
- if (!!$scope.dateMaxLimit &&
- year > new Date($scope.dateMaxLimit).getFullYear()) {
+ return true;
+ };
- return false;
- }
+ $scope.isSelectableMaxYear = function isSelectableMaxYear(year) {
+ if (!!$scope.dateMaxLimit &&
+ year > new Date($scope.dateMaxLimit).getFullYear()) {
- return true;
- };
+ return false;
+ }
- $scope.isSelectableMinYear = function isSelectableMinYear(year) {
- if (!!$scope.dateMinLimit &&
- year < new Date($scope.dateMinLimit).getFullYear()) {
+ return true;
+ };
- return false;
- }
+ $scope.isSelectableMinYear = function isSelectableMinYear(year) {
+ if (!!$scope.dateMinLimit &&
+ year < new Date($scope.dateMinLimit).getFullYear()) {
- return true;
- };
+ return false;
+ }
- $scope.validateWeekDay = function isValidWeekDay(weekDay) {
- var validWeekDay = Number(weekDay, 10);
- // making sure that the given option is valid
- if (!validWeekDay || validWeekDay < 0 || validWeekDay > 6) {
+ return true;
+ };
- validWeekDay = 0;
- }
- return validWeekDay;
- };
-
- // respect previously configured interpolation symbols.
- htmlTemplate = htmlTemplate.replace(/{{/g, $interpolate.startSymbol()).replace(/}}/g, $interpolate.endSymbol());
- $scope.dateMonthTitle = $scope.dateMonthTitle || 'Select month';
- $scope.dateYearTitle = $scope.dateYearTitle || 'Select year';
- $scope.buttonNextTitle = $scope.buttonNextTitle || 'Next';
- $scope.buttonPrevTitle = $scope.buttonPrevTitle || 'Prev';
- $scope.month = $filter('date')(date, 'MMMM');//december-November like
- $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
- $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
- $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay);
+ $scope.validateWeekDay = function isValidWeekDay(weekDay) {
+ var validWeekDay = Number(weekDay, 10);
+ // making sure that the given option is valid
+ if (!validWeekDay || validWeekDay < 0 || validWeekDay > 6) {
- if ($scope.dateMaxLimit) {
+ validWeekDay = 0;
+ }
+ return validWeekDay;
+ };
- $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like
- } else {
+ // respect previously configured interpolation symbols.
+ htmlTemplate = htmlTemplate.replace(/{{/g, $interpolate.startSymbol()).replace(/}}/g, $interpolate.endSymbol());
+ $scope.dateMonthTitle = $scope.dateMonthTitle || 'Select month';
+ $scope.dateYearTitle = $scope.dateYearTitle || 'Select year';
+ $scope.buttonNextTitle = $scope.buttonNextTitle || 'Next';
+ $scope.buttonPrevTitle = $scope.buttonPrevTitle || 'Prev';
+ $scope.month = $filter('date')(date, 'MMMM');//december-November like
+ $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
+ $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
+ $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay);
- $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
- }
- $scope.months = datetime.MONTH;
+ if ($scope.dateMaxLimit) {
- $scope.daysInString = [];
- for (n = $scope.dateWeekStartDay; n <= $scope.dateWeekStartDay + 6; n += 1) {
+ $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like
+ } else {
- $scope.daysInString.push(n % 7);
- }
- $scope.daysInString = $scope.daysInString.map(function mappingFunc(el) {
+ $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like
+ }
+ $scope.months = datetime.MONTH;
- return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE');
- });
+ $scope.daysInString = [];
+ for (n = $scope.dateWeekStartDay; n <= $scope.dateWeekStartDay + 6; n += 1) {
- //create the calendar holder and append where needed
- if ($scope.datepickerAppendTo &&
- $scope.datepickerAppendTo.indexOf('.') !== -1) {
+ $scope.daysInString.push(n % 7);
+ }
+ $scope.daysInString = $scope.daysInString.map(function mappingFunc(el) {
- $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8);
- angular.element(document.getElementsByClassName($scope.datepickerAppendTo.replace('.', ''))[0]).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) {
+ return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE');
+ });
- theCalendar = angular.element(el)[0];
- }));
- } else if ($scope.datepickerAppendTo &&
- $scope.datepickerAppendTo.indexOf('#') !== -1) {
+ //create the calendar holder and append where needed
+ if ($scope.datepickerAppendTo &&
+ $scope.datepickerAppendTo.indexOf('.') !== -1) {
- $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8);
- angular.element(document.getElementById($scope.datepickerAppendTo.replace('#', ''))).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) {
+ $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8);
+ angular.element(document.getElementsByClassName($scope.datepickerAppendTo.replace('.', ''))[0]).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) {
- theCalendar = angular.element(el)[0];
- }));
- } else if ($scope.datepickerAppendTo &&
- $scope.datepickerAppendTo === 'body') {
- $scope.datepickerID = 'datepicker-id-' + (new Date().getTime() + (Math.floor(Math.random() * 6) + 8));
- angular.element(document).find('body').append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) {
+ theCalendar = angular.element(el)[0];
+ }));
+ } else if ($scope.datepickerAppendTo &&
+ $scope.datepickerAppendTo.indexOf('#') !== -1) {
- theCalendar = angular.element(el)[0];
- }));
- } else {
+ $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8);
+ angular.element(document.getElementById($scope.datepickerAppendTo.replace('#', ''))).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) {
- thisInput.after($compile(angular.element(htmlTemplate))($scope));
- //get the calendar as element
- theCalendar = element[0].querySelector('._720kb-datepicker-calendar');
- }
- //if datepicker-toggle="" is not present or true by default
- if (checkToggle()) {
+ theCalendar = angular.element(el)[0];
+ }));
+ } else if ($scope.datepickerAppendTo &&
+ $scope.datepickerAppendTo === 'body') {
+ $scope.datepickerID = 'datepicker-id-' + (new Date().getTime() + (Math.floor(Math.random() * 6) + 8));
+ angular.element(document).find('body').append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) {
- thisInput.on('focus click focusin', function onFocusAndClick() {
+ theCalendar = angular.element(el)[0];
+ }));
+ } else {
- isMouseOnInput = true;
+ thisInput.after($compile(angular.element(htmlTemplate))($scope));
+ //get the calendar as element
+ theCalendar = element[0].querySelector('._720kb-datepicker-calendar');
+ }
+ //if datepicker-toggle="" is not present or true by default
+ if (checkToggle()) {
- if (!isMouseOn &&
- !isMouseOnInput && theCalendar) {
+ thisInput.on('focus click focusin', function onFocusAndClick() {
- $scope.hideCalendar();
- } else {
+ isMouseOnInput = true;
- showCalendar();
- }
- });
- }
+ if (!isMouseOn &&
+ !isMouseOnInput && theCalendar) {
- thisInput.on('focusout blur', function onBlurAndFocusOut() {
+ $scope.hideCalendar();
+ } else {
- isMouseOnInput = false;
+ showCalendar();
+ }
});
- //some tricky dirty events to fire if click is outside of the calendar and show/hide calendar when needed
- angular.element(theCalendar).on('mouseenter', function onMouseEnter() {
+ }
- isMouseOn = true;
- });
+ thisInput.on('focusout blur', function onBlurAndFocusOut() {
- angular.element(theCalendar).on('mouseleave', function onMouseLeave() {
+ isMouseOnInput = false;
+ });
+ //some tricky dirty events to fire if click is outside of the calendar and show/hide calendar when needed
+ angular.element(theCalendar).on('mouseenter', function onMouseEnter() {
- isMouseOn = false;
- });
+ isMouseOn = true;
+ });
- angular.element(theCalendar).on('focusin', function onCalendarFocus() {
+ angular.element(theCalendar).on('mouseleave', function onMouseLeave() {
- isMouseOn = true;
- });
+ isMouseOn = false;
+ });
- angular.element($window).on('click focus focusin', onClickOnWindow);
+ angular.element(theCalendar).on('focusin', function onCalendarFocus() {
- //check always if given range of dates is ok
- if ($scope.dateMinLimit &&
- !$scope.isSelectableMinYear($scope.year) ||
- !$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
+ isMouseOn = true;
+ });
- resetToMinDate();
- }
+ angular.element($window).on('click focus focusin', onClickOnWindow);
- if ($scope.dateMaxLimit &&
- !$scope.isSelectableMaxYear($scope.year) ||
- !$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
+ //check always if given range of dates is ok
+ if ($scope.dateMinLimit &&
+ !$scope.isSelectableMinYear($scope.year) ||
+ !$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
- resetToMaxDate();
- }
+ resetToMinDate();
+ }
- //datepicker boot start
- $scope.paginateYears($scope.year);
+ if ($scope.dateMaxLimit &&
+ !$scope.isSelectableMaxYear($scope.year) ||
+ !$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) {
- setDaysInMonth($scope.monthNumber, $scope.year);
- $scope.checkVisibility = checkVisibility;
-
- $scope.$on('$destroy', function unregisterListener() {
-
- unregisterDataSetWatcher();
- unregisterDateMinLimitWatcher();
- unregisterDateMaxLimitWatcher();
- unregisterDateFormatWatcher();
- unregisterDateDisabledDatesWatcher();
- unregisterDateEnabledDatesWatcher();
- thisInput.off('focus click focusout blur');
- angular.element(theCalendar).off('mouseenter mouseleave focusin');
- angular.element($window).off('click focus focusin', onClickOnWindow);
- });
- };
+ resetToMaxDate();
+ }
- return {
- 'restrict': 'AEC',
- 'scope': {
- 'dateSet': '@',
- 'dateMinLimit': '@',
- 'dateMaxLimit': '@',
- 'dateMonthTitle': '@',
- 'dateYearTitle': '@',
- 'buttonNextTitle': '@',
- 'buttonPrevTitle': '@',
- 'dateDisabledDates': '@',
- 'dateEnabledDates': '@',
- 'dateDisabledWeekdays': '@',
- 'dateSetHidden': '@',
- 'dateTyper': '@',
- 'dateWeekStartDay': '@',
- 'datepickerAppendTo': '@',
- 'datepickerToggle': '@',
- 'datepickerClass': '@',
- 'datepickerShow': '@'
- },
- 'link': linkingFunction
- };
+ //datepicker boot start
+ $scope.paginateYears($scope.year);
+
+ setDaysInMonth($scope.monthNumber, $scope.year);
+ $scope.checkVisibility = checkVisibility;
+
+ $scope.$on('$destroy', function unregisterListener() {
+
+ unregisterDataSetWatcher();
+ unregisterDateMinLimitWatcher();
+ unregisterDateMaxLimitWatcher();
+ unregisterDateFormatWatcher();
+ unregisterDateDisabledDatesWatcher();
+ unregisterDateEnabledDatesWatcher();
+ thisInput.off('focus click focusout blur');
+ angular.element(theCalendar).off('mouseenter mouseleave focusin');
+ angular.element($window).off('click focus focusin', onClickOnWindow);
+ });
+ };
+
+ return {
+ 'restrict': 'AEC',
+ 'scope': {
+ 'dateSet': '@',
+ 'dateMinLimit': '@',
+ 'dateMaxLimit': '@',
+ 'dateMonthTitle': '@',
+ 'dateYearTitle': '@',
+ 'buttonNextTitle': '@',
+ 'buttonPrevTitle': '@',
+ 'dateDisabledDates': '@',
+ 'dateEnabledDates': '@',
+ 'dateDisabledWeekdays': '@',
+ 'dateSetHidden': '@',
+ 'dateTyper': '@',
+ 'dateWeekStartDay': '@',
+ 'datepickerAppendTo': '@',
+ 'datepickerToggle': '@',
+ 'datepickerClass': '@',
+ 'datepickerShow': '@',
+ 'anyDay': '@'
+ },
+ 'link': linkingFunction
};
+ };
angular.module('720kb.datepicker', [])
- .directive('datepicker', ['$window', '$compile', '$locale', '$filter', '$interpolate', '$timeout', datepickerDirective]);
+ .directive('datepicker', ['$window', '$compile', '$locale', '$filter', '$interpolate', '$timeout', datepickerDirective]);
}(angular, navigator));