X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/3789b528d8dd8aad4558e38e22d775bcab1cbd36..6746dc89c47ed01b165cc1152533605f97eb8e8d:/docs/source/Number3.html diff --git a/docs/source/Number3.html b/docs/source/Number3.html index fd2f71f5..9076b4a7 100644 --- a/docs/source/Number3.html +++ b/docs/source/Number3.html @@ -28,7 +28,7 @@ var isToFixedBroken = (0.9).toFixed() !== '1'; Ext.Number = { /** - * Checks whether or not the current number is within a desired range. If the number is already within the + * Checks whether or not the passed number is within a desired range. If the number is already within the * range it is returned, otherwise the min or max value is returned depending on which side of the range is * exceeded. Note that this method returns the constrained value but does not change the current number. * @param {Number} number The number to check @@ -48,6 +48,33 @@ Ext.Number = { return number; }, + /** + * Snaps the passed number between stopping points based upon a passed increment value. + * @param {Number} value The unsnapped value. + * @param {Number} increment The increment by which the value must move. + * @param {Number} minValue The minimum value to which the returned value must be constrained. Overrides the increment.. + * @param {Number} maxValue The maximum value to which the returned value must be constrained. Overrides the increment.. + * @return {Number} The value of the nearest snap target. + */ + snap : function(value, increment, minValue, maxValue) { + var newValue = value, + m; + + if (!(increment && value)) { + return value; + } + m = value % increment; + if (m !== 0) { + newValue -= m; + if (m * 2 >= increment) { + newValue += increment; + } else if (m * 2 < -increment) { + newValue -= increment; + } + } + return Ext.Number.constrain(newValue, minValue, maxValue); + }, + /** * Formats a number using fixed-point notation * @param {Number} value The number to format