|
1 |
| -/*global angular, navigator*/ |
| 1 | +/*global angular, document, navigator*/ |
2 | 2 | (function withAngular(angular, navigator) {
|
3 | 3 | 'use strict';
|
4 | 4 |
|
|
116 | 116 | , generateHtmlTemplate = function generateHtmlTemplate(prevButton, nextButton) {
|
117 | 117 |
|
118 | 118 | var toReturn = [
|
119 |
| - '<div class="_720kb-datepicker-calendar" ng-blur="hideCalendar()">', |
| 119 | + '<div class="_720kb-datepicker-calendar {{datepickerID}} {{classForToggle}}" ng-blur="hideCalendar()">', |
120 | 120 | '</div>'
|
121 | 121 | ]
|
122 | 122 | , monthAndYearHeader = generateMonthAndYearHeader(prevButton, nextButton)
|
|
617 | 617 | $scope.dateYearTitle = $scope.dateYearTitle || 'Select year';
|
618 | 618 | $scope.buttonNextTitle = $scope.buttonNextTitle || 'Next';
|
619 | 619 | $scope.buttonPrevTitle = $scope.buttonPrevTitle || 'Prev';
|
620 |
| - |
621 | 620 | $scope.month = $filter('date')(date, 'MMMM');//december-November like
|
622 | 621 | $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like
|
623 | 622 | $scope.day = Number($filter('date')(date, 'dd')); //01-31 like
|
| 623 | + |
624 | 624 | if ($scope.dateMaxLimit) {
|
625 | 625 |
|
626 | 626 | $scope.year = Number($filter('date')(new Date($scope.dateMaxLimit), 'yyyy'));//2014 like
|
|
633 | 633 |
|
634 | 634 | return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE');
|
635 | 635 | });
|
| 636 | + //can this toggle blur/focus? |
| 637 | + if ($scope.datepickerToggle === 'false') { |
636 | 638 |
|
637 |
| - //create the calendar holder |
638 |
| - thisInput.after($compile(angular.element(htmlTemplate))($scope)); |
639 |
| - //get the calendar as element |
640 |
| - theCalendar = element[0].querySelector('._720kb-datepicker-calendar'); |
| 639 | + $scope.classForToggle = 'no-toggle'; |
| 640 | + } |
| 641 | + //create the calendar holder and append where needed |
| 642 | + if ($scope.datepickerAppendTo && |
| 643 | + $scope.datepickerAppendTo.indexOf('.') !== -1) { |
| 644 | + |
| 645 | + $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8); |
| 646 | + angular.element(document.getElementsByClassName($scope.datepickerAppendTo.replace('.', ''))[0]).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { |
| 647 | + |
| 648 | + theCalendar = angular.element(el)[0]; |
| 649 | + })); |
| 650 | + } else if ($scope.datepickerAppendTo && |
| 651 | + $scope.datepickerAppendTo.indexOf('#') !== -1) { |
| 652 | + |
| 653 | + $scope.datepickerID = 'datepicker-id-' + new Date().getTime() + (Math.floor(Math.random() * 6) + 8); |
| 654 | + angular.element(document.getElementById($scope.datepickerAppendTo.replace('#', ''))).append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { |
| 655 | + |
| 656 | + theCalendar = angular.element(el)[0]; |
| 657 | + })); |
| 658 | + } else if ($scope.datepickerAppendTo && |
| 659 | + $scope.datepickerAppendTo === 'body') { |
| 660 | + $scope.datepickerID = 'datepicker-id-' + (new Date().getTime() + (Math.floor(Math.random() * 6) + 8)); |
| 661 | + angular.element(document).find('body').append($compile(angular.element(htmlTemplate))($scope, function afterCompile(el) { |
| 662 | + |
| 663 | + theCalendar = angular.element(el)[0]; |
| 664 | + })); |
| 665 | + } else { |
641 | 666 |
|
| 667 | + thisInput.after($compile(angular.element(htmlTemplate))($scope)); |
| 668 | + //get the calendar as element |
| 669 | + theCalendar = element[0].querySelector('._720kb-datepicker-calendar'); |
| 670 | + } |
642 | 671 | //some tricky dirty events to fire if click is outside of the calendar and show/hide calendar when needed
|
643 | 672 | thisInput.on('focus click', function onFocusAndClick() {
|
644 | 673 |
|
|
666 | 695 | isMouseOn = true;
|
667 | 696 | });
|
668 | 697 |
|
669 |
| - angular.element($window).on('click focus', function onClickOnWindow() { |
| 698 | + angular.element($window).on('click focus focusin', function onClickOnWindow() { |
670 | 699 |
|
671 | 700 | if (!isMouseOn &&
|
672 | 701 | !isMouseOnInput && theCalendar) {
|
|
716 | 745 | 'buttonPrevTitle': '@',
|
717 | 746 | 'dateDisabledDates': '@',
|
718 | 747 | 'dateSetHidden': '@',
|
719 |
| - 'dateTyper': '@' |
| 748 | + 'dateTyper': '@', |
| 749 | + 'datepickerAppendTo': '@', |
| 750 | + 'datepickerToggle': '@' |
720 | 751 | },
|
721 | 752 | 'link': linkingFunction
|
722 | 753 | };
|
|
0 commit comments