diff --git a/src/js/angular-datepicker.js b/src/js/angular-datepicker.js index 971dbc9..1755f84 100644 --- a/src/js/angular-datepicker.js +++ b/src/js/angular-datepicker.js @@ -143,824 +143,827 @@ } , 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(); - } - } - , 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 linkingFunction = function linkingFunction($scope, element, attr) { + + //get child input + var selector = attr.selector + , thisSelector = angular.element(selector ? element[0].querySelector('.' + selector) : element[0].children[0])//Sonali + , thisInput = angular.element(selector ? element[0].querySelector('input:first-child') : 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) { + + 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) { - - //no need for it - $scope.prevMonthDays = []; - } else { + //get previous month days if first day in month is not first day in week + if (firstDayMonthNumber === $scope.dateWeekStartDay) { - howManyPreviousDays = firstDayMonthNumber - $scope.dateWeekStartDay; + //no need for it + $scope.prevMonthDays = []; + } else { - if (firstDayMonthNumber < $scope.dateWeekStartDay) { + howManyPreviousDays = firstDayMonthNumber - $scope.dateWeekStartDay; - howManyPreviousDays += 7; - } + if (firstDayMonthNumber < $scope.dateWeekStartDay) { - //get previous month - if (Number(month) === 1) { + howManyPreviousDays += 7; + } - monthAlias = 12; - } else { + //get previous month + if (Number(month) === 1) { - monthAlias = month - 1; - } - //return previous month days - for (i = 1; i <= new Date(year, monthAlias, 0).getDate(); i += 1) { + monthAlias = 12; + } else { - prevMonthDays.push(i); - } - //attach previous month days - $scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays); - } + monthAlias = month - 1; + } + //return previous month days + for (i = 1; i <= new Date(year, monthAlias, 0).getDate(); i += 1) { - //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; + prevMonthDays.push(i); + } + //attach previous month days + $scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays); + } - if (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; - howManyNextDays -= 7; - } - //get previous month + if (lastDayMonthNumber < $scope.dateWeekStartDay) { - //return next month days - for (i = 1; i <= howManyNextDays; i += 1) { + howManyNextDays -= 7; + } + //get previous month - nextMonthDays.push(i); - } - //attach previous month days - $scope.nextMonthDays = nextMonthDays; - } - } - , 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')); - - 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')); - - setDaysInMonth($scope.monthNumber, $scope.year); - } - , prevYear = function prevYear() { - - $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 - ,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]; - - if (rawDate.indexOf(longName) !== -1) { - rawDate = rawDate.replace(longName, index + 1); - break; - } - - if (rawDate.indexOf(shortName) !== -1) { - rawDate = rawDate.replace(shortName, index + 1); - break; - } - } + //return next month days + for (i = 1; i <= howManyNextDays; i += 1) { - 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; + nextMonthDays.push(i); + } + //attach previous month days + $scope.nextMonthDays = nextMonthDays; } - default: { - break; - } - } } + , resetToMinDate = function resetToMinDate() { - return new Date(y + '/' + m + '/' + d); - } - , setInputValue = function setInputValue() { + $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')); - if ($scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day) && - $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { + setDaysInMonth($scope.monthNumber, $scope.year); + } + , resetToMaxDate = function resetToMaxDate() { - var modelDate = new Date($scope.year + '/' + $scope.monthNumber + '/' + $scope.day); + $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')); - if (attr.dateFormat) { + setDaysInMonth($scope.monthNumber, $scope.year); + } + , prevYear = function prevYear() { - thisInput.val($filter('date')(modelDate, dateFormat)); - } else { + $scope.year = Number($scope.year) - 1; + } + , nextYear = function nextYear() { - thisInput.val(modelDate); - } + $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]; + + if (rawDate.indexOf(longName) !== -1) { + rawDate = rawDate.replace(longName, index + 1); + break; + } + + if (rawDate.indexOf(shortName) !== -1) { + rawDate = rawDate.replace(shortName, index + 1); + break; + } + } - thisInput.triggerHandler('input'); - thisInput.triggerHandler('change');//just to be sure; - } else { + 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 false; + return new Date(y + '/' + m + '/' + d); } - } - , classHelper = { - 'add': function add(ele, klass) { - var classes; + , setInputValue = function setInputValue() { - if (ele.className.indexOf(klass) > -1) { + if ($scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day) && + $scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.day)) { - return; - } + var modelDate = new Date($scope.year + '/' + $scope.monthNumber + '/' + $scope.day); - classes = ele.className.split(' '); - classes.push(klass); - ele.className = classes.join(' '); - }, - 'remove': function remove(ele, klass) { - var i - , classes; + if (attr.dateFormat) { - if (ele.className.indexOf(klass) === -1) { + thisInput.val($filter('date')(modelDate, dateFormat)); + } else { - return; - } + thisInput.val(modelDate); + } - classes = ele.className.split(' '); - for (i = 0; i < classes.length; i += 1) { + thisInput.triggerHandler('input'); + thisInput.triggerHandler('change');//just to be sure; + } else { - if (classes[i] === klass) { - - classes = classes.slice(0, i).concat(classes.slice(i + 1)); - break; + return false; } - } - ele.className = classes.join(' '); } - } - , showCalendar = function showCalendar() { - //lets hide all the latest instances of datepicker - pageDatepickers = $window.document.getElementsByClassName('_720kb-datepicker-calendar'); + , classHelper = { + 'add': function add(ele, klass) { + var classes; - angular.forEach(pageDatepickers, function forEachDatepickerPages(value, key) { - if (pageDatepickers[key].classList) { + if (ele.className.indexOf(klass) > -1) { - pageDatepickers[key].classList.remove('_720kb-datepicker-open'); - } else { + return; + } - classHelper.remove(pageDatepickers[key], '_720kb-datepicker-open'); - } - }); + classes = ele.className.split(' '); + classes.push(klass); + ele.className = classes.join(' '); + }, + 'remove': function remove(ele, klass) { + var i + , classes; - if (theCalendar.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')); - } else { + if (ele.className.indexOf(klass) === -1) { - 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; - } + return; + } + + classes = ele.className.split(' '); + for (i = 0; i < classes.length; i += 1) { - return $scope.$eval($scope.datepickerToggle); - } - , checkVisibility = function checkVisibility() { - if (!$scope.datepickerShow) { + if (classes[i] === klass) { - return false; + classes = classes.slice(0, i).concat(classes.slice(i + 1)); + break; + } + } + ele.className = classes.join(' '); + } } - if (dateFormat) { - date = localDateTimestamp(thisInput[0].value.toString(), dateFormat); - } else { - date = new Date(thisInput[0].value.toString()); + , 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) { + + pageDatepickers[key].classList.remove('_720kb-datepicker-open'); + } else { + + classHelper.remove(pageDatepickers[key], '_720kb-datepicker-open'); + } + }); + + if (theCalendar.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')); + } 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); } - $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))) { - - date = new Date(newValue); + , checkToggle = function checkToggle() { + if (!$scope.datepickerToggle) { - $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') { + return true; + } - setInputValue(); - } + return $scope.$eval($scope.datepickerToggle); } - }) - , 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; - } + , 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) { - $scope.nextMonth = function nextMonth() { + if (newValue && !isNaN(Date.parse(newValue))) { - if ($scope.monthNumber === 12) { + date = new Date(newValue); - $scope.monthNumber = 1; - //its happy new year - nextYear(); - } else { + $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.monthNumber += 1; - } + setDaysInMonth($scope.monthNumber, $scope.year); - //check if max date is ok - if ($scope.dateMaxLimit) { + if ($scope.dateSetHidden !== 'true') { - if (!$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[0])) { - - 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; - }; + 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; + } + } + }) + , 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.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.nextMonth = function nextMonth() { - if (monthNumber === 1) { + if ($scope.monthNumber === 12) { - monthNumber = 12; - year = year - 1; - } else { + $scope.monthNumber = 1; + //its happy new year + nextYear(); + } else { - monthNumber -= 1; - } + $scope.monthNumber += 1; + } - if ($scope.dateMinLimit) { - if (!$scope.isSelectableMinDate(year + '/' + monthNumber + '/' + prevDay)) { + //check if max date is ok + if ($scope.dateMaxLimit) { - return false; - } - } + if (!$scope.isSelectableMaxDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[0])) { - return true; - }; + resetToMaxDate(); + } + } - $scope.willNextMonthBeSelectable = function willNextMonthBeSelectable() { - var monthNumber = $scope.monthNumber - , year = $scope.year; + //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; + }; - if (monthNumber === 12) { + $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 - monthNumber = 1; - year += 1; - } else { + if (monthNumber === 1) { - monthNumber += 1; - } + monthNumber = 12; + year = year - 1; + } else { - if ($scope.dateMaxLimit) { - if (!$scope.isSelectableMaxDate(year + '/' + monthNumber + '/01')) { + monthNumber -= 1; + } - return false; - } - } + if ($scope.dateMinLimit) { + if (!$scope.isSelectableMinDate(year + '/' + monthNumber + '/' + prevDay)) { - return true; - }; + return false; + } + } - $scope.prevMonth = function managePrevMonth() { + return true; + }; - if ($scope.monthNumber === 1) { + $scope.willNextMonthBeSelectable = function willNextMonthBeSelectable() { + var monthNumber = $scope.monthNumber + , year = $scope.year; - $scope.monthNumber = 12; - //its happy new year - prevYear(); - } else { + if (monthNumber === 12) { - $scope.monthNumber -= 1; - } - //check if min date is ok - if ($scope.dateMinLimit) { + monthNumber = 1; + year += 1; + } else { - if (!$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[$scope.days.length - 1])) { + monthNumber += 1; + } - 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 - $scope.day = undefined; - }; + if ($scope.dateMaxLimit) { + if (!$scope.isSelectableMaxDate(year + '/' + monthNumber + '/01')) { - $scope.selectedMonthHandle = function manageSelectedMonthHandle(selectedMonthNumber) { + return false; + } + } - $scope.monthNumber = Number($filter('date')(new Date(selectedMonthNumber + '/01/2000'), 'MM')); - setDaysInMonth($scope.monthNumber, $scope.year); - setInputValue(); - }; + return true; + }; - $scope.setNewYear = function setNewYear(year) { + $scope.prevMonth = function managePrevMonth() { - //deactivate selected day - if (!isMobile) { - $scope.day = undefined; - } + if ($scope.monthNumber === 1) { - if ($scope.dateMaxLimit && - $scope.year < Number(year)) { + $scope.monthNumber = 12; + //its happy new year + prevYear(); + } else { - if (!$scope.isSelectableMaxYear(year)) { + $scope.monthNumber -= 1; + } + //check if min date is ok + if ($scope.dateMinLimit) { - return; - } - } else if ($scope.dateMinLimit && - $scope.year > Number(year)) { + if (!$scope.isSelectableMinDate($scope.year + '/' + $scope.monthNumber + '/' + $scope.days[$scope.days.length - 1])) { - if (!$scope.isSelectableMinYear(year)) { + 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 + $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(); + }; - return; - } - } + $scope.setNewYear = function setNewYear(year) { - $scope.paginateYears(year); - $scope.showYearsPagination = false; - $timeout(function timeoutForYears() { - $scope.year = Number(year); - setDaysInMonth($scope.monthNumber, $scope.year); - }, 0); - }; + //deactivate selected day + if (!isMobile) { + $scope.day = undefined; + } - $scope.hideCalendar = function hideCalendar() { - if (theCalendar.classList) { - theCalendar.classList.remove('_720kb-datepicker-open'); - } else { + if ($scope.dateMaxLimit && + $scope.year < Number(year)) { - classHelper.remove(theCalendar, '_720kb-datepicker-open'); - } - }; + if (!$scope.isSelectableMaxYear(year)) { - $scope.setDatepickerDay = function setDatepickerDay(day) { + return; + } + } else if ($scope.dateMinLimit && + $scope.year > Number(year)) { - 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 (!$scope.isSelectableMinYear(year)) { - $scope.day = Number(day); - $scope.selectedDay = $scope.day; - $scope.selectedMonth = $scope.monthNumber; - $scope.selectedYear = $scope.year; + return; + } + } - setInputValue(); + $scope.paginateYears(year); + $scope.showYearsPagination = false; + $timeout(function timeoutForYears() { + $scope.year = Number(year); + setDaysInMonth($scope.monthNumber, $scope.year); + }, 0); + }; - if (attr.hasOwnProperty('dateRefocus')) { - thisInput[0].focus(); - } + $scope.hideCalendar = function hideCalendar() { + if (theCalendar.classList) { + theCalendar.classList.remove('_720kb-datepicker-open'); + } else { - $scope.hideCalendar(); - } - }; + classHelper.remove(theCalendar, '_720kb-datepicker-open'); + } + }; - $scope.paginateYears = function paginateYears(startingYear) { - var i - , theNewYears = [] - , daysToPrepend = 10 - , daysToAppend = 10; + $scope.setDatepickerDay = function setDatepickerDay(day) { - $scope.paginationYears = []; - if (isMobile) { + 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)) { - daysToPrepend = 50; - daysToAppend = 50; - if ( $scope.dateMinLimit && $scope.dateMaxLimit) { + $scope.day = Number(day); + $scope.selectedDay = $scope.day; + $scope.selectedMonth = $scope.monthNumber; + $scope.selectedYear = $scope.year; - startingYear = new Date($scope.dateMaxLimit).getFullYear(); - daysToPrepend = startingYear - new Date($scope.dateMinLimit).getFullYear(); - daysToAppend = 1; - } - } + setInputValue(); - for (i = daysToPrepend; i > 0; i -= 1) { + if (attr.hasOwnProperty('dateRefocus')) { + thisInput[0].focus(); + } - theNewYears.push(Number(startingYear) - i); - } + $scope.hideCalendar(); + } + }; - for (i = 0; i < daysToAppend; i += 1) { + $scope.paginateYears = function paginateYears(startingYear) { + var i + , theNewYears = [] + , daysToPrepend = 10 + , daysToAppend = 10; - theNewYears.push(Number(startingYear) + i); - } - //date typing in input date-typer - if ($scope.dateTyper === 'true') { + $scope.paginationYears = []; + if (isMobile) { - thisInput.on('keyup blur', function onTyping() { + daysToPrepend = 50; + daysToAppend = 50; + if ( $scope.dateMinLimit && $scope.dateMaxLimit) { - if (thisInput[0].value && - thisInput[0].value.length && - thisInput[0].value.length > 0) { + startingYear = new Date($scope.dateMaxLimit).getFullYear(); + daysToPrepend = startingYear - new Date($scope.dateMinLimit).getFullYear(); + daysToAppend = 1; + } + } - 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) { + for (i = daysToPrepend; i > 0; i -= 1) { - return e; + theNewYears.push(Number(startingYear) - i); } - } - }); - } - //check range dates - if ($scope.dateMaxLimit && - theNewYears && - theNewYears.length && - !$scope.isSelectableMaxYear(Number(theNewYears[theNewYears.length - 1]) + 1)) { - $scope.paginationYearsNextDisabled = true; - } else { + for (i = 0; i < daysToAppend; i += 1) { - $scope.paginationYearsNextDisabled = false; - } + theNewYears.push(Number(startingYear) + i); + } + //date typing in input date-typer + if ($scope.dateTyper === 'true') { + + //thisInput.on('keyup blur', function onTyping() {//Sonali + thisSelector.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; + } + } + }); + } + //check range dates + if ($scope.dateMaxLimit && + theNewYears && + theNewYears.length && + !$scope.isSelectableMaxYear(Number(theNewYears[theNewYears.length - 1]) + 1)) { - if ($scope.dateMinLimit && - theNewYears && - theNewYears.length && - !$scope.isSelectableMinYear(Number(theNewYears[0]) - 1)) { + $scope.paginationYearsNextDisabled = true; + } else { - $scope.paginationYearsPrevDisabled = true; - } else { + $scope.paginationYearsNextDisabled = false; + } - $scope.paginationYearsPrevDisabled = false; - } + if ($scope.dateMinLimit && + theNewYears && + theNewYears.length && + !$scope.isSelectableMinYear(Number(theNewYears[0]) - 1)) { - $scope.paginationYears = theNewYears; - }; + $scope.paginationYearsPrevDisabled = true; + } else { - $scope.isSelectableDay = function isSelectableDay(monthNumber, year, day) { - var i = 0; + $scope.paginationYearsPrevDisabled = false; + } - if (dateDisabledWeekdays && dateDisabledWeekdays.length > 0) { - for (i; i <= dateDisabledWeekdays.length; i += 1) { - if (dateDisabledWeekdays[i] === new Date(monthNumber + '/' + day + '/' + year).getDay()) { - return false; - } - } - } + $scope.paginationYears = theNewYears; + }; - return true; - }; + $scope.isSelectableDay = function isSelectableDay(monthNumber, year, day) { + var i = 0; - $scope.isSelectableDate = function isSelectableDate(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 (dateDisabledDates && - dateDisabledDates.length > 0) { + return true; + }; - for (i; i <= dateDisabledDates.length; i += 1) { + $scope.isSelectableDate = function isSelectableDate(monthNumber, year, day) { + var i = 0; - if (new Date(dateDisabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) { + if (dateDisabledDates && + dateDisabledDates.length > 0) { - return false; - } - } - } + for (i; i <= dateDisabledDates.length; i += 1) { - if (dateEnabledDates) { + if (new Date(dateDisabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) { - for (i; i <= dateEnabledDates.length; i += 1) { + return false; + } + } + } - if (new Date(dateEnabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) { + if (dateEnabledDates) { - return true; - } - } + for (i; i <= dateEnabledDates.length; i += 1) { - return false; - } + if (new Date(dateEnabledDates[i]).getTime() === new Date(monthNumber + '/' + day + '/' + year).getTime()) { - return true; - }; + return true; + } + } - $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 false; + } - return false; - } + return true; + }; - return true; - }; + $scope.isSelectableMinDate = function isSelectableMinDate(aDate) { + //if current date + if (!!$scope.dateMinLimit && + !!new Date($scope.dateMinLimit) && + new Date(aDate).getTime() < new Date($scope.dateMinLimit).getTime()) { - $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 false; + } - return false; - } + return true; + }; - return true; - }; + $scope.isSelectableMaxDate = function isSelectableMaxDate(aDate) { + //if current date + if (!!$scope.dateMaxLimit && + !!new Date($scope.dateMaxLimit) && + new Date(aDate).getTime() > new Date($scope.dateMaxLimit).getTime()) { - $scope.isSelectableMaxYear = function isSelectableMaxYear(year) { - if (!!$scope.dateMaxLimit && - year > new Date($scope.dateMaxLimit).getFullYear()) { + return false; + } - return false; - } + return true; + }; - return true; - }; + $scope.isSelectableMaxYear = function isSelectableMaxYear(year) { + if (!!$scope.dateMaxLimit && + year > new Date($scope.dateMaxLimit).getFullYear()) { - $scope.isSelectableMinYear = function isSelectableMinYear(year) { - if (!!$scope.dateMinLimit && - year < new Date($scope.dateMinLimit).getFullYear()) { + return false; + } - return false; - } + return true; + }; - return true; - }; + $scope.isSelectableMinYear = function isSelectableMinYear(year) { + if (!!$scope.dateMinLimit && + year < new Date($scope.dateMinLimit).getFullYear()) { - $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 false; + } - validWeekDay = 0; - } - return validWeekDay; - }; + return true; + }; - // 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; + }; + + // 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')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like - } else { + if ($scope.dateMaxLimit) { - $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like - } - $scope.months = datetime.MONTH; + $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like + } else { - $scope.daysInString = []; - for (n = $scope.dateWeekStartDay; n <= $scope.dateWeekStartDay + 6; n += 1) { + $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like + } + $scope.months = datetime.MONTH; - $scope.daysInString.push(n % 7); - } - $scope.daysInString = $scope.daysInString.map(function mappingFunc(el) { + $scope.daysInString = []; + for (n = $scope.dateWeekStartDay; n <= $scope.dateWeekStartDay + 6; n += 1) { - return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE'); - }); + $scope.daysInString.push(n % 7); + } + $scope.daysInString = $scope.daysInString.map(function mappingFunc(el) { - //create the calendar holder and append where needed - if ($scope.datepickerAppendTo && - $scope.datepickerAppendTo.indexOf('.') !== -1) { + return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE'); + }); - $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) { + //create the calendar holder and append where needed + if ($scope.datepickerAppendTo && + $scope.datepickerAppendTo.indexOf('.') !== -1) { - theCalendar = angular.element(el)[0]; - })); - } else if ($scope.datepickerAppendTo && - $scope.datepickerAppendTo.indexOf('#') !== -1) { + $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) { - $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) { + theCalendar = angular.element(el)[0]; + })); + } else if ($scope.datepickerAppendTo && + $scope.datepickerAppendTo.indexOf('#') !== -1) { - 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) { + $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) { - theCalendar = angular.element(el)[0]; - })); - } else { + 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.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 { - thisInput.on('focus click focusin', function onFocusAndClick() { + //thisInput.after($compile(angular.element(htmlTemplate))($scope));//Sonali + thisSelector.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()) { - isMouseOnInput = true; + //thisInput.on('focus click focusin', function onFocusAndClick() {//Sonali + thisSelector.on('focus click focusin', function onFocusAndClick() { + isMouseOnInput = true; - if (!isMouseOn && - !isMouseOnInput && theCalendar) { + if (!isMouseOn && + !isMouseOnInput && theCalendar) { - $scope.hideCalendar(); - } else { + $scope.hideCalendar(); + } else { - showCalendar(); + showCalendar(); + } + }); } - }); - } + //thisInput.on('focusout blur', function onInputBlurAndFocusOut() { //Sonali - thisInput.on('focusout blur', function onBlurAndFocusOut() { - isMouseOnInput = false; - }); + thisSelector.on('focusout blur mouseleave', function onSelectorBlurAndFocusOut() {//Sonali + isMouseOnInput = false; //Sonali + });//Sonali //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() { @@ -968,7 +971,6 @@ }); angular.element(theCalendar).on('mouseleave', function onMouseLeave() { - isMouseOn = false; }); @@ -1009,6 +1011,7 @@ unregisterDateDisabledDatesWatcher(); unregisterDateEnabledDatesWatcher(); thisInput.off('focus click focusout blur'); + thisSelector.off('focus click focusout blur');//Sonali angular.element(theCalendar).off('mouseenter mouseleave focusin'); angular.element($window).off('click focus focusin', onClickOnWindow); }); @@ -1042,3 +1045,5 @@ angular.module('720kb.datepicker', []) .directive('datepicker', ['$window', '$compile', '$locale', '$filter', '$interpolate', '$timeout', datepickerDirective]); }(angular, navigator)); + +