From 684846ade157e4f93ae2c5e3f72b0bd92435659c Mon Sep 17 00:00:00 2001 From: Leon Gersen Date: Wed, 11 Jan 2017 10:23:22 +0100 Subject: [PATCH] add version --- Gruntfile.js | 14 +- README.md | 5 + distribute/nouislider.css | 274 ++++++++++++++++++-------------------- distribute/nouislider.js | 173 +++++++++++++----------- package.json | 2 +- src/js/interface.js | 3 +- src/js/intro.js | 2 + src/js/options.js | 56 ++++---- src/js/pips.js | 102 ++++++++------ src/js/range.js | 6 +- src/js/scope.js | 2 +- 11 files changed, 333 insertions(+), 306 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index d688194c..5761fdb5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -29,11 +29,21 @@ module.exports = function(grunt) { { src: ['**/*'], dest: '', cwd: 'distribute/', expand: true } ]; + var pkg = grunt.file.readJSON('package.json'); + grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), + pkg: pkg, concat: { options: { - banner: VERSION_TEMPLATE + banner: VERSION_TEMPLATE, + process: function(src, filepath) { + + if ( filepath === 'src/js/intro.js' ) { + src = src.replace('%%REPLACE_THIS_WITH_VERSION%%', pkg.version); + } + + return src; + } }, basic: { src: getFiles(), diff --git a/README.md b/README.md index 92b1c370..48a85b74 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,11 @@ npm [(package)](https://www.npmjs.com/package/nouislider) Changelog --------- +### 9.1.1 (*2017-01-17*) +- Added: Version number to exceptions; +- Added: `noUiSlider.version` holds current version number; +- Added: Throw exception on invalid `pips` configuration (#721); + ### 9.1.0 (*2016-12-10*) - Fixed: Slider not properly handling multitouch (#700, #704); - Fixed: Removed a querySelector for the currently active handle (#720); diff --git a/distribute/nouislider.css b/distribute/nouislider.css index d8cea660..395fefc2 100644 --- a/distribute/nouislider.css +++ b/distribute/nouislider.css @@ -1,278 +1,256 @@ -/*! nouislider - 9.1.0 - 2016-12-10 16:00:32 */ - - /* Functional styling; * These styles are required for noUiSlider to function. * You don't need to change these rules to apply your design. */ .noUi-target, .noUi-target * { --webkit-touch-callout: none; --webkit-tap-highlight-color: rgba(0,0,0,0); --webkit-user-select: none; --ms-touch-action: none; - touch-action: none; --ms-user-select: none; --moz-user-select: none; - user-select: none; --moz-box-sizing: border-box; - box-sizing: border-box; + -webkit-touch-callout: none; + -webkit-tap-highlight-color: rgba(0, 0, 0, 0); + -webkit-user-select: none; + -ms-touch-action: none; + touch-action: none; + -ms-user-select: none; + -moz-user-select: none; + user-select: none; + -moz-box-sizing: border-box; + box-sizing: border-box; } .noUi-target { - position: relative; - direction: ltr; + position: relative; + direction: ltr; } .noUi-base { - width: 100%; - height: 100%; - position: relative; - z-index: 1; /* Fix 401 */ + width: 100%; + height: 100%; + position: relative; + z-index: 1; + /* Fix 401 */ } .noUi-connect { - position: absolute; - right: 0; - top: 0; - left: 0; - bottom: 0; + position: absolute; + right: 0; + top: 0; + left: 0; + bottom: 0; } .noUi-origin { - position: absolute; - height: 0; - width: 0; + position: absolute; + height: 0; + width: 0; } .noUi-handle { - position: relative; - z-index: 1; + position: relative; + z-index: 1; } .noUi-state-tap .noUi-connect, .noUi-state-tap .noUi-origin { --webkit-transition: top 0.3s, right 0.3s, bottom 0.3s, left 0.3s; - transition: top 0.3s, right 0.3s, bottom 0.3s, left 0.3s; + -webkit-transition: top 0.3s, right 0.3s, bottom 0.3s, left 0.3s; + transition: top 0.3s, right 0.3s, bottom 0.3s, left 0.3s; } .noUi-state-drag * { - cursor: inherit !important; + cursor: inherit !important; } - /* Painting and performance; * Browsers can paint handles in their own layer. */ .noUi-base, .noUi-handle { - -webkit-transform: translate3d(0,0,0); - transform: translate3d(0,0,0); + -webkit-transform: translate3d(0, 0, 0); + transform: translate3d(0, 0, 0); } - /* Slider size and handle placement; */ .noUi-horizontal { - height: 18px; + height: 18px; } .noUi-horizontal .noUi-handle { - width: 34px; - height: 28px; - left: -17px; - top: -6px; + width: 34px; + height: 28px; + left: -17px; + top: -6px; } .noUi-vertical { - width: 18px; + width: 18px; } .noUi-vertical .noUi-handle { - width: 28px; - height: 34px; - left: -6px; - top: -17px; + width: 28px; + height: 34px; + left: -6px; + top: -17px; } - /* Styling; */ .noUi-target { - background: #FAFAFA; - border-radius: 4px; - border: 1px solid #D3D3D3; - box-shadow: inset 0 1px 1px #F0F0F0, 0 3px 6px -5px #BBB; + background: #FAFAFA; + border-radius: 4px; + border: 1px solid #D3D3D3; + box-shadow: inset 0 1px 1px #F0F0F0, 0 3px 6px -5px #BBB; } .noUi-connect { - background: #3FB8AF; - box-shadow: inset 0 0 3px rgba(51,51,51,0.45); --webkit-transition: background 450ms; - transition: background 450ms; + background: #3FB8AF; + box-shadow: inset 0 0 3px rgba(51, 51, 51, 0.45); + -webkit-transition: background 450ms; + transition: background 450ms; } - /* Handles and cursors; */ .noUi-draggable { - cursor: ew-resize; + cursor: ew-resize; } .noUi-vertical .noUi-draggable { - cursor: ns-resize; + cursor: ns-resize; } .noUi-handle { - border: 1px solid #D9D9D9; - border-radius: 3px; - background: #FFF; - cursor: default; - box-shadow: inset 0 0 1px #FFF, - inset 0 1px 7px #EBEBEB, - 0 3px 6px -3px #BBB; + border: 1px solid #D9D9D9; + border-radius: 3px; + background: #FFF; + cursor: default; + box-shadow: inset 0 0 1px #FFF, inset 0 1px 7px #EBEBEB, 0 3px 6px -3px #BBB; } .noUi-active { - box-shadow: inset 0 0 1px #FFF, - inset 0 1px 7px #DDD, - 0 3px 6px -3px #BBB; + box-shadow: inset 0 0 1px #FFF, inset 0 1px 7px #DDD, 0 3px 6px -3px #BBB; } - /* Handle stripes; */ .noUi-handle:before, .noUi-handle:after { - content: ""; - display: block; - position: absolute; - height: 14px; - width: 1px; - background: #E8E7E6; - left: 14px; - top: 6px; + content: ""; + display: block; + position: absolute; + height: 14px; + width: 1px; + background: #E8E7E6; + left: 14px; + top: 6px; } .noUi-handle:after { - left: 17px; + left: 17px; } .noUi-vertical .noUi-handle:before, .noUi-vertical .noUi-handle:after { - width: 14px; - height: 1px; - left: 6px; - top: 14px; + width: 14px; + height: 1px; + left: 6px; + top: 14px; } .noUi-vertical .noUi-handle:after { - top: 17px; + top: 17px; } - /* Disabled state; */ - [disabled] .noUi-connect { - background: #B8B8B8; + background: #B8B8B8; } [disabled].noUi-target, [disabled].noUi-handle, [disabled] .noUi-handle { - cursor: not-allowed; + cursor: not-allowed; } - - /* Base; * */ .noUi-pips, .noUi-pips * { --moz-box-sizing: border-box; - box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; } .noUi-pips { - position: absolute; - color: #999; + position: absolute; + color: #999; } - /* Values; * */ .noUi-value { - position: absolute; - text-align: center; + position: absolute; + text-align: center; } .noUi-value-sub { - color: #ccc; - font-size: 10px; + color: #ccc; + font-size: 10px; } - /* Markings; * */ .noUi-marker { - position: absolute; - background: #CCC; + position: absolute; + background: #CCC; } .noUi-marker-sub { - background: #AAA; + background: #AAA; } .noUi-marker-large { - background: #AAA; + background: #AAA; } - /* Horizontal layout; * */ .noUi-pips-horizontal { - padding: 10px 0; - height: 80px; - top: 100%; - left: 0; - width: 100%; + padding: 10px 0; + height: 80px; + top: 100%; + left: 0; + width: 100%; } .noUi-value-horizontal { - -webkit-transform: translate3d(-50%,50%,0); - transform: translate3d(-50%,50%,0); + -webkit-transform: translate3d(-50%, 50%, 0); + transform: translate3d(-50%, 50%, 0); } - .noUi-marker-horizontal.noUi-marker { - margin-left: -1px; - width: 2px; - height: 5px; + margin-left: -1px; + width: 2px; + height: 5px; } .noUi-marker-horizontal.noUi-marker-sub { - height: 10px; + height: 10px; } .noUi-marker-horizontal.noUi-marker-large { - height: 15px; + height: 15px; } - /* Vertical layout; * */ .noUi-pips-vertical { - padding: 0 10px; - height: 100%; - top: 0; - left: 100%; + padding: 0 10px; + height: 100%; + top: 0; + left: 100%; } .noUi-value-vertical { - -webkit-transform: translate3d(0,50%,0); - transform: translate3d(0,50%,0); - padding-left: 25px; + -webkit-transform: translate3d(0, 50%, 0); + transform: translate3d(0, 50%, 0); + padding-left: 25px; } - .noUi-marker-vertical.noUi-marker { - width: 5px; - height: 2px; - margin-top: -1px; + width: 5px; + height: 2px; + margin-top: -1px; } .noUi-marker-vertical.noUi-marker-sub { - width: 10px; + width: 10px; } .noUi-marker-vertical.noUi-marker-large { - width: 15px; + width: 15px; } - .noUi-tooltip { - display: block; - position: absolute; - border: 1px solid #D9D9D9; - border-radius: 3px; - background: #fff; - color: #000; - padding: 5px; - text-align: center; + display: block; + position: absolute; + border: 1px solid #D9D9D9; + border-radius: 3px; + background: #fff; + color: #000; + padding: 5px; + text-align: center; } .noUi-horizontal .noUi-tooltip { --webkit-transform: translate(-50%, 0); - transform: translate(-50%, 0); - left: 50%; - bottom: 120%; + -webkit-transform: translate(-50%, 0); + transform: translate(-50%, 0); + left: 50%; + bottom: 120%; } .noUi-vertical .noUi-tooltip { --webkit-transform: translate(0, -50%); - transform: translate(0, -50%); - top: 50%; - right: 120%; + -webkit-transform: translate(0, -50%); + transform: translate(0, -50%); + top: 50%; + right: 120%; } diff --git a/distribute/nouislider.js b/distribute/nouislider.js index e02404f2..9e277bf7 100644 --- a/distribute/nouislider.js +++ b/distribute/nouislider.js @@ -1,4 +1,4 @@ -/*! nouislider - 9.1.0 - 2016-12-10 16:00:32 */ +/*! nouislider - 9.1.1 - 2017-01-11 10:01:29 */ (function (factory) { @@ -22,6 +22,8 @@ 'use strict'; + var VERSION = '9.1.1'; + // Creates a node, adds it to target, returns the new node. function addNodeTo ( target, className ) { @@ -274,7 +276,7 @@ // Reject any invalid input, by testing whether value is an array. if ( Object.prototype.toString.call( value ) !== '[object Array]' ){ - throw new Error("noUiSlider: 'range' contains invalid value."); + throw new Error("noUiSlider (" + VERSION + "): 'range' contains invalid value."); } // Covert min/max syntax to 0 and 100. @@ -288,7 +290,7 @@ // Check for correct input. if ( !isNumeric( percentage ) || !isNumeric( value[0] ) ) { - throw new Error("noUiSlider: 'range' value isn't numeric."); + throw new Error("noUiSlider (" + VERSION + "): 'range' value isn't numeric."); } // Store values. @@ -385,7 +387,7 @@ var step = this.xNumSteps[0]; if ( step && ((value / step) % 1) !== 0 ) { - throw new Error("noUiSlider: 'limit', 'margin' and 'padding' must be divisible by step."); + throw new Error("noUiSlider (" + VERSION + "): 'limit', 'margin' and 'padding' must be divisible by step."); } return this.xPct.length === 2 ? fromPercentage(this.xVal, value) : false; @@ -451,7 +453,7 @@ function testStep ( parsed, entry ) { if ( !isNumeric( entry ) ) { - throw new Error("noUiSlider: 'step' is not numeric."); + throw new Error("noUiSlider (" + VERSION + "): 'step' is not numeric."); } // The step option can still be used to set stepping @@ -463,17 +465,17 @@ // Filter incorrect input. if ( typeof entry !== 'object' || Array.isArray(entry) ) { - throw new Error("noUiSlider: 'range' is not an object."); + throw new Error("noUiSlider (" + VERSION + "): 'range' is not an object."); } // Catch missing start or end. if ( entry.min === undefined || entry.max === undefined ) { - throw new Error("noUiSlider: Missing 'min' or 'max' in 'range'."); + throw new Error("noUiSlider (" + VERSION + "): Missing 'min' or 'max' in 'range'."); } // Catch equal start or end. if ( entry.min === entry.max ) { - throw new Error("noUiSlider: 'range' 'min' and 'max' cannot be equal."); + throw new Error("noUiSlider (" + VERSION + "): 'range' 'min' and 'max' cannot be equal."); } parsed.spectrum = new Spectrum(entry, parsed.snap, parsed.dir, parsed.singleStep); @@ -486,7 +488,7 @@ // Validate input. Values aren't tested, as the public .val method // will always provide a valid location. if ( !Array.isArray( entry ) || !entry.length ) { - throw new Error("noUiSlider: 'start' option is incorrect."); + throw new Error("noUiSlider (" + VERSION + "): 'start' option is incorrect."); } // Store the number of handles. @@ -503,7 +505,7 @@ parsed.snap = entry; if ( typeof entry !== 'boolean' ){ - throw new Error("noUiSlider: 'snap' option must be a boolean."); + throw new Error("noUiSlider (" + VERSION + "): 'snap' option must be a boolean."); } } @@ -513,7 +515,7 @@ parsed.animate = entry; if ( typeof entry !== 'boolean' ){ - throw new Error("noUiSlider: 'animate' option must be a boolean."); + throw new Error("noUiSlider (" + VERSION + "): 'animate' option must be a boolean."); } } @@ -522,7 +524,7 @@ parsed.animationDuration = entry; if ( typeof entry !== 'number' ){ - throw new Error("noUiSlider: 'animationDuration' option must be a number."); + throw new Error("noUiSlider (" + VERSION + "): 'animationDuration' option must be a number."); } } @@ -552,7 +554,7 @@ // Reject invalid input else if ( !Array.isArray( entry ) || !entry.length || entry.length !== parsed.handles + 1 ) { - throw new Error("noUiSlider: 'connect' option doesn't match handle count."); + throw new Error("noUiSlider (" + VERSION + "): 'connect' option doesn't match handle count."); } else { @@ -574,14 +576,14 @@ parsed.ort = 1; break; default: - throw new Error("noUiSlider: 'orientation' option is invalid."); + throw new Error("noUiSlider (" + VERSION + "): 'orientation' option is invalid."); } } function testMargin ( parsed, entry ) { if ( !isNumeric(entry) ){ - throw new Error("noUiSlider: 'margin' option must be numeric."); + throw new Error("noUiSlider (" + VERSION + "): 'margin' option must be numeric."); } // Issue #582 @@ -592,27 +594,27 @@ parsed.margin = parsed.spectrum.getMargin(entry); if ( !parsed.margin ) { - throw new Error("noUiSlider: 'margin' option is only supported on linear sliders."); + throw new Error("noUiSlider (" + VERSION + "): 'margin' option is only supported on linear sliders."); } } function testLimit ( parsed, entry ) { if ( !isNumeric(entry) ){ - throw new Error("noUiSlider: 'limit' option must be numeric."); + throw new Error("noUiSlider (" + VERSION + "): 'limit' option must be numeric."); } parsed.limit = parsed.spectrum.getMargin(entry); if ( !parsed.limit || parsed.handles < 2 ) { - throw new Error("noUiSlider: 'limit' option is only supported on linear sliders with 2 or more handles."); + throw new Error("noUiSlider (" + VERSION + "): 'limit' option is only supported on linear sliders with 2 or more handles."); } } function testPadding ( parsed, entry ) { if ( !isNumeric(entry) ){ - throw new Error("noUiSlider: 'padding' option must be numeric."); + throw new Error("noUiSlider (" + VERSION + "): 'padding' option must be numeric."); } if ( entry === 0 ) { @@ -622,15 +624,15 @@ parsed.padding = parsed.spectrum.getMargin(entry); if ( !parsed.padding ) { - throw new Error("noUiSlider: 'padding' option is only supported on linear sliders."); + throw new Error("noUiSlider (" + VERSION + "): 'padding' option is only supported on linear sliders."); } if ( parsed.padding < 0 ) { - throw new Error("noUiSlider: 'padding' option must be a positive number."); + throw new Error("noUiSlider (" + VERSION + "): 'padding' option must be a positive number."); } if ( parsed.padding >= 50 ) { - throw new Error("noUiSlider: 'padding' option must be less than half the range."); + throw new Error("noUiSlider (" + VERSION + "): 'padding' option must be less than half the range."); } } @@ -647,7 +649,7 @@ parsed.dir = 1; break; default: - throw new Error("noUiSlider: 'direction' option was not recognized."); + throw new Error("noUiSlider (" + VERSION + "): 'direction' option was not recognized."); } } @@ -655,7 +657,7 @@ // Make sure the input is a string. if ( typeof entry !== 'string' ) { - throw new Error("noUiSlider: 'behaviour' must be a string containing options."); + throw new Error("noUiSlider (" + VERSION + "): 'behaviour' must be a string containing options."); } // Check if the string contains any keywords. @@ -669,7 +671,7 @@ if ( fixed ) { if ( parsed.handles !== 2 ) { - throw new Error("noUiSlider: 'fixed' behaviour must be used with 2 handles"); + throw new Error("noUiSlider (" + VERSION + "): 'fixed' behaviour must be used with 2 handles"); } // Use margin to enforce fixed state @@ -705,12 +707,12 @@ parsed.tooltips = asArray(entry); if ( parsed.tooltips.length !== parsed.handles ) { - throw new Error("noUiSlider: must pass a formatter for all handles."); + throw new Error("noUiSlider (" + VERSION + "): must pass a formatter for all handles."); } parsed.tooltips.forEach(function(formatter){ if ( typeof formatter !== 'boolean' && (typeof formatter !== 'object' || typeof formatter.to !== 'function') ) { - throw new Error("noUiSlider: 'tooltips' must be passed a formatter or 'false'."); + throw new Error("noUiSlider (" + VERSION + "): 'tooltips' must be passed a formatter or 'false'."); } }); } @@ -725,13 +727,13 @@ return true; } - throw new Error("noUiSlider: 'format' requires 'to' and 'from' methods."); + throw new Error("noUiSlider (" + VERSION + "): 'format' requires 'to' and 'from' methods."); } function testCssPrefix ( parsed, entry ) { if ( entry !== undefined && typeof entry !== 'string' && entry !== false ) { - throw new Error("noUiSlider: 'cssPrefix' must be a string or `false`."); + throw new Error("noUiSlider (" + VERSION + "): 'cssPrefix' must be a string or `false`."); } parsed.cssPrefix = entry; @@ -740,7 +742,7 @@ function testCssClasses ( parsed, entry ) { if ( entry !== undefined && typeof entry !== 'object' ) { - throw new Error("noUiSlider: 'cssClasses' must be an object."); + throw new Error("noUiSlider (" + VERSION + "): 'cssClasses' must be an object."); } if ( typeof parsed.cssPrefix === 'string' ) { @@ -760,7 +762,7 @@ if ( entry === true || entry === false ) { parsed.useRequestAnimationFrame = entry; } else { - throw new Error("noUiSlider: 'useRequestAnimationFrame' option should be true (default) or false."); + throw new Error("noUiSlider (" + VERSION + "): 'useRequestAnimationFrame' option should be true (default) or false."); } } @@ -854,7 +856,7 @@ if ( options[name] === undefined && defaults[name] === undefined ) { if ( tests[name].r ) { - throw new Error("noUiSlider: '" + name + "' is required."); + throw new Error("noUiSlider (" + VERSION + "): '" + name + "' is required."); } return true; @@ -1005,12 +1007,19 @@ function closure ( target, options, originalOptions ){ if ( mode === 'count' ) { + if ( !values ) { + throw new Error("noUiSlider (" + VERSION + "): 'values' required for mode 'count'."); + } + // Divide 0 - 100 in 'count' parts. - var spread = ( 100 / (values-1) ), v, i = 0; + var spread = ( 100 / (values - 1) ); + var v; + var i = 0; + values = []; // List these parts and have them handled as 'positions'. - while ((v=i++*spread) <= 100 ) { + while ( (v = i++ * spread) <= 100 ) { values.push(v); } @@ -1050,12 +1059,12 @@ function closure ( target, options, originalOptions ){ return (value + increment).toFixed(7) / 1; } - var indexes = {}, - firstInRange = scope_Spectrum.xVal[0], - lastInRange = scope_Spectrum.xVal[scope_Spectrum.xVal.length-1], - ignoreFirst = false, - ignoreLast = false, - prevPct = 0; + var indexes = {}; + var firstInRange = scope_Spectrum.xVal[0]; + var lastInRange = scope_Spectrum.xVal[scope_Spectrum.xVal.length-1]; + var ignoreFirst = false; + var ignoreLast = false; + var prevPct = 0; // Create a copy of the group, sort it and filter away all duplicates. group = unique(group.slice().sort(function(a, b){ return a - b; })); @@ -1075,11 +1084,18 @@ function closure ( target, options, originalOptions ){ group.forEach(function ( current, index ) { // Get the current step and the lower + upper positions. - var step, i, q, - low = current, - high = group[index+1], - newPct, pctDifference, pctPos, type, - steps, realSteps, stepsize; + var step; + var i; + var q; + var low = current; + var high = group[index+1]; + var newPct; + var pctDifference; + var pctPos; + var type; + var steps; + var realSteps; + var stepsize; // When using 'steps' mode, use the provided steps. // Otherwise, we'll step on to the next subrange. @@ -1153,34 +1169,34 @@ function closure ( target, options, originalOptions ){ function addMarking ( spread, filterFunc, formatter ) { - var element = document.createElement('div'), - out = '', - valueSizeClasses = [ - options.cssClasses.valueNormal, - options.cssClasses.valueLarge, - options.cssClasses.valueSub - ], - markerSizeClasses = [ - options.cssClasses.markerNormal, - options.cssClasses.markerLarge, - options.cssClasses.markerSub - ], - valueOrientationClasses = [ - options.cssClasses.valueHorizontal, - options.cssClasses.valueVertical - ], - markerOrientationClasses = [ - options.cssClasses.markerHorizontal, - options.cssClasses.markerVertical - ]; + var element = document.createElement('div'); + var out = ''; + var valueSizeClasses = [ + options.cssClasses.valueNormal, + options.cssClasses.valueLarge, + options.cssClasses.valueSub + ]; + var markerSizeClasses = [ + options.cssClasses.markerNormal, + options.cssClasses.markerLarge, + options.cssClasses.markerSub + ]; + var valueOrientationClasses = [ + options.cssClasses.valueHorizontal, + options.cssClasses.valueVertical + ]; + var markerOrientationClasses = [ + options.cssClasses.markerHorizontal, + options.cssClasses.markerVertical + ]; addClass(element, options.cssClasses.pips); addClass(element, options.ort === 0 ? options.cssClasses.pipsHorizontal : options.cssClasses.pipsVertical); function getClasses( type, source ){ - var a = source === options.cssClasses.value, - orientationClasses = a ? valueOrientationClasses : markerOrientationClasses, - sizeClasses = a ? valueSizeClasses : markerSizeClasses; + var a = source === options.cssClasses.value; + var orientationClasses = a ? valueOrientationClasses : markerOrientationClasses; + var sizeClasses = a ? valueSizeClasses : markerSizeClasses; return source + ' ' + orientationClasses[options.ort] + ' ' + sizeClasses[type]; } @@ -1215,14 +1231,14 @@ function closure ( target, options, originalOptions ){ function pips ( grid ) { - var mode = grid.mode, - density = grid.density || 1, - filter = grid.filter || false, - values = grid.values || false, - stepped = grid.stepped || false, - group = getGroup( mode, values, stepped ), - spread = generateSpread( density, mode, group ), - format = grid.format || { + var mode = grid.mode; + var density = grid.density || 1; + var filter = grid.filter || false; + var values = grid.values || false; + var stepped = grid.stepped || false; + var group = getGroup( mode, values, stepped ); + var spread = generateSpread( density, mode, group ); + var format = grid.format || { to: Math.round }; @@ -2062,7 +2078,7 @@ function closure ( target, options, originalOptions ){ // Throw an error if the slider was already initialized. if ( scope_Target.noUiSlider ) { - throw new Error('Slider was already initialized.'); + throw new Error("noUiSlider (" + VERSION + "): Slider was already initialized."); } // Create the base element, initialise HTML and set classes. @@ -2109,7 +2125,7 @@ function closure ( target, options, originalOptions ){ function initialize ( target, originalOptions ) { if ( !target.nodeName ) { - throw new Error('noUiSlider.create requires a single element.'); + throw new Error("noUiSlider (" + VERSION + "): create requires a single element."); } // Test the options and create the slider environment; @@ -2123,6 +2139,7 @@ function closure ( target, options, originalOptions ){ // Use an object instead of a function for future expansibility; return { + version: VERSION, create: initialize }; diff --git a/package.json b/package.json index 8c8b4e6f..b93e19ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nouislider", - "version": "9.1.0", + "version": "9.1.1", "main": "distribute/nouislider", "style": "distribute/nouislider.min.css", "license": "WTFPL", diff --git a/src/js/interface.js b/src/js/interface.js index 5a98625c..e45716ca 100644 --- a/src/js/interface.js +++ b/src/js/interface.js @@ -3,7 +3,7 @@ function initialize ( target, originalOptions ) { if ( !target.nodeName ) { - throw new Error('noUiSlider.create requires a single element.'); + throw new Error("noUiSlider (" + VERSION + "): create requires a single element."); } // Test the options and create the slider environment; @@ -17,5 +17,6 @@ // Use an object instead of a function for future expansibility; return { + version: VERSION, create: initialize }; diff --git a/src/js/intro.js b/src/js/intro.js index be3175e5..b0a4368a 100644 --- a/src/js/intro.js +++ b/src/js/intro.js @@ -19,3 +19,5 @@ }(function( ){ 'use strict'; + + var VERSION = '%%REPLACE_THIS_WITH_VERSION%%'; diff --git a/src/js/options.js b/src/js/options.js index 3caf0734..8de17cd4 100644 --- a/src/js/options.js +++ b/src/js/options.js @@ -18,7 +18,7 @@ function testStep ( parsed, entry ) { if ( !isNumeric( entry ) ) { - throw new Error("noUiSlider: 'step' is not numeric."); + throw new Error("noUiSlider (" + VERSION + "): 'step' is not numeric."); } // The step option can still be used to set stepping @@ -30,17 +30,17 @@ // Filter incorrect input. if ( typeof entry !== 'object' || Array.isArray(entry) ) { - throw new Error("noUiSlider: 'range' is not an object."); + throw new Error("noUiSlider (" + VERSION + "): 'range' is not an object."); } // Catch missing start or end. if ( entry.min === undefined || entry.max === undefined ) { - throw new Error("noUiSlider: Missing 'min' or 'max' in 'range'."); + throw new Error("noUiSlider (" + VERSION + "): Missing 'min' or 'max' in 'range'."); } // Catch equal start or end. if ( entry.min === entry.max ) { - throw new Error("noUiSlider: 'range' 'min' and 'max' cannot be equal."); + throw new Error("noUiSlider (" + VERSION + "): 'range' 'min' and 'max' cannot be equal."); } parsed.spectrum = new Spectrum(entry, parsed.snap, parsed.dir, parsed.singleStep); @@ -53,7 +53,7 @@ // Validate input. Values aren't tested, as the public .val method // will always provide a valid location. if ( !Array.isArray( entry ) || !entry.length ) { - throw new Error("noUiSlider: 'start' option is incorrect."); + throw new Error("noUiSlider (" + VERSION + "): 'start' option is incorrect."); } // Store the number of handles. @@ -70,7 +70,7 @@ parsed.snap = entry; if ( typeof entry !== 'boolean' ){ - throw new Error("noUiSlider: 'snap' option must be a boolean."); + throw new Error("noUiSlider (" + VERSION + "): 'snap' option must be a boolean."); } } @@ -80,7 +80,7 @@ parsed.animate = entry; if ( typeof entry !== 'boolean' ){ - throw new Error("noUiSlider: 'animate' option must be a boolean."); + throw new Error("noUiSlider (" + VERSION + "): 'animate' option must be a boolean."); } } @@ -89,7 +89,7 @@ parsed.animationDuration = entry; if ( typeof entry !== 'number' ){ - throw new Error("noUiSlider: 'animationDuration' option must be a number."); + throw new Error("noUiSlider (" + VERSION + "): 'animationDuration' option must be a number."); } } @@ -119,7 +119,7 @@ // Reject invalid input else if ( !Array.isArray( entry ) || !entry.length || entry.length !== parsed.handles + 1 ) { - throw new Error("noUiSlider: 'connect' option doesn't match handle count."); + throw new Error("noUiSlider (" + VERSION + "): 'connect' option doesn't match handle count."); } else { @@ -141,14 +141,14 @@ parsed.ort = 1; break; default: - throw new Error("noUiSlider: 'orientation' option is invalid."); + throw new Error("noUiSlider (" + VERSION + "): 'orientation' option is invalid."); } } function testMargin ( parsed, entry ) { if ( !isNumeric(entry) ){ - throw new Error("noUiSlider: 'margin' option must be numeric."); + throw new Error("noUiSlider (" + VERSION + "): 'margin' option must be numeric."); } // Issue #582 @@ -159,27 +159,27 @@ parsed.margin = parsed.spectrum.getMargin(entry); if ( !parsed.margin ) { - throw new Error("noUiSlider: 'margin' option is only supported on linear sliders."); + throw new Error("noUiSlider (" + VERSION + "): 'margin' option is only supported on linear sliders."); } } function testLimit ( parsed, entry ) { if ( !isNumeric(entry) ){ - throw new Error("noUiSlider: 'limit' option must be numeric."); + throw new Error("noUiSlider (" + VERSION + "): 'limit' option must be numeric."); } parsed.limit = parsed.spectrum.getMargin(entry); if ( !parsed.limit || parsed.handles < 2 ) { - throw new Error("noUiSlider: 'limit' option is only supported on linear sliders with 2 or more handles."); + throw new Error("noUiSlider (" + VERSION + "): 'limit' option is only supported on linear sliders with 2 or more handles."); } } function testPadding ( parsed, entry ) { if ( !isNumeric(entry) ){ - throw new Error("noUiSlider: 'padding' option must be numeric."); + throw new Error("noUiSlider (" + VERSION + "): 'padding' option must be numeric."); } if ( entry === 0 ) { @@ -189,15 +189,15 @@ parsed.padding = parsed.spectrum.getMargin(entry); if ( !parsed.padding ) { - throw new Error("noUiSlider: 'padding' option is only supported on linear sliders."); + throw new Error("noUiSlider (" + VERSION + "): 'padding' option is only supported on linear sliders."); } if ( parsed.padding < 0 ) { - throw new Error("noUiSlider: 'padding' option must be a positive number."); + throw new Error("noUiSlider (" + VERSION + "): 'padding' option must be a positive number."); } if ( parsed.padding >= 50 ) { - throw new Error("noUiSlider: 'padding' option must be less than half the range."); + throw new Error("noUiSlider (" + VERSION + "): 'padding' option must be less than half the range."); } } @@ -214,7 +214,7 @@ parsed.dir = 1; break; default: - throw new Error("noUiSlider: 'direction' option was not recognized."); + throw new Error("noUiSlider (" + VERSION + "): 'direction' option was not recognized."); } } @@ -222,7 +222,7 @@ // Make sure the input is a string. if ( typeof entry !== 'string' ) { - throw new Error("noUiSlider: 'behaviour' must be a string containing options."); + throw new Error("noUiSlider (" + VERSION + "): 'behaviour' must be a string containing options."); } // Check if the string contains any keywords. @@ -236,7 +236,7 @@ if ( fixed ) { if ( parsed.handles !== 2 ) { - throw new Error("noUiSlider: 'fixed' behaviour must be used with 2 handles"); + throw new Error("noUiSlider (" + VERSION + "): 'fixed' behaviour must be used with 2 handles"); } // Use margin to enforce fixed state @@ -272,12 +272,12 @@ parsed.tooltips = asArray(entry); if ( parsed.tooltips.length !== parsed.handles ) { - throw new Error("noUiSlider: must pass a formatter for all handles."); + throw new Error("noUiSlider (" + VERSION + "): must pass a formatter for all handles."); } parsed.tooltips.forEach(function(formatter){ if ( typeof formatter !== 'boolean' && (typeof formatter !== 'object' || typeof formatter.to !== 'function') ) { - throw new Error("noUiSlider: 'tooltips' must be passed a formatter or 'false'."); + throw new Error("noUiSlider (" + VERSION + "): 'tooltips' must be passed a formatter or 'false'."); } }); } @@ -292,13 +292,13 @@ return true; } - throw new Error("noUiSlider: 'format' requires 'to' and 'from' methods."); + throw new Error("noUiSlider (" + VERSION + "): 'format' requires 'to' and 'from' methods."); } function testCssPrefix ( parsed, entry ) { if ( entry !== undefined && typeof entry !== 'string' && entry !== false ) { - throw new Error("noUiSlider: 'cssPrefix' must be a string or `false`."); + throw new Error("noUiSlider (" + VERSION + "): 'cssPrefix' must be a string or `false`."); } parsed.cssPrefix = entry; @@ -307,7 +307,7 @@ function testCssClasses ( parsed, entry ) { if ( entry !== undefined && typeof entry !== 'object' ) { - throw new Error("noUiSlider: 'cssClasses' must be an object."); + throw new Error("noUiSlider (" + VERSION + "): 'cssClasses' must be an object."); } if ( typeof parsed.cssPrefix === 'string' ) { @@ -327,7 +327,7 @@ if ( entry === true || entry === false ) { parsed.useRequestAnimationFrame = entry; } else { - throw new Error("noUiSlider: 'useRequestAnimationFrame' option should be true (default) or false."); + throw new Error("noUiSlider (" + VERSION + "): 'useRequestAnimationFrame' option should be true (default) or false."); } } @@ -421,7 +421,7 @@ if ( options[name] === undefined && defaults[name] === undefined ) { if ( tests[name].r ) { - throw new Error("noUiSlider: '" + name + "' is required."); + throw new Error("noUiSlider (" + VERSION + "): '" + name + "' is required."); } return true; diff --git a/src/js/pips.js b/src/js/pips.js index b1f665e6..8bd74482 100644 --- a/src/js/pips.js +++ b/src/js/pips.js @@ -8,12 +8,19 @@ if ( mode === 'count' ) { + if ( !values ) { + throw new Error("noUiSlider (" + VERSION + "): 'values' required for mode 'count'."); + } + // Divide 0 - 100 in 'count' parts. - var spread = ( 100 / (values-1) ), v, i = 0; + var spread = ( 100 / (values - 1) ); + var v; + var i = 0; + values = []; // List these parts and have them handled as 'positions'. - while ((v=i++*spread) <= 100 ) { + while ( (v = i++ * spread) <= 100 ) { values.push(v); } @@ -53,12 +60,12 @@ return (value + increment).toFixed(7) / 1; } - var indexes = {}, - firstInRange = scope_Spectrum.xVal[0], - lastInRange = scope_Spectrum.xVal[scope_Spectrum.xVal.length-1], - ignoreFirst = false, - ignoreLast = false, - prevPct = 0; + var indexes = {}; + var firstInRange = scope_Spectrum.xVal[0]; + var lastInRange = scope_Spectrum.xVal[scope_Spectrum.xVal.length-1]; + var ignoreFirst = false; + var ignoreLast = false; + var prevPct = 0; // Create a copy of the group, sort it and filter away all duplicates. group = unique(group.slice().sort(function(a, b){ return a - b; })); @@ -78,11 +85,18 @@ group.forEach(function ( current, index ) { // Get the current step and the lower + upper positions. - var step, i, q, - low = current, - high = group[index+1], - newPct, pctDifference, pctPos, type, - steps, realSteps, stepsize; + var step; + var i; + var q; + var low = current; + var high = group[index+1]; + var newPct; + var pctDifference; + var pctPos; + var type; + var steps; + var realSteps; + var stepsize; // When using 'steps' mode, use the provided steps. // Otherwise, we'll step on to the next subrange. @@ -156,34 +170,34 @@ function addMarking ( spread, filterFunc, formatter ) { - var element = document.createElement('div'), - out = '', - valueSizeClasses = [ - options.cssClasses.valueNormal, - options.cssClasses.valueLarge, - options.cssClasses.valueSub - ], - markerSizeClasses = [ - options.cssClasses.markerNormal, - options.cssClasses.markerLarge, - options.cssClasses.markerSub - ], - valueOrientationClasses = [ - options.cssClasses.valueHorizontal, - options.cssClasses.valueVertical - ], - markerOrientationClasses = [ - options.cssClasses.markerHorizontal, - options.cssClasses.markerVertical - ]; + var element = document.createElement('div'); + var out = ''; + var valueSizeClasses = [ + options.cssClasses.valueNormal, + options.cssClasses.valueLarge, + options.cssClasses.valueSub + ]; + var markerSizeClasses = [ + options.cssClasses.markerNormal, + options.cssClasses.markerLarge, + options.cssClasses.markerSub + ]; + var valueOrientationClasses = [ + options.cssClasses.valueHorizontal, + options.cssClasses.valueVertical + ]; + var markerOrientationClasses = [ + options.cssClasses.markerHorizontal, + options.cssClasses.markerVertical + ]; addClass(element, options.cssClasses.pips); addClass(element, options.ort === 0 ? options.cssClasses.pipsHorizontal : options.cssClasses.pipsVertical); function getClasses( type, source ){ - var a = source === options.cssClasses.value, - orientationClasses = a ? valueOrientationClasses : markerOrientationClasses, - sizeClasses = a ? valueSizeClasses : markerSizeClasses; + var a = source === options.cssClasses.value; + var orientationClasses = a ? valueOrientationClasses : markerOrientationClasses; + var sizeClasses = a ? valueSizeClasses : markerSizeClasses; return source + ' ' + orientationClasses[options.ort] + ' ' + sizeClasses[type]; } @@ -218,14 +232,14 @@ function pips ( grid ) { - var mode = grid.mode, - density = grid.density || 1, - filter = grid.filter || false, - values = grid.values || false, - stepped = grid.stepped || false, - group = getGroup( mode, values, stepped ), - spread = generateSpread( density, mode, group ), - format = grid.format || { + var mode = grid.mode; + var density = grid.density || 1; + var filter = grid.filter || false; + var values = grid.values || false; + var stepped = grid.stepped || false; + var group = getGroup( mode, values, stepped ); + var spread = generateSpread( density, mode, group ); + var format = grid.format || { to: Math.round }; diff --git a/src/js/range.js b/src/js/range.js index 178a1ede..0a4e873e 100644 --- a/src/js/range.js +++ b/src/js/range.js @@ -119,7 +119,7 @@ // Reject any invalid input, by testing whether value is an array. if ( Object.prototype.toString.call( value ) !== '[object Array]' ){ - throw new Error("noUiSlider: 'range' contains invalid value."); + throw new Error("noUiSlider (" + VERSION + "): 'range' contains invalid value."); } // Covert min/max syntax to 0 and 100. @@ -133,7 +133,7 @@ // Check for correct input. if ( !isNumeric( percentage ) || !isNumeric( value[0] ) ) { - throw new Error("noUiSlider: 'range' value isn't numeric."); + throw new Error("noUiSlider (" + VERSION + "): 'range' value isn't numeric."); } // Store values. @@ -230,7 +230,7 @@ var step = this.xNumSteps[0]; if ( step && ((value / step) % 1) !== 0 ) { - throw new Error("noUiSlider: 'limit', 'margin' and 'padding' must be divisible by step."); + throw new Error("noUiSlider (" + VERSION + "): 'limit', 'margin' and 'padding' must be divisible by step."); } return this.xPct.length === 2 ? fromPercentage(this.xVal, value) : false; diff --git a/src/js/scope.js b/src/js/scope.js index 72141e1d..e0880203 100644 --- a/src/js/scope.js +++ b/src/js/scope.js @@ -360,7 +360,7 @@ // Throw an error if the slider was already initialized. if ( scope_Target.noUiSlider ) { - throw new Error('Slider was already initialized.'); + throw new Error("noUiSlider (" + VERSION + "): Slider was already initialized."); } // Create the base element, initialise HTML and set classes.