From 897e0af5dc97f89fee43555261cebf8047e43966 Mon Sep 17 00:00:00 2001 From: Leon Gersen Date: Sun, 22 Sep 2013 22:40:46 +0200 Subject: [PATCH] Fixed setting val by integer --- jquery.nouislider.js | 8 +++++++- jquery.nouislider.min.js | 24 ++++++++++++------------ 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/jquery.nouislider.js b/jquery.nouislider.js index 9f74f691..c730df9c 100644 --- a/jquery.nouislider.js +++ b/jquery.nouislider.js @@ -742,8 +742,14 @@ function val ( args, ignore ) { // Setter - if( args && args.length ){ + if( args !== UNDEF ){ + // If the val is to be set to a number, which is valid + // when using a one-handle slider, wrap it in an array. + if(!$.isArray(args)){ + args = [args]; + } + // Setting is handled properly for each slider in the data set. return this.each(function(){ diff --git a/jquery.nouislider.min.js b/jquery.nouislider.min.js index 6c9fbac9..a9ec7d2c 100644 --- a/jquery.nouislider.min.js +++ b/jquery.nouislider.min.js @@ -1,16 +1,16 @@ /** noUiSlider 4.0.0 */ -(function(f,u){f.fn.noUiSlider=function(k){function z(a){a.stopPropagation()}function v(a,c,d){f.each(a,function(a,l){"function"===typeof l&&l.call(c,d)})}function p(a){return a.data.base.data("target").is('[class*="noUi-state-"], [disabled]')}function r(a,c){c&&a.preventDefault();var d=a,h=0===a.type.indexOf("touch"),l=0===a.type.indexOf("mouse"),b=0===a.type.indexOf("MSPointer"),q,e;a=a.originalEvent;h&&(q=a.changedTouches[0].pageX,e=a.changedTouches[0].pageY);l&&(window.pageXOffset===u&&(window.pageXOffset= -document.documentElement.scrollLeft,window.pageYOffset=document.documentElement.scrollTop),q=a.clientX+window.pageXOffset,e=a.clientY+window.pageYOffset);b&&(q=a.pageX,e=a.pageY);return{pass:d.data,e:a,x:q,y:e,t:[h,l,b]}}function A(a){return parseFloat(this.style[a])}function B(a,c){function d(a){return a instanceof f||"string"===typeof a||!1===a}var h={handles:{r:!0,t:function(a,b){b=parseInt(b,10);return 1===b||2===b}},range:{r:!0,t:function(a,b,c){if(2!==b.length)return!1;b=[parseFloat(b[0]),parseFloat(b[1])]; +(function(f,p){f.fn.noUiSlider=function(k){function z(a){a.stopPropagation()}function v(a,c,d){f.each(a,function(a,l){"function"===typeof l&&l.call(c,d)})}function q(a){return a.data.base.data("target").is('[class*="noUi-state-"], [disabled]')}function u(a,c){c&&a.preventDefault();var d=a,h=0===a.type.indexOf("touch"),l=0===a.type.indexOf("mouse"),b=0===a.type.indexOf("MSPointer"),s,e;a=a.originalEvent;h&&(s=a.changedTouches[0].pageX,e=a.changedTouches[0].pageY);l&&(window.pageXOffset===p&&(window.pageXOffset= +document.documentElement.scrollLeft,window.pageYOffset=document.documentElement.scrollTop),s=a.clientX+window.pageXOffset,e=a.clientY+window.pageYOffset);b&&(s=a.pageX,e=a.pageY);return{pass:d.data,e:a,x:s,y:e,t:[h,l,b]}}function A(a){return parseFloat(this.style[a])}function B(a,c){function d(a){return a instanceof f||"string"===typeof a||!1===a}var h={handles:{r:!0,t:function(a,b){b=parseInt(b,10);return 1===b||2===b}},range:{r:!0,t:function(a,b,c){if(2!==b.length)return!1;b=[parseFloat(b[0]),parseFloat(b[1])]; if(isNaN(b[0])||!isFinite(b[0])||isNaN(b[1])||!isFinite(b[1]))return!1;a[c]=b;return!0}},start:{r:!0,t:function(a,b,c){return 1===a.handles?(f.isArray(b)&&(b=b[0]),b=parseFloat(b),a.start=[b],!isNaN(b)&&isFinite(b)):this.parent.range.t(a,b,c)}},connect:{t:function(a,b){return!0===b||!1===b||"lower"===b&&1===a.handles||"upper"===b&&1===a.handles}},orientation:{t:function(a,b){return"horizontal"===b||"vertical"===b}},margin:{r:!0,t:function(a,b,c){b=parseFloat(b);a[c]=b;return!isNaN(b)&&isFinite(b)}}, serialization:{r:!0,t:function(a,b){if(b.resolution)switch(b.resolution){case 1:case 0.1:case 0.01:case 0.001:case 1E-4:case 1E-5:break;default:return!1}else a.serialization.resolution=0.01;return b.to?1===a.handles?(f.isArray(b.to)||(b.to=[b.to]),a.serialization.to=b.to,d(b.to[0])):2===b.to.length&&d(b.to[0])&&d(b.to[1]):!1}},slide:{t:function(a,b){return"function"===typeof b}},step:{t:function(a,b,c){return this.parent.margin.t(a,b,c)}},init:function(){var a=this;f.each(a,function(b,c){c.parent= -a});delete this.init;return this}}.init();f.each(h,function(d,b){if(b.r&&!a[d]&&0!==a[d]||(a[d]||0===a[d])&&!b.t(a,a[d],d))return console&&console.log&&console.log("Slider:\t\t\t",c,"\nOption:\t\t\t",d,"\nValue:\t\t\t",a[d]),f.error("Error on noUiSlider initialisation."),!1})}function t(a,c,d){var h=a.data("nui").options,l=a.data("nui").base.data(e[12]),b=a.data("nui").style,q=a.data("nui").decimals;if(c===a[0].getPercentage(b))return!1;c=0>c?0:100d?d:c),c===a[0].getPercentage(b)))return!1;0===a.data("nui").number&&95').appendTo(a).change(z);if(!1===c.to[d])return{val:function(a){if(a===u)return this._handle.data("nui-val");this._handle.data("nui-val",a)},hasClass:function(){return!1},_handle:a}}function D(a){if(a=r(a,!0)){var c=a.pass.base,d=c.data("style"),e=a.x-a.pass.startEvent.x,c="left"===d?c.width():c.height();"top"===d&&(e=a.y-a.pass.startEvent.y); -e=a.pass.position+100*e/c;t(a.pass.handle,e);v([a.pass.base.data("options").slide],a.pass.base.data("target"))}}function w(a){p(a)||(a.data.handle.children().removeClass(e[4]),m.off(n.move),m.off(n.end),f("body").off(g),a.data.base.data("target").change())}function E(a){if(!p(a)&&(a=r(a))){var c=a.pass.handle,d=c[0].getPercentage(c.data("nui").style);c.children().addClass("noUi-active");m.on(n.move,{startEvent:a,position:d,base:a.pass.base,handle:c},D);m.on(n.end,{base:a.pass.base,handle:c},w);f("body").on("selectstart"+ -g,function(){return!1})}}function F(a){w({data:{base:a.data.base,handle:a.data.handle}});a.stopPropagation()}function G(a){if(!p(a)&&!a.data.base.find("."+e[4]).length&&(a=r(a))){var c,d,h=a.pass.base;d=a.pass.handles;var l=h.data("style"),b=a["left"===l?"x":"y"],f="left"===l?h.width():h.height(),k=a.t[2]?window.pageXOffset:0,g=[];a={left:h.offset().left-k,top:h.offset().top};for(c=0;ca[0]?c+Math.abs(a[0]):c-a[0];return 100*c/this._length(a)},from:function(a,c){return 100*c/this._length(a)},is:function(a,c){return c*this._length(a)/100+a[0]},_length:function(a){return a[0]>a[1]?a[0]-a[1]:a[1]-a[0]}};window.navigator.msPointerEnabled&&(n={start:"MSPointerDown"+g,move:"MSPointerMove"+g,end:"MSPointerUp"+g});f.fn.val=function(){return this.hasClass(e[6])?H.apply(this,arguments):I.apply(this,arguments)};return function(){return this.each(function(a,c){c=f(c); -c.addClass(e[6]);var d,h,l,b,g=f("
").appendTo(c),m=[];d=J;var p=[x.concat([e[1]+e[7]]),x.concat([e[1]+e[8]])],r=[y.concat([e[2]+e[7]]),y.concat([e[2]+e[8]])];k=f.extend({handles:2,margin:0,orientation:"horizontal"},k)||{};k.serialization||(k.serialization={to:[!1,!1],resolution:0.01});B(k,c);k.S=k.serialization;k.connect&&(p[0].push(e[9]),"lower"===k.connect?(d.push(e[9],e[9]+e[7]),p[0].push(e[13])):d.push(e[9]+e[8]));h="vertical"===k.orientation?"top":"left";l=k.S.resolution.toString().split("."); -l=1==l[0]?0:l[1].length;"vertical"===k.orientation?d.push(e[10]):d.push(e[11]);g.addClass(d.join(" ")).data("target",c);for(d=0;d
").appendTo(g),b.addClass(p[d].join(" ")),b.children().addClass(r[d].join(" ")),b.children().on(n.start,{base:g,handle:b},E).on(n.end,{base:g,handle:b},F),b.data("nui",{target:c,decimals:l,options:k,base:g,style:h,number:d}).data("store",C(b,k.S)),b[0].getPercentage=A,m.push(b),t(b,s.to(k.range,k.start[d]));g.data({options:k,handles:m, +a});delete this.init;return this}}.init();f.each(h,function(d,b){if(b.r&&!a[d]&&0!==a[d]||(a[d]||0===a[d])&&!b.t(a,a[d],d))return console&&console.log&&console.log("Slider:\t\t\t",c,"\nOption:\t\t\t",d,"\nValue:\t\t\t",a[d]),f.error("Error on noUiSlider initialisation."),!1})}function t(a,c,d){var h=a.data("nui").options,l=a.data("nui").base.data(e[12]),b=a.data("nui").style,f=a.data("nui").decimals;if(c===a[0].getPercentage(b))return!1;c=0>c?0:100d?d:c),c===a[0].getPercentage(b)))return!1;0===a.data("nui").number&&95').appendTo(a).change(z);if(!1===c.to[d])return{val:function(a){if(a===p)return this._handle.data("nui-val");this._handle.data("nui-val",a)},hasClass:function(){return!1},_handle:a}}function D(a){if(a=u(a,!0)){var c=a.pass.base,d=c.data("style"),e=a.x-a.pass.startEvent.x,c="left"===d?c.width():c.height();"top"===d&&(e=a.y-a.pass.startEvent.y); +e=a.pass.position+100*e/c;t(a.pass.handle,e);v([a.pass.base.data("options").slide],a.pass.base.data("target"))}}function w(a){q(a)||(a.data.handle.children().removeClass(e[4]),m.off(n.move),m.off(n.end),f("body").off(g),a.data.base.data("target").change())}function E(a){if(!q(a)&&(a=u(a))){var c=a.pass.handle,d=c[0].getPercentage(c.data("nui").style);c.children().addClass("noUi-active");m.on(n.move,{startEvent:a,position:d,base:a.pass.base,handle:c},D);m.on(n.end,{base:a.pass.base,handle:c},w);f("body").on("selectstart"+ +g,function(){return!1})}}function F(a){w({data:{base:a.data.base,handle:a.data.handle}});a.stopPropagation()}function G(a){if(!q(a)&&!a.data.base.find("."+e[4]).length&&(a=u(a))){var c,d,h=a.pass.base;d=a.pass.handles;var l=h.data("style"),b=a["left"===l?"x":"y"],f="left"===l?h.width():h.height(),k=a.t[2]?window.pageXOffset:0,g=[];a={left:h.offset().left-k,top:h.offset().top};for(c=0;ca[0]?c+Math.abs(a[0]):c-a[0];return 100*c/this._length(a)},from:function(a,c){return 100*c/this._length(a)},is:function(a,c){return c*this._length(a)/100+a[0]},_length:function(a){return a[0]>a[1]?a[0]-a[1]:a[1]-a[0]}};window.navigator.msPointerEnabled&&(n={start:"MSPointerDown"+g,move:"MSPointerMove"+g,end:"MSPointerUp"+g});f.fn.val=function(){return this.hasClass(e[6])?H.apply(this,arguments):I.apply(this,arguments)};return function(){return this.each(function(a, +c){c=f(c);c.addClass(e[6]);var d,h,l,b,g=f("
").appendTo(c),m=[];d=J;var p=[x.concat([e[1]+e[7]]),x.concat([e[1]+e[8]])],q=[y.concat([e[2]+e[7]]),y.concat([e[2]+e[8]])];k=f.extend({handles:2,margin:0,orientation:"horizontal"},k)||{};k.serialization||(k.serialization={to:[!1,!1],resolution:0.01});B(k,c);k.S=k.serialization;k.connect&&(p[0].push(e[9]),"lower"===k.connect?(d.push(e[9],e[9]+e[7]),p[0].push(e[13])):d.push(e[9]+e[8]));h="vertical"===k.orientation?"top":"left";l=k.S.resolution.toString().split("."); +l=1==l[0]?0:l[1].length;"vertical"===k.orientation?d.push(e[10]):d.push(e[11]);g.addClass(d.join(" ")).data("target",c);for(d=0;d
").appendTo(g),b.addClass(p[d].join(" ")),b.children().addClass(q[d].join(" ")),b.children().on(n.start,{base:g,handle:b},E).on(n.end,{base:g,handle:b},F),b.data("nui",{target:c,decimals:l,options:k,base:g,style:h,number:d}).data("store",C(b,k.S)),b[0].getPercentage=A,m.push(b),t(b,r.to(k.range,k.start[d]));g.data({options:k,handles:m, style:h});c.data({base:g,handles:m});g.on(n.end,{base:g,handles:m},G)})}.apply(this,arguments)}})(jQuery);