From 0cd7435cfbf4e987baf9b1c322d760db0f1c7f36 Mon Sep 17 00:00:00 2001 From: Chaelgutierrez Date: Wed, 4 Oct 2017 13:08:09 +0800 Subject: [PATCH] Fixed angular module errors --- angular-date-picker.js | 138 +++++++++++++++++------------------------ 1 file changed, 57 insertions(+), 81 deletions(-) diff --git a/angular-date-picker.js b/angular-date-picker.js index c165fe0..6e74090 100644 --- a/angular-date-picker.js +++ b/angular-date-picker.js @@ -1,39 +1,27 @@ -(function (root, factory) { - if (typeof define === 'function' && define.amd) { - define([ 'module', 'angular' ], function (module, angular) { - module.exports = factory(angular); - }); - } else if (typeof module === 'object') { - module.exports = factory(require('angular')); - } else { - if (!root.mp) { - root.mp = {}; - } - - root.mp.datePicker = factory(root.angular); - } -}(this, function (angular) { - 'use strict'; - - return angular.module('mp.datePicker', []).directive('datePicker', [ '$window', '$locale', function ($window, $locale) { +'use strict'; + +/* + Branch Commit: Removed reimport of angular module causing errors +*/ + +angular.module('mp.datePicker', []).directive('datePicker', ['$window', '$locale', function($window, $locale) { // Introduce custom elements for IE8 $window.document.createElement('date-picker'); - var tmpl = '' -+ '
' -+ '
' -+ ' ' -+ ' {{ months[month] }} {{ year }}' -+ ' ' -+ '
' -+ '
' -+ '
{{ dayOfWeek.formattedDay || dayOfWeek.firstLetter }}
' -+ '
{{ day.day }}
' -+ '
{{ day.day }}
' -+ '
{{ day.day }}
' -+ '
' -+ '
' - ; + var tmpl = '' + + '
' + + '
' + + ' ' + + ' {{ months[month].shortName }} {{ year }}' + + ' ' + + '
' + + '
' + + '
{{ dayOfWeek.firstLetter }}
' + + '
{{ day }}
' + + '
{{ day }}
' + + '
{{ day }}
' + + '
' + + '
'; return { restrict: 'AE', @@ -43,31 +31,35 @@ scope: { onDateSelected: '&', formatDate: '=', // @todo breaking change: change to & to allow use of date filter directly - parseDate: '=', // @todo change to & - allowDate: '=', - formatDayOfWeek: '=' + parseDate: '=' // @todo change to & }, - link: function ($scope, $element, $attributes, ngModel) { + link: function($scope, $element, $attributes, ngModel) { var selectedDate = null, days = [], // Slices of this are used for ngRepeat - months = $locale.DATETIME_FORMATS.STANDALONEMONTH.slice(0), + months = [], daysOfWeek = [], - firstDayOfWeek = typeof $locale.DATETIME_FORMATS.FIRSTDAYOFWEEK === 'number' - ? ($locale.DATETIME_FORMATS.FIRSTDAYOFWEEK + 1) % 7 - : 0; + firstDayOfWeek = typeof $locale.DATETIME_FORMATS.FIRSTDAYOFWEEK === 'number' ? + ($locale.DATETIME_FORMATS.FIRSTDAYOFWEEK + 1) % 7 : + 0; for (var i = 1; i <= 31; i++) { days.push(i); } + for (var i = 0; i < 12; i++) { + months.push({ + fullName: $locale.DATETIME_FORMATS.MONTH[i], + shortName: $locale.DATETIME_FORMATS.SHORTMONTH[i] + }); + } + for (var i = 0; i < 7; i++) { var day = $locale.DATETIME_FORMATS.DAY[(i + firstDayOfWeek) % 7]; daysOfWeek.push({ fullName: day, - firstLetter: day.substr(0, 1), - formattedDay: $scope.formatDayOfWeek(day) + firstLetter: day.substr(0, 1) }); } @@ -80,15 +72,15 @@ var now = new Date(); - $scope.today = now.getFullYear() === $scope.year && now.getMonth() === $scope.month - ? now.getDate() - : null; + $scope.today = now.getFullYear() === $scope.year && now.getMonth() === $scope.month ? + now.getDate() : + null; - $scope.selectedDay = selectedDate - && selectedDate.getFullYear() === $scope.year - && selectedDate.getMonth() === $scope.month - ? selectedDate.getDate() - : null; + $scope.selectedDay = selectedDate && + selectedDate.getFullYear() === $scope.year && + selectedDate.getMonth() === $scope.month ? + selectedDate.getDate() : + null; var firstDayOfMonth = new Date($scope.year, $scope.month, 1), lastDayOfMonth = new Date($scope.year, $scope.month + 1, 0), @@ -96,39 +88,24 @@ daysInMonth = lastDayOfMonth.getDate(), daysInLastMonth = lastDayOfPreviousMonth.getDate(), dayOfWeek = firstDayOfMonth.getDay(), - leadingDays = (dayOfWeek - firstDayOfWeek + 7) % 7 || 7, // Ensure there are always leading days to give context - checkIfDateIsAllowed = $scope.allowDate !== undefined && typeof $scope.allowDate === 'function'; + leadingDays = (dayOfWeek - firstDayOfWeek + 7) % 7 || 7; // Ensure there are always leading days to give context - $scope.leadingDays = days.slice(- leadingDays - (31 - daysInLastMonth), daysInLastMonth); + $scope.leadingDays = days.slice(-leadingDays - (31 - daysInLastMonth), daysInLastMonth); $scope.days = days.slice(0, daysInMonth); // Ensure a total of 6 rows to maintain height consistency $scope.trailingDays = days.slice(0, 6 * 7 - (leadingDays + daysInMonth)); - - // Add disabled property to days - $scope.leadingDays = getDaysWithDisabledProperty($scope.leadingDays, -1); - $scope.days = getDaysWithDisabledProperty($scope.days, 0); - $scope.trailingDays = getDaysWithDisabledProperty($scope.trailingDays, 1); - - function getDaysWithDisabledProperty(days, monthOffset) { - return days.map(function(day) { - if (!checkIfDateIsAllowed) { - return {day: day, disabled: false}; - } - return {day: day, disabled: !$scope.allowDate(new Date($scope.year, $scope.month + monthOffset, day))}; - }); - } } // Default to current year and month setYearAndMonth(new Date()); if (ngModel) { - ngModel.$render = function () { - selectedDate = ngModel.$viewValue - ? $scope.parseDate - ? $scope.parseDate(ngModel.$viewValue) - : new Date(ngModel.$viewValue) - : null; + ngModel.$render = function() { + selectedDate = ngModel.$viewValue ? + $scope.parseDate ? + $scope.parseDate(ngModel.$viewValue) : + new Date(ngModel.$viewValue) : + null; if (selectedDate && !isNaN(selectedDate)) { setYearAndMonth(selectedDate); @@ -139,12 +116,12 @@ }; } - $scope.changeMonthBy = function (amount) { + $scope.changeMonthBy = function(amount) { var date = new Date($scope.year, $scope.month + amount, 1); setYearAndMonth(date); }; - $scope.pickDay = function (evt) { + $scope.pickDay = function(evt) { var target = angular.element(evt.target); if (target.hasClass('_day')) { @@ -161,9 +138,9 @@ if (ngModel) { ngModel.$setViewValue( - $scope.formatDate - ? $scope.formatDate(selectedDate) - : selectedDate.toLocaleDateString() + $scope.formatDate ? + $scope.formatDate(selectedDate) : + selectedDate.toLocaleDateString() ); } @@ -173,5 +150,4 @@ } }; }]) - .name; // pass back as dependency name -})); + .name; // pass back as dependency name \ No newline at end of file