fm-timepicker
Advanced tools
Comparing version 5.0.1 to 6.0.0
@@ -34,2 +34,4 @@ /** | ||
fmTimepickerController.$inject = ["$scope"]; | ||
fmTimepicker.$inject = ["$timeout"]; | ||
angular.module( "fmTimepicker", [] ); | ||
@@ -183,2 +185,3 @@ | ||
} | ||
// Check if we've already passed the time value that would fit our current model. | ||
@@ -198,3 +201,3 @@ if( time.isAfter( model ) ) { | ||
// The index of the last element in our time value collection. | ||
$scope.largestPossibleIndex = Number.MAX_VALUE; | ||
$scope.largestPossibleIndex = Number.MAX_VALUE; | ||
// The amount of list items we should skip when we perform a large jump through the collection. | ||
@@ -224,4 +227,4 @@ $scope.largeIntervalIndexJump = Number.MAX_VALUE; | ||
// Pick array apart. | ||
var newInterval = newValues[ 0 ]; | ||
var newLargeInterval = newValues[ 1 ]; | ||
var newInterval = newValues[ 0 ]; | ||
var newLargeInterval = newValues[ 1 ]; | ||
// Get millisecond values for the intervals. | ||
@@ -241,3 +244,2 @@ var newIntervalMilliseconds = newInterval.asMilliseconds(); | ||
} | ||
fmTimepickerController.$inject = ["$scope"]; | ||
@@ -253,2 +255,3 @@ function fmTimepickerToggle() { | ||
scope.closePopup(); | ||
} else { | ||
@@ -304,3 +307,3 @@ // Focusing the input element will automatically open the popup | ||
// Convert the moment instance we got to a string in our desired format. | ||
var time = moment( controller.$modelValue ).format( scope.fmFormat ); | ||
var time = moment( controller.$modelValue ).format( scope.fmFormat ); | ||
// Check if the given time is valid. | ||
@@ -316,4 +319,2 @@ var timeValid = checkTimeValueValid( time ); | ||
scope.time = time; | ||
} else { | ||
throw new Error( "The provided time value is invalid." ); | ||
} | ||
@@ -332,2 +333,3 @@ }; | ||
controller.$setValidity( "end", to ); | ||
controller.$setValidity( "required", to ); | ||
} | ||
@@ -341,2 +343,10 @@ | ||
resetValidity( true ); | ||
if( !scope.time ) { | ||
if( attributes.required ) { | ||
controller.$setValidity( "required", false ); | ||
} | ||
controller.$setViewValue( null ); | ||
} | ||
// Check if the string in the input box represents a valid date according to the rules set through parameters in our scope. | ||
@@ -388,2 +398,6 @@ var timeValid = checkTimeValueValid( scope.time ); | ||
function checkTimeValueValid( timeString ) { | ||
if( !timeString ) { | ||
return false; | ||
} | ||
var time; | ||
@@ -402,2 +416,3 @@ if( moment.tz ) { | ||
return false; | ||
} else { | ||
@@ -421,5 +436,7 @@ controller.$setValidity( "time", true ); | ||
scope.fmReference.tz() ) : moment.invalid(); | ||
} else { | ||
time = timeString ? moment( timeString, scope.fmFormat ) : moment.invalid(); | ||
} | ||
time = scope.constrainToReference( time ); | ||
@@ -430,2 +447,3 @@ if( !time.isValid() || time.isBefore( scope.fmStartTime ) || time.isAfter( scope.fmEndTime ) ) { | ||
return false; | ||
} else { | ||
@@ -449,2 +467,3 @@ controller.$setValidity( "bounds", true ); | ||
scope.fmReference.tz() ) : moment.invalid(); | ||
} else { | ||
@@ -459,5 +478,5 @@ time = timeString ? moment( timeString, scope.fmFormat ) : moment.invalid(); | ||
// Calculate how many milliseconds are within the given time interval. | ||
var intervalMilliseconds = scope.fmInterval.asMilliseconds(); | ||
var intervalMilliseconds = scope.fmInterval.asMilliseconds(); | ||
// Check if the modulo operation has a remainder. | ||
isValid = ( 0 === ( durationSinceStartTime % intervalMilliseconds ) ); | ||
isValid = ( 0 === ( durationSinceStartTime % intervalMilliseconds ) ); | ||
} | ||
@@ -469,2 +488,3 @@ | ||
return false; | ||
} else { | ||
@@ -500,4 +520,4 @@ controller.$setValidity( "interval", true ); | ||
// Retrieve offset from the top and height of the list element. | ||
var top = selectedListElement.length ? selectedListElement.position().top : 0; | ||
var height = selectedListElement.length ? selectedListElement.outerHeight( true ) : 0; | ||
var top = selectedListElement.length ? selectedListElement.position().top : 0; | ||
var height = selectedListElement.length ? selectedListElement.outerHeight( true ) : 0; | ||
// Scroll the list to bring the selected list element into the view. | ||
@@ -531,2 +551,3 @@ $( popupListElement ).scrollTop( top - height ); | ||
}, 200 ); | ||
} else { | ||
@@ -573,2 +594,3 @@ scope.fmIsOpen = false; | ||
scope.modelPreview = scope.ensureTimeIsWithinBounds( scope.modelPreview ); | ||
} else { | ||
@@ -586,2 +608,3 @@ scope.ngModel.add( scope.fmInterval ); | ||
scope.modelPreview = scope.ensureTimeIsWithinBounds( scope.modelPreview ); | ||
} else { | ||
@@ -606,5 +629,7 @@ scope.ngModel.subtract( scope.fmInterval ); | ||
scope.fmReference.tz() ); | ||
} else { | ||
newTime = moment( scope.time, scope.fmFormat ); | ||
} | ||
newTime = scope.constrainToReference( newTime ); | ||
@@ -624,2 +649,3 @@ controller.$setViewValue( newTime ); | ||
break; | ||
case 27: | ||
@@ -629,2 +655,3 @@ // Escape | ||
break; | ||
case 33: | ||
@@ -638,2 +665,3 @@ // Page up | ||
break; | ||
case 34: | ||
@@ -647,2 +675,3 @@ // Page down | ||
break; | ||
case 38: | ||
@@ -653,2 +682,3 @@ // Up arrow | ||
break; | ||
case 40: | ||
@@ -659,2 +689,3 @@ // Down arrow | ||
break; | ||
default: | ||
@@ -733,8 +764,5 @@ } | ||
} | ||
} | ||
}; | ||
} | ||
fmTimepicker.$inject = ["$timeout"]; | ||
})(); |
@@ -1,1 +0,1 @@ | ||
!function(){"use strict";function a(){return function(a,b){return"number"==typeof a&&(a=moment(a)),moment(a).format(b)}}function b(){return function(a,b,c,d){if(!b||!c)return a;b=moment(b),c=moment(c),d=d||moment.duration(30,"minutes");for(var e=b.clone();+c>=+e;e.add(d))a.push(+e);return a}}function c(a){if(a.fmReference=a.fmReference?moment(a.fmReference):moment(),a.fmStyle=a.fmStyle||"dropdown",a.fmIsOpen=a.fmIsOpen||!1,a.fmFormat=a.fmFormat||"LT",a.fmStartTime=a.fmStartTime||moment(a.fmReference).startOf("day"),a.fmEndTime=a.fmEndTime||moment(a.fmReference).endOf("day"),a.fmInterval=a.fmInterval||moment.duration(30,"minutes"),a.fmLargeInterval=a.fmLargeInterval||moment.duration(60,"minutes"),a.fmStrict=a.fmStrict||!1,a.fmBtnClass=a.fmBtnClass||"btn btn-default",a.fmIconClasses=a.fmIconClasses||{plus:"glyphicon glyphicon-plus",minus:"glyphicon glyphicon-minus",time:"glyphicon glyphicon-time"},moment.tz&&(a.fmStartTime.tz(a.fmReference.tz()),a.fmEndTime.tz(a.fmReference.tz())),a.fmStrict){var b=a.ngModel.valueOf(),c=a.fmInterval.asMilliseconds();b-=b%c,b+=c,a.ngModel=moment(b)}a.constrainToReference=function(b){return b?(moment.tz&&b.tz(a.fmReference.tz()),b.isSame(a.fmReference,"day")||b.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),b):(a.fmStartTime.isSame(a.fmReference,"day")||a.fmStartTime.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),a.fmEndTime.isSame(a.fmReference,"day")||a.fmEndTime.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),a.ngModel&&!a.ngModel.isSame(a.fmReference,"day")&&a.ngModel.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),null)},a.constrainToReference(),a.ensureTimeIsWithinBounds=function(b){return b&&moment.isMoment(b)?b.isBefore(a.fmStartTime)?moment(a.fmStartTime):b.isAfter(a.fmEndTime)?moment(a.fmEndTime):b:b},a.ngModel=a.ensureTimeIsWithinBounds(a.ngModel),a.findActiveIndex=function(b){if(a.activeIndex=0,b)for(var c=a.fmStartTime.clone();+c<=+a.fmEndTime&&!c.isSame(b);c.add(a.fmInterval),++a.activeIndex)if(c.isAfter(b)){a.fmStrict&&(a.activeIndex=-1),a.activeIndex-=1;break}},a.largestPossibleIndex=Number.MAX_VALUE,a.largeIntervalIndexJump=Number.MAX_VALUE,a.findActiveIndex(a.ngModel),a.$watch("fmInterval",function(b,c){b.asMilliseconds()<1&&(console.error("[fm-timepicker] Error: Supplied interval length is smaller than 1ms! Reverting to default."),a.fmInterval=moment.duration(30,"minutes"))}),a.$watch("fmLargeInterval",function(b,c){b.asMilliseconds()<10&&(console.error("[fm-timepicker] Error: Supplied large interval length is smaller than 10ms! Reverting to default."),a.fmLargeInterval=moment.duration(60,"minutes"))}),a.$watchCollection("[fmInterval,fmLargeInterval]",function(b){var c=b[0],d=b[1],e=c.asMilliseconds(),f=d.asMilliseconds();0!==f%e&&(console.warn("[fm-timepicker] Warning: Large interval is not a multiple of interval! Using internally computed value instead."),a.fmLargeInterval=moment.duration(5*e),f=a.fmLargeInterval.asMilliseconds()),a.largeIntervalIndexJump=f/e})}function d(){return{restrict:"A",link:function(a,b,c){b.bind("click",function(){a.fmIsOpen?(a.focusInputElement(),a.closePopup()):a.focusInputElement()})}}}function e(a){return{templateUrl:"fmTimepicker.html",replace:!0,restrict:"EA",scope:{ngModel:"=",fmFormat:"=?",fmStartTime:"=?",fmEndTime:"=?",fmReference:"=?",fmInterval:"=?",fmLargeInterval:"=?",fmIsOpen:"=?",fmStyle:"=?",fmStrict:"=?",fmBtnClass:"=?",fmIconClasses:"=?",fmDisabled:"=?"},controller:"fmTimepickerController",require:"ngModel",link:function(b,c,d,e){function f(a){e.$setValidity("time",a),e.$setValidity("bounds",a),e.$setValidity("interval",a),e.$setValidity("start",a),e.$setValidity("end",a)}function g(){f(!0);var a=h(b.time);if(b.fmStrict&&(a=a&&i(b.time)&&j(b.time)),b.fmStartTime.isValid()||e.$setValidity("start",!1),b.fmEndTime.isValid()||e.$setValidity("end",!1),a){var c;c=moment.tz?moment.tz(b.time,b.fmFormat,b.fmReference.tz()):moment(b.time,b.fmFormat),c=b.constrainToReference(c),e.$setViewValue(c),moment.tz?b.time=moment.tz(b.time,b.fmFormat,b.fmReference.tz()).format(b.fmFormat):b.time=moment(b.time,b.fmFormat).format(b.fmFormat)}}function h(a){var c;return c=moment.tz?a?moment.tz(a,b.fmFormat,b.fmReference.tz()):moment.invalid():a?moment(a,b.fmFormat):moment.invalid(),c.isValid()?(e.$setValidity("time",!0),!0):(e.$setValidity("time",!1),e.$setViewValue(null),!1)}function i(a){var c;return c=moment.tz?a?moment.tz(a,b.fmFormat,b.fmReference.tz()):moment.invalid():a?moment(a,b.fmFormat):moment.invalid(),c=b.constrainToReference(c),!c.isValid()||c.isBefore(b.fmStartTime)||c.isAfter(b.fmEndTime)?(e.$setValidity("bounds",!1),e.$setViewValue(null),!1):(e.$setValidity("bounds",!0),!0)}function j(a){var c;c=moment.tz?a?moment.tz(a,b.fmFormat,b.fmReference.tz()):moment.invalid():a?moment(a,b.fmFormat):moment.invalid();var d=c.isValid();if(d){var f=c.diff(b.fmStartTime),g=b.fmInterval.asMilliseconds();d=0===f%g}return d?(e.$setValidity("interval",!0),!0):(e.$setValidity("interval",!1),e.$setViewValue(null),!1)}function k(){a(function(){b.$apply()}),b.fmIsOpen&&a(l)}function l(){var a=c.find("ul");$(a).scrollTop(0);var b=$("li.active",a),d=b.length?b.position().top:0,e=b.length?b.outerHeight(!0):0;$(a).scrollTop(d-e)}function m(){b.fmIsOpen||(b.fmIsOpen=!0,b.modelPreview=b.ngModel?b.ngModel.clone():b.fmStartTime.clone(),a(k))}b.$watchCollection("[fmStartTime,fmEndTime,fmInterval,fmStrict]",function(){b.constrainToReference(),g()}),b.$watchCollection("[fmStartTime,fmEndTime,fmInterval,ngModel]",function(){b.findActiveIndex(b.ngModel)}),e.$render=function(){var a=moment(e.$modelValue).format(b.fmFormat),c=h(a);if(b.fmStrict&&(c=c&&i(a)&&j(a)),!c)throw new Error("The provided time value is invalid.");b.time=a},b.closePopup=function(c){c?a(function(){b.fmIsOpen=!1},200):(b.fmIsOpen=!1,a(k))},b.handleListClick=function(a){return a.preventDefault(),!1},b.select=function(a,c){var d;d=moment.tz&&b.fmReference.tz()?moment(a).tz(b.fmReference.tz()):moment(a),b.time=d.format(b.fmFormat),b.activeIndex=c,b.update(),b.closePopup()},b.increment=function(){b.fmIsOpen?(b.modelPreview.add(b.fmInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview)):(b.ngModel.add(b.fmInterval),b.ngModel=b.ensureTimeIsWithinBounds(b.ngModel),b.time=b.ngModel.format(b.fmFormat)),b.activeIndex=Math.min(b.largestPossibleIndex,b.activeIndex+1)},b.decrement=function(){b.fmIsOpen?(b.modelPreview.subtract(b.fmInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview)):(b.ngModel.subtract(b.fmInterval),b.ngModel=b.ensureTimeIsWithinBounds(b.ngModel),b.time=b.ngModel.format(b.fmFormat)),b.activeIndex=Math.max(0,b.activeIndex-1)},b.update=function(){var a=h(b.time)&&i(b.time);if(a){var c;c=moment.tz?moment.tz(b.time,b.fmFormat,b.fmReference.tz()):moment(b.time,b.fmFormat),c=b.constrainToReference(c),e.$setViewValue(c)}},b.handleKeyboardInput=function(c){switch(c.keyCode){case 13:b.modelPreview&&(b.ngModel=b.modelPreview,b.fmIsOpen=!1);break;case 27:b.closePopup();break;case 33:m(),b.modelPreview.subtract(b.fmLargeInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview),b.activeIndex=Math.max(0,b.activeIndex-b.largeIntervalIndexJump);break;case 34:m(),b.modelPreview.add(b.fmLargeInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview),b.activeIndex=Math.min(b.largestPossibleIndex,b.activeIndex+b.largeIntervalIndexJump);break;case 38:m(),b.decrement();break;case 40:m(),b.increment()}a(k)},b.preventDefault=function(a){a.preventDefault()},b.largestPossibleIndexIs=function(a){b.largestPossibleIndex=a},b.focusInputElement=function(){$(n).focus()};var n=c.find("input"),o=c.find("ul");n.bind("focus",function(){a(m,150),b.isFocused=!0}),n.bind("blur",function(){a(function(){$(n).is(":focus")||(b.closePopup(),g())},150),b.isFocused=!1}),o.bind("mousedown",function(a){a.preventDefault()}),"function"==typeof Hamster&&Hamster(n[0]).wheel(function(c,d,e,f){b.isFocused&&(c.preventDefault(),b.activeIndex-=d,b.activeIndex=Math.min(b.largestPossibleIndex,Math.max(0,b.activeIndex)),b.select(b.dropDownOptions[b.activeIndex],b.activeIndex),a(k))})}}}angular.module("fmTimepicker",[]),angular.module("fmTimepicker").filter("fmTimeFormat",a).filter("fmTimeInterval",b).controller("fmTimepickerController",c).directive("fmTimepickerToggle",d).directive("fmTimepicker",e),c.$inject=["$scope"],e.$inject=["$timeout"]}(); | ||
!function(){"use strict";function a(){return function(a,b){return"number"==typeof a&&(a=moment(a)),moment(a).format(b)}}function b(){return function(a,b,c,d){if(!b||!c)return a;b=moment(b),c=moment(c),d=d||moment.duration(30,"minutes");for(var e=b.clone();+c>=+e;e.add(d))a.push(+e);return a}}function c(a){if(a.fmReference=a.fmReference?moment(a.fmReference):moment(),a.fmStyle=a.fmStyle||"dropdown",a.fmIsOpen=a.fmIsOpen||!1,a.fmFormat=a.fmFormat||"LT",a.fmStartTime=a.fmStartTime||moment(a.fmReference).startOf("day"),a.fmEndTime=a.fmEndTime||moment(a.fmReference).endOf("day"),a.fmInterval=a.fmInterval||moment.duration(30,"minutes"),a.fmLargeInterval=a.fmLargeInterval||moment.duration(60,"minutes"),a.fmStrict=a.fmStrict||!1,a.fmBtnClass=a.fmBtnClass||"btn btn-default",a.fmIconClasses=a.fmIconClasses||{plus:"glyphicon glyphicon-plus",minus:"glyphicon glyphicon-minus",time:"glyphicon glyphicon-time"},moment.tz&&(a.fmStartTime.tz(a.fmReference.tz()),a.fmEndTime.tz(a.fmReference.tz())),a.fmStrict){var b=a.ngModel.valueOf(),c=a.fmInterval.asMilliseconds();b-=b%c,b+=c,a.ngModel=moment(b)}a.constrainToReference=function(b){return b?(moment.tz&&b.tz(a.fmReference.tz()),b.isSame(a.fmReference,"day")||b.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),b):(a.fmStartTime.isSame(a.fmReference,"day")||a.fmStartTime.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),a.fmEndTime.isSame(a.fmReference,"day")||a.fmEndTime.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),a.ngModel&&!a.ngModel.isSame(a.fmReference,"day")&&a.ngModel.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),null)},a.constrainToReference(),a.ensureTimeIsWithinBounds=function(b){return b&&moment.isMoment(b)?b.isBefore(a.fmStartTime)?moment(a.fmStartTime):b.isAfter(a.fmEndTime)?moment(a.fmEndTime):b:b},a.ngModel=a.ensureTimeIsWithinBounds(a.ngModel),a.findActiveIndex=function(b){if(a.activeIndex=0,b)for(var c=a.fmStartTime.clone();+c<=+a.fmEndTime&&!c.isSame(b);c.add(a.fmInterval),++a.activeIndex)if(c.isAfter(b)){a.fmStrict&&(a.activeIndex=-1),a.activeIndex-=1;break}},a.largestPossibleIndex=Number.MAX_VALUE,a.largeIntervalIndexJump=Number.MAX_VALUE,a.findActiveIndex(a.ngModel),a.$watch("fmInterval",function(b,c){b.asMilliseconds()<1&&(console.error("[fm-timepicker] Error: Supplied interval length is smaller than 1ms! Reverting to default."),a.fmInterval=moment.duration(30,"minutes"))}),a.$watch("fmLargeInterval",function(b,c){b.asMilliseconds()<10&&(console.error("[fm-timepicker] Error: Supplied large interval length is smaller than 10ms! Reverting to default."),a.fmLargeInterval=moment.duration(60,"minutes"))}),a.$watchCollection("[fmInterval,fmLargeInterval]",function(b){var c=b[0],d=b[1],e=c.asMilliseconds(),f=d.asMilliseconds();0!==f%e&&(console.warn("[fm-timepicker] Warning: Large interval is not a multiple of interval! Using internally computed value instead."),a.fmLargeInterval=moment.duration(5*e),f=a.fmLargeInterval.asMilliseconds()),a.largeIntervalIndexJump=f/e})}function d(){return{restrict:"A",link:function(a,b,c){b.bind("click",function(){a.fmIsOpen?(a.focusInputElement(),a.closePopup()):a.focusInputElement()})}}}function e(a){return{templateUrl:"fmTimepicker.html",replace:!0,restrict:"EA",scope:{ngModel:"=",fmFormat:"=?",fmStartTime:"=?",fmEndTime:"=?",fmReference:"=?",fmInterval:"=?",fmLargeInterval:"=?",fmIsOpen:"=?",fmStyle:"=?",fmStrict:"=?",fmBtnClass:"=?",fmIconClasses:"=?",fmDisabled:"=?"},controller:"fmTimepickerController",require:"ngModel",link:function(b,c,d,e){function f(a){e.$setValidity("time",a),e.$setValidity("bounds",a),e.$setValidity("interval",a),e.$setValidity("start",a),e.$setValidity("end",a),e.$setValidity("required",a)}function g(){f(!0),b.time||(d.required&&e.$setValidity("required",!1),e.$setViewValue(null));var a=h(b.time);if(b.fmStrict&&(a=a&&i(b.time)&&j(b.time)),b.fmStartTime.isValid()||e.$setValidity("start",!1),b.fmEndTime.isValid()||e.$setValidity("end",!1),a){var c;c=moment.tz?moment.tz(b.time,b.fmFormat,b.fmReference.tz()):moment(b.time,b.fmFormat),c=b.constrainToReference(c),e.$setViewValue(c),moment.tz?b.time=moment.tz(b.time,b.fmFormat,b.fmReference.tz()).format(b.fmFormat):b.time=moment(b.time,b.fmFormat).format(b.fmFormat)}}function h(a){if(!a)return!1;var c;return c=moment.tz?a?moment.tz(a,b.fmFormat,b.fmReference.tz()):moment.invalid():a?moment(a,b.fmFormat):moment.invalid(),c.isValid()?(e.$setValidity("time",!0),!0):(e.$setValidity("time",!1),e.$setViewValue(null),!1)}function i(a){var c;return c=moment.tz?a?moment.tz(a,b.fmFormat,b.fmReference.tz()):moment.invalid():a?moment(a,b.fmFormat):moment.invalid(),c=b.constrainToReference(c),!c.isValid()||c.isBefore(b.fmStartTime)||c.isAfter(b.fmEndTime)?(e.$setValidity("bounds",!1),e.$setViewValue(null),!1):(e.$setValidity("bounds",!0),!0)}function j(a){var c;c=moment.tz?a?moment.tz(a,b.fmFormat,b.fmReference.tz()):moment.invalid():a?moment(a,b.fmFormat):moment.invalid();var d=c.isValid();if(d){var f=c.diff(b.fmStartTime),g=b.fmInterval.asMilliseconds();d=0===f%g}return d?(e.$setValidity("interval",!0),!0):(e.$setValidity("interval",!1),e.$setViewValue(null),!1)}function k(){a(function(){b.$apply()}),b.fmIsOpen&&a(l)}function l(){var a=c.find("ul");$(a).scrollTop(0);var b=$("li.active",a),d=b.length?b.position().top:0,e=b.length?b.outerHeight(!0):0;$(a).scrollTop(d-e)}function m(){b.fmIsOpen||(b.fmIsOpen=!0,b.modelPreview=b.ngModel?b.ngModel.clone():b.fmStartTime.clone(),a(k))}b.$watchCollection("[fmStartTime,fmEndTime,fmInterval,fmStrict]",function(){b.constrainToReference(),g()}),b.$watchCollection("[fmStartTime,fmEndTime,fmInterval,ngModel]",function(){b.findActiveIndex(b.ngModel)}),e.$render=function(){var a=moment(e.$modelValue).format(b.fmFormat),c=h(a);b.fmStrict&&(c=c&&i(a)&&j(a)),c&&(b.time=a)},b.closePopup=function(c){c?a(function(){b.fmIsOpen=!1},200):(b.fmIsOpen=!1,a(k))},b.handleListClick=function(a){return a.preventDefault(),!1},b.select=function(a,c){var d;d=moment.tz&&b.fmReference.tz()?moment(a).tz(b.fmReference.tz()):moment(a),b.time=d.format(b.fmFormat),b.activeIndex=c,b.update(),b.closePopup()},b.increment=function(){b.fmIsOpen?(b.modelPreview.add(b.fmInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview)):(b.ngModel.add(b.fmInterval),b.ngModel=b.ensureTimeIsWithinBounds(b.ngModel),b.time=b.ngModel.format(b.fmFormat)),b.activeIndex=Math.min(b.largestPossibleIndex,b.activeIndex+1)},b.decrement=function(){b.fmIsOpen?(b.modelPreview.subtract(b.fmInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview)):(b.ngModel.subtract(b.fmInterval),b.ngModel=b.ensureTimeIsWithinBounds(b.ngModel),b.time=b.ngModel.format(b.fmFormat)),b.activeIndex=Math.max(0,b.activeIndex-1)},b.update=function(){var a=h(b.time)&&i(b.time);if(a){var c;c=moment.tz?moment.tz(b.time,b.fmFormat,b.fmReference.tz()):moment(b.time,b.fmFormat),c=b.constrainToReference(c),e.$setViewValue(c)}},b.handleKeyboardInput=function(c){switch(c.keyCode){case 13:b.modelPreview&&(b.ngModel=b.modelPreview,b.fmIsOpen=!1);break;case 27:b.closePopup();break;case 33:m(),b.modelPreview.subtract(b.fmLargeInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview),b.activeIndex=Math.max(0,b.activeIndex-b.largeIntervalIndexJump);break;case 34:m(),b.modelPreview.add(b.fmLargeInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview),b.activeIndex=Math.min(b.largestPossibleIndex,b.activeIndex+b.largeIntervalIndexJump);break;case 38:m(),b.decrement();break;case 40:m(),b.increment()}a(k)},b.preventDefault=function(a){a.preventDefault()},b.largestPossibleIndexIs=function(a){b.largestPossibleIndex=a},b.focusInputElement=function(){$(n).focus()};var n=c.find("input"),o=c.find("ul");n.bind("focus",function(){a(m,150),b.isFocused=!0}),n.bind("blur",function(){a(function(){$(n).is(":focus")||(b.closePopup(),g())},150),b.isFocused=!1}),o.bind("mousedown",function(a){a.preventDefault()}),"function"==typeof Hamster&&Hamster(n[0]).wheel(function(c,d,e,f){b.isFocused&&(c.preventDefault(),b.activeIndex-=d,b.activeIndex=Math.min(b.largestPossibleIndex,Math.max(0,b.activeIndex)),b.select(b.dropDownOptions[b.activeIndex],b.activeIndex),a(k))})}}}c.$inject=["$scope"],e.$inject=["$timeout"],angular.module("fmTimepicker",[]),angular.module("fmTimepicker").filter("fmTimeFormat",a).filter("fmTimeInterval",b).controller("fmTimepickerController",c).directive("fmTimepickerToggle",d).directive("fmTimepicker",e)}(); |
@@ -34,2 +34,4 @@ /** | ||
fmTimepickerController.$inject = ["$scope"]; | ||
fmTimepicker.$inject = ["$timeout"]; | ||
angular.module( "fmTimepicker", [] ); | ||
@@ -183,2 +185,3 @@ | ||
} | ||
// Check if we've already passed the time value that would fit our current model. | ||
@@ -198,3 +201,3 @@ if( time.isAfter( model ) ) { | ||
// The index of the last element in our time value collection. | ||
$scope.largestPossibleIndex = Number.MAX_VALUE; | ||
$scope.largestPossibleIndex = Number.MAX_VALUE; | ||
// The amount of list items we should skip when we perform a large jump through the collection. | ||
@@ -224,4 +227,4 @@ $scope.largeIntervalIndexJump = Number.MAX_VALUE; | ||
// Pick array apart. | ||
var newInterval = newValues[ 0 ]; | ||
var newLargeInterval = newValues[ 1 ]; | ||
var newInterval = newValues[ 0 ]; | ||
var newLargeInterval = newValues[ 1 ]; | ||
// Get millisecond values for the intervals. | ||
@@ -241,3 +244,2 @@ var newIntervalMilliseconds = newInterval.asMilliseconds(); | ||
} | ||
fmTimepickerController.$inject = ["$scope"]; | ||
@@ -253,2 +255,3 @@ function fmTimepickerToggle() { | ||
scope.closePopup(); | ||
} else { | ||
@@ -304,3 +307,3 @@ // Focusing the input element will automatically open the popup | ||
// Convert the moment instance we got to a string in our desired format. | ||
var time = moment( controller.$modelValue ).format( scope.fmFormat ); | ||
var time = moment( controller.$modelValue ).format( scope.fmFormat ); | ||
// Check if the given time is valid. | ||
@@ -316,4 +319,2 @@ var timeValid = checkTimeValueValid( time ); | ||
scope.time = time; | ||
} else { | ||
throw new Error( "The provided time value is invalid." ); | ||
} | ||
@@ -332,2 +333,3 @@ }; | ||
controller.$setValidity( "end", to ); | ||
controller.$setValidity( "required", to ); | ||
} | ||
@@ -341,2 +343,10 @@ | ||
resetValidity( true ); | ||
if( !scope.time ) { | ||
if( attributes.required ) { | ||
controller.$setValidity( "required", false ); | ||
} | ||
controller.$setViewValue( null ); | ||
} | ||
// Check if the string in the input box represents a valid date according to the rules set through parameters in our scope. | ||
@@ -388,2 +398,6 @@ var timeValid = checkTimeValueValid( scope.time ); | ||
function checkTimeValueValid( timeString ) { | ||
if( !timeString ) { | ||
return false; | ||
} | ||
var time; | ||
@@ -402,2 +416,3 @@ if( moment.tz ) { | ||
return false; | ||
} else { | ||
@@ -421,5 +436,7 @@ controller.$setValidity( "time", true ); | ||
scope.fmReference.tz() ) : moment.invalid(); | ||
} else { | ||
time = timeString ? moment( timeString, scope.fmFormat ) : moment.invalid(); | ||
} | ||
time = scope.constrainToReference( time ); | ||
@@ -430,2 +447,3 @@ if( !time.isValid() || time.isBefore( scope.fmStartTime ) || time.isAfter( scope.fmEndTime ) ) { | ||
return false; | ||
} else { | ||
@@ -449,2 +467,3 @@ controller.$setValidity( "bounds", true ); | ||
scope.fmReference.tz() ) : moment.invalid(); | ||
} else { | ||
@@ -459,5 +478,5 @@ time = timeString ? moment( timeString, scope.fmFormat ) : moment.invalid(); | ||
// Calculate how many milliseconds are within the given time interval. | ||
var intervalMilliseconds = scope.fmInterval.asMilliseconds(); | ||
var intervalMilliseconds = scope.fmInterval.asMilliseconds(); | ||
// Check if the modulo operation has a remainder. | ||
isValid = ( 0 === ( durationSinceStartTime % intervalMilliseconds ) ); | ||
isValid = ( 0 === ( durationSinceStartTime % intervalMilliseconds ) ); | ||
} | ||
@@ -469,2 +488,3 @@ | ||
return false; | ||
} else { | ||
@@ -500,4 +520,4 @@ controller.$setValidity( "interval", true ); | ||
// Retrieve offset from the top and height of the list element. | ||
var top = selectedListElement.length ? selectedListElement.position().top : 0; | ||
var height = selectedListElement.length ? selectedListElement.outerHeight( true ) : 0; | ||
var top = selectedListElement.length ? selectedListElement.position().top : 0; | ||
var height = selectedListElement.length ? selectedListElement.outerHeight( true ) : 0; | ||
// Scroll the list to bring the selected list element into the view. | ||
@@ -531,2 +551,3 @@ $( popupListElement ).scrollTop( top - height ); | ||
}, 200 ); | ||
} else { | ||
@@ -573,2 +594,3 @@ scope.fmIsOpen = false; | ||
scope.modelPreview = scope.ensureTimeIsWithinBounds( scope.modelPreview ); | ||
} else { | ||
@@ -586,2 +608,3 @@ scope.ngModel.add( scope.fmInterval ); | ||
scope.modelPreview = scope.ensureTimeIsWithinBounds( scope.modelPreview ); | ||
} else { | ||
@@ -606,5 +629,7 @@ scope.ngModel.subtract( scope.fmInterval ); | ||
scope.fmReference.tz() ); | ||
} else { | ||
newTime = moment( scope.time, scope.fmFormat ); | ||
} | ||
newTime = scope.constrainToReference( newTime ); | ||
@@ -624,2 +649,3 @@ controller.$setViewValue( newTime ); | ||
break; | ||
case 27: | ||
@@ -629,2 +655,3 @@ // Escape | ||
break; | ||
case 33: | ||
@@ -638,2 +665,3 @@ // Page up | ||
break; | ||
case 34: | ||
@@ -647,2 +675,3 @@ // Page down | ||
break; | ||
case 38: | ||
@@ -653,2 +682,3 @@ // Up arrow | ||
break; | ||
case 40: | ||
@@ -659,2 +689,3 @@ // Down arrow | ||
break; | ||
default: | ||
@@ -733,8 +764,5 @@ } | ||
} | ||
} | ||
}; | ||
} | ||
fmTimepicker.$inject = ["$timeout"]; | ||
})(); | ||
@@ -741,0 +769,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function(){"use strict";function a(){return function(a,b){return"number"==typeof a&&(a=moment(a)),moment(a).format(b)}}function b(){return function(a,b,c,d){if(!b||!c)return a;b=moment(b),c=moment(c),d=d||moment.duration(30,"minutes");for(var e=b.clone();+c>=+e;e.add(d))a.push(+e);return a}}function c(a){if(a.fmReference=a.fmReference?moment(a.fmReference):moment(),a.fmStyle=a.fmStyle||"dropdown",a.fmIsOpen=a.fmIsOpen||!1,a.fmFormat=a.fmFormat||"LT",a.fmStartTime=a.fmStartTime||moment(a.fmReference).startOf("day"),a.fmEndTime=a.fmEndTime||moment(a.fmReference).endOf("day"),a.fmInterval=a.fmInterval||moment.duration(30,"minutes"),a.fmLargeInterval=a.fmLargeInterval||moment.duration(60,"minutes"),a.fmStrict=a.fmStrict||!1,a.fmBtnClass=a.fmBtnClass||"btn btn-default",a.fmIconClasses=a.fmIconClasses||{plus:"glyphicon glyphicon-plus",minus:"glyphicon glyphicon-minus",time:"glyphicon glyphicon-time"},moment.tz&&(a.fmStartTime.tz(a.fmReference.tz()),a.fmEndTime.tz(a.fmReference.tz())),a.fmStrict){var b=a.ngModel.valueOf(),c=a.fmInterval.asMilliseconds();b-=b%c,b+=c,a.ngModel=moment(b)}a.constrainToReference=function(b){return b?(moment.tz&&b.tz(a.fmReference.tz()),b.isSame(a.fmReference,"day")||b.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),b):(a.fmStartTime.isSame(a.fmReference,"day")||a.fmStartTime.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),a.fmEndTime.isSame(a.fmReference,"day")||a.fmEndTime.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),a.ngModel&&!a.ngModel.isSame(a.fmReference,"day")&&a.ngModel.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),null)},a.constrainToReference(),a.ensureTimeIsWithinBounds=function(b){return b&&moment.isMoment(b)?b.isBefore(a.fmStartTime)?moment(a.fmStartTime):b.isAfter(a.fmEndTime)?moment(a.fmEndTime):b:b},a.ngModel=a.ensureTimeIsWithinBounds(a.ngModel),a.findActiveIndex=function(b){if(a.activeIndex=0,b)for(var c=a.fmStartTime.clone();+c<=+a.fmEndTime&&!c.isSame(b);c.add(a.fmInterval),++a.activeIndex)if(c.isAfter(b)){a.fmStrict&&(a.activeIndex=-1),a.activeIndex-=1;break}},a.largestPossibleIndex=Number.MAX_VALUE,a.largeIntervalIndexJump=Number.MAX_VALUE,a.findActiveIndex(a.ngModel),a.$watch("fmInterval",function(b,c){b.asMilliseconds()<1&&(console.error("[fm-timepicker] Error: Supplied interval length is smaller than 1ms! Reverting to default."),a.fmInterval=moment.duration(30,"minutes"))}),a.$watch("fmLargeInterval",function(b,c){b.asMilliseconds()<10&&(console.error("[fm-timepicker] Error: Supplied large interval length is smaller than 10ms! Reverting to default."),a.fmLargeInterval=moment.duration(60,"minutes"))}),a.$watchCollection("[fmInterval,fmLargeInterval]",function(b){var c=b[0],d=b[1],e=c.asMilliseconds(),f=d.asMilliseconds();0!==f%e&&(console.warn("[fm-timepicker] Warning: Large interval is not a multiple of interval! Using internally computed value instead."),a.fmLargeInterval=moment.duration(5*e),f=a.fmLargeInterval.asMilliseconds()),a.largeIntervalIndexJump=f/e})}function d(){return{restrict:"A",link:function(a,b,c){b.bind("click",function(){a.fmIsOpen?(a.focusInputElement(),a.closePopup()):a.focusInputElement()})}}}function e(a){return{templateUrl:"fmTimepicker.html",replace:!0,restrict:"EA",scope:{ngModel:"=",fmFormat:"=?",fmStartTime:"=?",fmEndTime:"=?",fmReference:"=?",fmInterval:"=?",fmLargeInterval:"=?",fmIsOpen:"=?",fmStyle:"=?",fmStrict:"=?",fmBtnClass:"=?",fmIconClasses:"=?",fmDisabled:"=?"},controller:"fmTimepickerController",require:"ngModel",link:function(b,c,d,e){function f(a){e.$setValidity("time",a),e.$setValidity("bounds",a),e.$setValidity("interval",a),e.$setValidity("start",a),e.$setValidity("end",a)}function g(){f(!0);var a=h(b.time);if(b.fmStrict&&(a=a&&i(b.time)&&j(b.time)),b.fmStartTime.isValid()||e.$setValidity("start",!1),b.fmEndTime.isValid()||e.$setValidity("end",!1),a){var c;c=moment.tz?moment.tz(b.time,b.fmFormat,b.fmReference.tz()):moment(b.time,b.fmFormat),c=b.constrainToReference(c),e.$setViewValue(c),moment.tz?b.time=moment.tz(b.time,b.fmFormat,b.fmReference.tz()).format(b.fmFormat):b.time=moment(b.time,b.fmFormat).format(b.fmFormat)}}function h(a){var c;return c=moment.tz?a?moment.tz(a,b.fmFormat,b.fmReference.tz()):moment.invalid():a?moment(a,b.fmFormat):moment.invalid(),c.isValid()?(e.$setValidity("time",!0),!0):(e.$setValidity("time",!1),e.$setViewValue(null),!1)}function i(a){var c;return c=moment.tz?a?moment.tz(a,b.fmFormat,b.fmReference.tz()):moment.invalid():a?moment(a,b.fmFormat):moment.invalid(),c=b.constrainToReference(c),!c.isValid()||c.isBefore(b.fmStartTime)||c.isAfter(b.fmEndTime)?(e.$setValidity("bounds",!1),e.$setViewValue(null),!1):(e.$setValidity("bounds",!0),!0)}function j(a){var c;c=moment.tz?a?moment.tz(a,b.fmFormat,b.fmReference.tz()):moment.invalid():a?moment(a,b.fmFormat):moment.invalid();var d=c.isValid();if(d){var f=c.diff(b.fmStartTime),g=b.fmInterval.asMilliseconds();d=0===f%g}return d?(e.$setValidity("interval",!0),!0):(e.$setValidity("interval",!1),e.$setViewValue(null),!1)}function k(){a(function(){b.$apply()}),b.fmIsOpen&&a(l)}function l(){var a=c.find("ul");$(a).scrollTop(0);var b=$("li.active",a),d=b.length?b.position().top:0,e=b.length?b.outerHeight(!0):0;$(a).scrollTop(d-e)}function m(){b.fmIsOpen||(b.fmIsOpen=!0,b.modelPreview=b.ngModel?b.ngModel.clone():b.fmStartTime.clone(),a(k))}b.$watchCollection("[fmStartTime,fmEndTime,fmInterval,fmStrict]",function(){b.constrainToReference(),g()}),b.$watchCollection("[fmStartTime,fmEndTime,fmInterval,ngModel]",function(){b.findActiveIndex(b.ngModel)}),e.$render=function(){var a=moment(e.$modelValue).format(b.fmFormat),c=h(a);if(b.fmStrict&&(c=c&&i(a)&&j(a)),!c)throw new Error("The provided time value is invalid.");b.time=a},b.closePopup=function(c){c?a(function(){b.fmIsOpen=!1},200):(b.fmIsOpen=!1,a(k))},b.handleListClick=function(a){return a.preventDefault(),!1},b.select=function(a,c){var d;d=moment.tz&&b.fmReference.tz()?moment(a).tz(b.fmReference.tz()):moment(a),b.time=d.format(b.fmFormat),b.activeIndex=c,b.update(),b.closePopup()},b.increment=function(){b.fmIsOpen?(b.modelPreview.add(b.fmInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview)):(b.ngModel.add(b.fmInterval),b.ngModel=b.ensureTimeIsWithinBounds(b.ngModel),b.time=b.ngModel.format(b.fmFormat)),b.activeIndex=Math.min(b.largestPossibleIndex,b.activeIndex+1)},b.decrement=function(){b.fmIsOpen?(b.modelPreview.subtract(b.fmInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview)):(b.ngModel.subtract(b.fmInterval),b.ngModel=b.ensureTimeIsWithinBounds(b.ngModel),b.time=b.ngModel.format(b.fmFormat)),b.activeIndex=Math.max(0,b.activeIndex-1)},b.update=function(){var a=h(b.time)&&i(b.time);if(a){var c;c=moment.tz?moment.tz(b.time,b.fmFormat,b.fmReference.tz()):moment(b.time,b.fmFormat),c=b.constrainToReference(c),e.$setViewValue(c)}},b.handleKeyboardInput=function(c){switch(c.keyCode){case 13:b.modelPreview&&(b.ngModel=b.modelPreview,b.fmIsOpen=!1);break;case 27:b.closePopup();break;case 33:m(),b.modelPreview.subtract(b.fmLargeInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview),b.activeIndex=Math.max(0,b.activeIndex-b.largeIntervalIndexJump);break;case 34:m(),b.modelPreview.add(b.fmLargeInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview),b.activeIndex=Math.min(b.largestPossibleIndex,b.activeIndex+b.largeIntervalIndexJump);break;case 38:m(),b.decrement();break;case 40:m(),b.increment()}a(k)},b.preventDefault=function(a){a.preventDefault()},b.largestPossibleIndexIs=function(a){b.largestPossibleIndex=a},b.focusInputElement=function(){$(n).focus()};var n=c.find("input"),o=c.find("ul");n.bind("focus",function(){a(m,150),b.isFocused=!0}),n.bind("blur",function(){a(function(){$(n).is(":focus")||(b.closePopup(),g())},150),b.isFocused=!1}),o.bind("mousedown",function(a){a.preventDefault()}),"function"==typeof Hamster&&Hamster(n[0]).wheel(function(c,d,e,f){b.isFocused&&(c.preventDefault(),b.activeIndex-=d,b.activeIndex=Math.min(b.largestPossibleIndex,Math.max(0,b.activeIndex)),b.select(b.dropDownOptions[b.activeIndex],b.activeIndex),a(k))})}}}angular.module("fmTimepicker",[]),angular.module("fmTimepicker").filter("fmTimeFormat",a).filter("fmTimeInterval",b).controller("fmTimepickerController",c).directive("fmTimepickerToggle",d).directive("fmTimepicker",e),c.$inject=["$scope"],e.$inject=["$timeout"]}(),angular.module("fmTimepicker").run(["$templateCache",function(a){a.put("fmTimepicker.html",'<div><div class="input-group"><span class="input-group-btn" ng-if="fmStyle === \'sequential\'"><button type="button" class="{{fmBtnClass}}" ng-click="decrement()" ng-disabled="activeIndex === 0 || fmDisabled"><span class="{{fmIconClasses.minus}}"></span></button></span> <input type="text" class="form-control" ng-model="time" ng-keyup="handleKeyboardInput( $event )" ng-change="update()" ng-disabled="fmDisabled"> <span class="input-group-btn"><button type="button" class="{{fmBtnClass}}" ng-if="fmStyle === \'sequential\'" ng-click="increment()" ng-disabled="activeIndex === largestPossibleIndex || fmDisabled"><span class="{{fmIconClasses.plus}}"></span></button> <button type="button" class="{{fmBtnClass}}" ng-if="fmStyle === \'dropdown\'" ng-class="{active : fmIsOpen}" fm-timepicker-toggle ng-disabled="fmDisabled"><span class="{{fmIconClasses.time}}"></span></button></span></div><div class="dropdown" ng-if="fmStyle === \'dropdown\' && fmIsOpen" ng-class="{open : fmIsOpen}"><ul class="dropdown-menu form-control" style="height:auto; max-height:160px; overflow-y:scroll" ng-mousedown="handleListClick( $event )"><!-- Fill an empty array with time values between start and end time with the given interval, then iterate over that array. --><li ng-repeat="time in ( $parent.dropDownOptions = ( [] | fmTimeInterval:fmStartTime:fmEndTime:fmInterval ) )" ng-click="select( time, $index )" ng-class="{active : activeIndex === $index}"><!-- For each item, check if it is the last item. If it is, communicate the index to a method in the scope. -->{{$last ? largestPossibleIndexIs( $index ) : angular.noop()}}<!-- Render a link into the list item, with the formatted time value. --><a href="#" ng-click="preventDefault( $event )">{{time | fmTimeFormat:fmFormat}}</a></li></ul></div></div>')}]); | ||
!function(){"use strict";function a(){return function(a,b){return"number"==typeof a&&(a=moment(a)),moment(a).format(b)}}function b(){return function(a,b,c,d){if(!b||!c)return a;b=moment(b),c=moment(c),d=d||moment.duration(30,"minutes");for(var e=b.clone();+c>=+e;e.add(d))a.push(+e);return a}}function c(a){if(a.fmReference=a.fmReference?moment(a.fmReference):moment(),a.fmStyle=a.fmStyle||"dropdown",a.fmIsOpen=a.fmIsOpen||!1,a.fmFormat=a.fmFormat||"LT",a.fmStartTime=a.fmStartTime||moment(a.fmReference).startOf("day"),a.fmEndTime=a.fmEndTime||moment(a.fmReference).endOf("day"),a.fmInterval=a.fmInterval||moment.duration(30,"minutes"),a.fmLargeInterval=a.fmLargeInterval||moment.duration(60,"minutes"),a.fmStrict=a.fmStrict||!1,a.fmBtnClass=a.fmBtnClass||"btn btn-default",a.fmIconClasses=a.fmIconClasses||{plus:"glyphicon glyphicon-plus",minus:"glyphicon glyphicon-minus",time:"glyphicon glyphicon-time"},moment.tz&&(a.fmStartTime.tz(a.fmReference.tz()),a.fmEndTime.tz(a.fmReference.tz())),a.fmStrict){var b=a.ngModel.valueOf(),c=a.fmInterval.asMilliseconds();b-=b%c,b+=c,a.ngModel=moment(b)}a.constrainToReference=function(b){return b?(moment.tz&&b.tz(a.fmReference.tz()),b.isSame(a.fmReference,"day")||b.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),b):(a.fmStartTime.isSame(a.fmReference,"day")||a.fmStartTime.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),a.fmEndTime.isSame(a.fmReference,"day")||a.fmEndTime.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),a.ngModel&&!a.ngModel.isSame(a.fmReference,"day")&&a.ngModel.year(a.fmReference.year()).month(a.fmReference.month()).date(a.fmReference.date()),null)},a.constrainToReference(),a.ensureTimeIsWithinBounds=function(b){return b&&moment.isMoment(b)?b.isBefore(a.fmStartTime)?moment(a.fmStartTime):b.isAfter(a.fmEndTime)?moment(a.fmEndTime):b:b},a.ngModel=a.ensureTimeIsWithinBounds(a.ngModel),a.findActiveIndex=function(b){if(a.activeIndex=0,b)for(var c=a.fmStartTime.clone();+c<=+a.fmEndTime&&!c.isSame(b);c.add(a.fmInterval),++a.activeIndex)if(c.isAfter(b)){a.fmStrict&&(a.activeIndex=-1),a.activeIndex-=1;break}},a.largestPossibleIndex=Number.MAX_VALUE,a.largeIntervalIndexJump=Number.MAX_VALUE,a.findActiveIndex(a.ngModel),a.$watch("fmInterval",function(b,c){b.asMilliseconds()<1&&(console.error("[fm-timepicker] Error: Supplied interval length is smaller than 1ms! Reverting to default."),a.fmInterval=moment.duration(30,"minutes"))}),a.$watch("fmLargeInterval",function(b,c){b.asMilliseconds()<10&&(console.error("[fm-timepicker] Error: Supplied large interval length is smaller than 10ms! Reverting to default."),a.fmLargeInterval=moment.duration(60,"minutes"))}),a.$watchCollection("[fmInterval,fmLargeInterval]",function(b){var c=b[0],d=b[1],e=c.asMilliseconds(),f=d.asMilliseconds();0!==f%e&&(console.warn("[fm-timepicker] Warning: Large interval is not a multiple of interval! Using internally computed value instead."),a.fmLargeInterval=moment.duration(5*e),f=a.fmLargeInterval.asMilliseconds()),a.largeIntervalIndexJump=f/e})}function d(){return{restrict:"A",link:function(a,b,c){b.bind("click",function(){a.fmIsOpen?(a.focusInputElement(),a.closePopup()):a.focusInputElement()})}}}function e(a){return{templateUrl:"fmTimepicker.html",replace:!0,restrict:"EA",scope:{ngModel:"=",fmFormat:"=?",fmStartTime:"=?",fmEndTime:"=?",fmReference:"=?",fmInterval:"=?",fmLargeInterval:"=?",fmIsOpen:"=?",fmStyle:"=?",fmStrict:"=?",fmBtnClass:"=?",fmIconClasses:"=?",fmDisabled:"=?"},controller:"fmTimepickerController",require:"ngModel",link:function(b,c,d,e){function f(a){e.$setValidity("time",a),e.$setValidity("bounds",a),e.$setValidity("interval",a),e.$setValidity("start",a),e.$setValidity("end",a),e.$setValidity("required",a)}function g(){f(!0),b.time||(d.required&&e.$setValidity("required",!1),e.$setViewValue(null));var a=h(b.time);if(b.fmStrict&&(a=a&&i(b.time)&&j(b.time)),b.fmStartTime.isValid()||e.$setValidity("start",!1),b.fmEndTime.isValid()||e.$setValidity("end",!1),a){var c;c=moment.tz?moment.tz(b.time,b.fmFormat,b.fmReference.tz()):moment(b.time,b.fmFormat),c=b.constrainToReference(c),e.$setViewValue(c),moment.tz?b.time=moment.tz(b.time,b.fmFormat,b.fmReference.tz()).format(b.fmFormat):b.time=moment(b.time,b.fmFormat).format(b.fmFormat)}}function h(a){if(!a)return!1;var c;return c=moment.tz?a?moment.tz(a,b.fmFormat,b.fmReference.tz()):moment.invalid():a?moment(a,b.fmFormat):moment.invalid(),c.isValid()?(e.$setValidity("time",!0),!0):(e.$setValidity("time",!1),e.$setViewValue(null),!1)}function i(a){var c;return c=moment.tz?a?moment.tz(a,b.fmFormat,b.fmReference.tz()):moment.invalid():a?moment(a,b.fmFormat):moment.invalid(),c=b.constrainToReference(c),!c.isValid()||c.isBefore(b.fmStartTime)||c.isAfter(b.fmEndTime)?(e.$setValidity("bounds",!1),e.$setViewValue(null),!1):(e.$setValidity("bounds",!0),!0)}function j(a){var c;c=moment.tz?a?moment.tz(a,b.fmFormat,b.fmReference.tz()):moment.invalid():a?moment(a,b.fmFormat):moment.invalid();var d=c.isValid();if(d){var f=c.diff(b.fmStartTime),g=b.fmInterval.asMilliseconds();d=0===f%g}return d?(e.$setValidity("interval",!0),!0):(e.$setValidity("interval",!1),e.$setViewValue(null),!1)}function k(){a(function(){b.$apply()}),b.fmIsOpen&&a(l)}function l(){var a=c.find("ul");$(a).scrollTop(0);var b=$("li.active",a),d=b.length?b.position().top:0,e=b.length?b.outerHeight(!0):0;$(a).scrollTop(d-e)}function m(){b.fmIsOpen||(b.fmIsOpen=!0,b.modelPreview=b.ngModel?b.ngModel.clone():b.fmStartTime.clone(),a(k))}b.$watchCollection("[fmStartTime,fmEndTime,fmInterval,fmStrict]",function(){b.constrainToReference(),g()}),b.$watchCollection("[fmStartTime,fmEndTime,fmInterval,ngModel]",function(){b.findActiveIndex(b.ngModel)}),e.$render=function(){var a=moment(e.$modelValue).format(b.fmFormat),c=h(a);b.fmStrict&&(c=c&&i(a)&&j(a)),c&&(b.time=a)},b.closePopup=function(c){c?a(function(){b.fmIsOpen=!1},200):(b.fmIsOpen=!1,a(k))},b.handleListClick=function(a){return a.preventDefault(),!1},b.select=function(a,c){var d;d=moment.tz&&b.fmReference.tz()?moment(a).tz(b.fmReference.tz()):moment(a),b.time=d.format(b.fmFormat),b.activeIndex=c,b.update(),b.closePopup()},b.increment=function(){b.fmIsOpen?(b.modelPreview.add(b.fmInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview)):(b.ngModel.add(b.fmInterval),b.ngModel=b.ensureTimeIsWithinBounds(b.ngModel),b.time=b.ngModel.format(b.fmFormat)),b.activeIndex=Math.min(b.largestPossibleIndex,b.activeIndex+1)},b.decrement=function(){b.fmIsOpen?(b.modelPreview.subtract(b.fmInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview)):(b.ngModel.subtract(b.fmInterval),b.ngModel=b.ensureTimeIsWithinBounds(b.ngModel),b.time=b.ngModel.format(b.fmFormat)),b.activeIndex=Math.max(0,b.activeIndex-1)},b.update=function(){var a=h(b.time)&&i(b.time);if(a){var c;c=moment.tz?moment.tz(b.time,b.fmFormat,b.fmReference.tz()):moment(b.time,b.fmFormat),c=b.constrainToReference(c),e.$setViewValue(c)}},b.handleKeyboardInput=function(c){switch(c.keyCode){case 13:b.modelPreview&&(b.ngModel=b.modelPreview,b.fmIsOpen=!1);break;case 27:b.closePopup();break;case 33:m(),b.modelPreview.subtract(b.fmLargeInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview),b.activeIndex=Math.max(0,b.activeIndex-b.largeIntervalIndexJump);break;case 34:m(),b.modelPreview.add(b.fmLargeInterval),b.modelPreview=b.ensureTimeIsWithinBounds(b.modelPreview),b.activeIndex=Math.min(b.largestPossibleIndex,b.activeIndex+b.largeIntervalIndexJump);break;case 38:m(),b.decrement();break;case 40:m(),b.increment()}a(k)},b.preventDefault=function(a){a.preventDefault()},b.largestPossibleIndexIs=function(a){b.largestPossibleIndex=a},b.focusInputElement=function(){$(n).focus()};var n=c.find("input"),o=c.find("ul");n.bind("focus",function(){a(m,150),b.isFocused=!0}),n.bind("blur",function(){a(function(){$(n).is(":focus")||(b.closePopup(),g())},150),b.isFocused=!1}),o.bind("mousedown",function(a){a.preventDefault()}),"function"==typeof Hamster&&Hamster(n[0]).wheel(function(c,d,e,f){b.isFocused&&(c.preventDefault(),b.activeIndex-=d,b.activeIndex=Math.min(b.largestPossibleIndex,Math.max(0,b.activeIndex)),b.select(b.dropDownOptions[b.activeIndex],b.activeIndex),a(k))})}}}c.$inject=["$scope"],e.$inject=["$timeout"],angular.module("fmTimepicker",[]),angular.module("fmTimepicker").filter("fmTimeFormat",a).filter("fmTimeInterval",b).controller("fmTimepickerController",c).directive("fmTimepickerToggle",d).directive("fmTimepicker",e)}(),angular.module("fmTimepicker").run(["$templateCache",function(a){a.put("fmTimepicker.html",'<div><div class="input-group"><span class="input-group-btn" ng-if="fmStyle === \'sequential\'"><button type="button" class="{{fmBtnClass}}" ng-click="decrement()" ng-disabled="activeIndex === 0 || fmDisabled"><span class="{{fmIconClasses.minus}}"></span></button></span> <input type="text" class="form-control" ng-model="time" ng-keyup="handleKeyboardInput( $event )" ng-change="update()" ng-disabled="fmDisabled"> <span class="input-group-btn"><button type="button" class="{{fmBtnClass}}" ng-if="fmStyle === \'sequential\'" ng-click="increment()" ng-disabled="activeIndex === largestPossibleIndex || fmDisabled"><span class="{{fmIconClasses.plus}}"></span></button> <button type="button" class="{{fmBtnClass}}" ng-if="fmStyle === \'dropdown\'" ng-class="{active : fmIsOpen}" fm-timepicker-toggle ng-disabled="fmDisabled"><span class="{{fmIconClasses.time}}"></span></button></span></div><div class="dropdown" ng-if="fmStyle === \'dropdown\' && fmIsOpen" ng-class="{open : fmIsOpen}"><ul class="dropdown-menu form-control" style="height:auto; max-height:160px; overflow-y:scroll" ng-mousedown="handleListClick( $event )"><!-- Fill an empty array with time values between start and end time with the given interval, then iterate over that array. --><li ng-repeat="time in ( $parent.dropDownOptions = ( [] | fmTimeInterval:fmStartTime:fmEndTime:fmInterval ) )" ng-click="select( time, $index )" ng-class="{active : activeIndex === $index}"><!-- For each item, check if it is the last item. If it is, communicate the index to a method in the scope. -->{{$last ? largestPossibleIndexIs( $index ) : angular.noop()}}<!-- Render a link into the list item, with the formatted time value. --><a href="#" ng-click="preventDefault( $event )">{{time | fmTimeFormat:fmFormat}}</a></li></ul></div></div>')}]); |
{ | ||
"name": "fm-timepicker", | ||
"version": "5.0.1", | ||
"version": "6.0.0", | ||
"description": "FairManager Time Picker Component", | ||
@@ -5,0 +5,0 @@ "main": "src/fm-timepicker.js", |
@@ -182,2 +182,3 @@ /** | ||
} | ||
// Check if we've already passed the time value that would fit our current model. | ||
@@ -197,3 +198,3 @@ if( time.isAfter( model ) ) { | ||
// The index of the last element in our time value collection. | ||
$scope.largestPossibleIndex = Number.MAX_VALUE; | ||
$scope.largestPossibleIndex = Number.MAX_VALUE; | ||
// The amount of list items we should skip when we perform a large jump through the collection. | ||
@@ -223,4 +224,4 @@ $scope.largeIntervalIndexJump = Number.MAX_VALUE; | ||
// Pick array apart. | ||
var newInterval = newValues[ 0 ]; | ||
var newLargeInterval = newValues[ 1 ]; | ||
var newInterval = newValues[ 0 ]; | ||
var newLargeInterval = newValues[ 1 ]; | ||
// Get millisecond values for the intervals. | ||
@@ -250,2 +251,3 @@ var newIntervalMilliseconds = newInterval.asMilliseconds(); | ||
scope.closePopup(); | ||
} else { | ||
@@ -301,3 +303,3 @@ // Focusing the input element will automatically open the popup | ||
// Convert the moment instance we got to a string in our desired format. | ||
var time = moment( controller.$modelValue ).format( scope.fmFormat ); | ||
var time = moment( controller.$modelValue ).format( scope.fmFormat ); | ||
// Check if the given time is valid. | ||
@@ -313,4 +315,2 @@ var timeValid = checkTimeValueValid( time ); | ||
scope.time = time; | ||
} else { | ||
throw new Error( "The provided time value is invalid." ); | ||
} | ||
@@ -329,2 +329,3 @@ }; | ||
controller.$setValidity( "end", to ); | ||
controller.$setValidity( "required", to ); | ||
} | ||
@@ -338,2 +339,10 @@ | ||
resetValidity( true ); | ||
if( !scope.time ) { | ||
if( attributes.required ) { | ||
controller.$setValidity( "required", false ); | ||
} | ||
controller.$setViewValue( null ); | ||
} | ||
// Check if the string in the input box represents a valid date according to the rules set through parameters in our scope. | ||
@@ -385,2 +394,6 @@ var timeValid = checkTimeValueValid( scope.time ); | ||
function checkTimeValueValid( timeString ) { | ||
if( !timeString ) { | ||
return false; | ||
} | ||
var time; | ||
@@ -399,2 +412,3 @@ if( moment.tz ) { | ||
return false; | ||
} else { | ||
@@ -418,5 +432,7 @@ controller.$setValidity( "time", true ); | ||
scope.fmReference.tz() ) : moment.invalid(); | ||
} else { | ||
time = timeString ? moment( timeString, scope.fmFormat ) : moment.invalid(); | ||
} | ||
time = scope.constrainToReference( time ); | ||
@@ -427,2 +443,3 @@ if( !time.isValid() || time.isBefore( scope.fmStartTime ) || time.isAfter( scope.fmEndTime ) ) { | ||
return false; | ||
} else { | ||
@@ -446,2 +463,3 @@ controller.$setValidity( "bounds", true ); | ||
scope.fmReference.tz() ) : moment.invalid(); | ||
} else { | ||
@@ -456,5 +474,5 @@ time = timeString ? moment( timeString, scope.fmFormat ) : moment.invalid(); | ||
// Calculate how many milliseconds are within the given time interval. | ||
var intervalMilliseconds = scope.fmInterval.asMilliseconds(); | ||
var intervalMilliseconds = scope.fmInterval.asMilliseconds(); | ||
// Check if the modulo operation has a remainder. | ||
isValid = ( 0 === ( durationSinceStartTime % intervalMilliseconds ) ); | ||
isValid = ( 0 === ( durationSinceStartTime % intervalMilliseconds ) ); | ||
} | ||
@@ -466,2 +484,3 @@ | ||
return false; | ||
} else { | ||
@@ -497,4 +516,4 @@ controller.$setValidity( "interval", true ); | ||
// Retrieve offset from the top and height of the list element. | ||
var top = selectedListElement.length ? selectedListElement.position().top : 0; | ||
var height = selectedListElement.length ? selectedListElement.outerHeight( true ) : 0; | ||
var top = selectedListElement.length ? selectedListElement.position().top : 0; | ||
var height = selectedListElement.length ? selectedListElement.outerHeight( true ) : 0; | ||
// Scroll the list to bring the selected list element into the view. | ||
@@ -528,2 +547,3 @@ $( popupListElement ).scrollTop( top - height ); | ||
}, 200 ); | ||
} else { | ||
@@ -570,2 +590,3 @@ scope.fmIsOpen = false; | ||
scope.modelPreview = scope.ensureTimeIsWithinBounds( scope.modelPreview ); | ||
} else { | ||
@@ -583,2 +604,3 @@ scope.ngModel.add( scope.fmInterval ); | ||
scope.modelPreview = scope.ensureTimeIsWithinBounds( scope.modelPreview ); | ||
} else { | ||
@@ -603,5 +625,7 @@ scope.ngModel.subtract( scope.fmInterval ); | ||
scope.fmReference.tz() ); | ||
} else { | ||
newTime = moment( scope.time, scope.fmFormat ); | ||
} | ||
newTime = scope.constrainToReference( newTime ); | ||
@@ -621,2 +645,3 @@ controller.$setViewValue( newTime ); | ||
break; | ||
case 27: | ||
@@ -626,2 +651,3 @@ // Escape | ||
break; | ||
case 33: | ||
@@ -635,2 +661,3 @@ // Page up | ||
break; | ||
case 34: | ||
@@ -644,2 +671,3 @@ // Page down | ||
break; | ||
case 38: | ||
@@ -650,2 +678,3 @@ // Up arrow | ||
break; | ||
case 40: | ||
@@ -656,2 +685,3 @@ // Down arrow | ||
break; | ||
default: | ||
@@ -730,7 +760,5 @@ } | ||
} | ||
} | ||
}; | ||
} | ||
})(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
230855
39
3983