/*! noUiSlider - 7.0.10 - 2014-12-27 14:50:46 */ (function(){ 'use strict'; var /** @const */ FormatOptions = [ 'decimals', 'thousand', 'mark', 'prefix', 'postfix', 'encoder', 'decoder', 'negativeBefore', 'negative', 'edit', 'undo' ]; // General // Reverse a string function strReverse ( a ) { return a.split('').reverse().join(''); } // Check if a string starts with a specified prefix. function strStartsWith ( input, match ) { return input.substring(0, match.length) === match; } // Check is a string ends in a specified postfix. function strEndsWith ( input, match ) { return input.slice(-1 * match.length) === match; } // Throw an error if formatting options are incompatible. function throwEqualError( F, a, b ) { if ( (F[a] || F[b]) && (F[a] === F[b]) ) { throw new Error(a); } } // Check if a number is finite and not NaN function isValidNumber ( input ) { return typeof input === 'number' && isFinite( input ); } // Provide rounding-accurate toFixed method. function toFixed ( value, decimals ) { var scale = Math.pow(10, decimals); return ( Math.round(value * scale) / scale).toFixed( decimals ); } // Formatting // Accept a number as input, output formatted string. function formatTo ( decimals, thousand, mark, prefix, postfix, encoder, decoder, negativeBefore, negative, edit, undo, input ) { var originalInput = input, inputIsNegative, inputPieces, inputBase, inputDecimals = '', output = ''; // Apply user encoder to the input. // Expected outcome: number. if ( encoder ) { input = encoder(input); } // Stop if no valid number was provided, the number is infinite or NaN. if ( !isValidNumber(input) ) { return false; } // Rounding away decimals might cause a value of -0 // when using very small ranges. Remove those cases. if ( decimals !== false && parseFloat(input.toFixed(decimals)) === 0 ) { input = 0; } // Formatting is done on absolute numbers, // decorated by an optional negative symbol. if ( input < 0 ) { inputIsNegative = true; input = Math.abs(input); } // Reduce the number of decimals to the specified option. if ( decimals !== false ) { input = toFixed( input, decimals ); } // Transform the number into a string, so it can be split. input = input.toString(); // Break the number on the decimal separator. if ( input.indexOf('.') !== -1 ) { inputPieces = input.split('.'); inputBase = inputPieces[0]; if ( mark ) { inputDecimals = mark + inputPieces[1]; } } else { // If it isn't split, the entire number will do. inputBase = input; } // Group numbers in sets of three. if ( thousand ) { inputBase = strReverse(inputBase).match(/.{1,3}/g); inputBase = strReverse(inputBase.join( strReverse( thousand ) )); } // If the number is negative, prefix with negation symbol. if ( inputIsNegative && negativeBefore ) { output += negativeBefore; } // Prefix the number if ( prefix ) { output += prefix; } // Normal negative option comes after the prefix. Defaults to '-'. if ( inputIsNegative && negative ) { output += negative; } // Append the actual number. output += inputBase; output += inputDecimals; // Apply the postfix. if ( postfix ) { output += postfix; } // Run the output through a user-specified post-formatter. if ( edit ) { output = edit ( output, originalInput ); } // All done. return output; } // Accept a sting as input, output decoded number. function formatFrom ( decimals, thousand, mark, prefix, postfix, encoder, decoder, negativeBefore, negative, edit, undo, input ) { var originalInput = input, inputIsNegative, output = ''; // User defined pre-decoder. Result must be a non empty string. if ( undo ) { input = undo(input); } // Test the input. Can't be empty. if ( !input || typeof input !== 'string' ) { return false; } // If the string starts with the negativeBefore value: remove it. // Remember is was there, the number is negative. if ( negativeBefore && strStartsWith(input, negativeBefore) ) { input = input.replace(negativeBefore, ''); inputIsNegative = true; } // Repeat the same procedure for the prefix. if ( prefix && strStartsWith(input, prefix) ) { input = input.replace(prefix, ''); } // And again for negative. if ( negative && strStartsWith(input, negative) ) { input = input.replace(negative, ''); inputIsNegative = true; } // Remove the postfix. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice if ( postfix && strEndsWith(input, postfix) ) { input = input.slice(0, -1 * postfix.length); } // Remove the thousand grouping. if ( thousand ) { input = input.split(thousand).join(''); } // Set the decimal separator back to period. if ( mark ) { input = input.replace(mark, '.'); } // Prepend the negative symbol. if ( inputIsNegative ) { output += '-'; } // Add the number output += input; // Trim all non-numeric characters (allow '.' and '-'); output = output.replace(/[^0-9\.\-.]/g, ''); // The value contains no parse-able number. if ( output === '' ) { return false; } // Covert to number. output = Number(output); // Run the user-specified post-decoder. if ( decoder ) { output = decoder(output); } // Check is the output is valid, otherwise: return false. if ( !isValidNumber(output) ) { return false; } return output; } // Framework // Validate formatting options function validate ( inputOptions ) { var i, optionName, optionValue, filteredOptions = {}; for ( i = 0; i < FormatOptions.length; i+=1 ) { optionName = FormatOptions[i]; optionValue = inputOptions[optionName]; if ( optionValue === undefined ) { // Only default if negativeBefore isn't set. if ( optionName === 'negative' && !filteredOptions.negativeBefore ) { filteredOptions[optionName] = '-'; // Don't set a default for mark when 'thousand' is set. } else if ( optionName === 'mark' && filteredOptions.thousand !== '.' ) { filteredOptions[optionName] = '.'; } else { filteredOptions[optionName] = false; } // Floating points in JS are stable up to 7 decimals. } else if ( optionName === 'decimals' ) { if ( optionValue >= 0 && optionValue < 8 ) { filteredOptions[optionName] = optionValue; } else { throw new Error(optionName); } // These options, when provided, must be functions. } else if ( optionName === 'encoder' || optionName === 'decoder' || optionName === 'edit' || optionName === 'undo' ) { if ( typeof optionValue === 'function' ) { filteredOptions[optionName] = optionValue; } else { throw new Error(optionName); } // Other options are strings. } else { if ( typeof optionValue === 'string' ) { filteredOptions[optionName] = optionValue; } else { throw new Error(optionName); } } } // Some values can't be extracted from a // string if certain combinations are present. throwEqualError(filteredOptions, 'mark', 'thousand'); throwEqualError(filteredOptions, 'prefix', 'negative'); throwEqualError(filteredOptions, 'prefix', 'negativeBefore'); return filteredOptions; } // Pass all options as function arguments function passAll ( options, method, input ) { var i, args = []; // Add all options in order of FormatOptions for ( i = 0; i < FormatOptions.length; i+=1 ) { args.push(options[FormatOptions[i]]); } // Append the input, then call the method, presenting all // options as arguments. args.push(input); return method.apply('', args); } /** @constructor */ function wNumb ( options ) { if ( !(this instanceof wNumb) ) { return new wNumb ( options ); } if ( typeof options !== "object" ) { return; } options = validate(options); // Call 'formatTo' with proper arguments. this.to = function ( input ) { return passAll(options, formatTo, input); }; // Call 'formatFrom' with proper arguments. this.from = function ( input ) { return passAll(options, formatFrom, input); }; } /** @export */ window.wNumb = wNumb; }()); /*jslint browser: true */ /*jslint white: true */ (function( $ ){ 'use strict'; // Helpers // Test in an object is an instance of jQuery or Zepto. function isInstance ( a ) { return a instanceof $ || ( $.zepto && $.zepto.isZ(a) ); } // Link types function fromPrefix ( target, method ) { // If target is a string, a new hidden input will be created. if ( typeof target === 'string' && target.indexOf('-inline-') === 0 ) { // By default, use the 'html' method. this.method = method || 'html'; // Use jQuery to create the element this.target = this.el = $( target.replace('-inline-', '') || '
' ); return true; } } function fromString ( target ) { // If the string doesn't begin with '-', which is reserved, add a new hidden input. if ( typeof target === 'string' && target.indexOf('-') !== 0 ) { this.method = 'val'; var element = document.createElement('input'); element.name = target; element.type = 'hidden'; this.target = this.el = $(element); return true; } } function fromFunction ( target ) { // The target can also be a function, which will be called. if ( typeof target === 'function' ) { this.target = false; this.method = target; return true; } } function fromInstance ( target, method ) { if ( isInstance( target ) && !method ) { // If a jQuery/Zepto input element is provided, but no method is set, // the element can assume it needs to respond to 'change'... if ( target.is('input, select, textarea') ) { // Default to .val if this is an input element. this.method = 'val'; // Fire the API changehandler when the target changes. this.target = target.on('change.liblink', this.changeHandler); } else { this.target = target; // If no method is set, and we are not auto-binding an input, default to 'html'. this.method = 'html'; } return true; } } function fromInstanceMethod ( target, method ) { // The method must exist on the element. if ( isInstance( target ) && (typeof method === 'function' || (typeof method === 'string' && target[method])) ) { this.method = method; this.target = target; return true; } } var /** @const */ creationFunctions = [fromPrefix, fromString, fromFunction, fromInstance, fromInstanceMethod]; // Link Instance /** @constructor */ function Link ( target, method, format ) { var that = this, valid = false; // Forward calls within scope. this.changeHandler = function ( changeEvent ) { var decodedValue = that.formatInstance.from( $(this).val() ); // If the value is invalid, stop this event, as well as it's propagation. if ( decodedValue === false || isNaN(decodedValue) ) { // Reset the value. $(this).val(that.lastSetValue); return false; } that.changeHandlerMethod.call( '', changeEvent, decodedValue ); }; // See if this Link needs individual targets based on its usage. // If so, return the element that needs to be copied by the // implementing interface. // Default the element to false. this.el = false; // Store the formatter, or use the default. this.formatInstance = format; // Try all Link types. /*jslint unparam: true*/ $.each(creationFunctions, function(i, fn){ valid = fn.call(that, target, method); return !valid; }); /*jslint unparam: false*/ // Nothing matched, throw error. if ( !valid ) { throw new RangeError("(Link) Invalid Link."); } } // Provides external items with the object value. Link.prototype.set = function ( value ) { // Ignore the value, so only the passed-on arguments remain. var args = Array.prototype.slice.call( arguments ), additionalArgs = args.slice(1); // Store some values. The actual, numerical value, // the formatted value and the parameters for use in 'resetValue'. // Slice additionalArgs to break the relation. this.lastSetValue = this.formatInstance.to( value ); // Prepend the value to the function arguments. additionalArgs.unshift( this.lastSetValue ); // When target is undefined, the target was a function. // In that case, provided the object as the calling scope. // Branch between writing to a function or an object. ( typeof this.method === 'function' ? this.method : this.target[ this.method ] ).apply( this.target, additionalArgs ); }; // Developer API /** @constructor */ function LinkAPI ( origin ) { this.items = []; this.elements = []; this.origin = origin; } LinkAPI.prototype.push = function( item, element ) { this.items.push(item); // Prevent 'false' elements if ( element ) { this.elements.push(element); } }; LinkAPI.prototype.reconfirm = function ( flag ) { var i; for ( i = 0; i < this.elements.length; i += 1 ) { this.origin.LinkConfirm(flag, this.elements[i]); } }; LinkAPI.prototype.remove = function ( flag ) { var i; for ( i = 0; i < this.items.length; i += 1 ) { this.items[i].target.off('.liblink'); } for ( i = 0; i < this.elements.length; i += 1 ) { this.elements[i].remove(); } }; LinkAPI.prototype.change = function ( value ) { if ( this.origin.LinkIsEmitting ) { return false; } this.origin.LinkIsEmitting = true; var args = Array.prototype.slice.call( arguments, 1 ), i; args.unshift( value ); // Write values to serialization Links. // Convert the value to the correct relative representation. for ( i = 0; i < this.items.length; i += 1 ) { this.items[i].set.apply(this.items[i], args); } this.origin.LinkIsEmitting = false; }; // jQuery plugin function binder ( flag, target, method, format ){ if ( flag === 0 ) { flag = this.LinkDefaultFlag; } // Create a list of API's (if it didn't exist yet); if ( !this.linkAPI ) { this.linkAPI = {}; } // Add an API point. if ( !this.linkAPI[flag] ) { this.linkAPI[flag] = new LinkAPI(this); } var linkInstance = new Link ( target, method, format || this.LinkDefaultFormatter ); // Default the calling scope to the linked object. if ( !linkInstance.target ) { linkInstance.target = $(this); } // If the Link requires creation of a new element, // Pass the element and request confirmation to get the changehandler. // Set the method to be called when a Link changes. linkInstance.changeHandlerMethod = this.LinkConfirm( flag, linkInstance.el ); // Store the linkInstance in the flagged list. this.linkAPI[flag].push( linkInstance, linkInstance.el ); // Now that Link have been connected, request an update. this.LinkUpdate( flag ); } /** @export */ $.fn.Link = function( flag ){ var that = this; // Delete all linkAPI if ( flag === false ) { return that.each(function(){ // .Link(false) can be called on elements without Links. // When that happens, the objects can't be looped. if ( !this.linkAPI ) { return; } $.map(this.linkAPI, function(api){ api.remove(); }); delete this.linkAPI; }); } if ( flag === undefined ) { flag = 0; } else if ( typeof flag !== 'string') { throw new Error("Flag must be string."); } return { to: function( a, b, c ){ return that.each(function(){ binder.call(this, flag, a, b, c); }); } }; }; }( window.jQuery || window.Zepto )); /*jslint browser: true */ /*jslint white: true */ (function( $ ){ 'use strict'; // Removes duplicates from an array. function unique(array) { return $.grep(array, function(el, index) { return index === $.inArray(el, array); }); } // Round a value to the closest 'to'. function closest ( value, to ) { return Math.round(value / to) * to; } // Checks whether a value is numerical. function isNumeric ( a ) { return typeof a === 'number' && !isNaN( a ) && isFinite( a ); } // Rounds a number to 7 supported decimals. function accurateNumber( number ) { var p = Math.pow(10, 7); return Number((Math.round(number*p)/p).toFixed(7)); } // Sets a class and removes it after [duration] ms. function addClassFor ( element, className, duration ) { element.addClass(className); setTimeout(function(){ element.removeClass(className); }, duration); } // Limits a value to 0 - 100 function limit ( a ) { return Math.max(Math.min(a, 100), 0); } // Wraps a variable as an array, if it isn't one yet. function asArray ( a ) { return $.isArray(a) ? a : [a]; } // Counts decimals function countDecimals ( numStr ) { var pieces = numStr.split("."); return pieces.length > 1 ? pieces[1].length : 0; } var // Cache the document selector; /** @const */ doc = $(document), // Make a backup of the original jQuery/Zepto .val() method. /** @const */ $val = $.fn.val, // Namespace for binding and unbinding slider events; /** @const */ namespace = '.nui', // Determine the events to bind. IE11 implements pointerEvents without // a prefix, which breaks compatibility with the IE10 implementation. /** @const */ actions = window.navigator.pointerEnabled ? { start: 'pointerdown', move: 'pointermove', end: 'pointerup' } : window.navigator.msPointerEnabled ? { start: 'MSPointerDown', move: 'MSPointerMove', end: 'MSPointerUp' } : { start: 'mousedown touchstart', move: 'mousemove touchmove', end: 'mouseup touchend' }, // Re-usable list of classes; /** @const */ Classes = [ /* 0 */ 'noUi-target' /* 1 */ ,'noUi-base' /* 2 */ ,'noUi-origin' /* 3 */ ,'noUi-handle' /* 4 */ ,'noUi-horizontal' /* 5 */ ,'noUi-vertical' /* 6 */ ,'noUi-background' /* 7 */ ,'noUi-connect' /* 8 */ ,'noUi-ltr' /* 9 */ ,'noUi-rtl' /* 10 */ ,'noUi-dragable' /* 11 */ ,'' /* 12 */ ,'noUi-state-drag' /* 13 */ ,'' /* 14 */ ,'noUi-state-tap' /* 15 */ ,'noUi-active' /* 16 */ ,'' /* 17 */ ,'noUi-stacking' ]; // Value calculation // Determine the size of a sub-range in relation to a full range. function subRangeRatio ( pa, pb ) { return (100 / (pb - pa)); } // (percentage) How many percent is this value of this range? function fromPercentage ( range, value ) { return (value * 100) / ( range[1] - range[0] ); } // (percentage) Where is this value on this range? function toPercentage ( range, value ) { return fromPercentage( range, range[0] < 0 ? value + Math.abs(range[0]) : value - range[0] ); } // (value) How much is this percentage on this range? function isPercentage ( range, value ) { return ((value * ( range[1] - range[0] )) / 100) + range[0]; } // Range conversion function getJ ( value, arr ) { var j = 1; while ( value >= arr[j] ){ j += 1; } return j; } // (percentage) Input a value, find where, on a scale of 0-100, it applies. function toStepping ( xVal, xPct, value ) { if ( value >= xVal.slice(-1)[0] ){ return 100; } var j = getJ( value, xVal ), va, vb, pa, pb; va = xVal[j-1]; vb = xVal[j]; pa = xPct[j-1]; pb = xPct[j]; return pa + (toPercentage([va, vb], value) / subRangeRatio (pa, pb)); } // (value) Input a percentage, find where it is on the specified range. function fromStepping ( xVal, xPct, value ) { // There is no range group that fits 100 if ( value >= 100 ){ return xVal.slice(-1)[0]; } var j = getJ( value, xPct ), va, vb, pa, pb; va = xVal[j-1]; vb = xVal[j]; pa = xPct[j-1]; pb = xPct[j]; return isPercentage([va, vb], (value - pa) * subRangeRatio (pa, pb)); } // (percentage) Get the step that applies at a certain value. function getStep ( xPct, xSteps, snap, value ) { if ( value === 100 ) { return value; } var j = getJ( value, xPct ), a, b; // If 'snap' is set, steps are used as fixed points on the slider. if ( snap ) { a = xPct[j-1]; b = xPct[j]; // Find the closest position, a or b. if ((value - a) > ((b-a)/2)){ return b; } return a; } if ( !xSteps[j-1] ){ return value; } return xPct[j-1] + closest( value - xPct[j-1], xSteps[j-1] ); } // Entry parsing function handleEntryPoint ( index, value, that ) { var percentage; // Wrap numerical input in an array. if ( typeof value === "number" ) { value = [value]; } // 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."); } // Covert min/max syntax to 0 and 100. if ( index === 'min' ) { percentage = 0; } else if ( index === 'max' ) { percentage = 100; } else { percentage = parseFloat( index ); } // Check for correct input. if ( !isNumeric( percentage ) || !isNumeric( value[0] ) ) { throw new Error("noUiSlider: 'range' value isn't numeric."); } // Store values. that.xPct.push( percentage ); that.xVal.push( value[0] ); // NaN will evaluate to false too, but to keep // logging clear, set step explicitly. Make sure // not to override the 'step' setting with false. if ( !percentage ) { if ( !isNaN( value[1] ) ) { that.xSteps[0] = value[1]; } } else { that.xSteps.push( isNaN(value[1]) ? false : value[1] ); } } function handleStepPoint ( i, n, that ) { // Ignore 'false' stepping. if ( !n ) { return true; } // Factor to range ratio that.xSteps[i] = fromPercentage([ that.xVal[i] ,that.xVal[i+1] ], n) / subRangeRatio ( that.xPct[i], that.xPct[i+1] ); } // Interface // The interface to Spectrum handles all direction-based // conversions, so the above values are unaware. function Spectrum ( entry, snap, direction, singleStep ) { this.xPct = []; this.xVal = []; this.xSteps = [ singleStep || false ]; this.xNumSteps = [ false ]; this.snap = snap; this.direction = direction; var index, ordered = [ /* [0, 'min'], [1, '50%'], [2, 'max'] */ ]; // Map the object keys to an array. for ( index in entry ) { if ( entry.hasOwnProperty(index) ) { ordered.push([entry[index], index]); } } // Sort all entries by value (numeric sort). ordered.sort(function(a, b) { return a[0] - b[0]; }); // Convert all entries to subranges. for ( index = 0; index < ordered.length; index++ ) { handleEntryPoint(ordered[index][1], ordered[index][0], this); } // Store the actual step values. // xSteps is sorted in the same order as xPct and xVal. this.xNumSteps = this.xSteps.slice(0); // Convert all numeric steps to the percentage of the subrange they represent. for ( index = 0; index < this.xNumSteps.length; index++ ) { handleStepPoint(index, this.xNumSteps[index], this); } } Spectrum.prototype.getMargin = function ( value ) { return this.xPct.length === 2 ? fromPercentage(this.xVal, value) : false; }; Spectrum.prototype.toStepping = function ( value ) { value = toStepping( this.xVal, this.xPct, value ); // Invert the value if this is a right-to-left slider. if ( this.direction ) { value = 100 - value; } return value; }; Spectrum.prototype.fromStepping = function ( value ) { // Invert the value if this is a right-to-left slider. if ( this.direction ) { value = 100 - value; } return accurateNumber(fromStepping( this.xVal, this.xPct, value )); }; Spectrum.prototype.getStep = function ( value ) { // Find the proper step for rtl sliders by search in inverse direction. // Fixes issue #262. if ( this.direction ) { value = 100 - value; } value = getStep(this.xPct, this.xSteps, this.snap, value ); if ( this.direction ) { value = 100 - value; } return value; }; Spectrum.prototype.getApplicableStep = function ( value ) { // If the value is 100%, return the negative step twice. var j = getJ(value, this.xPct), offset = value === 100 ? 2 : 1; return [this.xNumSteps[j-2], this.xVal[j-offset], this.xNumSteps[j-offset]]; }; // Outside testing Spectrum.prototype.convert = function ( value ) { return this.getStep(this.toStepping(value)); }; /* Every input option is tested and parsed. This'll prevent endless validation in internal methods. These tests are structured with an item for every option available. An option can be marked as required by setting the 'r' flag. The testing function is provided with three arguments: - The provided value for the option; - A reference to the options object; - The name for the option; The testing function returns false when an error is detected, or true when everything is OK. It can also modify the option object, to make sure all values can be correctly looped elsewhere. */ /** @const */ var defaultFormatter = { 'to': function( value ){ return value.toFixed(2); }, 'from': Number }; function testStep ( parsed, entry ) { if ( !isNumeric( entry ) ) { throw new Error("noUiSlider: 'step' is not numeric."); } // The step option can still be used to set stepping // for linear sliders. Overwritten if set in 'range'. parsed.singleStep = entry; } function testRange ( parsed, entry ) { // Filter incorrect input. if ( typeof entry !== 'object' || $.isArray(entry) ) { throw new Error("noUiSlider: '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'."); } parsed.spectrum = new Spectrum(entry, parsed.snap, parsed.dir, parsed.singleStep); } function testStart ( parsed, entry ) { entry = asArray(entry); // Validate input. Values aren't tested, as the public .val method // will always provide a valid location. if ( !$.isArray( entry ) || !entry.length || entry.length > 2 ) { throw new Error("noUiSlider: 'start' option is incorrect."); } // Store the number of handles. parsed.handles = entry.length; // When the slider is initialized, the .val method will // be called with the start options. parsed.start = entry; } function testSnap ( parsed, entry ) { // Enforce 100% stepping within subranges. parsed.snap = entry; if ( typeof entry !== 'boolean' ){ throw new Error("noUiSlider: 'snap' option must be a boolean."); } } function testAnimate ( parsed, entry ) { // Enforce 100% stepping within subranges. parsed.animate = entry; if ( typeof entry !== 'boolean' ){ throw new Error("noUiSlider: 'animate' option must be a boolean."); } } function testConnect ( parsed, entry ) { if ( entry === 'lower' && parsed.handles === 1 ) { parsed.connect = 1; } else if ( entry === 'upper' && parsed.handles === 1 ) { parsed.connect = 2; } else if ( entry === true && parsed.handles === 2 ) { parsed.connect = 3; } else if ( entry === false ) { parsed.connect = 0; } else { throw new Error("noUiSlider: 'connect' option doesn't match handle count."); } } function testOrientation ( parsed, entry ) { // Set orientation to an a numerical value for easy // array selection. switch ( entry ){ case 'horizontal': parsed.ort = 0; break; case 'vertical': parsed.ort = 1; break; default: throw new Error("noUiSlider: 'orientation' option is invalid."); } } function testMargin ( parsed, entry ) { if ( !isNumeric(entry) ){ throw new Error("noUiSlider: 'margin' option must be numeric."); } parsed.margin = parsed.spectrum.getMargin(entry); if ( !parsed.margin ) { throw new Error("noUiSlider: 'margin' option is only supported on linear sliders."); } } function testLimit ( parsed, entry ) { if ( !isNumeric(entry) ){ throw new Error("noUiSlider: 'limit' option must be numeric."); } parsed.limit = parsed.spectrum.getMargin(entry); if ( !parsed.limit ) { throw new Error("noUiSlider: 'limit' option is only supported on linear sliders."); } } function testDirection ( parsed, entry ) { // Set direction as a numerical value for easy parsing. // Invert connection for RTL sliders, so that the proper // handles get the connect/background classes. switch ( entry ) { case 'ltr': parsed.dir = 0; break; case 'rtl': parsed.dir = 1; parsed.connect = [0,2,1,3][parsed.connect]; break; default: throw new Error("noUiSlider: 'direction' option was not recognized."); } } function testBehaviour ( parsed, entry ) { // Make sure the input is a string. if ( typeof entry !== 'string' ) { throw new Error("noUiSlider: 'behaviour' must be a string containing options."); } // Check if the string contains any keywords. // None are required. var tap = entry.indexOf('tap') >= 0, drag = entry.indexOf('drag') >= 0, fixed = entry.indexOf('fixed') >= 0, snap = entry.indexOf('snap') >= 0; parsed.events = { tap: tap || snap, drag: drag, fixed: fixed, snap: snap }; } function testFormat ( parsed, entry ) { parsed.format = entry; // Any object with a to and from method is supported. if ( typeof entry.to === 'function' && typeof entry.from === 'function' ) { return true; } throw new Error( "noUiSlider: 'format' requires 'to' and 'from' methods."); } // Test all developer settings and parse to assumption-safe values. function testOptions ( options ) { var parsed = { margin: 0, limit: 0, animate: true, format: defaultFormatter }, tests; // Tests are executed in the order they are presented here. tests = { 'step': { r: false, t: testStep }, 'start': { r: true, t: testStart }, 'connect': { r: true, t: testConnect }, 'direction': { r: true, t: testDirection }, 'snap': { r: false, t: testSnap }, 'animate': { r: false, t: testAnimate }, 'range': { r: true, t: testRange }, 'orientation': { r: false, t: testOrientation }, 'margin': { r: false, t: testMargin }, 'limit': { r: false, t: testLimit }, 'behaviour': { r: true, t: testBehaviour }, 'format': { r: false, t: testFormat } }; // Set defaults where applicable. options = $.extend({ 'connect': false, 'direction': 'ltr', 'behaviour': 'tap', 'orientation': 'horizontal' }, options); // Run all options through a testing mechanism to ensure correct // input. It should be noted that options might get modified to // be handled properly. E.g. wrapping integers in arrays. $.each( tests, function( name, test ){ // If the option isn't set, but it is required, throw an error. if ( options[name] === undefined ) { if ( test.r ) { throw new Error("noUiSlider: '" + name + "' is required."); } return true; } test.t( parsed, options[name] ); }); // Pre-define the styles. parsed.style = parsed.ort ? 'top' : 'left'; return parsed; } // Class handling // Delimit proposed values for handle positions. function getPositions ( a, b, delimit ) { // Add movement to current position. var c = a + b[0], d = a + b[1]; // Only alter the other position on drag, // not on standard sliding. if ( delimit ) { if ( c < 0 ) { d += Math.abs(c); } if ( d > 100 ) { c -= ( d - 100 ); } // Limit values to 0 and 100. return [limit(c), limit(d)]; } return [c,d]; } // Event handling // Provide a clean event with standardized offset values. function fixEvent ( e ) { // Prevent scrolling and panning on touch events, while // attempting to slide. The tap event also depends on this. e.preventDefault(); // Filter the event to register the type, which can be // touch, mouse or pointer. Offset changes need to be // made on an event specific basis. var touch = e.type.indexOf('touch') === 0 ,mouse = e.type.indexOf('mouse') === 0 ,pointer = e.type.indexOf('pointer') === 0 ,x,y, event = e; // IE10 implemented pointer events with a prefix; if ( e.type.indexOf('MSPointer') === 0 ) { pointer = true; } // Get the originalEvent, if the event has been wrapped // by jQuery. Zepto doesn't wrap the event. if ( e.originalEvent ) { e = e.originalEvent; } if ( touch ) { // noUiSlider supports one movement at a time, // so we can select the first 'changedTouch'. x = e.changedTouches[0].pageX; y = e.changedTouches[0].pageY; } if ( mouse || pointer ) { // Polyfill the pageXOffset and pageYOffset // variables for IE7 and IE8; if( !pointer && window.pageXOffset === undefined ){ window.pageXOffset = document.documentElement.scrollLeft; window.pageYOffset = document.documentElement.scrollTop; } x = e.clientX + window.pageXOffset; y = e.clientY + window.pageYOffset; } event.points = [x, y]; event.cursor = mouse; return event; } // DOM additions // Append a handle to the base. function addHandle ( direction, index ) { var handle = $('