diff --git a/README.md b/README.md index d76d72e..ede8abb 100644 --- a/README.md +++ b/README.md @@ -75,9 +75,10 @@ max-view | `"minute"` | Maximum navigable view. start-view | `"year"` | Initial view when the picker is open. min-date | | Two-way bindable property representing the minimum selectable date in the same format of the value. max-date | | Two-way bindable property representing the maximum selectable date in the same format of the value. -today | `false` | Highlights the current day. disable | `false` | Disables the picker if truly. autoclose | `true` | Closes the picker after selecting a date. +today | `false` | Highlights the current day. +keyboard | `false` | Allows using the keyboard to navigate the picker. ## Events @@ -114,8 +115,9 @@ format | `"L LTS"` | Format of the output value and min/max date. 1 min-view | `"decade"` | Minimum navigable view. max-view | `"minute"` | Maximum navigable view. start-view | `"year"` | Initial view after picker opening. -today | `false` | Highlights the current day. autoclose | `true` | Closes the picker after selecting a date. +today | `false` | Highlights the current day. +keyboard | `false` | Allows using the keyboard to navigate the picker. left-arrow | `"←"` | Left arrow string (HTML allowed). right-arrow | `"→"` | Right arrow string (HTML allowed). yearsFormat | `"YYYY"` | Years format in `decade` view. diff --git a/bower.json b/bower.json index 90922c1..95ccf8a 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-moment-picker", - "version": "0.5.7", + "version": "0.6.0", "authors": [ "Indri Muska " ], diff --git a/dist/angular-moment-picker.css b/dist/angular-moment-picker.css index 5e12ff8..625c21f 100644 --- a/dist/angular-moment-picker.css +++ b/dist/angular-moment-picker.css @@ -1,4 +1,4 @@ -/*! Angular Moment Picker - v0.5.7 - https://github.com/indrimuska/angular-moment-picker - (c) 2015 Indri Muska - MIT */ +/*! Angular Moment Picker - v0.6.0 - https://github.com/indrimuska/angular-moment-picker - (c) 2015 Indri Muska - MIT */ .moment-picker { position: relative; display: block; } .moment-picker .moment-picker-contents { cursor: pointer; } .moment-picker .moment-picker-container { color: #404040; min-width: 15em; background: #fff; padding: 4px; border: 1px solid #f0f3f4; border-radius: 4px; position: absolute; @@ -43,6 +43,12 @@ background-image: -ms-linear-gradient(#45b1e8, #3097de); background-image: -o-linear-gradient(#45b1e8, #3097de); background-image: linear-gradient(#45b1e8, #3097de); } +.moment-picker td.highlighted { background: rgba(0, 0, 0, .15) + background-image: -webkit-radial-gradient(transparent, rgba(0, 0, 0, .1)); + background-image: -moz-radial-gradient(transparent, rgba(0, 0, 0, .1)); + background-image: -ms-radial-gradient(transparent, rgba(0, 0, 0, .1)); + background-image: -o-radial-gradient(transparent, rgba(0, 0, 0, .1)); + background-image: radial-gradient(transparent, rgba(0, 0, 0, .1)); } .moment-picker th.disabled, .moment-picker th.disabled:hover, .moment-picker td.disabled, diff --git a/dist/angular-moment-picker.js b/dist/angular-moment-picker.js index 260e18c..b0db1c6 100644 --- a/dist/angular-moment-picker.js +++ b/dist/angular-moment-picker.js @@ -1,7 +1,9 @@ -/*! Angular Moment Picker - v0.5.7 - https://github.com/indrimuska/angular-moment-picker - (c) 2015 Indri Muska - MIT */ +/*! Angular Moment Picker - v0.6.0 - https://github.com/indrimuska/angular-moment-picker - (c) 2015 Indri Muska - MIT */ (function (angular) { 'use strict'; + var KEYS = { up: 38, down: 40, left: 37, right: 39, escape: 27, enter: 13 }; + var momentPickerProvider = (function () { var defaults; @@ -12,8 +14,9 @@ minView: 'decade', maxView: 'minute', startView: 'year', - today: false, autoclose: true, + today: false, + keyboard: false, leftArrow: '←', rightArrow: '→', yearsFormat: 'YYYY', @@ -36,7 +39,7 @@ return momentPickerProvider; })(); - var $timeout, $sce, $compile, $document, $window, momentPicker; + var $timeout, $sce, $compile, $window, momentPicker; var MomentPickerDirective = (function () { @@ -57,7 +60,7 @@ } // Directive - function MomentPickerDirective(timeout, sce, compile, document, window, momentPickerProvider) { + function MomentPickerDirective(timeout, sce, compile, window, momentPickerProvider) { this.restrict = 'A', this.scope = { model: '=momentPicker', @@ -68,19 +71,19 @@ startView: '@?', minDate: '=?', maxDate: '=?', - today: '=?', disabled: '=?disable', autoclose: '=?', + today: '=?', + keyboard: '=?', change: '&?' }; $timeout = timeout; $sce = sce; $compile = compile; - $document = document; $window = window; momentPicker = momentPickerProvider; } - MomentPickerDirective.prototype.$inject = ['$timeout', '$sce', '$compile', '$document', '$window', 'momentPicker']; + MomentPickerDirective.prototype.$inject = ['$timeout', '$sce', '$compile', '$window', 'momentPicker']; MomentPickerDirective.prototype.link = function ($scope, $element, $attrs) { $scope.template = ( '
' + '' + '' + - '' + + '' + '' + '' + '' + @@ -150,14 +153,15 @@ ); // one-way binding attributes - angular.forEach(['locale', 'format', 'minView', 'maxView', 'startView', 'today', 'leftArrow', 'rightArrow', 'autoclose'], function (attr) { + angular.forEach(['locale', 'format', 'minView', 'maxView', 'startView', 'autoclose', 'today', 'keyboard', 'leftArrow', 'rightArrow'], function (attr) { if (!angular.isDefined($scope[attr])) $scope[attr] = momentPicker[attr]; if (!angular.isDefined($attrs[attr])) $attrs[attr] = $scope[attr]; }); // utilities - $scope.momentToDate = function (value) { return angular.isDefined(value) && value.isValid() ? value.clone().toDate() : undefined; }; - $scope.valueUpdate = function () { if (!$scope.disabled) $scope.value = $scope.momentToDate($scope.valueMoment); }; + $scope.momentToDate = function (value) { return $scope.isValidMoment(value) ? value.clone().toDate() : undefined; }; + $scope.valueUpdate = function () { if (!$scope.disabled) $scope.value = $scope.momentToDate($scope.valueMoment); }; + $scope.isValidMoment = function (value) { return angular.isDefined(value) && value.isValid(); }; $scope.limits = { isAfterOrEqualMin: function (value, precision) { return !angular.isDefined($scope.minDateMoment) || value.isAfter($scope.minDateMoment, precision) || value.isSame($scope.minDateMoment, precision); @@ -223,12 +227,9 @@ update: function () { $scope.view.value = $scope.momentToDate($scope.view.moment); }, toggle: function () { $scope.view.isOpen ? $scope.view.close() : $scope.view.open(); }, open: function () { - // close every open picker - // this is required because every picker stops click event propagation - angular.forEach($document[0].querySelectorAll('.moment-picker-container.open'), function (element) { - ((angular.element(element).scope().view || {}).close || angular.noop)(); - }); - if (!$scope.disabled) $scope.view.isOpen = true; + if ($scope.disabled) return; + + $scope.view.isOpen = true; $timeout($scope.view.position, 0, false); }, close: function () { @@ -248,6 +249,39 @@ if (top + $window.pageYOffset - container.offsetHeight > 0 && top > winHeight / 2) $scope.picker.addClass('top'); if (left + container.offsetWidth > winWidth) $scope.picker.addClass('left'); }, + keydown: function (e) { + var view = $scope.view.selected + 'View', + precision = { decade: 'year', year: 'month', month: 'day', day: 'hour', hour: 'minute', minute: 'second' }[$scope.view.selected], + singleUnit = momentPicker[precision + 'sStep'] || 1, + operation = [KEYS.up, KEYS.left].indexOf(e.keyCode) >= 0 ? 'subtract' : 'add'; + + switch (e.keyCode) { + case KEYS.up: + case KEYS.down: + e.preventDefault(); + if (!$scope.view.isOpen) $scope.view.open(); + else { + $scope.view.update($scope.view.moment[operation](singleUnit * $scope[view].perLine, precision)); + $scope.view.render(); + } + break; + case KEYS.left: + case KEYS.right: + if (!$scope.view.isOpen) break; + $scope.view.update($scope.view.moment[operation](singleUnit, precision)); + $scope.view.render(); + e.preventDefault(); + break; + case KEYS.enter: + if (!$scope.view.isOpen) break; + $scope.view.change(precision); + e.preventDefault(); + break; + case KEYS.escape: + $scope.view.toggle(); + break; + } + }, // utility unit: function () { return $scope.view.selected == 'decade' ? 10 : 1; }, precision: function () { return $scope.view.selected.replace('decade', 'year'); }, @@ -286,12 +320,13 @@ if (nextView < 0 || nextView > maxView) { $scope.valueUpdate($scope.valueMoment = $scope.view.moment.clone()); - if ($scope.autoclose) $scope.view.close(); + if ($scope.autoclose) $timeout($scope.view.close); } else if (nextView >= minView) $scope.view.selected = view; } }; // decade view $scope.decadeView = { + perLine: 4, fourYears: {}, render: function () { var year = $scope.view.moment.clone(), @@ -307,7 +342,11 @@ $scope.decadeView.fourYears[index].push({ label: year.format(momentPicker.yearsFormat), year: year.year(), - class: !selectable || [0, 11].indexOf(y) >= 0 ? 'disabled' : year.isSame($scope.valueMoment, 'year') ? 'selected' : '', + class: [ + $scope.keyboard && year.isSame($scope.view.moment, 'year') ? 'highlighted' : '', + !selectable || [0, 11].indexOf(y) >= 0 ? 'disabled' : + $scope.isValidMoment($scope.valueMoment) && year.isSame($scope.valueMoment, 'year') ? 'selected' : '' + ].join(' ').trim(), selectable: selectable }); year.add(1, 'years'); @@ -323,6 +362,7 @@ }; // year view $scope.yearView = { + perLine: 4, fourMonths: {}, render: function () { var month = $scope.view.moment.clone().startOf('year'), @@ -338,7 +378,10 @@ label: month.format(momentPicker.monthsFormat), year: month.year(), month: month.month(), - class: !selectable ? 'disabled' : month.isSame($scope.valueMoment, 'month') ? 'selected' : '', + class: [ + $scope.keyboard && month.isSame($scope.view.moment, 'month') ? 'highlighted' : '', + !selectable ? 'disabled' : $scope.isValidMoment($scope.valueMoment) && month.isSame($scope.valueMoment, 'month') ? 'selected' : '' + ].join(' ').trim(), selectable: selectable }); month.add(1, 'months'); @@ -354,10 +397,12 @@ }; // month view $scope.monthView = { + perLine: 7, days: (function () { var days = [], - day = moment().locale($scope.locale).startOf('week'); - for (var i = 0; i < 7; i++) { + day = moment().locale($scope.locale).startOf('week'), + end = day.clone().endOf('week'); + while (!day.isSame(end, 'day')) { days.push(day.format('dd')); day.add(1, 'days'); } @@ -373,7 +418,7 @@ $scope.monthView.weeks = []; for (var w = firstWeek; w <= lastWeek; w++) - weeks[w] = '0000000'.split('').map(function () { + weeks[w] = Array.apply(null, Array($scope.monthView.perLine)).map(function () { var selectable = $scope.limits.isSelectable(day, 'day'), d = { label: day.format(momentPicker.daysFormat), @@ -381,8 +426,10 @@ date: day.date(), month: day.month(), class: [ + $scope.keyboard && day.isSame($scope.view.moment, 'day') ? 'highlighted' : '', !!$scope.today && day.isSame(new Date(), 'day') ? 'today' : '', - !selectable || day.month() != month ? 'disabled' : day.isSame($scope.valueMoment, 'day') ? 'selected' : '' + !selectable || day.month() != month ? 'disabled' : + $scope.isValidMoment($scope.valueMoment) && day.isSame($scope.valueMoment, 'day') ? 'selected' : '' ].join(' ').trim(), selectable: selectable }; @@ -396,7 +443,7 @@ // return title return $scope.view.moment.format('MMMM YYYY'); }, - setDate: function (day) { + setDay: function (day) { if (!day.selectable) return; $scope.view.update($scope.view.moment.year(day.year).month(day.month).date(day.date)); $scope.view.change('day'); @@ -404,13 +451,14 @@ }; // day view $scope.dayView = { + perLine: 4, threeHours: [], render: function () { var hour = $scope.view.moment.clone().startOf('day'); $scope.dayView.threeHours = []; for (var h = 0; h < 24; h++) { - var index = Math.floor(h / 4), + var index = Math.floor(h / $scope.dayView.perLine), selectable = $scope.limits.isSelectable(hour, 'hour'); if (!$scope.dayView.threeHours[index]) @@ -421,7 +469,10 @@ month: hour.month(), date: hour.date(), hour: hour.hour(), - class: !selectable ? 'disabled' : hour.isSame($scope.valueMoment, 'hour') ? 'selected' : '', + class: [ + $scope.keyboard && hour.isSame($scope.view.moment, 'hour') ? 'highlighted' : '', + !selectable ? 'disabled' : $scope.isValidMoment($scope.valueMoment) && hour.isSame($scope.valueMoment, 'hour') ? 'selected' : '' + ].join(' ').trim(), selectable: selectable }); hour.add(1, 'hours'); @@ -437,6 +488,7 @@ }; // hour view $scope.hourView = { + perLine: 4, minutes: [], render: function () { var i = 0, @@ -445,7 +497,7 @@ $scope.hourView.minutes = []; for (var m = 0; m < 60; m += momentPicker.minutesStep) { - var index = Math.floor(i / 4), + var index = Math.floor(i / $scope.hourView.perLine), selectable = $scope.limits.isSelectable(minute, 'minute'); if (!$scope.hourView.minutes[index]) @@ -457,12 +509,16 @@ date: minute.date(), hour: minute.hour(), minute: minute.minute(), - class: !selectable ? 'disabled' : minute.isSame($scope.valueMoment, 'minute') ? 'selected' : '', + class: [ + $scope.keyboard && minute.isSame($scope.view.moment, 'minute') ? 'highlighted' : '', + !selectable ? 'disabled' : $scope.isValidMoment($scope.valueMoment) && minute.isSame($scope.valueMoment, 'minute') ? 'selected' : '' + ].join(' ').trim(), selectable: selectable }); i++; minute.add(momentPicker.minutesStep, 'minutes'); } + if ($scope.keyboard) $scope.hourView.highlightClosest(); // return title return $scope.view.moment.clone().startOf('hour').format('lll'); }, @@ -470,10 +526,25 @@ if (!minute.selectable) return; $scope.view.update($scope.view.moment.year(minute.year).month(minute.month).date(minute.date).hour(minute.hour).minute(minute.minute)); $scope.view.change('minute'); + }, + highlightClosest: function () { + var minutes = [], minute; + angular.forEach($scope.hourView.minutes, function (line) { + angular.forEach(line, function (value) { + if (Math.abs(value.minute - $scope.view.moment.minute()) < momentPicker.minutesStep) minutes.push(value); + }); + }); + minute = minutes.sort(function (value1, value2) { + return Math.abs(value1.minute - $scope.view.moment.minute()) > Math.abs(value2.minute - $scope.view.moment.minute()); + })[0]; + if (minute.minute - $scope.view.moment.minute() == 0) return; + $scope.view.update($scope.view.moment.year(minute.year).month(minute.month).date(minute.date).hour(minute.hour).minute(minute.minute)); + if (minute.selectable) minute.class = (minute.class + ' highlighted').trim(); } }; // minute view $scope.minuteView = { + perLine: 6, seconds: [], render: function () { var i = 0, @@ -481,7 +552,7 @@ $scope.minuteView.seconds = []; for (var s = 0; s < 60; s += momentPicker.secondsStep) { - var index = Math.floor(i / 6), + var index = Math.floor(i / $scope.minuteView.perLine), selectable = $scope.limits.isSelectable(second, 'second'); if (!$scope.minuteView.seconds[index]) @@ -494,12 +565,16 @@ hour: second.hour(), minute: second.minute(), second: second.second(), - class: !selectable ? 'disabled' : second.isSame($scope.valueMoment, 'second') ? 'selected' : '', + class: [ + $scope.keyboard && second.isSame($scope.view.moment, 'second') ? 'highlighted' : '', + !selectable ? 'disabled' : $scope.isValidMoment($scope.valueMoment) && second.isSame($scope.valueMoment, 'second') ? 'selected' : '' + ].join(' ').trim(), selectable: selectable }); i++; second.add(momentPicker.secondsStep, 'seconds'); } + if ($scope.keyboard) $scope.minuteView.highlightClosest(); // return title return $scope.view.moment.clone().startOf('minute').format('lll'); }, @@ -507,6 +582,20 @@ if (!second.selectable) return; $scope.view.update($scope.view.moment.year(second.year).month(second.month).date(second.date).hour(second.hour).minute(second.minute).second(second.second)); $scope.view.change('second'); + }, + highlightClosest: function () { + var seconds = [], second; + angular.forEach($scope.minuteView.seconds, function (line) { + angular.forEach(line, function (value) { + if (Math.abs(value.second - $scope.view.moment.second()) < momentPicker.secondsStep) seconds.push(value); + }); + }); + second = seconds.sort(function (value1, value2) { + return Math.abs(value1.second - $scope.view.moment.second()) > Math.abs(value2.second - $scope.view.moment.second()); + })[0]; + if (second.second - $scope.view.moment.second() == 0) return; + $scope.view.update($scope.view.moment.year(second.year).month(second.month).date(second.date).hour(second.hour).minute(second.minute).second(second.second)); + if (second.selectable) second.class = (second.class + ' highlighted').trim(); } }; @@ -517,6 +606,10 @@ $scope.container = $compile($scope.template)($scope); $scope.picker.append($scope.contents); $scope.picker.append($scope.container); + $scope.input = $scope.contents[0].tagName.toLowerCase() != 'input' && $scope.contents[0].querySelectorAll('input').length > 0 + ? angular.element($scope.contents[0].querySelectorAll('input')) + : angular.element($scope.contents[0]); + $scope.input.attr('tabindex', 0); // initialization $scope.views.detectMinMax(); @@ -587,15 +680,13 @@ $scope.view.render(); }); - // open/close listeners - $document.on('click', function () { if ($scope.view.isOpen) $timeout($scope.view.close); }); - $scope.container.on('click', function (e) { e.stopPropagation(); }); - $scope.contents.on('click', function (e) { - e.stopPropagation(); - if (!$scope.view.isOpen) $timeout($scope.view.open); - }); - angular.element($scope.contents[0].querySelector('input')).on('focus', function () { if (!$scope.view.isOpen) $timeout($scope.view.open); }); - angular.element($window).on('resize', $scope.view.position); + // event listeners + $scope.input + .on('focus', function () { if (!$scope.view.isOpen) $scope.$apply($scope.view.open); }) + .on('blur', function () { $timeout(function () { if ($scope.view.isOpen && document.activeElement !== $scope.input[0]) $scope.view.close(); }, 10); }) + .on('keydown', function (e) { if ($scope.keyboard) $scope.$apply(function () { $scope.view.keydown(e); }); }); + $scope.container.on('click', function () { $scope.input[0].focus(); }); + angular.element($window).on('resize scroll', $scope.view.position); }; return MomentPickerDirective; @@ -607,9 +698,9 @@ return new momentPickerProvider(); }]) .directive('momentPicker', [ - '$timeout', '$sce', '$compile', '$document', '$window', 'momentPicker', - function ($timeout, $sce, $compile, $document, $window, momentPicker) { - return new MomentPickerDirective($timeout, $sce, $compile, $document, $window, momentPicker); + '$timeout', '$sce', '$compile', '$window', 'momentPicker', + function ($timeout, $sce, $compile, $window, momentPicker) { + return new MomentPickerDirective($timeout, $sce, $compile, $window, momentPicker); } ]); diff --git a/dist/angular-moment-picker.min.css b/dist/angular-moment-picker.min.css index 98d64f0..3bfb061 100644 --- a/dist/angular-moment-picker.min.css +++ b/dist/angular-moment-picker.min.css @@ -1,2 +1,2 @@ -/*! Angular Moment Picker - v0.5.7 - https://github.com/indrimuska/angular-moment-picker - (c) 2015 Indri Muska - MIT */ -.moment-picker{position:relative;display:block}.moment-picker .moment-picker-contents{cursor:pointer}.moment-picker .moment-picker-container{color:#404040;min-width:15em;background:#fff;padding:4px;border:1px solid #f0f3f4;border-radius:4px;position:absolute;top:100%;margin-top:4px;margin-left:-.5em;box-shadow:0 2px 4px rgba(0,0,0,.075);z-index:5}.moment-picker .moment-picker-container:after,.moment-picker .moment-picker-container:before{content:'';display:block;width:0;height:0;border:8px solid transparent;border-top:none;position:absolute;top:-9px;left:15px}.moment-picker .moment-picker-container:before{border-bottom-color:#f0f3f4;border-width:9px}.moment-picker .moment-picker-container:after{border-bottom-color:#fff;margin-top:1px;margin-left:1px}.moment-picker table{border-collapse:collapse;border-spacing:0;min-width:100%;table-layout:fixed}.moment-picker.top .moment-picker-container{top:auto;bottom:100%;margin-top:auto;margin-bottom:4px}.moment-picker.top .moment-picker-container:after,.moment-picker.top .moment-picker-container:before{border:8px solid transparent;border-bottom:none;top:auto;bottom:-9px}.moment-picker.top .moment-picker-container:before{border-top-color:#f0f3f4;border-width:9px}.moment-picker.top .moment-picker-container:after{border-top-color:#fff;margin-top:auto;margin-bottom:1px}.moment-picker.left .moment-picker-container{right:0;margin-left:auto;margin-right:-.5em}.moment-picker.left .moment-picker-container:after,.moment-picker.left .moment-picker-container:before{left:auto;right:15px}.moment-picker.left .moment-picker-container:after{margin-left:auto;margin-right:1px}.moment-picker th{font-weight:700}.moment-picker th:first-child,.moment-picker th:last-child{width:2em}.moment-picker td,.moment-picker th{padding:0;text-align:center;min-width:2em;height:2em;text-shadow:0 1px 0 rgba(255,255,255,.9);cursor:pointer;border-radius:4px}.moment-picker td.today{background:#e4eef5;color:#404040;text-shadow:0 1px 0 rgba(255,255,255,.9)}.moment-picker td:hover,.moment-picker th:hover{background:#fafbfb;background-image:-webkit-linear-gradient(#f0f3f4,#fafbfb);background-image:-moz-linear-gradient(#f0f3f4,#fafbfb);background-image:-ms-linear-gradient(#f0f3f4,#fafbfb);background-image:-o-linear-gradient(#f0f3f4,#fafbfb);background-image:linear-gradient(#f0f3f4,#fafbfb)}.moment-picker td.selected{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.3);border-color:#3ca0dd;background:#45b1e8;background-image:-webkit-linear-gradient(#45b1e8,#3097de);background-image:-moz-linear-gradient(#45b1e8,#3097de);background-image:-ms-linear-gradient(#45b1e8,#3097de);background-image:-o-linear-gradient(#45b1e8,#3097de);background-image:linear-gradient(#45b1e8,#3097de)}.moment-picker td.disabled,.moment-picker td.disabled:hover,.moment-picker th.disabled,.moment-picker th.disabled:hover{color:#abbbc7;background:0 0;cursor:default}.moment-picker .decade-view td,.moment-picker .year-view td{height:3.4em}.moment-picker .month-view .moment-picker-specific-views th{background:0 0;cursor:default}.moment-picker .month-view td{width:1.4285714286em}.moment-picker .day-view td,.moment-picker .hour-view td{height:2.3333333333em}.moment-picker .minute-view td{height:1.8em} \ No newline at end of file +/*! Angular Moment Picker - v0.6.0 - https://github.com/indrimuska/angular-moment-picker - (c) 2015 Indri Muska - MIT */ +.moment-picker{position:relative;display:block}.moment-picker .moment-picker-contents{cursor:pointer}.moment-picker .moment-picker-container{color:#404040;min-width:15em;background:#fff;padding:4px;border:1px solid #f0f3f4;border-radius:4px;position:absolute;top:100%;margin-top:4px;margin-left:-.5em;box-shadow:0 2px 4px rgba(0,0,0,.075);z-index:5}.moment-picker .moment-picker-container:after,.moment-picker .moment-picker-container:before{content:'';display:block;width:0;height:0;border:8px solid transparent;border-top:none;position:absolute;top:-9px;left:15px}.moment-picker .moment-picker-container:before{border-bottom-color:#f0f3f4;border-width:9px}.moment-picker .moment-picker-container:after{border-bottom-color:#fff;margin-top:1px;margin-left:1px}.moment-picker table{border-collapse:collapse;border-spacing:0;min-width:100%;table-layout:fixed}.moment-picker.top .moment-picker-container{top:auto;bottom:100%;margin-top:auto;margin-bottom:4px}.moment-picker.top .moment-picker-container:after,.moment-picker.top .moment-picker-container:before{border:8px solid transparent;border-bottom:none;top:auto;bottom:-9px}.moment-picker.top .moment-picker-container:before{border-top-color:#f0f3f4;border-width:9px}.moment-picker.top .moment-picker-container:after{border-top-color:#fff;margin-top:auto;margin-bottom:1px}.moment-picker.left .moment-picker-container{right:0;margin-left:auto;margin-right:-.5em}.moment-picker.left .moment-picker-container:after,.moment-picker.left .moment-picker-container:before{left:auto;right:15px}.moment-picker.left .moment-picker-container:after{margin-left:auto;margin-right:1px}.moment-picker th{font-weight:700}.moment-picker th:first-child,.moment-picker th:last-child{width:2em}.moment-picker td,.moment-picker th{padding:0;text-align:center;min-width:2em;height:2em;text-shadow:0 1px 0 rgba(255,255,255,.9);cursor:pointer;border-radius:4px}.moment-picker td.today{background:#e4eef5;color:#404040;text-shadow:0 1px 0 rgba(255,255,255,.9)}.moment-picker td:hover,.moment-picker th:hover{background:#fafbfb;background-image:-webkit-linear-gradient(#f0f3f4,#fafbfb);background-image:-moz-linear-gradient(#f0f3f4,#fafbfb);background-image:-ms-linear-gradient(#f0f3f4,#fafbfb);background-image:-o-linear-gradient(#f0f3f4,#fafbfb);background-image:linear-gradient(#f0f3f4,#fafbfb)}.moment-picker td.selected{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.3);border-color:#3ca0dd;background:#45b1e8;background-image:-webkit-linear-gradient(#45b1e8,#3097de);background-image:-moz-linear-gradient(#45b1e8,#3097de);background-image:-ms-linear-gradient(#45b1e8,#3097de);background-image:-o-linear-gradient(#45b1e8,#3097de);background-image:linear-gradient(#45b1e8,#3097de)}.moment-picker td.highlighted{background:-webkit-radial-gradient(transparent,rgba(0,0,0,.1));background-image:-moz-radial-gradient(transparent,rgba(0,0,0,.1));background-image:-ms-radial-gradient(transparent,rgba(0,0,0,.1));background-image:-o-radial-gradient(transparent,rgba(0,0,0,.1));background-image:radial-gradient(transparent,rgba(0,0,0,.1))}.moment-picker td.disabled,.moment-picker td.disabled:hover,.moment-picker th.disabled,.moment-picker th.disabled:hover{color:#abbbc7;background:0 0;cursor:default}.moment-picker .decade-view td,.moment-picker .year-view td{height:3.4em}.moment-picker .month-view .moment-picker-specific-views th{background:0 0;cursor:default}.moment-picker .month-view td{width:1.4285714286em}.moment-picker .day-view td,.moment-picker .hour-view td{height:2.3333333333em}.moment-picker .minute-view td{height:1.8em} \ No newline at end of file diff --git a/dist/angular-moment-picker.min.js b/dist/angular-moment-picker.min.js index 49d3c29..a11b0d6 100644 --- a/dist/angular-moment-picker.min.js +++ b/dist/angular-moment-picker.min.js @@ -1,2 +1,2 @@ -/*! Angular Moment Picker - v0.5.7 - https://github.com/indrimuska/angular-moment-picker - (c) 2015 Indri Muska - MIT */ -!function(a){"use strict";var b,c,d,e,f,g,h=function(){function b(){c={locale:"en",format:"L LTS",minView:"decade",maxView:"minute",startView:"year",today:!1,autoclose:!0,leftArrow:"←",rightArrow:"→",yearsFormat:"YYYY",monthsFormat:"MMM",daysFormat:"D",hoursFormat:"HH:[00]",secondsFormat:"ss",minutesStep:5,secondsStep:1}}var c;return b.prototype.options=function(b){return a.extend(c,b),a.copy(c)},b.prototype.$get=function(){return c},b}(),i=function(){function h(a){var b,c,d,e;if(a)return a.getClientRects().length?(d=a.getBoundingClientRect(),d.width||d.height?(e=a.ownerDocument,c=null!=e&&e===e.window?a:9===e.nodeType&&e.defaultView,b=e.documentElement,{top:d.top+c.pageYOffset-b.clientTop,left:d.left+c.pageXOffset-b.clientLeft}):d):{top:0,left:0}}function i(a,h,i,j,k,l){this.restrict="A",this.scope={model:"=momentPicker",locale:"@?",format:"@?",minView:"@?",maxView:"@?",startView:"@?",minDate:"=?",maxDate:"=?",today:"=?",disabled:"=?disable",autoclose:"=?",change:"&?"},b=a,c=h,d=i,e=j,f=k,g=l}return i.prototype.$inject=["$timeout","$sce","$compile","$document","$window","momentPicker"],i.prototype.link=function(i,j,k){i.template='
',a.forEach(["locale","format","minView","maxView","startView","today","leftArrow","rightArrow","autoclose"],function(b){a.isDefined(i[b])||(i[b]=g[b]),a.isDefined(k[b])||(k[b]=i[b])}),i.momentToDate=function(b){return a.isDefined(b)&&b.isValid()?b.clone().toDate():void 0},i.valueUpdate=function(){i.disabled||(i.value=i.momentToDate(i.valueMoment))},i.limits={isAfterOrEqualMin:function(b,c){return!a.isDefined(i.minDateMoment)||b.isAfter(i.minDateMoment,c)||b.isSame(i.minDateMoment,c)},isBeforeOrEqualMax:function(b,c){return!a.isDefined(i.maxDateMoment)||b.isBefore(i.maxDateMoment,c)||b.isSame(i.maxDateMoment,c)},isSelectable:function(a,b){return i.limits.isAfterOrEqualMin(a,b)&&i.limits.isBeforeOrEqualMax(a,b)},checkValue:function(){a.isDefined(i.valueMoment)&&(i.limits.isAfterOrEqualMin(i.valueMoment)||i.valueUpdate(i.valueMoment=i.minDateMoment.clone()),i.limits.isBeforeOrEqualMax(i.valueMoment)||i.valueUpdate(i.valueMoment=i.maxDateMoment.clone()))},checkView:function(){a.isDefined(i.view.moment)||(i.view.moment=moment().locale(i.locale)),i.limits.isAfterOrEqualMin(i.view.moment)||(i.view.moment=i.minDateMoment.clone()),i.limits.isBeforeOrEqualMax(i.view.moment)||(i.view.moment=i.maxDateMoment.clone()),i.view.update()}},i.views={all:["decade","year","month","day","hour","minute"],formats:{decade:"Y{1,2}(?!Y)|YYYY|[Ll]{1,4}(?!T)",year:"M{1,4}(?![Mo])|Mo|Q",month:"[Dd]{1,4}(?![Ddo])|DDDo|[Dd]o|[Ww]{1,2}(?![Wwo])|[Ww]o|[Ee]|L{1,2}(?!T)|l{1,2}",day:"[Hh]{1,2}|LTS?",hour:"m{1,2}|[Ll]{3,4}|LT(?!S)",minute:"s{1,2}|S{1,}|X|LTS"},detectMinMax:function(){var b,c;a.forEach(i.views.formats,function(d,e){var f=new RegExp("("+d+")(?![^[]*])","g");i.format.match(f)&&(a.isDefined(b)||(b=e),c=e)}),b=a.isDefined(b)?Math.max(0,i.views.all.indexOf(b)):0,c=a.isDefined(c)?Math.min(i.views.all.length-1,i.views.all.indexOf(c)):i.views.all.length-1,b>i.views.all.indexOf(i.minView)&&(i.minView=i.views.all[b]),c0&&c>g/2&&i.picker.addClass("top"),d+a.offsetWidth>e&&i.picker.addClass("left")},unit:function(){return"decade"==i.view.selected?10:1},precision:function(){return i.view.selected.replace("decade","year")},title:"",previous:{label:c.trustAsHtml(i.leftArrow),selectable:!0,set:function(){i.view.previous.selectable&&i.view.update(i.view.moment.subtract(i.view.unit(),i.view.precision()).toDate())}},next:{selectable:!0,label:c.trustAsHtml(i.rightArrow),set:function(){i.view.next.selectable&&i.view.update(i.view.moment.add(i.view.unit(),i.view.precision()).toDate())}},setParentView:function(){i.view.change(i.views.all[Math.max(0,i.views.all.indexOf(i.view.selected)-1)])},render:function(){var a=i.view.moment.clone().startOf(i.view.precision()).subtract(i.view.unit(),i.view.precision()),b=i.view.moment.clone().endOf(i.view.precision()).add(i.view.unit(),i.view.precision());i.view.previous.selectable=i.limits.isAfterOrEqualMin(a,i.view.precision()),i.view.previous.label=c.trustAsHtml(i.view.previous.selectable?i.leftArrow:" "),i.view.next.selectable=i.limits.isBeforeOrEqualMax(b,i.view.precision()),i.view.next.label=c.trustAsHtml(i.view.next.selectable?i.rightArrow:" "),i.view.title=i[i.view.selected+"View"].render()},change:function(a){var b=i.views.all.indexOf(a),c=i.views.all.indexOf(i.minView),d=i.views.all.indexOf(i.maxView);0>b||b>d?(i.valueUpdate(i.valueMoment=i.view.moment.clone()),i.autoclose&&i.view.close()):b>=c&&(i.view.selected=a)}},i.decadeView={fourYears:{},render:function(){var a=i.view.moment.clone(),b=10*Math.floor(a.year()/10)-1;a.year(b),i.decadeView.fourYears={};for(var c=0;12>c;c++){var d=Math.floor(c/4),e=i.limits.isSelectable(a,"year");i.decadeView.fourYears[d]||(i.decadeView.fourYears[d]=[]),i.decadeView.fourYears[d].push({label:a.format(g.yearsFormat),year:a.year(),"class":!e||[0,11].indexOf(c)>=0?"disabled":a.isSame(i.valueMoment,"year")?"selected":"",selectable:e}),a.add(1,"years")}return[a.subtract(2,"years").format("YYYY"),a.subtract(9,"years").format("YYYY")].reverse().join(" - ")},setYear:function(a){a.selectable&&(i.view.update(i.view.moment.year(a.year)),i.view.change("year"))}},i.yearView={fourMonths:{},render:function(){var a=i.view.moment.clone().startOf("year"),b=moment.monthsShort();return i.yearView.fourMonths={},b.forEach(function(b,c){var d=Math.floor(c/4),e=i.limits.isSelectable(a,"month");i.yearView.fourMonths[d]||(i.yearView.fourMonths[d]=[]),i.yearView.fourMonths[d].push({label:a.format(g.monthsFormat),year:a.year(),month:a.month(),"class":e?a.isSame(i.valueMoment,"month")?"selected":"":"disabled",selectable:e}),a.add(1,"months")}),i.view.moment.format("YYYY")},setMonth:function(a){a.selectable&&(i.view.update(i.view.moment.year(a.year).month(a.month)),i.view.change("month"))}},i.monthView={days:function(){for(var a=[],b=moment().locale(i.locale).startOf("week"),c=0;7>c;c++)a.push(b.format("dd")),b.add(1,"days");return a}(),weeks:[],render:function(){var b=i.view.moment.month(),c=i.view.moment.clone().startOf("month").startOf("week"),d={},e=c.week(),f=e+5;i.monthView.weeks=[];for(var h=e;f>=h;h++)d[h]="0000000".split("").map(function(){var a=i.limits.isSelectable(c,"day"),d={label:c.format(g.daysFormat),year:c.year(),date:c.date(),month:c.month(),"class":[i.today&&c.isSame(new Date,"day")?"today":"",a&&c.month()==b?c.isSame(i.valueMoment,"day")?"selected":"":"disabled"].join(" ").trim(),selectable:a};return c.add(1,"days"),d});return a.forEach(d,function(a){i.monthView.weeks.push(a)}),i.view.moment.format("MMMM YYYY")},setDate:function(a){a.selectable&&(i.view.update(i.view.moment.year(a.year).month(a.month).date(a.date)),i.view.change("day"))}},i.dayView={threeHours:[],render:function(){var a=i.view.moment.clone().startOf("day");i.dayView.threeHours=[];for(var b=0;24>b;b++){var c=Math.floor(b/4),d=i.limits.isSelectable(a,"hour");i.dayView.threeHours[c]||(i.dayView.threeHours[c]=[]),i.dayView.threeHours[c].push({label:a.format(g.hoursFormat),year:a.year(),month:a.month(),date:a.date(),hour:a.hour(),"class":d?a.isSame(i.valueMoment,"hour")?"selected":"":"disabled",selectable:d}),a.add(1,"hours")}return i.view.moment.format("LL")},setHour:function(a){a.selectable&&(i.view.update(i.view.moment.year(a.year).month(a.month).date(a.date).hour(a.hour)),i.view.change("hour"))}},i.hourView={minutes:[],render:function(){var a=0,b=i.view.moment.clone().startOf("hour"),c=g.minutesFormat||moment.localeData(i.locale).longDateFormat("LT").replace(/[aA]/,"");i.hourView.minutes=[];for(var d=0;60>d;d+=g.minutesStep){var e=Math.floor(a/4),f=i.limits.isSelectable(b,"minute");i.hourView.minutes[e]||(i.hourView.minutes[e]=[]),i.hourView.minutes[e].push({label:b.format(c),year:b.year(),month:b.month(),date:b.date(),hour:b.hour(),minute:b.minute(),"class":f?b.isSame(i.valueMoment,"minute")?"selected":"":"disabled",selectable:f}),a++,b.add(g.minutesStep,"minutes")}return i.view.moment.clone().startOf("hour").format("lll")},setMinute:function(a){a.selectable&&(i.view.update(i.view.moment.year(a.year).month(a.month).date(a.date).hour(a.hour).minute(a.minute)),i.view.change("minute"))}},i.minuteView={seconds:[],render:function(){var a=0,b=i.view.moment.clone().startOf("minute");i.minuteView.seconds=[];for(var c=0;60>c;c+=g.secondsStep){var d=Math.floor(a/6),e=i.limits.isSelectable(b,"second");i.minuteView.seconds[d]||(i.minuteView.seconds[d]=[]),i.minuteView.seconds[d].push({label:b.format(g.secondsFormat),year:b.year(),month:b.month(),date:b.date(),hour:b.hour(),minute:b.minute(),second:b.second(),"class":e?b.isSame(i.valueMoment,"second")?"selected":"":"disabled",selectable:e}),a++,b.add(g.secondsStep,"seconds")}return i.view.moment.clone().startOf("minute").format("lll")},setSecond:function(a){a.selectable&&(i.view.update(i.view.moment.year(a.year).month(a.month).date(a.date).hour(a.hour).minute(a.minute).second(a.second)),i.view.change("second"))}},i.picker=a.element(''),j.after(i.picker),i.contents=j.addClass("moment-picker-contents").removeAttr("moment-picker"),i.container=d(i.template)(i),i.picker.append(i.contents),i.picker.append(i.container),i.views.detectMinMax(),i.limits.checkView(),i.$watch("model",function(b){a.isDefined(b)&&(i.valueMoment=moment(b,i.format,i.locale),i.valueMoment.isValid()?(i.view.moment=i.valueMoment.clone(),i.view.update()):i.valueMoment=void 0),i.valueUpdate(i.valueMoment),i.limits.checkValue()}),i.$watch("value",function(){if(a.isDefined(i.valueMoment)){var c=i.model,d=i.valueMoment.format(i.format);d!=c&&b(function(){i.view.update(i.view.moment=i.valueMoment.clone()),i.model=d,a.isFunction(i.change)&&b(function(){i.change({newValue:d,oldValue:c})},0,!1)})}}),i.$watch("[view.selected, view.value]",i.view.render,!0),i.$watch("[minView, maxView]",function(){i.views.detectMinMax(),i.startView=i.views.all[Math.max(Math.min(i.views.all.indexOf(i.startView),i.views.all.indexOf(i.maxView)),i.views.all.indexOf(i.minView))],i.view.selected=i.startView}),i.$watch("[minDate, maxDate]",function(){a.forEach(["minDate","maxDate"],function(b){a.isDefined(i[b])&&(i[b+"Moment"]=moment(i[b],i.format,i.locale),i[b+"Moment"].isValid()||(i[b+"Moment"]=void 0))}),i.limits.checkValue(),i.limits.checkView(),i.view.render()},!0),i.$watch("locale",function(b,c){a.isDefined(c)&&b!=c&&(a.forEach(["model","minDate","maxDate"],function(d){a.isDefined(i[d])&&(i[d]=moment(i[d],i.format,c).locale(b).format(i.format))}),i.view.render())}),e.on("click",function(){i.view.isOpen&&b(i.view.close)}),i.container.on("click",function(a){a.stopPropagation()}),i.contents.on("click",function(a){a.stopPropagation(),i.view.isOpen||b(i.view.open)}),a.element(i.contents[0].querySelector("input")).on("focus",function(){i.view.isOpen||b(i.view.open)}),a.element(f).on("resize",i.view.position)},i}();a.module("moment-picker",[]).provider("momentPicker",[function(){return new h}]).directive("momentPicker",["$timeout","$sce","$compile","$document","$window","momentPicker",function(a,b,c,d,e,f){return new i(a,b,c,d,e,f)}])}(window.angular); \ No newline at end of file +/*! Angular Moment Picker - v0.6.0 - https://github.com/indrimuska/angular-moment-picker - (c) 2015 Indri Muska - MIT */ +!function(a){"use strict";var b,c,d,e,f,g={up:38,down:40,left:37,right:39,escape:27,enter:13},h=function(){function b(){c={locale:"en",format:"L LTS",minView:"decade",maxView:"minute",startView:"year",autoclose:!0,today:!1,keyboard:!1,leftArrow:"←",rightArrow:"→",yearsFormat:"YYYY",monthsFormat:"MMM",daysFormat:"D",hoursFormat:"HH:[00]",secondsFormat:"ss",minutesStep:5,secondsStep:1}}var c;return b.prototype.options=function(b){return a.extend(c,b),a.copy(c)},b.prototype.$get=function(){return c},b}(),i=function(){function h(a){var b,c,d,e;if(a)return a.getClientRects().length?(d=a.getBoundingClientRect(),d.width||d.height?(e=a.ownerDocument,c=null!=e&&e===e.window?a:9===e.nodeType&&e.defaultView,b=e.documentElement,{top:d.top+c.pageYOffset-b.clientTop,left:d.left+c.pageXOffset-b.clientLeft}):d):{top:0,left:0}}function i(a,g,h,i,j){this.restrict="A",this.scope={model:"=momentPicker",locale:"@?",format:"@?",minView:"@?",maxView:"@?",startView:"@?",minDate:"=?",maxDate:"=?",disabled:"=?disable",autoclose:"=?",today:"=?",keyboard:"=?",change:"&?"},b=a,c=g,d=h,e=i,f=j}return i.prototype.$inject=["$timeout","$sce","$compile","$window","momentPicker"],i.prototype.link=function(i,j,k){i.template='
',a.forEach(["locale","format","minView","maxView","startView","autoclose","today","keyboard","leftArrow","rightArrow"],function(b){a.isDefined(i[b])||(i[b]=f[b]),a.isDefined(k[b])||(k[b]=i[b])}),i.momentToDate=function(a){return i.isValidMoment(a)?a.clone().toDate():void 0},i.valueUpdate=function(){i.disabled||(i.value=i.momentToDate(i.valueMoment))},i.isValidMoment=function(b){return a.isDefined(b)&&b.isValid()},i.limits={isAfterOrEqualMin:function(b,c){return!a.isDefined(i.minDateMoment)||b.isAfter(i.minDateMoment,c)||b.isSame(i.minDateMoment,c)},isBeforeOrEqualMax:function(b,c){return!a.isDefined(i.maxDateMoment)||b.isBefore(i.maxDateMoment,c)||b.isSame(i.maxDateMoment,c)},isSelectable:function(a,b){return i.limits.isAfterOrEqualMin(a,b)&&i.limits.isBeforeOrEqualMax(a,b)},checkValue:function(){a.isDefined(i.valueMoment)&&(i.limits.isAfterOrEqualMin(i.valueMoment)||i.valueUpdate(i.valueMoment=i.minDateMoment.clone()),i.limits.isBeforeOrEqualMax(i.valueMoment)||i.valueUpdate(i.valueMoment=i.maxDateMoment.clone()))},checkView:function(){a.isDefined(i.view.moment)||(i.view.moment=moment().locale(i.locale)),i.limits.isAfterOrEqualMin(i.view.moment)||(i.view.moment=i.minDateMoment.clone()),i.limits.isBeforeOrEqualMax(i.view.moment)||(i.view.moment=i.maxDateMoment.clone()),i.view.update()}},i.views={all:["decade","year","month","day","hour","minute"],formats:{decade:"Y{1,2}(?!Y)|YYYY|[Ll]{1,4}(?!T)",year:"M{1,4}(?![Mo])|Mo|Q",month:"[Dd]{1,4}(?![Ddo])|DDDo|[Dd]o|[Ww]{1,2}(?![Wwo])|[Ww]o|[Ee]|L{1,2}(?!T)|l{1,2}",day:"[Hh]{1,2}|LTS?",hour:"m{1,2}|[Ll]{3,4}|LT(?!S)",minute:"s{1,2}|S{1,}|X|LTS"},detectMinMax:function(){var b,c;a.forEach(i.views.formats,function(d,e){var f=new RegExp("("+d+")(?![^[]*])","g");i.format.match(f)&&(a.isDefined(b)||(b=e),c=e)}),b=a.isDefined(b)?Math.max(0,i.views.all.indexOf(b)):0,c=a.isDefined(c)?Math.min(i.views.all.length-1,i.views.all.indexOf(c)):i.views.all.length-1,b>i.views.all.indexOf(i.minView)&&(i.minView=i.views.all[b]),c0&&c>g/2&&i.picker.addClass("top"),d+a.offsetWidth>f&&i.picker.addClass("left")},keydown:function(a){var b=i.view.selected+"View",c={decade:"year",year:"month",month:"day",day:"hour",hour:"minute",minute:"second"}[i.view.selected],d=f[c+"sStep"]||1,e=[g.up,g.left].indexOf(a.keyCode)>=0?"subtract":"add";switch(a.keyCode){case g.up:case g.down:a.preventDefault(),i.view.isOpen?(i.view.update(i.view.moment[e](d*i[b].perLine,c)),i.view.render()):i.view.open();break;case g.left:case g.right:if(!i.view.isOpen)break;i.view.update(i.view.moment[e](d,c)),i.view.render(),a.preventDefault();break;case g.enter:if(!i.view.isOpen)break;i.view.change(c),a.preventDefault();break;case g.escape:i.view.toggle()}},unit:function(){return"decade"==i.view.selected?10:1},precision:function(){return i.view.selected.replace("decade","year")},title:"",previous:{label:c.trustAsHtml(i.leftArrow),selectable:!0,set:function(){i.view.previous.selectable&&i.view.update(i.view.moment.subtract(i.view.unit(),i.view.precision()).toDate())}},next:{selectable:!0,label:c.trustAsHtml(i.rightArrow),set:function(){i.view.next.selectable&&i.view.update(i.view.moment.add(i.view.unit(),i.view.precision()).toDate())}},setParentView:function(){i.view.change(i.views.all[Math.max(0,i.views.all.indexOf(i.view.selected)-1)])},render:function(){var a=i.view.moment.clone().startOf(i.view.precision()).subtract(i.view.unit(),i.view.precision()),b=i.view.moment.clone().endOf(i.view.precision()).add(i.view.unit(),i.view.precision());i.view.previous.selectable=i.limits.isAfterOrEqualMin(a,i.view.precision()),i.view.previous.label=c.trustAsHtml(i.view.previous.selectable?i.leftArrow:" "),i.view.next.selectable=i.limits.isBeforeOrEqualMax(b,i.view.precision()),i.view.next.label=c.trustAsHtml(i.view.next.selectable?i.rightArrow:" "),i.view.title=i[i.view.selected+"View"].render()},change:function(a){var c=i.views.all.indexOf(a),d=i.views.all.indexOf(i.minView),e=i.views.all.indexOf(i.maxView);0>c||c>e?(i.valueUpdate(i.valueMoment=i.view.moment.clone()),i.autoclose&&b(i.view.close)):c>=d&&(i.view.selected=a)}},i.decadeView={perLine:4,fourYears:{},render:function(){var a=i.view.moment.clone(),b=10*Math.floor(a.year()/10)-1;a.year(b),i.decadeView.fourYears={};for(var c=0;12>c;c++){var d=Math.floor(c/4),e=i.limits.isSelectable(a,"year");i.decadeView.fourYears[d]||(i.decadeView.fourYears[d]=[]),i.decadeView.fourYears[d].push({label:a.format(f.yearsFormat),year:a.year(),"class":[i.keyboard&&a.isSame(i.view.moment,"year")?"highlighted":"",!e||[0,11].indexOf(c)>=0?"disabled":i.isValidMoment(i.valueMoment)&&a.isSame(i.valueMoment,"year")?"selected":""].join(" ").trim(),selectable:e}),a.add(1,"years")}return[a.subtract(2,"years").format("YYYY"),a.subtract(9,"years").format("YYYY")].reverse().join(" - ")},setYear:function(a){a.selectable&&(i.view.update(i.view.moment.year(a.year)),i.view.change("year"))}},i.yearView={perLine:4,fourMonths:{},render:function(){var a=i.view.moment.clone().startOf("year"),b=moment.monthsShort();return i.yearView.fourMonths={},b.forEach(function(b,c){var d=Math.floor(c/4),e=i.limits.isSelectable(a,"month");i.yearView.fourMonths[d]||(i.yearView.fourMonths[d]=[]),i.yearView.fourMonths[d].push({label:a.format(f.monthsFormat),year:a.year(),month:a.month(),"class":[i.keyboard&&a.isSame(i.view.moment,"month")?"highlighted":"",e?i.isValidMoment(i.valueMoment)&&a.isSame(i.valueMoment,"month")?"selected":"":"disabled"].join(" ").trim(),selectable:e}),a.add(1,"months")}),i.view.moment.format("YYYY")},setMonth:function(a){a.selectable&&(i.view.update(i.view.moment.year(a.year).month(a.month)),i.view.change("month"))}},i.monthView={perLine:7,days:function(){for(var a=[],b=moment().locale(i.locale).startOf("week"),c=b.clone().endOf("week");!b.isSame(c,"day");)a.push(b.format("dd")),b.add(1,"days");return a}(),weeks:[],render:function(){var b=i.view.moment.month(),c=i.view.moment.clone().startOf("month").startOf("week"),d={},e=c.week(),g=e+5;i.monthView.weeks=[];for(var h=e;g>=h;h++)d[h]=Array.apply(null,Array(i.monthView.perLine)).map(function(){var a=i.limits.isSelectable(c,"day"),d={label:c.format(f.daysFormat),year:c.year(),date:c.date(),month:c.month(),"class":[i.keyboard&&c.isSame(i.view.moment,"day")?"highlighted":"",i.today&&c.isSame(new Date,"day")?"today":"",a&&c.month()==b?i.isValidMoment(i.valueMoment)&&c.isSame(i.valueMoment,"day")?"selected":"":"disabled"].join(" ").trim(),selectable:a};return c.add(1,"days"),d});return a.forEach(d,function(a){i.monthView.weeks.push(a)}),i.view.moment.format("MMMM YYYY")},setDay:function(a){a.selectable&&(i.view.update(i.view.moment.year(a.year).month(a.month).date(a.date)),i.view.change("day"))}},i.dayView={perLine:4,threeHours:[],render:function(){var a=i.view.moment.clone().startOf("day");i.dayView.threeHours=[];for(var b=0;24>b;b++){var c=Math.floor(b/i.dayView.perLine),d=i.limits.isSelectable(a,"hour");i.dayView.threeHours[c]||(i.dayView.threeHours[c]=[]),i.dayView.threeHours[c].push({label:a.format(f.hoursFormat),year:a.year(),month:a.month(),date:a.date(),hour:a.hour(),"class":[i.keyboard&&a.isSame(i.view.moment,"hour")?"highlighted":"",d?i.isValidMoment(i.valueMoment)&&a.isSame(i.valueMoment,"hour")?"selected":"":"disabled"].join(" ").trim(),selectable:d}),a.add(1,"hours")}return i.view.moment.format("LL")},setHour:function(a){a.selectable&&(i.view.update(i.view.moment.year(a.year).month(a.month).date(a.date).hour(a.hour)),i.view.change("hour"))}},i.hourView={perLine:4,minutes:[],render:function(){var a=0,b=i.view.moment.clone().startOf("hour"),c=f.minutesFormat||moment.localeData(i.locale).longDateFormat("LT").replace(/[aA]/,"");i.hourView.minutes=[];for(var d=0;60>d;d+=f.minutesStep){var e=Math.floor(a/i.hourView.perLine),g=i.limits.isSelectable(b,"minute");i.hourView.minutes[e]||(i.hourView.minutes[e]=[]),i.hourView.minutes[e].push({label:b.format(c),year:b.year(),month:b.month(),date:b.date(),hour:b.hour(),minute:b.minute(),"class":[i.keyboard&&b.isSame(i.view.moment,"minute")?"highlighted":"",g?i.isValidMoment(i.valueMoment)&&b.isSame(i.valueMoment,"minute")?"selected":"":"disabled"].join(" ").trim(),selectable:g}),a++,b.add(f.minutesStep,"minutes")}return i.keyboard&&i.hourView.highlightClosest(),i.view.moment.clone().startOf("hour").format("lll")},setMinute:function(a){a.selectable&&(i.view.update(i.view.moment.year(a.year).month(a.month).date(a.date).hour(a.hour).minute(a.minute)),i.view.change("minute"))},highlightClosest:function(){var b,c=[];a.forEach(i.hourView.minutes,function(b){a.forEach(b,function(a){Math.abs(a.minute-i.view.moment.minute())Math.abs(b.minute-i.view.moment.minute())})[0],b.minute-i.view.moment.minute()!=0&&(i.view.update(i.view.moment.year(b.year).month(b.month).date(b.date).hour(b.hour).minute(b.minute)),b.selectable&&(b["class"]=(b["class"]+" highlighted").trim()))}},i.minuteView={perLine:6,seconds:[],render:function(){var a=0,b=i.view.moment.clone().startOf("minute");i.minuteView.seconds=[];for(var c=0;60>c;c+=f.secondsStep){var d=Math.floor(a/i.minuteView.perLine),e=i.limits.isSelectable(b,"second");i.minuteView.seconds[d]||(i.minuteView.seconds[d]=[]),i.minuteView.seconds[d].push({label:b.format(f.secondsFormat),year:b.year(),month:b.month(),date:b.date(),hour:b.hour(),minute:b.minute(),second:b.second(),"class":[i.keyboard&&b.isSame(i.view.moment,"second")?"highlighted":"",e?i.isValidMoment(i.valueMoment)&&b.isSame(i.valueMoment,"second")?"selected":"":"disabled"].join(" ").trim(),selectable:e}),a++,b.add(f.secondsStep,"seconds")}return i.keyboard&&i.minuteView.highlightClosest(),i.view.moment.clone().startOf("minute").format("lll")},setSecond:function(a){a.selectable&&(i.view.update(i.view.moment.year(a.year).month(a.month).date(a.date).hour(a.hour).minute(a.minute).second(a.second)),i.view.change("second"))},highlightClosest:function(){var b,c=[];a.forEach(i.minuteView.seconds,function(b){a.forEach(b,function(a){Math.abs(a.second-i.view.moment.second())Math.abs(b.second-i.view.moment.second())})[0],b.second-i.view.moment.second()!=0&&(i.view.update(i.view.moment.year(b.year).month(b.month).date(b.date).hour(b.hour).minute(b.minute).second(b.second)),b.selectable&&(b["class"]=(b["class"]+" highlighted").trim()))}},i.picker=a.element(''),j.after(i.picker),i.contents=j.addClass("moment-picker-contents").removeAttr("moment-picker"),i.container=d(i.template)(i),i.picker.append(i.contents),i.picker.append(i.container),i.input="input"!=i.contents[0].tagName.toLowerCase()&&i.contents[0].querySelectorAll("input").length>0?a.element(i.contents[0].querySelectorAll("input")):a.element(i.contents[0]),i.input.attr("tabindex",0),i.views.detectMinMax(),i.limits.checkView(),i.$watch("model",function(b){a.isDefined(b)&&(i.valueMoment=moment(b,i.format,i.locale),i.valueMoment.isValid()?(i.view.moment=i.valueMoment.clone(),i.view.update()):i.valueMoment=void 0),i.valueUpdate(i.valueMoment),i.limits.checkValue()}),i.$watch("value",function(){if(a.isDefined(i.valueMoment)){var c=i.model,d=i.valueMoment.format(i.format);d!=c&&b(function(){i.view.update(i.view.moment=i.valueMoment.clone()),i.model=d,a.isFunction(i.change)&&b(function(){i.change({newValue:d,oldValue:c})},0,!1)})}}),i.$watch("[view.selected, view.value]",i.view.render,!0),i.$watch("[minView, maxView]",function(){i.views.detectMinMax(),i.startView=i.views.all[Math.max(Math.min(i.views.all.indexOf(i.startView),i.views.all.indexOf(i.maxView)),i.views.all.indexOf(i.minView))],i.view.selected=i.startView}),i.$watch("[minDate, maxDate]",function(){a.forEach(["minDate","maxDate"],function(b){a.isDefined(i[b])&&(i[b+"Moment"]=moment(i[b],i.format,i.locale),i[b+"Moment"].isValid()||(i[b+"Moment"]=void 0))}),i.limits.checkValue(),i.limits.checkView(),i.view.render()},!0),i.$watch("locale",function(b,c){a.isDefined(c)&&b!=c&&(a.forEach(["model","minDate","maxDate"],function(d){a.isDefined(i[d])&&(i[d]=moment(i[d],i.format,c).locale(b).format(i.format))}),i.view.render())}),i.input.on("focus",function(){i.view.isOpen||i.$apply(i.view.open)}).on("blur",function(){b(function(){i.view.isOpen&&document.activeElement!==i.input[0]&&i.view.close()},10)}).on("keydown",function(a){i.keyboard&&i.$apply(function(){i.view.keydown(a)})}),i.container.on("click",function(){i.input[0].focus()}),a.element(e).on("resize scroll",i.view.position)},i}();a.module("moment-picker",[]).provider("momentPicker",[function(){return new h}]).directive("momentPicker",["$timeout","$sce","$compile","$window","momentPicker",function(a,b,c,d,e){return new i(a,b,c,d,e)}])}(window.angular); \ No newline at end of file diff --git a/package.json b/package.json index 4250149..2165a62 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-moment-picker", - "version": "0.5.7", + "version": "0.6.0", "description": "Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js", "main": "dist/angular-moment-picker.js", "repository": {