Skip to content

Commit

Permalink
accept 'null' option resets
Browse files Browse the repository at this point in the history
  • Loading branch information
leongersen committed Apr 2, 2018
1 parent efdf079 commit 1b7301a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion documentation/_run/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

$url = strtolower($_SERVER['REQUEST_URI']);

if ( strpos($url, '.js') || strpos($url, '.css') ) {
if ( strpos($url, '.js') || strpos($url, '.css') || strpos($url, '.html') ) {
return false;
}

Expand Down
4 changes: 4 additions & 0 deletions src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
el.parentElement.removeChild(el);
}

function isSet ( value ) {
return value !== null && value !== undefined;
}

// Bindable version
function preventDefault ( e ) {
e.preventDefault();
Expand Down
16 changes: 10 additions & 6 deletions src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@
if ( parsed.padding[0] < 0 || parsed.padding[1] < 0 ) {
throw new Error("noUiSlider (" + VERSION + "): 'padding' option must be a positive number(s).");
}

if ( parsed.padding[0] + parsed.padding[1] >= 100 ) {
throw new Error("noUiSlider (" + VERSION + "): 'padding' option must not exceed 100% of the range.");
}
}

function testDirection ( parsed, entry ) {
Expand Down Expand Up @@ -310,7 +314,7 @@

function testCssPrefix ( parsed, entry ) {

if ( entry !== undefined && typeof entry !== 'string' && entry !== false ) {
if ( typeof entry !== 'string' && entry !== false ) {
throw new Error("noUiSlider (" + VERSION + "): 'cssPrefix' must be a string or `false`.");
}

Expand All @@ -319,7 +323,7 @@

function testCssClasses ( parsed, entry ) {

if ( entry !== undefined && typeof entry !== 'object' ) {
if ( typeof entry !== 'object' ) {
throw new Error("noUiSlider (" + VERSION + "): 'cssClasses' must be an object.");
}

Expand Down Expand Up @@ -371,8 +375,8 @@
'ariaFormat': { r: false, t: testAriaFormat },
'format': { r: false, t: testFormat },
'tooltips': { r: false, t: testTooltips },
'cssPrefix': { r: false, t: testCssPrefix },
'cssClasses': { r: false, t: testCssClasses }
'cssPrefix': { r: true, t: testCssPrefix },
'cssClasses': { r: true, t: testCssClasses }
};

var defaults = {
Expand Down Expand Up @@ -429,7 +433,7 @@
Object.keys(tests).forEach(function( name ){

// If the option isn't set, but it is required, throw an error.
if ( options[name] === undefined && defaults[name] === undefined ) {
if ( !isSet(options[name]) && defaults[name] === undefined ) {

if ( tests[name].r ) {
throw new Error("noUiSlider (" + VERSION + "): '" + name + "' is required.");
Expand All @@ -438,7 +442,7 @@
return true;
}

tests[name].t( parsed, options[name] === undefined ? defaults[name] : options[name] );
tests[name].t( parsed, !isSet(options[name]) ? defaults[name] : options[name] );
});

// Forward pips options
Expand Down
2 changes: 2 additions & 0 deletions tests/slider_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
noUiSlider.create(slider, {
start: 1,
margin: 0, // Does not throw, issue #582
cssPrefix: null, // #856
step: null,
range: {
'min': 0,
'max': 10
Expand Down

0 comments on commit 1b7301a

Please sign in to comment.