diff --git a/bower.json b/bower.json index 0b26d6f..736f54c 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "angular-moment-picker", - "version": "0.9.4", + "version": "0.9.5", "authors": [ "Indri Muska " ], diff --git a/dist/angular-moment-picker.css b/dist/angular-moment-picker.css index 7c0ebd5..1930eec 100644 --- a/dist/angular-moment-picker.css +++ b/dist/angular-moment-picker.css @@ -1,4 +1,4 @@ -/*! Angular Moment Picker - v0.9.4 - http://indrimuska.github.io/angular-moment-picker - (c) 2015 Indri Muska - MIT */ +/*! Angular Moment Picker - v0.9.5 - http://indrimuska.github.io/angular-moment-picker - (c) 2015 Indri Muska - MIT */ .moment-picker { position: relative; display: block; diff --git a/dist/angular-moment-picker.js b/dist/angular-moment-picker.js index 7ffff22..1c07afc 100644 --- a/dist/angular-moment-picker.js +++ b/dist/angular-moment-picker.js @@ -1,4 +1,4 @@ -/*! Angular Moment Picker - v0.9.4 - http://indrimuska.github.io/angular-moment-picker - (c) 2015 Indri Muska - MIT */ +/*! Angular Moment Picker - v0.9.5 - http://indrimuska.github.io/angular-moment-picker - (c) 2015 Indri Muska - MIT */ /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; @@ -144,6 +144,7 @@ var template = __webpack_require__(15); var Directive = (function () { function Directive($timeout, $sce, $log, $window, provider) { + var _this = this; this.$timeout = $timeout; this.$sce = $sce; this.$log = $log; @@ -175,337 +176,344 @@ change: '&?', selectable: '&?' }; - this.link = this.linkFn.bind(this); - } - Directive.prototype.linkFn = function ($scope, $element, $attrs, $ctrl, $transclude) { - var _this = this; - $transclude(function ($transElement) { - // one-way binding attributes - angular.forEach([ - 'locale', 'format', 'minView', 'maxView', 'startView', 'validate', 'autoclose', 'today', 'keyboard', 'showHeader', - 'leftArrow', 'rightArrow', 'additions' - ], function (attr) { - if (!angular.isDefined($scope[attr])) - $scope[attr] = _this.provider[attr]; - if (!angular.isDefined($attrs[attr])) - $attrs[attr] = $scope[attr]; - }); - // check if ngModel has been set - if (!$attrs['ngModel']) - $ctrl = {}; // tslint:disable-line:no-any - // limits - $scope.limits = { - minDate: utility_1.toMoment($scope.minDate, $scope.format, $scope.locale), - maxDate: utility_1.toMoment($scope.maxDate, $scope.format, $scope.locale), - isAfterOrEqualMin: function (value, precision) { - return !angular.isDefined($scope.limits.minDate) || value.isAfter($scope.limits.minDate, precision) || value.isSame($scope.limits.minDate, precision); - }, - isBeforeOrEqualMax: function (value, precision) { - return !angular.isDefined($scope.limits.maxDate) || value.isBefore($scope.limits.maxDate, precision) || value.isSame($scope.limits.maxDate, precision); - }, - isSelectable: function (value, precision) { - var selectable = true; - try { - if (angular.isFunction($scope.selectable)) - selectable = $scope.selectable({ date: value, type: precision }); - } - catch (e) { - _this.$log.error(e); + this.link = function ($scope, $element, $attrs, $ctrl, $transclude) { + $transclude(function ($transElement) { + // one-way binding attributes + angular.forEach([ + 'locale', 'format', 'minView', 'maxView', 'startView', 'validate', 'autoclose', 'today', 'keyboard', 'showHeader', + 'leftArrow', 'rightArrow', 'additions' + ], function (attr) { + if (!angular.isDefined($scope[attr])) + $scope[attr] = _this.provider[attr]; + if (!angular.isDefined($attrs[attr])) + $attrs[attr] = $scope[attr]; + }); + // check if ngModel has been set + if (!$attrs['ngModel']) + $ctrl = {}; // tslint:disable-line:no-any + // limits + $scope.limits = { + minDate: utility_1.toMoment($scope.minDate, $scope.format, $scope.locale), + maxDate: utility_1.toMoment($scope.maxDate, $scope.format, $scope.locale), + isAfterOrEqualMin: function (value, precision) { + return !angular.isDefined($scope.limits.minDate) || value.isAfter($scope.limits.minDate, precision) || value.isSame($scope.limits.minDate, precision); + }, + isBeforeOrEqualMax: function (value, precision) { + return !angular.isDefined($scope.limits.maxDate) || value.isBefore($scope.limits.maxDate, precision) || value.isSame($scope.limits.maxDate, precision); + }, + isSelectable: function (value, precision) { + var selectable = true; + try { + if (angular.isFunction($scope.selectable)) + selectable = $scope.selectable({ date: value, type: precision }); + } + catch (e) { + _this.$log.error(e); + } + return $scope.limits.isAfterOrEqualMin(value, precision) && $scope.limits.isBeforeOrEqualMax(value, precision) && selectable; + }, + checkValue: function () { + if (!utility_1.isValidMoment($ctrl.$modelValue) || !$scope.validate) + return; + if (!$scope.limits.isAfterOrEqualMin($ctrl.$modelValue)) + utility_1.setValue($scope.limits.minDate, $scope, $ctrl, $attrs); + if (!$scope.limits.isBeforeOrEqualMax($ctrl.$modelValue)) + utility_1.setValue($scope.limits.maxDate, $scope, $ctrl, $attrs); + }, + checkView: function () { + if (!angular.isDefined($scope.view.moment)) + $scope.view.moment = moment().locale($scope.locale); + if (!$scope.limits.isAfterOrEqualMin($scope.view.moment)) + $scope.view.moment = $scope.limits.minDate.clone(); + if (!$scope.limits.isBeforeOrEqualMax($scope.view.moment)) + $scope.view.moment = $scope.limits.maxDate.clone(); + $scope.view.update(); + $scope.view.render(); } - return $scope.limits.isAfterOrEqualMin(value, precision) && $scope.limits.isBeforeOrEqualMax(value, precision) && selectable; - }, - checkValue: function () { - if (!utility_1.isValidMoment($ctrl.$modelValue) || !$scope.validate) - return; - if (!$scope.limits.isAfterOrEqualMin($ctrl.$modelValue)) - utility_1.setValue($scope.limits.minDate, $scope, $ctrl, $attrs); - if (!$scope.limits.isBeforeOrEqualMax($ctrl.$modelValue)) - utility_1.setValue($scope.limits.maxDate, $scope, $ctrl, $attrs); - }, - checkView: function () { - if (!angular.isDefined($scope.view.moment)) - $scope.view.moment = moment().locale($scope.locale); - if (!$scope.limits.isAfterOrEqualMin($scope.view.moment)) - $scope.view.moment = $scope.limits.minDate.clone(); - if (!$scope.limits.isBeforeOrEqualMax($scope.view.moment)) - $scope.view.moment = $scope.limits.maxDate.clone(); - $scope.view.update(); - } - }; - $scope.views = { - all: ['decade', 'year', 'month', 'day', 'hour', 'minute'], - // for each view, `$scope.views.formats` object contains the available moment formats - // formats present in more views are used to perform min/max view detection (i.e. 'LTS', 'LT', ...) - formats: { - decade: 'Y{1,2}(?!Y)|YYYY|[Ll]{1,4}(?!T)', - /* formats: Y,YY,YYYY,L,LL,LLL,LLLL,l,ll,lll,llll */ - year: 'M{1,4}(?![Mo])|Mo|Q', - /* formats: M,MM,MMM,MMM,Mo,Q */ - month: '[Dd]{1,4}(?![Ddo])|DDDo|[Dd]o|[Ww]{1,2}(?![Wwo])|[Ww]o|[Ee]|L{1,2}(?!T)|l{1,2}', - /* formats: D,DD,DDD,DDDD,d,dd,ddd,dddd,DDDo,Do,do,W,WW,w,ww,Wo,wo,E,e,L,LL,l,ll */ - day: '[Hh]{1,2}|LTS?', - /* formats: H,HH,h,hh,LT,LTS */ - hour: 'm{1,2}|[Ll]{3,4}|LT(?!S)', - /* formats: m,mm,LLL,LLLL,lll,llll,LT */ - minute: 's{1,2}|S{1,}|X|LTS' - }, - detectMinMax: function () { - if (!$scope.format) - return; - var minView, maxView; - angular.forEach($scope.views.formats, function (formats, view) { - var regexp = new RegExp('(' + formats + ')(?![^\[]*\])', 'g'); - if (!$scope.format.match(regexp)) + }; + $scope.views = { + all: ['decade', 'year', 'month', 'day', 'hour', 'minute'], + precisions: { decade: 'year', year: 'month', month: 'date', day: 'hour', hour: 'minute', minute: 'second' }, + // for each view, `$scope.views.formats` object contains the available moment formats + // formats present in more views are used to perform min/max view detection (i.e. 'LTS', 'LT', ...) + formats: { + decade: 'Y{1,2}(?!Y)|YYYY|[Ll]{1,4}(?!T)', + /* formats: Y,YY,YYYY,L,LL,LLL,LLLL,l,ll,lll,llll */ + year: 'M{1,4}(?![Mo])|Mo|Q', + /* formats: M,MM,MMM,MMM,Mo,Q */ + month: '[Dd]{1,4}(?![Ddo])|DDDo|[Dd]o|[Ww]{1,2}(?![Wwo])|[Ww]o|[Ee]|L{1,2}(?!T)|l{1,2}', + /* formats: D,DD,DDD,DDDD,d,dd,ddd,dddd,DDDo,Do,do,W,WW,w,ww,Wo,wo,E,e,L,LL,l,ll */ + day: '[Hh]{1,2}|LTS?', + /* formats: H,HH,h,hh,LT,LTS */ + hour: 'm{1,2}|[Ll]{3,4}|LT(?!S)', + /* formats: m,mm,LLL,LLLL,lll,llll,LT */ + minute: 's{1,2}|S{1,}|X|LTS' + }, + detectMinMax: function () { + if (!$scope.format) return; + var minView, maxView; + angular.forEach($scope.views.formats, function (formats, view) { + var regexp = new RegExp('(' + formats + ')(?![^\[]*\])', 'g'); + if (!$scope.format.match(regexp)) + return; + if (!angular.isDefined(minView)) + minView = view; + maxView = view; + }); if (!angular.isDefined(minView)) - minView = view; - maxView = view; - }); - if (!angular.isDefined(minView)) - minView = 0; - else - minView = Math.max(0, $scope.views.all.indexOf(minView)); - if (!angular.isDefined(maxView)) - maxView = $scope.views.all.length - 1; - else - maxView = Math.min($scope.views.all.length - 1, $scope.views.all.indexOf(maxView)); - if (minView > $scope.views.all.indexOf($scope.minView)) - $scope.minView = $scope.views.all[minView]; - if (maxView < $scope.views.all.indexOf($scope.maxView)) - $scope.maxView = $scope.views.all[maxView]; - }, - // specific views - decade: new views_1.DecadeView($scope, $ctrl, _this.provider), - year: new views_1.YearView($scope, $ctrl, _this.provider), - month: new views_1.MonthView($scope, $ctrl, _this.provider), - day: new views_1.DayView($scope, $ctrl, _this.provider), - hour: new views_1.HourView($scope, $ctrl, _this.provider), - minute: new views_1.MinuteView($scope, $ctrl, _this.provider) - }; - $scope.view = { - moment: undefined, - value: undefined, - isOpen: false, - selected: $scope.startView, - update: function () { $scope.view.value = utility_1.momentToValue($scope.view.moment, $scope.format); }, - toggle: function () { $scope.view.isOpen ? $scope.view.close() : $scope.view.open(); }, - open: function () { - if ($scope.disabled || $scope.view.isOpen) - return; - $scope.isOpen = true; - $scope.view.isOpen = true; - _this.$timeout($scope.view.position, 0, false); - }, - close: function () { - if (!$scope.view.isOpen) - return; - $scope.isOpen = false; - $scope.view.isOpen = false; - $scope.view.selected = $scope.startView; - }, - position: function () { - if (!$scope.view.isOpen) - return; - $scope.picker.removeClass('top').removeClass('left'); - var container = $scope.container[0], offset = helpers_1.getOffset(container), top = offset.top - _this.$window.pageYOffset, left = offset.left - _this.$window.pageXOffset, winWidth = _this.$window.innerWidth, winHeight = _this.$window.innerHeight; - if (top + _this.$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.views[$scope.view.selected], precision = { decade: 'year', year: 'month', month: 'day', day: 'hour', hour: 'minute', minute: 'second' }[$scope.view.selected], singleUnit = _this.provider[precision + 'sStep'] || 1, operation = [utility_1.KEYS.up, utility_1.KEYS.left].indexOf(e.keyCode) >= 0 ? 'subtract' : 'add', highlight = function (vertical) { - var unitMultiplier = vertical ? view.perLine : 1, nextDate = $scope.view.moment.clone()[operation](singleUnit * unitMultiplier, precision); - if ($scope.limits.isSelectable(nextDate, precision)) { - $scope.view.moment = nextDate; - $scope.view.update(); - $scope.view.render(); - } - }; - switch (e.keyCode) { - case utility_1.KEYS.up: - case utility_1.KEYS.down: - e.preventDefault(); - if (!$scope.view.isOpen) - $scope.view.open(); - else - highlight(true); - break; - case utility_1.KEYS.left: - case utility_1.KEYS.right: - if (!$scope.view.isOpen) + minView = 0; + else + minView = Math.max(0, $scope.views.all.indexOf(minView)); + if (!angular.isDefined(maxView)) + maxView = $scope.views.all.length - 1; + else + maxView = Math.min($scope.views.all.length - 1, $scope.views.all.indexOf(maxView)); + if (minView > $scope.views.all.indexOf($scope.minView)) + $scope.minView = $scope.views.all[minView]; + if (maxView < $scope.views.all.indexOf($scope.maxView)) + $scope.maxView = $scope.views.all[maxView]; + }, + // specific views + decade: new views_1.DecadeView($scope, $ctrl, _this.provider), + year: new views_1.YearView($scope, $ctrl, _this.provider), + month: new views_1.MonthView($scope, $ctrl, _this.provider), + day: new views_1.DayView($scope, $ctrl, _this.provider), + hour: new views_1.HourView($scope, $ctrl, _this.provider), + minute: new views_1.MinuteView($scope, $ctrl, _this.provider) + }; + $scope.view = { + moment: undefined, + value: undefined, + isOpen: false, + selected: $scope.startView, + update: function () { $scope.view.value = utility_1.momentToValue($scope.view.moment, $scope.format); }, + toggle: function () { $scope.view.isOpen ? $scope.view.close() : $scope.view.open(); }, + open: function () { + if ($scope.disabled || $scope.view.isOpen) + return; + $scope.isOpen = true; + $scope.view.isOpen = true; + _this.$timeout($scope.view.position, 0, false); + }, + close: function () { + if (!$scope.view.isOpen) + return; + $scope.isOpen = false; + $scope.view.isOpen = false; + $scope.view.selected = $scope.startView; + }, + position: function () { + if (!$scope.view.isOpen) + return; + $scope.picker.removeClass('top').removeClass('left'); + var container = $scope.container[0], offset = helpers_1.getOffset(container), top = offset.top - _this.$window.pageYOffset, left = offset.left - _this.$window.pageXOffset, winWidth = _this.$window.innerWidth, winHeight = _this.$window.innerHeight; + if (top + _this.$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.views[$scope.view.selected], precision = $scope.views.precisions[$scope.view.selected].replace('date', 'day'), singleUnit = _this.provider[precision + 'sStep'] || 1, operation = [utility_1.KEYS.up, utility_1.KEYS.left].indexOf(e.keyCode) >= 0 ? 'subtract' : 'add', highlight = function (vertical) { + var unitMultiplier = vertical ? view.perLine : 1, nextDate = $scope.view.moment.clone()[operation](singleUnit * unitMultiplier, precision); + if ($scope.limits.isSelectable(nextDate, precision)) { + $scope.view.moment = nextDate; + $scope.view.update(); + $scope.view.render(); + } + }; + switch (e.keyCode) { + case utility_1.KEYS.up: + case utility_1.KEYS.down: + e.preventDefault(); + if (!$scope.view.isOpen) + $scope.view.open(); + else + highlight(true); break; - e.preventDefault(); - highlight(); - break; - case utility_1.KEYS.enter: - if (!$scope.view.isOpen) + case utility_1.KEYS.left: + case utility_1.KEYS.right: + if (!$scope.view.isOpen) + break; + e.preventDefault(); + highlight(); + break; + case utility_1.KEYS.enter: + if (!$scope.view.isOpen) + break; + $scope.view.change(precision); + e.preventDefault(); + break; + case utility_1.KEYS.escape: + $scope.view.toggle(); break; - $scope.view.change(precision); - e.preventDefault(); - break; - case utility_1.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'); }, - // header - title: '', - previous: { - label: _this.$sce.trustAsHtml($scope.leftArrow), - selectable: true, - set: function () { - if ($scope.view.previous.selectable) { - $scope.view.moment.subtract($scope.view.unit(), $scope.view.precision()); - $scope.view.update(); } - } - }, - next: { - selectable: true, - label: _this.$sce.trustAsHtml($scope.rightArrow), - set: function () { - if ($scope.view.next.selectable) { - $scope.view.moment.add($scope.view.unit(), $scope.view.precision()); + }, + // utility + unit: function () { return $scope.view.selected == 'decade' ? 10 : 1; }, + precision: function () { return $scope.view.selected.replace('decade', 'year'); }, + // header + title: '', + previous: { + label: _this.$sce.trustAsHtml($scope.leftArrow), + selectable: true, + set: function () { + if ($scope.view.previous.selectable) { + $scope.view.moment.subtract($scope.view.unit(), $scope.view.precision()); + $scope.view.update(); + $scope.view.render(); + } + } + }, + next: { + selectable: true, + label: _this.$sce.trustAsHtml($scope.rightArrow), + set: function () { + if ($scope.view.next.selectable) { + $scope.view.moment.add($scope.view.unit(), $scope.view.precision()); + $scope.view.update(); + $scope.view.render(); + } + } + }, + setParentView: function () { $scope.view.change($scope.views.all[Math.max(0, $scope.views.all.indexOf($scope.view.selected) - 1)]); }, + // body + render: function () { + var momentPrevious = $scope.view.moment.clone().startOf($scope.view.precision()).subtract($scope.view.unit(), $scope.view.precision()), momentNext = $scope.view.moment.clone().endOf($scope.view.precision()).add($scope.view.unit(), $scope.view.precision()); + $scope.view.previous.selectable = $scope.limits.isAfterOrEqualMin(momentPrevious, $scope.view.precision()); + $scope.view.previous.label = _this.$sce.trustAsHtml($scope.view.previous.selectable ? $scope.leftArrow : ' '); + $scope.view.next.selectable = $scope.limits.isBeforeOrEqualMax(momentNext, $scope.view.precision()); + $scope.view.next.label = _this.$sce.trustAsHtml($scope.view.next.selectable ? $scope.rightArrow : ' '); + $scope.view.title = $scope.views[$scope.view.selected].render(); + }, + change: function (view) { + var nextView = $scope.views.all.indexOf(view), minView = $scope.views.all.indexOf($scope.minView), maxView = $scope.views.all.indexOf($scope.maxView); + if (nextView < 0 || nextView > maxView) { + utility_1.setValue($scope.view.moment, $scope, $ctrl, $attrs); $scope.view.update(); + if ($scope.autoclose) + _this.$timeout($scope.view.close); } + else if (nextView >= minView) + $scope.view.selected = view; } - }, - setParentView: function () { $scope.view.change($scope.views.all[Math.max(0, $scope.views.all.indexOf($scope.view.selected) - 1)]); }, - // body - render: function () { - var momentPrevious = $scope.view.moment.clone().startOf($scope.view.precision()).subtract($scope.view.unit(), $scope.view.precision()), momentNext = $scope.view.moment.clone().endOf($scope.view.precision()).add($scope.view.unit(), $scope.view.precision()); - $scope.view.previous.selectable = $scope.limits.isAfterOrEqualMin(momentPrevious, $scope.view.precision()); - $scope.view.previous.label = _this.$sce.trustAsHtml($scope.view.previous.selectable ? $scope.leftArrow : ' '); - $scope.view.next.selectable = $scope.limits.isBeforeOrEqualMax(momentNext, $scope.view.precision()); - $scope.view.next.label = _this.$sce.trustAsHtml($scope.view.next.selectable ? $scope.rightArrow : ' '); - $scope.view.title = $scope.views[$scope.view.selected].render(); - }, - change: function (view) { - var nextView = $scope.views.all.indexOf(view), minView = $scope.views.all.indexOf($scope.minView), maxView = $scope.views.all.indexOf($scope.maxView); - if (nextView < 0 || nextView > maxView) { - utility_1.setValue($scope.view.moment, $scope, $ctrl, $attrs); - if ($scope.autoclose) - _this.$timeout($scope.view.close); - } - else if (nextView >= minView) - $scope.view.selected = view; + }; + // creation + $scope.picker = angular.element($element[0].querySelectorAll('.moment-picker')); + $element.after($scope.picker); + $scope.contents = angular.element($scope.picker[0].querySelectorAll('.moment-picker-contents')); + $scope.container = angular.element($scope.picker[0].querySelectorAll('.moment-picker-container')); + $scope.contents.append($element.append($transElement)); + $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.addClass('moment-picker-input').attr('tabindex', 0); + // initialization + $scope.views.detectMinMax(); + $scope.limits.checkView(); + // model controller is initialized after linking function + _this.$timeout(function () { + if ($attrs['ngModel']) + $ctrl.$commitViewValue(); + // view initialization + if ($scope.startDate) + $scope.view.moment = utility_1.toMoment($scope.startDate, $scope.format, $scope.locale); + else if (utility_1.isValidMoment($ctrl.$modelValue)) + $scope.view.moment = $ctrl.$modelValue.clone(); + $scope.view.update(); + $scope.view.render(); + }); + // model <-> view conversion + if ($attrs['ngModel']) { + $ctrl.$parsers.push(function (viewValue) { return utility_1.updateMoment($ctrl.$modelValue, utility_1.valueToMoment(viewValue, $scope), $scope) || true; }); + $ctrl.$formatters.push(function (modelValue) { return utility_1.momentToValue(modelValue, $scope.format) || ''; }); + $ctrl.$viewChangeListeners.push(function () { if ($attrs['ngModel'] != $attrs['momentPicker']) + $scope.value = $ctrl.$viewValue; }); + $ctrl.$validators.minDate = function (value) { return $scope.validate || !utility_1.isValidMoment(value) || $scope.limits.isAfterOrEqualMin(value); }; + $ctrl.$validators.maxDate = function (value) { return $scope.validate || !utility_1.isValidMoment(value) || $scope.limits.isBeforeOrEqualMax(value); }; } - }; - // creation - $scope.picker = angular.element($element[0].querySelectorAll('.moment-picker')); - $element.after($scope.picker); - $scope.contents = angular.element($scope.picker[0].querySelectorAll('.moment-picker-contents')); - $scope.container = angular.element($scope.picker[0].querySelectorAll('.moment-picker-container')); - $scope.contents.append($element.append($transElement)); - $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.addClass('moment-picker-input').attr('tabindex', 0); - // initialization - $scope.views.detectMinMax(); - $scope.limits.checkView(); - // model controller is initialized after linking function - _this.$timeout(function () { - if ($attrs['ngModel']) - $ctrl.$commitViewValue(); - // view initialization - if ($scope.startDate) - $scope.view.moment = utility_1.toMoment($scope.startDate, $scope.format, $scope.locale); - else if (utility_1.isValidMoment($ctrl.$modelValue)) - $scope.view.moment = $ctrl.$modelValue.clone(); - $scope.view.update(); - }); - // model <-> view conversion - if ($attrs['ngModel']) { - $ctrl.$parsers.push(function (viewValue) { return ($scope.model = utility_1.valueToMoment(viewValue, $scope.format, $scope.locale)) || true; }); - $ctrl.$formatters.push(function (modelValue) { - var viewValue = utility_1.momentToValue(modelValue, $scope.format); - if ($attrs['ngModel'] != $attrs['momentPicker']) - $scope.value = viewValue; - return viewValue || ''; + // properties listeners + if ($attrs['ngModel'] != $attrs['momentPicker']) + $scope.$watch('value', function (newValue, oldValue) { + if (newValue !== oldValue) + utility_1.setValue(newValue, $scope, $ctrl, $attrs); + }); + $scope.$watch(function () { return utility_1.momentToValue($ctrl.$modelValue, $scope.format); }, function (newViewValue, oldViewValue) { + if (newViewValue == oldViewValue) + return; + var newModelValue = utility_1.valueToMoment(newViewValue, $scope); + utility_1.setValue(newModelValue, $scope, $ctrl, $attrs); + $scope.limits.checkValue(); + $scope.view.moment = (newModelValue || moment().locale($scope.locale)).clone(); + $scope.view.update(); + $scope.view.render(); + if (angular.isFunction($scope.change)) { + var oldModelValue_1 = utility_1.valueToMoment(oldViewValue, $scope); + _this.$timeout(function () { return $scope.change({ newValue: newModelValue, oldValue: oldModelValue_1 }); }, 0, false); + } }); - $ctrl.$viewChangeListeners.push(function () { if ($attrs['ngModel'] != $attrs['momentPicker']) - $scope.value = $ctrl.$viewValue; }); - $ctrl.$validators.minDate = function (value) { return $scope.validate || !utility_1.isValidMoment(value) || $scope.limits.isAfterOrEqualMin(value); }; - $ctrl.$validators.maxDate = function (value) { return $scope.validate || !utility_1.isValidMoment(value) || $scope.limits.isBeforeOrEqualMax(value); }; - } - // properties listeners - if ($attrs['ngModel'] != $attrs['momentPicker']) - $scope.$watch('value', function (newValue, oldValue) { - if (newValue !== oldValue) - utility_1.setValue(newValue, $scope, $ctrl, $attrs); + $scope.$watch(function () { return $ctrl.$modelValue && $ctrl.$modelValue.valueOf(); }, function () { + var viewMoment = ($ctrl.$modelValue || moment().locale($scope.locale)).clone(); + if (!viewMoment.isSame($scope.view.moment)) { + $scope.view.moment = viewMoment; + $scope.view.update(); + $scope.view.render(); + } }); - $scope.$watch(function () { return utility_1.momentToValue($ctrl.$modelValue, $scope.format); }, function (newViewValue, oldViewValue) { - if (newViewValue == oldViewValue) - return; - var newModelValue = utility_1.valueToMoment(newViewValue, $scope.format, $scope.locale); - utility_1.setValue(newModelValue, $scope, $ctrl, $attrs); - $scope.limits.checkValue(); - $scope.view.moment = (newModelValue || moment().locale($scope.locale)).clone(); - $scope.view.update(); - $scope.view.render(); - if (angular.isFunction($scope.change)) { - var oldModelValue_1 = utility_1.valueToMoment(oldViewValue, $scope.format, $scope.locale); - _this.$timeout(function () { return $scope.change({ newValue: newModelValue, oldValue: oldModelValue_1 }); }, 0, false); - } - }); - $scope.$watchGroup(['view.selected', 'view.value'], $scope.view.render); - $scope.$watchGroup(['minView', 'maxView'], function () { - // auto-detect minView/maxView - $scope.views.detectMinMax(); - // limit startView - $scope.startView = $scope.views.all[Math.max(Math.min($scope.views.all.indexOf($scope.startView), $scope.views.all.indexOf($scope.maxView)), $scope.views.all.indexOf($scope.minView))]; - $scope.view.selected = $scope.startView; - }); - $scope.$watchGroup([ - function () { return utility_1.toValue($scope.minDate, $scope.format, $scope.locale); }, - function () { return utility_1.toValue($scope.maxDate, $scope.format, $scope.locale); } - ], function () { - angular.forEach(['minDate', 'maxDate'], function (field) { - $scope.limits[field] = utility_1.toMoment($scope[field], $scope.format, $scope.locale); + $scope.$watch('view.selected', function () { return $scope.view.render(); }); + $scope.$watchGroup(['minView', 'maxView'], function () { + // auto-detect minView/maxView + $scope.views.detectMinMax(); + // limit startView + $scope.startView = $scope.views.all[Math.max(Math.min($scope.views.all.indexOf($scope.startView), $scope.views.all.indexOf($scope.maxView)), $scope.views.all.indexOf($scope.minView))]; + $scope.view.selected = $scope.startView; }); - $scope.limits.checkValue(); - $scope.limits.checkView(); - $scope.view.render(); - }); - $attrs.$observe('locale', function (locale) { return $scope.locale = locale; }); - $scope.$watch('locale', function (locale, previous) { - if (!angular.isDefined(previous) || locale == previous) - return; - if (utility_1.isValidMoment($ctrl.$modelValue)) - utility_1.setValue($ctrl.$modelValue.locale(locale), $scope, $ctrl, $attrs); - if (utility_1.isValidMoment($scope.view.moment)) - $scope.view.moment = $scope.view.moment.locale(locale); - if (utility_1.isValidMoment($scope.limits.minDate)) - $scope.limits.minDate = $scope.limits.minDate.locale(locale); - if (utility_1.isValidMoment($scope.limits.maxDate)) - $scope.limits.maxDate = $scope.limits.maxDate.locale(locale); - $scope.view.render(); - }); - $scope.$watch('validate', $scope.limits.checkValue); - $scope.$watch('isOpen', function (isOpen) { - if (angular.isDefined(isOpen) && isOpen != $scope.view.isOpen) - $scope.view.toggle(); + $scope.$watchGroup([ + function () { return utility_1.toValue($scope.minDate, $scope.format, $scope.locale); }, + function () { return utility_1.toValue($scope.maxDate, $scope.format, $scope.locale); } + ], function () { + angular.forEach(['minDate', 'maxDate'], function (field) { + $scope.limits[field] = utility_1.toMoment($scope[field], $scope.format, $scope.locale); + }); + $scope.limits.checkValue(); + $scope.limits.checkView(); + $scope.view.render(); + }); + $attrs.$observe('locale', function (locale) { return $scope.locale = locale; }); + $scope.$watch('locale', function (locale, previous) { + if (!angular.isDefined(previous) || locale == previous) + return; + if (utility_1.isValidMoment($ctrl.$modelValue)) + utility_1.setValue($ctrl.$modelValue.locale(locale), $scope, $ctrl, $attrs); + if (utility_1.isValidMoment($scope.view.moment)) + $scope.view.moment = $scope.view.moment.locale(locale); + if (utility_1.isValidMoment($scope.limits.minDate)) + $scope.limits.minDate = $scope.limits.minDate.locale(locale); + if (utility_1.isValidMoment($scope.limits.maxDate)) + $scope.limits.maxDate = $scope.limits.maxDate.locale(locale); + $scope.view.render(); + }); + $scope.$watch('validate', $scope.limits.checkValue); + $scope.$watch('isOpen', function (isOpen) { + if (angular.isDefined(isOpen) && isOpen != $scope.view.isOpen) + $scope.view.toggle(); + }); + // event listeners + var focusInput = function (e) { + if (e) + e.preventDefault(); + $scope.input[0].focus(); + }; + $scope.input + .on('focus click', function () { return $scope.$evalAsync($scope.view.open); }) + .on('blur', function () { return $scope.$evalAsync($scope.view.close); }) + .on('keydown', function (e) { return $scope.keyboard && $scope.$evalAsync(function () { return $scope.view.keydown(e); }); }); + $scope.contents.on('mousedown', function () { return focusInput(); }); + $scope.container.on('mousedown', function (e) { return focusInput(e); }); + angular.element(_this.$window).on('resize scroll', $scope.view.position); }); - // event listeners - var focusInput = function (e) { - if (e) - e.preventDefault(); - $scope.input[0].focus(); - }; - $scope.input - .on('focus click', function () { return $scope.$evalAsync($scope.view.open); }) - .on('blur', function () { return $scope.$evalAsync($scope.view.close); }) - .on('keydown', function (e) { return $scope.keyboard && $scope.$evalAsync(function () { return $scope.view.keydown(e); }); }); - $scope.contents.on('mousedown', function () { return focusInput(); }); - $scope.container.on('mousedown', function (e) { return focusInput(e); }); - angular.element(_this.$window).on('resize scroll', $scope.view.position); - }); - }; + }; + } return Directive; }()); exports.__esModule = true; @@ -621,6 +629,7 @@ /***/ function(module, exports, __webpack_require__) { "use strict"; + var angular = __webpack_require__(2); var moment = __webpack_require__(5); exports.KEYS = { up: 38, down: 40, left: 37, right: 39, escape: 27, enter: 13 }; exports.isValidMoment = function (value) { @@ -643,24 +652,50 @@ return undefined; return !format ? momentObject.valueOf() : momentObject.format(format); }; - exports.valueToMoment = function (formattedValue, format, locale) { + exports.valueToMoment = function (formattedValue, $scope) { + var momentValue; if (!formattedValue) - return undefined; - if (!format) - return moment(formattedValue); - return moment(formattedValue, format, locale); + return momentValue; + if (!$scope.format) + momentValue = moment(formattedValue); + else + momentValue = moment(formattedValue, $scope.format, $scope.locale); + if ($scope.model) { + // set value for each view precision (from Decade View to minView) + var views = $scope.views.all.slice(0, $scope.views.all.indexOf($scope.minView)); + angular.forEach(views, function (view) { + var precision = $scope.views.precisions[view]; + momentValue[precision]($scope.model[precision]()); + }); + } + return momentValue; }; exports.setValue = function (value, $scope, $ctrl, $attrs) { - var modelValue = exports.isValidMoment(value) ? value.clone() : exports.valueToMoment(value, $scope.format, $scope.locale), viewValue = exports.momentToValue(modelValue, $scope.format); - $scope.model = modelValue; - $ctrl.$modelValue = modelValue; - if (!$attrs['ngModel']) + var modelValue = exports.isValidMoment(value) ? value.clone() : exports.valueToMoment(value, $scope), viewValue = exports.momentToValue(modelValue, $scope.format); + exports.updateMoment($scope.model, modelValue, $scope); + exports.updateMoment($ctrl.$modelValue, modelValue, $scope); + if ($attrs['ngModel'] != $attrs['momentPicker']) $scope.value = viewValue; - else { + if ($attrs['ngModel']) { $ctrl.$setViewValue(viewValue); $ctrl.$render(); // render input value } }; + exports.updateMoment = function (model, value, $scope) { + if (!exports.isValidMoment(model) || !value) + model = value; + else { + if (!model.isSame(value)) { + // set value for each view precision (from Decade View to maxView) + var views = $scope.views.all.slice(0, $scope.views.all.indexOf($scope.maxView) + 1); + angular.forEach(views, function (view) { + var precision = $scope.views.precisions[view]; + model[precision](value[precision]()); + }); + } + } + return model; + }; /***/ }, diff --git a/dist/angular-moment-picker.min.css b/dist/angular-moment-picker.min.css index b007662..091e7e9 100644 --- a/dist/angular-moment-picker.min.css +++ b/dist/angular-moment-picker.min.css @@ -1,2 +1,2 @@ -/*! Angular Moment Picker - v0.9.4 - http://indrimuska.github.io/angular-moment-picker - (c) 2015 Indri Muska - MIT */ +/*! Angular Moment Picker - v0.9.5 - http://indrimuska.github.io/angular-moment-picker - (c) 2015 Indri Muska - MIT */ .moment-picker{position:relative;display:block}.moment-picker .moment-picker-input{cursor:pointer}.moment-picker .moment-picker-container{color:#404040;min-width:15em;background:#fff;padding:4px;border:1px solid #f0f3f4;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;position:absolute;top:100%;margin-top:4px;margin-left:-.5em;-webkit-box-shadow:0 2px 4px rgba(0,0,0,.075);-moz-box-shadow:0 2px 4px rgba(0,0,0,.075);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.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 table{border-collapse:collapse;border-spacing:0;min-width:100%;table-layout:fixed}.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 hsla(0,0%,100%,.9);cursor:pointer;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.moment-picker td:hover,.moment-picker th:hover{background-color:#fafbfb;background-image:-webkit-gradient(linear,left top,left bottom,from(#f0f3f4),to(#fafbfb));background-image:-webkit-linear-gradient(#f0f3f4,#fafbfb);background-image:-moz-linear-gradient(#f0f3f4,#fafbfb);background-image:-o-linear-gradient(#f0f3f4,#fafbfb);background-image:linear-gradient(#f0f3f4,#fafbfb)}.moment-picker td.disabled,.moment-picker td.disabled:hover,.moment-picker th.disabled,.moment-picker th.disabled:hover{color:#abbbc7;background:none;cursor:default}.moment-picker td.today{background:#e4eef5;color:#404040;text-shadow:0 1px 0 hsla(0,0%,100%,.9)}.moment-picker td.selected{color:#fff;text-shadow:0 -1px 0 rgba(0,0,0,.3);border-color:#3ca0dd;background-color:#45b1e8;background-image:-webkit-gradient(linear,left top,left bottom,from(#45b1e8),to(#3097de));background-image:-webkit-linear-gradient(#45b1e8,#3097de);background-image:-moz-linear-gradient(#45b1e8,#3097de);background-image:-o-linear-gradient(#45b1e8,#3097de);background-image:linear-gradient(#45b1e8,#3097de)}.moment-picker td.highlighted{background-image:-webkit-radial-gradient(transparent,rgba(0,0,0,.15));background-image:-moz-radial-gradient(transparent,rgba(0,0,0,.15));background-image:-o-radial-gradient(transparent,rgba(0,0,0,.15));background-image:radial-gradient(transparent,rgba(0,0,0,.15))}.moment-picker .decade-view td,.moment-picker .year-view td{height:3.4em}.moment-picker .month-view .moment-picker-specific-views th{background:none;cursor:default}.moment-picker .month-view td{width:1.42857143em}.moment-picker .day-view td,.moment-picker .hour-view td{height:2.33333333em}.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 5643c48..f6441bd 100644 --- a/dist/angular-moment-picker.min.js +++ b/dist/angular-moment-picker.min.js @@ -1,2 +1,2 @@ -/*! Angular Moment Picker - v0.9.4 - http://indrimuska.github.io/angular-moment-picker - (c) 2015 Indri Muska - MIT */ -!function(e){function t(o){if(i[o])return i[o].exports;var n=i[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var i={};return t.m=e,t.c=i,t.p="",t(0)}([function(e,t,i){i(8),e.exports=i(4)},function(e,t,i){"use strict";var o=i(3);t.KEYS={up:38,down:40,left:37,right:39,escape:27,enter:13},t.isValidMoment=function(e){return o.isMoment(e)&&e.isValid()},t.toValue=function(e,i,o){var n=e;return t.isValidMoment(e)||(n=t.toMoment(e,i,o)),t.momentToValue(n,i)},t.toMoment=function(e,i,n){var s=o(e,i,n);return t.isValidMoment(s)||(s=void 0),s},t.momentToValue=function(e,i){if(t.isValidMoment(e))return i?e.format(i):e.valueOf()},t.valueToMoment=function(e,t,i){if(e)return t?o(e,t,i):o(e)},t.setValue=function(e,i,o,n){var s=t.isValidMoment(e)?e.clone():t.valueToMoment(e,i.format,i.locale),a=t.momentToValue(s,i.format);i.model=s,o.$modelValue=s,n.ngModel?(o.$setViewValue(a),o.$render()):i.value=a}},function(e,t){e.exports=angular},function(e,t){e.exports=moment},function(e,t){},function(e,t){e.exports='
'},function(e,t,i){"use strict";var o=i(2),n=i(3),s=i(7),a=i(13),r=i(1),l=i(5),c=function(){function e(e,t,i,o,n){this.$timeout=e,this.$sce=t,this.$log=i,this.$window=o,this.provider=n,this.restrict="AE",this.require="?ngModel",this.transclude=!0,this.template=l,this.scope={value:"=?momentPicker",model:"=?ngModel",locale:"@?",format:"@?",minView:"@?",maxView:"@?",startView:"@?",minDate:"=?",maxDate:"=?",startDate:"=?",disabled:"=?disable",validate:"=?",autoclose:"=?",isOpen:"=?",today:"=?",keyboard:"=?",showHeader:"=?",additions:"=?",change:"&?",selectable:"&?"},this.link=this.linkFn.bind(this)}return e.prototype.linkFn=function(e,t,i,l,c){var m=this;c(function(c){o.forEach(["locale","format","minView","maxView","startView","validate","autoclose","today","keyboard","showHeader","leftArrow","rightArrow","additions"],function(t){o.isDefined(e[t])||(e[t]=m.provider[t]),o.isDefined(i[t])||(i[t]=e[t])}),i.ngModel||(l={}),e.limits={minDate:r.toMoment(e.minDate,e.format,e.locale),maxDate:r.toMoment(e.maxDate,e.format,e.locale),isAfterOrEqualMin:function(t,i){return!o.isDefined(e.limits.minDate)||t.isAfter(e.limits.minDate,i)||t.isSame(e.limits.minDate,i)},isBeforeOrEqualMax:function(t,i){return!o.isDefined(e.limits.maxDate)||t.isBefore(e.limits.maxDate,i)||t.isSame(e.limits.maxDate,i)},isSelectable:function(t,i){var n=!0;try{o.isFunction(e.selectable)&&(n=e.selectable({date:t,type:i}))}catch(e){m.$log.error(e)}return e.limits.isAfterOrEqualMin(t,i)&&e.limits.isBeforeOrEqualMax(t,i)&&n},checkValue:function(){r.isValidMoment(l.$modelValue)&&e.validate&&(e.limits.isAfterOrEqualMin(l.$modelValue)||r.setValue(e.limits.minDate,e,l,i),e.limits.isBeforeOrEqualMax(l.$modelValue)||r.setValue(e.limits.maxDate,e,l,i))},checkView:function(){o.isDefined(e.view.moment)||(e.view.moment=n().locale(e.locale)),e.limits.isAfterOrEqualMin(e.view.moment)||(e.view.moment=e.limits.minDate.clone()),e.limits.isBeforeOrEqualMax(e.view.moment)||(e.view.moment=e.limits.maxDate.clone()),e.view.update()}},e.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(){if(e.format){var t,i;o.forEach(e.views.formats,function(n,s){var a=new RegExp("("+n+")(?![^[]*])","g");e.format.match(a)&&(o.isDefined(t)||(t=s),i=s)}),t=o.isDefined(t)?Math.max(0,e.views.all.indexOf(t)):0,i=o.isDefined(i)?Math.min(e.views.all.length-1,e.views.all.indexOf(i)):e.views.all.length-1,t>e.views.all.indexOf(e.minView)&&(e.minView=e.views.all[t]),i0&&o>r/2&&e.picker.addClass("top"),n+t.offsetWidth>a&&e.picker.addClass("left")}},keydown:function(t){var i=e.views[e.view.selected],o={decade:"year",year:"month",month:"day",day:"hour",hour:"minute",minute:"second"}[e.view.selected],n=m.provider[o+"sStep"]||1,s=[r.KEYS.up,r.KEYS.left].indexOf(t.keyCode)>=0?"subtract":"add",a=function(t){var a=t?i.perLine:1,r=e.view.moment.clone()[s](n*a,o);e.limits.isSelectable(r,o)&&(e.view.moment=r,e.view.update(),e.view.render())};switch(t.keyCode){case r.KEYS.up:case r.KEYS.down:t.preventDefault(),e.view.isOpen?a(!0):e.view.open();break;case r.KEYS.left:case r.KEYS.right:if(!e.view.isOpen)break;t.preventDefault(),a();break;case r.KEYS.enter:if(!e.view.isOpen)break;e.view.change(o),t.preventDefault();break;case r.KEYS.escape:e.view.toggle()}},unit:function(){return"decade"==e.view.selected?10:1},precision:function(){return e.view.selected.replace("decade","year")},title:"",previous:{label:m.$sce.trustAsHtml(e.leftArrow),selectable:!0,set:function(){e.view.previous.selectable&&(e.view.moment.subtract(e.view.unit(),e.view.precision()),e.view.update())}},next:{selectable:!0,label:m.$sce.trustAsHtml(e.rightArrow),set:function(){e.view.next.selectable&&(e.view.moment.add(e.view.unit(),e.view.precision()),e.view.update())}},setParentView:function(){e.view.change(e.views.all[Math.max(0,e.views.all.indexOf(e.view.selected)-1)])},render:function(){var t=e.view.moment.clone().startOf(e.view.precision()).subtract(e.view.unit(),e.view.precision()),i=e.view.moment.clone().endOf(e.view.precision()).add(e.view.unit(),e.view.precision());e.view.previous.selectable=e.limits.isAfterOrEqualMin(t,e.view.precision()),e.view.previous.label=m.$sce.trustAsHtml(e.view.previous.selectable?e.leftArrow:" "),e.view.next.selectable=e.limits.isBeforeOrEqualMax(i,e.view.precision()),e.view.next.label=m.$sce.trustAsHtml(e.view.next.selectable?e.rightArrow:" "),e.view.title=e.views[e.view.selected].render()},change:function(t){var o=e.views.all.indexOf(t),n=e.views.all.indexOf(e.minView),s=e.views.all.indexOf(e.maxView);o<0||o>s?(r.setValue(e.view.moment,e,l,i),e.autoclose&&m.$timeout(e.view.close)):o>=n&&(e.view.selected=t)}},e.picker=o.element(t[0].querySelectorAll(".moment-picker")),t.after(e.picker),e.contents=o.element(e.picker[0].querySelectorAll(".moment-picker-contents")),e.container=o.element(e.picker[0].querySelectorAll(".moment-picker-container")),e.contents.append(t.append(c)),e.input="input"!=e.contents[0].tagName.toLowerCase()&&e.contents[0].querySelectorAll("input").length>0?o.element(e.contents[0].querySelectorAll("input")):o.element(e.contents[0]),e.input.addClass("moment-picker-input").attr("tabindex",0),e.views.detectMinMax(),e.limits.checkView(),m.$timeout(function(){i.ngModel&&l.$commitViewValue(),e.startDate?e.view.moment=r.toMoment(e.startDate,e.format,e.locale):r.isValidMoment(l.$modelValue)&&(e.view.moment=l.$modelValue.clone()),e.view.update()}),i.ngModel&&(l.$parsers.push(function(t){return(e.model=r.valueToMoment(t,e.format,e.locale))||!0}),l.$formatters.push(function(t){var o=r.momentToValue(t,e.format);return i.ngModel!=i.momentPicker&&(e.value=o),o||""}),l.$viewChangeListeners.push(function(){i.ngModel!=i.momentPicker&&(e.value=l.$viewValue)}),l.$validators.minDate=function(t){return e.validate||!r.isValidMoment(t)||e.limits.isAfterOrEqualMin(t)},l.$validators.maxDate=function(t){return e.validate||!r.isValidMoment(t)||e.limits.isBeforeOrEqualMax(t)}),i.ngModel!=i.momentPicker&&e.$watch("value",function(t,o){t!==o&&r.setValue(t,e,l,i)}),e.$watch(function(){return r.momentToValue(l.$modelValue,e.format)},function(t,s){if(t!=s){var a=r.valueToMoment(t,e.format,e.locale);if(r.setValue(a,e,l,i),e.limits.checkValue(),e.view.moment=(a||n().locale(e.locale)).clone(),e.view.update(),e.view.render(),o.isFunction(e.change)){var c=r.valueToMoment(s,e.format,e.locale);m.$timeout(function(){return e.change({newValue:a,oldValue:c})},0,!1)}}}),e.$watchGroup(["view.selected","view.value"],e.view.render),e.$watchGroup(["minView","maxView"],function(){e.views.detectMinMax(),e.startView=e.views.all[Math.max(Math.min(e.views.all.indexOf(e.startView),e.views.all.indexOf(e.maxView)),e.views.all.indexOf(e.minView))],e.view.selected=e.startView}),e.$watchGroup([function(){return r.toValue(e.minDate,e.format,e.locale)},function(){return r.toValue(e.maxDate,e.format,e.locale)}],function(){o.forEach(["minDate","maxDate"],function(t){e.limits[t]=r.toMoment(e[t],e.format,e.locale)}),e.limits.checkValue(),e.limits.checkView(),e.view.render()}),i.$observe("locale",function(t){return e.locale=t}),e.$watch("locale",function(t,n){o.isDefined(n)&&t!=n&&(r.isValidMoment(l.$modelValue)&&r.setValue(l.$modelValue.locale(t),e,l,i),r.isValidMoment(e.view.moment)&&(e.view.moment=e.view.moment.locale(t)),r.isValidMoment(e.limits.minDate)&&(e.limits.minDate=e.limits.minDate.locale(t)),r.isValidMoment(e.limits.maxDate)&&(e.limits.maxDate=e.limits.maxDate.locale(t)),e.view.render())}),e.$watch("validate",e.limits.checkValue),e.$watch("isOpen",function(t){o.isDefined(t)&&t!=e.view.isOpen&&e.view.toggle()});var d=function(t){t&&t.preventDefault(),e.input[0].focus()};e.input.on("focus click",function(){return e.$evalAsync(e.view.open)}).on("blur",function(){return e.$evalAsync(e.view.close)}).on("keydown",function(t){return e.keyboard&&e.$evalAsync(function(){return e.view.keydown(t)})}),e.contents.on("mousedown",function(){return d()}),e.container.on("mousedown",function(e){return d(e)}),o.element(m.$window).on("resize scroll",e.view.position)})},e}();t.__esModule=!0,t.default=c},function(e,t){"use strict";t.getOffset=function(e){if(e){if(!e.getClientRects().length)return{top:0,left:0};var t=function(e){return null!=e&&e===e.window},i=function(e){return t(e)?e:9===e.nodeType&&e.defaultView},o=e.getBoundingClientRect();if(!o.width&&!o.height)return o;var n=e.ownerDocument,s=i(n),a=n.documentElement;return{top:o.top+s.pageYOffset-a.clientTop,left:o.left+s.pageXOffset-a.clientLeft}}}},function(e,t,i){"use strict";var o=i(2),n=i(9);t.Provider=n.default;var s=i(6);t.Directive=s.default,o.module("moment-picker",[]).provider("momentPicker",[function(){return new n.default}]).directive("momentPicker",["$timeout","$sce","$log","$window","momentPicker",function(e,t,i,o,n){return new s.default(e,t,i,o,n)}])},function(e,t,i){"use strict";var o=i(2),n=function(){function e(){this.settings={locale:"en",format:"L LTS",minView:"decade",maxView:"minute",startView:"year",validate:!0,autoclose:!0,today:!1,keyboard:!1,showHeader:!0,leftArrow:"←",rightArrow:"→",yearsFormat:"YYYY",monthsFormat:"MMM",daysFormat:"D",hoursFormat:"HH:[00]",hoursStart:0,hoursEnd:23,minutesStep:5,minutesStart:0,minutesEnd:59,secondsFormat:"ss",secondsStep:1,secondsStart:0,secondsEnd:59}}return e.prototype.options=function(e){return o.extend(this.settings,e),o.copy(this.settings)},e.prototype.$get=function(){return this.settings},e}();t.__esModule=!0,t.default=n},function(e,t,i){"use strict";var o=i(1),n=function(){function e(e,t,i){this.$scope=e,this.$ctrl=t,this.provider=i,this.perLine=4,this.rows={}}return e.prototype.render=function(){var e=this.$scope.view.moment.clone().startOf("day").hour(this.provider.hoursStart);this.rows={};for(var t=0;t<=this.provider.hoursEnd-this.provider.hoursStart;t++){var i=Math.floor(t/this.perLine),n=this.$scope.limits.isSelectable(e,"hour");this.rows[i]||(this.rows[i]=[]),this.rows[i].push({index:t,label:e.format(this.provider.hoursFormat),year:e.year(),month:e.month(),date:e.date(),hour:e.hour(),class:[this.$scope.keyboard&&e.isSame(this.$scope.view.moment,"hour")?"highlighted":"",n?o.isValidMoment(this.$ctrl.$modelValue)&&e.isSame(this.$ctrl.$modelValue,"hour")?"selected":"":"disabled"].join(" ").trim(),selectable:n}),e.add(1,"hours")}return this.$scope.view.moment.format("LL")},e.prototype.set=function(e){e.selectable&&(this.$scope.view.moment.year(e.year).month(e.month).date(e.date).hour(e.hour),this.$scope.view.update(),this.$scope.view.change("hour"))},e}();t.__esModule=!0,t.default=n},function(e,t,i){"use strict";var o=i(1),n=function(){function e(e,t,i){this.$scope=e,this.$ctrl=t,this.provider=i,this.perLine=4,this.rows={}}return e.prototype.render=function(){var e=this.$scope.view.moment.clone(),t=10*Math.floor(e.year()/10)-1;this.rows={},e.year(t);for(var i=0;i<12;i++){var n=Math.floor(i/this.perLine),s=this.$scope.limits.isSelectable(e,"year");this.rows[n]||(this.rows[n]=[]),this.rows[n].push({index:e.year(),label:e.format(this.provider.yearsFormat),year:e.year(),class:[this.$scope.keyboard&&e.isSame(this.$scope.view.moment,"year")?"highlighted":"",!s||[0,11].indexOf(i)>=0?"disabled":o.isValidMoment(this.$ctrl.$modelValue)&&e.isSame(this.$ctrl.$modelValue,"year")?"selected":""].join(" ").trim(),selectable:s}),e.add(1,"years")}return[e.subtract(2,"years").format("YYYY"),e.subtract(9,"years").format("YYYY")].reverse().join(" - ")},e.prototype.set=function(e){e.selectable&&(this.$scope.view.moment.year(e.year),this.$scope.view.update(),this.$scope.view.change("year"))},e}();t.__esModule=!0,t.default=n},function(e,t,i){"use strict";var o=i(2),n=i(3),s=i(1),a=function(){function e(e,t,i){this.$scope=e,this.$ctrl=t,this.provider=i,this.perLine=4,this.rows={}}return e.prototype.render=function(){var e=0,t=this.$scope.view.moment.clone().startOf("hour").minute(this.provider.minutesStart),i=this.provider.minutesFormat||n.localeData(this.$scope.locale).longDateFormat("LT").replace(/[aA]/,"").trim();this.rows={};for(var o=0;o<=this.provider.minutesEnd-this.provider.minutesStart;o+=this.provider.minutesStep){var a=Math.floor(e/this.perLine),r=this.$scope.limits.isSelectable(t,"minute");this.rows[a]||(this.rows[a]=[]),this.rows[a].push({index:t.minute(),label:t.format(i),year:t.year(),month:t.month(),date:t.date(),hour:t.hour(),minute:t.minute(),class:[this.$scope.keyboard&&t.isSame(this.$scope.view.moment,"minute")?"highlighted":"",r?s.isValidMoment(this.$ctrl.$modelValue)&&t.isSame(this.$ctrl.$modelValue,"minute")?"selected":"":"disabled"].join(" ").trim(),selectable:r}),e++,t.add(this.provider.minutesStep,"minutes")}return this.$scope.keyboard&&this.highlightClosest(),this.$scope.view.moment.clone().startOf("hour").format("lll")},e.prototype.set=function(e){e.selectable&&(this.$scope.view.moment.year(e.year).month(e.month).date(e.date).hour(e.hour).minute(e.minute),this.$scope.view.update(),this.$scope.view.change("minute"))},e.prototype.highlightClosest=function(){var e,t=this,i=[];o.forEach(this.rows,function(e){o.forEach(e,function(e){Math.abs(e.minute-t.$scope.view.moment.minute())Math.abs(i.minute-t.$scope.view.moment.minute())?1:0})[0],e&&e.minute-this.$scope.view.moment.minute()!=0&&(this.$scope.view.moment.year(e.year).month(e.month).date(e.date).hour(e.hour).minute(e.minute),this.$scope.view.update(),e.selectable&&(e.class=(e.class+" highlighted").trim()))},e}();t.__esModule=!0,t.default=a},function(e,t,i){"use strict";var o=i(11);t.DecadeView=o.default;var n=i(16);t.YearView=n.default;var s=i(15);t.MonthView=s.default;var a=i(10);t.DayView=a.default;var r=i(12);t.HourView=r.default;var l=i(14);t.MinuteView=l.default},function(e,t,i){"use strict";var o=i(2),n=i(1),s=function(){function e(e,t,i){this.$scope=e,this.$ctrl=t,this.provider=i,this.perLine=6,this.rows={}}return e.prototype.render=function(){var e=0,t=this.$scope.view.moment.clone().startOf("minute").second(this.provider.secondsStart);this.rows={};for(var i=0;i<=this.provider.secondsEnd-this.provider.secondsStart;i+=this.provider.secondsStep){var o=Math.floor(e/this.perLine),s=this.$scope.limits.isSelectable(t,"second");this.rows[o]||(this.rows[o]=[]),this.rows[o].push({index:t.second(),label:t.format(this.provider.secondsFormat),year:t.year(),month:t.month(),date:t.date(),hour:t.hour(),minute:t.minute(),second:t.second(),class:[this.$scope.keyboard&&t.isSame(this.$scope.view.moment,"second")?"highlighted":"",s?n.isValidMoment(this.$ctrl.$modelValue)&&t.isSame(this.$ctrl.$modelValue,"second")?"selected":"":"disabled"].join(" ").trim(),selectable:s}),e++,t.add(this.provider.secondsStep,"seconds")}return this.$scope.keyboard&&this.highlightClosest(),this.$scope.view.moment.clone().startOf("minute").format("lll")},e.prototype.set=function(e){e.selectable&&(this.$scope.view.moment.year(e.year).month(e.month).date(e.date).hour(e.hour).minute(e.minute).second(e.second),this.$scope.view.update(),this.$scope.view.change())},e.prototype.highlightClosest=function(){var e,t=this,i=[];o.forEach(this.rows,function(e){o.forEach(e,function(e){Math.abs(e.second-t.$scope.view.moment.second())Math.abs(i.second-t.$scope.view.moment.second())?1:0})[0],e&&e.second-this.$scope.view.moment.second()!=0&&(this.$scope.view.moment.year(e.year).month(e.month).date(e.date).hour(e.hour).minute(e.minute).second(e.second),this.$scope.view.update(),e.selectable&&(e.class=(e.class+" highlighted").trim()))},e}();t.__esModule=!0,t.default=s},function(e,t,i){"use strict";var o=i(2),n=i(3),s=i(1),a=function(){function e(e,t,i){this.$scope=e,this.$ctrl=t,this.provider=i,this.perLine=n.weekdays().length,this.rows=[]}return e.prototype.render=function(){var e=this,t=this.$scope.view.moment.month(),i=this.$scope.view.moment.clone().startOf("month").startOf("week").hour(12),a={},r=i.week(),l=r+5;this.rows=[];for(var c=r;c<=l;c++)a[c]=Array.apply(null,Array(this.perLine)).map(function(){var o=e.$scope.limits.isSelectable(i,"day"),n={index:i.date(),label:i.format(e.provider.daysFormat),year:i.year(),month:i.month(),date:i.date(),class:[e.$scope.keyboard&&i.isSame(e.$scope.view.moment,"day")?"highlighted":"",e.$scope.today&&i.isSame(new Date,"day")?"today":"",o&&i.month()==t?s.isValidMoment(e.$ctrl.$modelValue)&&i.isSame(e.$ctrl.$modelValue,"day")?"selected":"":"disabled"].join(" ").trim(),selectable:o};return i.add(1,"days"),n});return o.forEach(a,function(t){return e.rows.push(t)}),this.headers=n.weekdays().map(function(t,i){return n().locale(e.$scope.locale).startOf("week").add(i,"day").format("dd")}),this.$scope.view.moment.format("MMMM YYYY")},e.prototype.set=function(e){e.selectable&&(this.$scope.view.moment.year(e.year).month(e.month).date(e.date),this.$scope.view.update(),this.$scope.view.change("day"))},e}();t.__esModule=!0,t.default=a},function(e,t,i){"use strict";var o=i(3),n=i(1),s=function(){function e(e,t,i){this.$scope=e,this.$ctrl=t,this.provider=i,this.perLine=4,this.rows={}}return e.prototype.render=function(){var e=this,t=this.$scope.view.moment.clone().startOf("year"),i=o.monthsShort();return this.rows={},i.forEach(function(i,o){var s=Math.floor(o/e.perLine),a=e.$scope.limits.isSelectable(t,"month");e.rows[s]||(e.rows[s]=[]),e.rows[s].push({index:t.month(),label:t.format(e.provider.monthsFormat),year:t.year(),month:t.month(),class:[e.$scope.keyboard&&t.isSame(e.$scope.view.moment,"month")?"highlighted":"",a?n.isValidMoment(e.$ctrl.$modelValue)&&t.isSame(e.$ctrl.$modelValue,"month")?"selected":"":"disabled"].join(" ").trim(),selectable:a}),t.add(1,"months")}),this.$scope.view.moment.format("YYYY")},e.prototype.set=function(e){e.selectable&&(this.$scope.view.moment.year(e.year).month(e.month),this.$scope.view.update(),this.$scope.view.change("month"))},e}();t.__esModule=!0,t.default=s}]); \ No newline at end of file +/*! Angular Moment Picker - v0.9.5 - http://indrimuska.github.io/angular-moment-picker - (c) 2015 Indri Muska - MIT */ +!function(e){function t(o){if(i[o])return i[o].exports;var n=i[o]={exports:{},id:o,loaded:!1};return e[o].call(n.exports,n,n.exports,t),n.loaded=!0,n.exports}var i={};return t.m=e,t.c=i,t.p="",t(0)}([function(e,t,i){i(8),e.exports=i(4)},function(e,t,i){"use strict";var o=i(2),n=i(3);t.KEYS={up:38,down:40,left:37,right:39,escape:27,enter:13},t.isValidMoment=function(e){return n.isMoment(e)&&e.isValid()},t.toValue=function(e,i,o){var n=e;return t.isValidMoment(e)||(n=t.toMoment(e,i,o)),t.momentToValue(n,i)},t.toMoment=function(e,i,o){var s=n(e,i,o);return t.isValidMoment(s)||(s=void 0),s},t.momentToValue=function(e,i){if(t.isValidMoment(e))return i?e.format(i):e.valueOf()},t.valueToMoment=function(e,t){var i;if(!e)return i;if(i=t.format?n(e,t.format,t.locale):n(e),t.model){var s=t.views.all.slice(0,t.views.all.indexOf(t.minView));o.forEach(s,function(e){var o=t.views.precisions[e];i[o](t.model[o]())})}return i},t.setValue=function(e,i,o,n){var s=t.isValidMoment(e)?e.clone():t.valueToMoment(e,i),r=t.momentToValue(s,i.format);t.updateMoment(i.model,s,i),t.updateMoment(o.$modelValue,s,i),n.ngModel!=n.momentPicker&&(i.value=r),n.ngModel&&(o.$setViewValue(r),o.$render())},t.updateMoment=function(e,i,n){if(t.isValidMoment(e)&&i){if(!e.isSame(i)){var s=n.views.all.slice(0,n.views.all.indexOf(n.maxView)+1);o.forEach(s,function(t){var o=n.views.precisions[t];e[o](i[o]())})}}else e=i;return e}},function(e,t){e.exports=angular},function(e,t){e.exports=moment},function(e,t){},function(e,t){e.exports='
'},function(e,t,i){"use strict";var o=i(2),n=i(3),s=i(7),r=i(13),a=i(1),l=i(5),c=function(){function e(e,t,i,c,m){var d=this;this.$timeout=e,this.$sce=t,this.$log=i,this.$window=c,this.provider=m,this.restrict="AE",this.require="?ngModel",this.transclude=!0,this.template=l,this.scope={value:"=?momentPicker",model:"=?ngModel",locale:"@?",format:"@?",minView:"@?",maxView:"@?",startView:"@?",minDate:"=?",maxDate:"=?",startDate:"=?",disabled:"=?disable",validate:"=?",autoclose:"=?",isOpen:"=?",today:"=?",keyboard:"=?",showHeader:"=?",additions:"=?",change:"&?",selectable:"&?"},this.link=function(e,t,i,l,c){c(function(c){o.forEach(["locale","format","minView","maxView","startView","validate","autoclose","today","keyboard","showHeader","leftArrow","rightArrow","additions"],function(t){o.isDefined(e[t])||(e[t]=d.provider[t]),o.isDefined(i[t])||(i[t]=e[t])}),i.ngModel||(l={}),e.limits={minDate:a.toMoment(e.minDate,e.format,e.locale),maxDate:a.toMoment(e.maxDate,e.format,e.locale),isAfterOrEqualMin:function(t,i){return!o.isDefined(e.limits.minDate)||t.isAfter(e.limits.minDate,i)||t.isSame(e.limits.minDate,i)},isBeforeOrEqualMax:function(t,i){return!o.isDefined(e.limits.maxDate)||t.isBefore(e.limits.maxDate,i)||t.isSame(e.limits.maxDate,i)},isSelectable:function(t,i){var n=!0;try{o.isFunction(e.selectable)&&(n=e.selectable({date:t,type:i}))}catch(e){d.$log.error(e)}return e.limits.isAfterOrEqualMin(t,i)&&e.limits.isBeforeOrEqualMax(t,i)&&n},checkValue:function(){a.isValidMoment(l.$modelValue)&&e.validate&&(e.limits.isAfterOrEqualMin(l.$modelValue)||a.setValue(e.limits.minDate,e,l,i),e.limits.isBeforeOrEqualMax(l.$modelValue)||a.setValue(e.limits.maxDate,e,l,i))},checkView:function(){o.isDefined(e.view.moment)||(e.view.moment=n().locale(e.locale)),e.limits.isAfterOrEqualMin(e.view.moment)||(e.view.moment=e.limits.minDate.clone()),e.limits.isBeforeOrEqualMax(e.view.moment)||(e.view.moment=e.limits.maxDate.clone()),e.view.update(),e.view.render()}},e.views={all:["decade","year","month","day","hour","minute"],precisions:{decade:"year",year:"month",month:"date",day:"hour",hour:"minute",minute:"second"},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(){if(e.format){var t,i;o.forEach(e.views.formats,function(n,s){var r=new RegExp("("+n+")(?![^[]*])","g");e.format.match(r)&&(o.isDefined(t)||(t=s),i=s)}),t=o.isDefined(t)?Math.max(0,e.views.all.indexOf(t)):0,i=o.isDefined(i)?Math.min(e.views.all.length-1,e.views.all.indexOf(i)):e.views.all.length-1,t>e.views.all.indexOf(e.minView)&&(e.minView=e.views.all[t]),i0&&o>a/2&&e.picker.addClass("top"),n+t.offsetWidth>r&&e.picker.addClass("left")}},keydown:function(t){var i=e.views[e.view.selected],o=e.views.precisions[e.view.selected].replace("date","day"),n=d.provider[o+"sStep"]||1,s=[a.KEYS.up,a.KEYS.left].indexOf(t.keyCode)>=0?"subtract":"add",r=function(t){var r=t?i.perLine:1,a=e.view.moment.clone()[s](n*r,o);e.limits.isSelectable(a,o)&&(e.view.moment=a,e.view.update(),e.view.render())};switch(t.keyCode){case a.KEYS.up:case a.KEYS.down:t.preventDefault(),e.view.isOpen?r(!0):e.view.open();break;case a.KEYS.left:case a.KEYS.right:if(!e.view.isOpen)break;t.preventDefault(),r();break;case a.KEYS.enter:if(!e.view.isOpen)break;e.view.change(o),t.preventDefault();break;case a.KEYS.escape:e.view.toggle()}},unit:function(){return"decade"==e.view.selected?10:1},precision:function(){return e.view.selected.replace("decade","year")},title:"",previous:{label:d.$sce.trustAsHtml(e.leftArrow),selectable:!0,set:function(){e.view.previous.selectable&&(e.view.moment.subtract(e.view.unit(),e.view.precision()),e.view.update(),e.view.render())}},next:{selectable:!0,label:d.$sce.trustAsHtml(e.rightArrow),set:function(){e.view.next.selectable&&(e.view.moment.add(e.view.unit(),e.view.precision()),e.view.update(),e.view.render())}},setParentView:function(){e.view.change(e.views.all[Math.max(0,e.views.all.indexOf(e.view.selected)-1)])},render:function(){var t=e.view.moment.clone().startOf(e.view.precision()).subtract(e.view.unit(),e.view.precision()),i=e.view.moment.clone().endOf(e.view.precision()).add(e.view.unit(),e.view.precision());e.view.previous.selectable=e.limits.isAfterOrEqualMin(t,e.view.precision()),e.view.previous.label=d.$sce.trustAsHtml(e.view.previous.selectable?e.leftArrow:" "),e.view.next.selectable=e.limits.isBeforeOrEqualMax(i,e.view.precision()),e.view.next.label=d.$sce.trustAsHtml(e.view.next.selectable?e.rightArrow:" "),e.view.title=e.views[e.view.selected].render()},change:function(t){var o=e.views.all.indexOf(t),n=e.views.all.indexOf(e.minView),s=e.views.all.indexOf(e.maxView);o<0||o>s?(a.setValue(e.view.moment,e,l,i),e.view.update(),e.autoclose&&d.$timeout(e.view.close)):o>=n&&(e.view.selected=t)}},e.picker=o.element(t[0].querySelectorAll(".moment-picker")),t.after(e.picker),e.contents=o.element(e.picker[0].querySelectorAll(".moment-picker-contents")),e.container=o.element(e.picker[0].querySelectorAll(".moment-picker-container")),e.contents.append(t.append(c)),e.input="input"!=e.contents[0].tagName.toLowerCase()&&e.contents[0].querySelectorAll("input").length>0?o.element(e.contents[0].querySelectorAll("input")):o.element(e.contents[0]),e.input.addClass("moment-picker-input").attr("tabindex",0),e.views.detectMinMax(),e.limits.checkView(),d.$timeout(function(){i.ngModel&&l.$commitViewValue(),e.startDate?e.view.moment=a.toMoment(e.startDate,e.format,e.locale):a.isValidMoment(l.$modelValue)&&(e.view.moment=l.$modelValue.clone()),e.view.update(),e.view.render()}),i.ngModel&&(l.$parsers.push(function(t){return a.updateMoment(l.$modelValue,a.valueToMoment(t,e),e)||!0}),l.$formatters.push(function(t){return a.momentToValue(t,e.format)||""}),l.$viewChangeListeners.push(function(){i.ngModel!=i.momentPicker&&(e.value=l.$viewValue)}),l.$validators.minDate=function(t){return e.validate||!a.isValidMoment(t)||e.limits.isAfterOrEqualMin(t)},l.$validators.maxDate=function(t){return e.validate||!a.isValidMoment(t)||e.limits.isBeforeOrEqualMax(t)}),i.ngModel!=i.momentPicker&&e.$watch("value",function(t,o){t!==o&&a.setValue(t,e,l,i)}),e.$watch(function(){return a.momentToValue(l.$modelValue,e.format)},function(t,s){if(t!=s){var r=a.valueToMoment(t,e);if(a.setValue(r,e,l,i),e.limits.checkValue(),e.view.moment=(r||n().locale(e.locale)).clone(),e.view.update(),e.view.render(),o.isFunction(e.change)){var c=a.valueToMoment(s,e);d.$timeout(function(){return e.change({newValue:r,oldValue:c})},0,!1)}}}),e.$watch(function(){return l.$modelValue&&l.$modelValue.valueOf()},function(){var t=(l.$modelValue||n().locale(e.locale)).clone();t.isSame(e.view.moment)||(e.view.moment=t,e.view.update(),e.view.render())}),e.$watch("view.selected",function(){return e.view.render()}),e.$watchGroup(["minView","maxView"],function(){e.views.detectMinMax(),e.startView=e.views.all[Math.max(Math.min(e.views.all.indexOf(e.startView),e.views.all.indexOf(e.maxView)),e.views.all.indexOf(e.minView))],e.view.selected=e.startView}),e.$watchGroup([function(){return a.toValue(e.minDate,e.format,e.locale)},function(){return a.toValue(e.maxDate,e.format,e.locale)}],function(){o.forEach(["minDate","maxDate"],function(t){e.limits[t]=a.toMoment(e[t],e.format,e.locale)}),e.limits.checkValue(),e.limits.checkView(),e.view.render()}),i.$observe("locale",function(t){return e.locale=t}),e.$watch("locale",function(t,n){o.isDefined(n)&&t!=n&&(a.isValidMoment(l.$modelValue)&&a.setValue(l.$modelValue.locale(t),e,l,i),a.isValidMoment(e.view.moment)&&(e.view.moment=e.view.moment.locale(t)),a.isValidMoment(e.limits.minDate)&&(e.limits.minDate=e.limits.minDate.locale(t)),a.isValidMoment(e.limits.maxDate)&&(e.limits.maxDate=e.limits.maxDate.locale(t)),e.view.render())}),e.$watch("validate",e.limits.checkValue),e.$watch("isOpen",function(t){o.isDefined(t)&&t!=e.view.isOpen&&e.view.toggle()});var m=function(t){t&&t.preventDefault(),e.input[0].focus()};e.input.on("focus click",function(){return e.$evalAsync(e.view.open)}).on("blur",function(){return e.$evalAsync(e.view.close)}).on("keydown",function(t){return e.keyboard&&e.$evalAsync(function(){return e.view.keydown(t)})}),e.contents.on("mousedown",function(){return m()}),e.container.on("mousedown",function(e){return m(e)}),o.element(d.$window).on("resize scroll",e.view.position)})}}return e}();t.__esModule=!0,t.default=c},function(e,t){"use strict";t.getOffset=function(e){if(e){if(!e.getClientRects().length)return{top:0,left:0};var t=function(e){return null!=e&&e===e.window},i=function(e){return t(e)?e:9===e.nodeType&&e.defaultView},o=e.getBoundingClientRect();if(!o.width&&!o.height)return o;var n=e.ownerDocument,s=i(n),r=n.documentElement;return{top:o.top+s.pageYOffset-r.clientTop,left:o.left+s.pageXOffset-r.clientLeft}}}},function(e,t,i){"use strict";var o=i(2),n=i(9);t.Provider=n.default;var s=i(6);t.Directive=s.default,o.module("moment-picker",[]).provider("momentPicker",[function(){return new n.default}]).directive("momentPicker",["$timeout","$sce","$log","$window","momentPicker",function(e,t,i,o,n){return new s.default(e,t,i,o,n)}])},function(e,t,i){"use strict";var o=i(2),n=function(){function e(){this.settings={locale:"en",format:"L LTS",minView:"decade",maxView:"minute",startView:"year",validate:!0,autoclose:!0,today:!1,keyboard:!1,showHeader:!0,leftArrow:"←",rightArrow:"→",yearsFormat:"YYYY",monthsFormat:"MMM",daysFormat:"D",hoursFormat:"HH:[00]",hoursStart:0,hoursEnd:23,minutesStep:5,minutesStart:0,minutesEnd:59,secondsFormat:"ss",secondsStep:1,secondsStart:0,secondsEnd:59}}return e.prototype.options=function(e){return o.extend(this.settings,e),o.copy(this.settings)},e.prototype.$get=function(){return this.settings},e}();t.__esModule=!0,t.default=n},function(e,t,i){"use strict";var o=i(1),n=function(){function e(e,t,i){this.$scope=e,this.$ctrl=t,this.provider=i,this.perLine=4,this.rows={}}return e.prototype.render=function(){var e=this.$scope.view.moment.clone().startOf("day").hour(this.provider.hoursStart);this.rows={};for(var t=0;t<=this.provider.hoursEnd-this.provider.hoursStart;t++){var i=Math.floor(t/this.perLine),n=this.$scope.limits.isSelectable(e,"hour");this.rows[i]||(this.rows[i]=[]),this.rows[i].push({index:t,label:e.format(this.provider.hoursFormat),year:e.year(),month:e.month(),date:e.date(),hour:e.hour(),class:[this.$scope.keyboard&&e.isSame(this.$scope.view.moment,"hour")?"highlighted":"",n?o.isValidMoment(this.$ctrl.$modelValue)&&e.isSame(this.$ctrl.$modelValue,"hour")?"selected":"":"disabled"].join(" ").trim(),selectable:n}),e.add(1,"hours")}return this.$scope.view.moment.format("LL")},e.prototype.set=function(e){e.selectable&&(this.$scope.view.moment.year(e.year).month(e.month).date(e.date).hour(e.hour),this.$scope.view.update(),this.$scope.view.change("hour"))},e}();t.__esModule=!0,t.default=n},function(e,t,i){"use strict";var o=i(1),n=function(){function e(e,t,i){this.$scope=e,this.$ctrl=t,this.provider=i,this.perLine=4,this.rows={}}return e.prototype.render=function(){var e=this.$scope.view.moment.clone(),t=10*Math.floor(e.year()/10)-1;this.rows={},e.year(t);for(var i=0;i<12;i++){var n=Math.floor(i/this.perLine),s=this.$scope.limits.isSelectable(e,"year");this.rows[n]||(this.rows[n]=[]),this.rows[n].push({index:e.year(),label:e.format(this.provider.yearsFormat),year:e.year(),class:[this.$scope.keyboard&&e.isSame(this.$scope.view.moment,"year")?"highlighted":"",!s||[0,11].indexOf(i)>=0?"disabled":o.isValidMoment(this.$ctrl.$modelValue)&&e.isSame(this.$ctrl.$modelValue,"year")?"selected":""].join(" ").trim(),selectable:s}),e.add(1,"years")}return[e.subtract(2,"years").format("YYYY"),e.subtract(9,"years").format("YYYY")].reverse().join(" - ")},e.prototype.set=function(e){e.selectable&&(this.$scope.view.moment.year(e.year),this.$scope.view.update(),this.$scope.view.change("year"))},e}();t.__esModule=!0,t.default=n},function(e,t,i){"use strict";var o=i(2),n=i(3),s=i(1),r=function(){function e(e,t,i){this.$scope=e,this.$ctrl=t,this.provider=i,this.perLine=4,this.rows={}}return e.prototype.render=function(){var e=0,t=this.$scope.view.moment.clone().startOf("hour").minute(this.provider.minutesStart),i=this.provider.minutesFormat||n.localeData(this.$scope.locale).longDateFormat("LT").replace(/[aA]/,"").trim();this.rows={};for(var o=0;o<=this.provider.minutesEnd-this.provider.minutesStart;o+=this.provider.minutesStep){var r=Math.floor(e/this.perLine),a=this.$scope.limits.isSelectable(t,"minute");this.rows[r]||(this.rows[r]=[]),this.rows[r].push({index:t.minute(),label:t.format(i),year:t.year(),month:t.month(),date:t.date(),hour:t.hour(),minute:t.minute(),class:[this.$scope.keyboard&&t.isSame(this.$scope.view.moment,"minute")?"highlighted":"",a?s.isValidMoment(this.$ctrl.$modelValue)&&t.isSame(this.$ctrl.$modelValue,"minute")?"selected":"":"disabled"].join(" ").trim(),selectable:a}),e++,t.add(this.provider.minutesStep,"minutes")}return this.$scope.keyboard&&this.highlightClosest(),this.$scope.view.moment.clone().startOf("hour").format("lll")},e.prototype.set=function(e){e.selectable&&(this.$scope.view.moment.year(e.year).month(e.month).date(e.date).hour(e.hour).minute(e.minute),this.$scope.view.update(),this.$scope.view.change("minute"))},e.prototype.highlightClosest=function(){var e,t=this,i=[];o.forEach(this.rows,function(e){o.forEach(e,function(e){Math.abs(e.minute-t.$scope.view.moment.minute())Math.abs(i.minute-t.$scope.view.moment.minute())?1:0})[0],e&&e.minute-this.$scope.view.moment.minute()!=0&&(this.$scope.view.moment.year(e.year).month(e.month).date(e.date).hour(e.hour).minute(e.minute),this.$scope.view.update(),e.selectable&&(e.class=(e.class+" highlighted").trim()))},e}();t.__esModule=!0,t.default=r},function(e,t,i){"use strict";var o=i(11);t.DecadeView=o.default;var n=i(16);t.YearView=n.default;var s=i(15);t.MonthView=s.default;var r=i(10);t.DayView=r.default;var a=i(12);t.HourView=a.default;var l=i(14);t.MinuteView=l.default},function(e,t,i){"use strict";var o=i(2),n=i(1),s=function(){function e(e,t,i){this.$scope=e,this.$ctrl=t,this.provider=i,this.perLine=6,this.rows={}}return e.prototype.render=function(){var e=0,t=this.$scope.view.moment.clone().startOf("minute").second(this.provider.secondsStart);this.rows={};for(var i=0;i<=this.provider.secondsEnd-this.provider.secondsStart;i+=this.provider.secondsStep){var o=Math.floor(e/this.perLine),s=this.$scope.limits.isSelectable(t,"second");this.rows[o]||(this.rows[o]=[]),this.rows[o].push({index:t.second(),label:t.format(this.provider.secondsFormat),year:t.year(),month:t.month(),date:t.date(),hour:t.hour(),minute:t.minute(),second:t.second(),class:[this.$scope.keyboard&&t.isSame(this.$scope.view.moment,"second")?"highlighted":"",s?n.isValidMoment(this.$ctrl.$modelValue)&&t.isSame(this.$ctrl.$modelValue,"second")?"selected":"":"disabled"].join(" ").trim(),selectable:s}),e++,t.add(this.provider.secondsStep,"seconds")}return this.$scope.keyboard&&this.highlightClosest(),this.$scope.view.moment.clone().startOf("minute").format("lll")},e.prototype.set=function(e){e.selectable&&(this.$scope.view.moment.year(e.year).month(e.month).date(e.date).hour(e.hour).minute(e.minute).second(e.second),this.$scope.view.update(),this.$scope.view.change())},e.prototype.highlightClosest=function(){var e,t=this,i=[];o.forEach(this.rows,function(e){o.forEach(e,function(e){Math.abs(e.second-t.$scope.view.moment.second())Math.abs(i.second-t.$scope.view.moment.second())?1:0})[0],e&&e.second-this.$scope.view.moment.second()!=0&&(this.$scope.view.moment.year(e.year).month(e.month).date(e.date).hour(e.hour).minute(e.minute).second(e.second),this.$scope.view.update(),e.selectable&&(e.class=(e.class+" highlighted").trim()))},e}();t.__esModule=!0,t.default=s},function(e,t,i){"use strict";var o=i(2),n=i(3),s=i(1),r=function(){function e(e,t,i){this.$scope=e,this.$ctrl=t,this.provider=i,this.perLine=n.weekdays().length,this.rows=[]}return e.prototype.render=function(){var e=this,t=this.$scope.view.moment.month(),i=this.$scope.view.moment.clone().startOf("month").startOf("week").hour(12),r={},a=i.week(),l=a+5;this.rows=[];for(var c=a;c<=l;c++)r[c]=Array.apply(null,Array(this.perLine)).map(function(){var o=e.$scope.limits.isSelectable(i,"day"),n={index:i.date(),label:i.format(e.provider.daysFormat),year:i.year(),month:i.month(),date:i.date(),class:[e.$scope.keyboard&&i.isSame(e.$scope.view.moment,"day")?"highlighted":"",e.$scope.today&&i.isSame(new Date,"day")?"today":"",o&&i.month()==t?s.isValidMoment(e.$ctrl.$modelValue)&&i.isSame(e.$ctrl.$modelValue,"day")?"selected":"":"disabled"].join(" ").trim(),selectable:o};return i.add(1,"days"),n});return o.forEach(r,function(t){return e.rows.push(t)}),this.headers=n.weekdays().map(function(t,i){return n().locale(e.$scope.locale).startOf("week").add(i,"day").format("dd")}),this.$scope.view.moment.format("MMMM YYYY")},e.prototype.set=function(e){e.selectable&&(this.$scope.view.moment.year(e.year).month(e.month).date(e.date),this.$scope.view.update(),this.$scope.view.change("day"))},e}();t.__esModule=!0,t.default=r},function(e,t,i){"use strict";var o=i(3),n=i(1),s=function(){function e(e,t,i){this.$scope=e,this.$ctrl=t,this.provider=i,this.perLine=4,this.rows={}}return e.prototype.render=function(){var e=this,t=this.$scope.view.moment.clone().startOf("year"),i=o.monthsShort();return this.rows={},i.forEach(function(i,o){var s=Math.floor(o/e.perLine),r=e.$scope.limits.isSelectable(t,"month");e.rows[s]||(e.rows[s]=[]),e.rows[s].push({index:t.month(),label:t.format(e.provider.monthsFormat),year:t.year(),month:t.month(),class:[e.$scope.keyboard&&t.isSame(e.$scope.view.moment,"month")?"highlighted":"",r?n.isValidMoment(e.$ctrl.$modelValue)&&t.isSame(e.$ctrl.$modelValue,"month")?"selected":"":"disabled"].join(" ").trim(),selectable:r}),t.add(1,"months")}),this.$scope.view.moment.format("YYYY")},e.prototype.set=function(e){e.selectable&&(this.$scope.view.moment.year(e.year).month(e.month),this.$scope.view.update(),this.$scope.view.change("month"))},e}();t.__esModule=!0,t.default=s}]); \ No newline at end of file diff --git a/package.json b/package.json index b839fe2..a3c2515 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-moment-picker", - "version": "0.9.4", + "version": "0.9.5", "description": "Angular Moment Picker is an AngularJS directive for date and time picker using Moment.js", "main": "dist/angular-moment-picker.js", "repository": {