diff --git a/.gitignore b/.gitignore
index 582b19e..aca36ee 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
.DS_Store
node_modules
.sass-cache
+
+# Ignore files beginning with a #
+\#*
diff --git a/.jshintrc b/.jshintrc
index 3fe39ce..36d95e5 100644
--- a/.jshintrc
+++ b/.jshintrc
@@ -19,6 +19,7 @@
"trailing": true,
"smarttabs": true,
"globals": {
- "jQuery": true
+ "jQuery": true,
+ "define": true
}
}
diff --git a/bower.json b/bower.json
index efc01d7..c45b0cd 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
{
"name": "rangeslider.js",
- "version": "0.2.4",
+ "version": "0.2.5",
"main": "dist/rangeslider.js",
"homepage": "https://github.com/andreruffert/rangeslider.js",
"author": "André Ruffert",
diff --git a/dist/rangeslider.css b/dist/rangeslider.css
index 1eeb189..1ca4266 100644
--- a/dist/rangeslider.css
+++ b/dist/rangeslider.css
@@ -1,8 +1,4 @@
-.rangeslider {
- position: relative;
-}
-
-.rangeslider__range,
+.rangeslider,
.rangeslider__fill {
background: #e6e6e6;
border: none;
@@ -20,6 +16,10 @@
border-radius: 10px;
}
+.rangeslider {
+ position: relative;
+}
+
.rangeslider__fill {
background: #00ff00;
position: absolute;
diff --git a/dist/rangeslider.js b/dist/rangeslider.js
index 8332870..4f25fc0 100644
--- a/dist/rangeslider.js
+++ b/dist/rangeslider.js
@@ -1,4 +1,4 @@
-/*! rangeslider.js - v0.2.4 | (c) 2014 @andreruffert | MIT license | https://github.com/andreruffert/rangeslider.js */
+/*! rangeslider.js - v0.2.5 | (c) 2014 @andreruffert | MIT license | https://github.com/andreruffert/rangeslider.js */
'use strict';
(function (module) {
@@ -39,8 +39,7 @@
inputrange = supportsRange(),
defaults = {
polyfill: true,
- baseClass: 'rangeslider',
- rangeClass: 'rangeslider__range',
+ rangeClass: 'rangeslider',
fillClass: 'rangeslider__fill',
handleClass: 'rangeslider__handle',
startEvent: ((!touchevents) ? 'mousedown' : 'touchstart') + '.' + pluginName,
@@ -109,14 +108,13 @@
}
this.identifier = 'js-' + pluginName + '-' +(+new Date());
- this.value = parseInt(this.$element[0].value) || 0;
- this.min = parseInt(this.$element[0].getAttribute('min')) || 0;
- this.max = parseInt(this.$element[0].getAttribute('max')) || 0;
- this.step = parseInt(this.$element[0].getAttribute('step')) || 1;
- this.$range = $('
');
+ this.value = parseFloat(this.$element[0].value) || 0;
+ this.min = parseFloat(this.$element[0].getAttribute('min')) || 0;
+ this.max = parseFloat(this.$element[0].getAttribute('max')) || 100;
+ this.step = parseFloat(this.$element[0].getAttribute('step')) || 1;
this.$fill = $('');
this.$handle = $('');
- this.$base = $('').insertBefore(this.$element).prepend(this.$range, this.$fill, this.$handle, this.$element);
+ this.$range = $('').insertBefore(this.$element).prepend(this.$fill, this.$handle, this.$element);
// visually hide the input
this.$element.css({
@@ -136,11 +134,24 @@
// Attach Events
var _this = this;
+
this.$window.on('resize' + '.' + pluginName, debounce(function() {
// Simulate resizeEnd event.
delay(function() { _this.update(); }, 300);
}, 20));
+
this.$document.on(this.options.startEvent, '#' + this.identifier, this.handleDown);
+
+ // Listen to programmatic value changes
+ this.$element.on('change' + '.' + pluginName, function(e, data) {
+ if (data && data.origin === pluginName) {
+ return;
+ }
+
+ var value = e.target.value,
+ pos = _this.getPositionFromValue(value);
+ _this.setPosition(pos);
+ });
}
Plugin.prototype.init = function() {
@@ -152,7 +163,7 @@
};
Plugin.prototype.update = function() {
- this.handleWidth = this.$handle.width();
+ this.handleWidth = this.$handle[0].offsetWidth;
this.rangeWidth = this.$range[0].offsetWidth;
this.maxHandleX = this.rangeWidth - this.handleWidth;
this.grabX = this.handleWidth / 2;
@@ -166,8 +177,13 @@
this.$document.on(this.options.moveEvent, this.handleMove);
this.$document.on(this.options.endEvent, this.handleEnd);
- var posX = this.getRelativePosition(this.$base[0], e),
- handleX = this.getPositionFromNode(this.$handle[0]) - this.getPositionFromNode(this.$base[0]);
+ // If we click on the handle don't set the new position
+ if ((' ' + e.target.className + ' ').replace(/[\n\t]/g, ' ').indexOf(this.options.handleClass) > -1) {
+ return false;
+ }
+
+ var posX = this.getRelativePosition(this.$range[0], e),
+ handleX = this.getPositionFromNode(this.$handle[0]) - this.getPositionFromNode(this.$range[0]);
this.setPosition(posX - this.grabX);
@@ -178,7 +194,7 @@
Plugin.prototype.handleMove = function(e) {
e.preventDefault();
- var posX = this.getRelativePosition(this.$base[0], e);
+ var posX = this.getRelativePosition(this.$range[0], e);
this.setPosition(posX - this.grabX);
};
@@ -187,7 +203,7 @@
this.$document.off(this.options.moveEvent, this.handleMove);
this.$document.off(this.options.endEvent, this.handleEnd);
- var posX = this.getRelativePosition(this.$base[0], e);
+ var posX = this.getRelativePosition(this.$range[0], e);
if (this.onSlideEnd && typeof this.onSlideEnd === 'function') {
this.onSlideEnd(posX - this.grabX, this.value);
}
@@ -203,17 +219,12 @@
Plugin.prototype.setPosition = function(pos) {
var left, value;
left = this.cap(pos, 0, this.maxHandleX);
- value = this.getValueFromPosition(left);
// Snap steps
- if (this.step > 1) {
- value = Math.ceil((value) / this.step ) * this.step;
- left = this.getPositionFromValue(value);
- }
+ value = (this.getValueFromPosition(left) / this.step) * this.step;
+ left = this.getPositionFromValue(value);
- left = Math.ceil(left);
-
- this.$fill[0].style.width = (left + this.handleWidth) + 'px';
+ this.$fill[0].style.width = (left + this.grabX) + 'px';
this.$handle[0].style.left = left + 'px';
this.setValue(value);
@@ -236,27 +247,25 @@
};
Plugin.prototype.getRelativePosition = function(node, e) {
- return (e.pageX || e.originalEvent.changedTouches[0].pageX || 0) - this.getPositionFromNode(node);
+ return (e.pageX || e.originalEvent.clientX || e.originalEvent.touches[0].clientX || e.currentPoint.x) - this.getPositionFromNode(node);
};
Plugin.prototype.getPositionFromValue = function(value) {
var percentage, pos;
- percentage = ((value - this.min) / (this.max - this.min)) * 100;
- pos = (percentage/100) * this.maxHandleX;
-
+ percentage = (value - this.min)/(this.max - this.min);
+ pos = percentage * this.maxHandleX;
return pos;
};
Plugin.prototype.getValueFromPosition = function(pos) {
var percentage, value;
- percentage = ((pos) / (this.maxHandleX)) * 100;
- value = Math.ceil(((percentage/100) * (this.max - this.min)) + this.min);
-
+ percentage = (pos) / (this.maxHandleX);
+ value = this.step * Math.ceil((((percentage) * (this.max - this.min)) + this.min) / this.step);
return value;
};
Plugin.prototype.setValue = function(value) {
- this.$element.val(value).trigger('change');
+ this.$element.val(value).trigger('change', {origin: pluginName});
};
// A really lightweight plugin wrapper around the constructor,
diff --git a/dist/rangeslider.min.js b/dist/rangeslider.min.js
index 57b3d45..c695bcc 100644
--- a/dist/rangeslider.min.js
+++ b/dist/rangeslider.min.js
@@ -1,2 +1,2 @@
-/*! rangeslider.js - v0.2.4 | (c) 2014 @andreruffert | MIT license | https://github.com/andreruffert/rangeslider.js */
-"use strict";!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){function b(){var a=document.createElement("input");return a.setAttribute("type","range"),"text"!==a.type}function c(){var a=!1,b=b||{};return("ontouchstart"in window||window.DocumentTouch&&document instanceof b)&&(a=!0),a}function d(a,b){var c=Array.prototype.slice.call(arguments,2);return setTimeout(function(){return a.apply(null,c)},b)}function e(a,b){return b=b||100,function(){if(!a.debouncing){var c=Array.prototype.slice.apply(arguments);a.lastReturnVal=a.apply(window,c),a.debouncing=!0}return clearTimeout(a.debounceTimeout),a.debounceTimeout=setTimeout(function(){a.debouncing=!1},b),a.lastReturnVal}}function f(b,c){if(this.$window=a(window),this.$document=a(document),this.$element=a(b),this.options=a.extend({},j,c),this._defaults=j,this._name=g,this.polyfill=this.options.polyfill,this.onInit=this.options.onInit,this.onSlide=this.options.onSlide,this.onSlideEnd=this.options.onSlideEnd,this.polyfill&&i)return!1;this.identifier="js-"+g+"-"+ +new Date,this.value=parseInt(this.$element[0].value)||0,this.min=parseInt(this.$element[0].getAttribute("min"))||0,this.max=parseInt(this.$element[0].getAttribute("max"))||0,this.step=parseInt(this.$element[0].getAttribute("step"))||1,this.$range=a(''),this.$fill=a(''),this.$handle=a(''),this.$base=a('').insertBefore(this.$element).prepend(this.$range,this.$fill,this.$handle,this.$element),this.$element.css({position:"absolute",width:"1px",height:"1px",overflow:"hidden",visibility:"hidden"}),this.handleDown=a.proxy(this.handleDown,this),this.handleMove=a.proxy(this.handleMove,this),this.handleEnd=a.proxy(this.handleEnd,this),this.init();var f=this;this.$window.on("resize."+g,e(function(){d(function(){f.update()},300)},20)),this.$document.on(this.options.startEvent,"#"+this.identifier,this.handleDown)}var g="rangeslider",h=c(),i=b(),j={polyfill:!0,baseClass:"rangeslider",rangeClass:"rangeslider__range",fillClass:"rangeslider__fill",handleClass:"rangeslider__handle",startEvent:(h?"touchstart":"mousedown")+"."+g,moveEvent:(h?"touchmove":"mousemove")+"."+g,endEvent:(h?"touchend":"mouseup")+"."+g};f.prototype.init=function(){this.update(),this.onInit&&"function"==typeof this.onInit&&this.onInit()},f.prototype.update=function(){this.handleWidth=this.$handle.width(),this.rangeWidth=this.$range[0].offsetWidth,this.maxHandleX=this.rangeWidth-this.handleWidth,this.grabX=this.handleWidth/2,this.position=this.getPositionFromValue(this.value),this.setPosition(this.position)},f.prototype.handleDown=function(a){a.preventDefault(),this.$document.on(this.options.moveEvent,this.handleMove),this.$document.on(this.options.endEvent,this.handleEnd);var b=this.getRelativePosition(this.$base[0],a),c=this.getPositionFromNode(this.$handle[0])-this.getPositionFromNode(this.$base[0]);this.setPosition(b-this.grabX),b>=c&&ba?b:a>c?c:a},f.prototype.setPosition=function(a){var b,c;b=this.cap(a,0,this.maxHandleX),c=this.getValueFromPosition(b),this.step>1&&(c=Math.ceil(c/this.step)*this.step,b=this.getPositionFromValue(c)),b=Math.ceil(b),this.$fill[0].style.width=b+this.handleWidth+"px",this.$handle[0].style.left=b+"px",this.setValue(c),this.position=b,this.value=c,this.onSlide&&"function"==typeof this.onSlide&&this.onSlide(b,c)},f.prototype.getPositionFromNode=function(a){for(var b=0;null!==a;)b+=a.offsetLeft,a=a.offsetParent;return b},f.prototype.getRelativePosition=function(a,b){return(b.pageX||b.originalEvent.changedTouches[0].pageX||0)-this.getPositionFromNode(a)},f.prototype.getPositionFromValue=function(a){var b,c;return b=(a-this.min)/(this.max-this.min)*100,c=b/100*this.maxHandleX},f.prototype.getValueFromPosition=function(a){var b,c;return b=a/this.maxHandleX*100,c=Math.ceil(b/100*(this.max-this.min)+this.min)},f.prototype.setValue=function(a){this.$element.val(a).trigger("change")},a.fn[g]=function(b){return this.each(function(){a.data(this,"plugin_"+g)||a.data(this,"plugin_"+g,new f(this,b))})}});
\ No newline at end of file
+/*! rangeslider.js - v0.2.5 | (c) 2014 @andreruffert | MIT license | https://github.com/andreruffert/rangeslider.js */
+"use strict";!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):a(jQuery)}(function(a){function b(){var a=document.createElement("input");return a.setAttribute("type","range"),"text"!==a.type}function c(){var a=!1,b=b||{};return("ontouchstart"in window||window.DocumentTouch&&document instanceof b)&&(a=!0),a}function d(a,b){var c=Array.prototype.slice.call(arguments,2);return setTimeout(function(){return a.apply(null,c)},b)}function e(a,b){return b=b||100,function(){if(!a.debouncing){var c=Array.prototype.slice.apply(arguments);a.lastReturnVal=a.apply(window,c),a.debouncing=!0}return clearTimeout(a.debounceTimeout),a.debounceTimeout=setTimeout(function(){a.debouncing=!1},b),a.lastReturnVal}}function f(b,c){if(this.$window=a(window),this.$document=a(document),this.$element=a(b),this.options=a.extend({},j,c),this._defaults=j,this._name=g,this.polyfill=this.options.polyfill,this.onInit=this.options.onInit,this.onSlide=this.options.onSlide,this.onSlideEnd=this.options.onSlideEnd,this.polyfill&&i)return!1;this.identifier="js-"+g+"-"+ +new Date,this.value=parseFloat(this.$element[0].value)||0,this.min=parseFloat(this.$element[0].getAttribute("min"))||0,this.max=parseFloat(this.$element[0].getAttribute("max"))||100,this.step=parseFloat(this.$element[0].getAttribute("step"))||1,this.$fill=a(''),this.$handle=a(''),this.$range=a('').insertBefore(this.$element).prepend(this.$fill,this.$handle,this.$element),this.$element.css({position:"absolute",width:"1px",height:"1px",overflow:"hidden",visibility:"hidden"}),this.handleDown=a.proxy(this.handleDown,this),this.handleMove=a.proxy(this.handleMove,this),this.handleEnd=a.proxy(this.handleEnd,this),this.init();var f=this;this.$window.on("resize."+g,e(function(){d(function(){f.update()},300)},20)),this.$document.on(this.options.startEvent,"#"+this.identifier,this.handleDown),this.$element.on("change."+g,function(a,b){if(!b||b.origin!==g){var c=a.target.value,d=f.getPositionFromValue(c);f.setPosition(d)}})}var g="rangeslider",h=c(),i=b(),j={polyfill:!0,rangeClass:"rangeslider",fillClass:"rangeslider__fill",handleClass:"rangeslider__handle",startEvent:(h?"touchstart":"mousedown")+"."+g,moveEvent:(h?"touchmove":"mousemove")+"."+g,endEvent:(h?"touchend":"mouseup")+"."+g};f.prototype.init=function(){this.update(),this.onInit&&"function"==typeof this.onInit&&this.onInit()},f.prototype.update=function(){this.handleWidth=this.$handle[0].offsetWidth,this.rangeWidth=this.$range[0].offsetWidth,this.maxHandleX=this.rangeWidth-this.handleWidth,this.grabX=this.handleWidth/2,this.position=this.getPositionFromValue(this.value),this.setPosition(this.position)},f.prototype.handleDown=function(a){if(a.preventDefault(),this.$document.on(this.options.moveEvent,this.handleMove),this.$document.on(this.options.endEvent,this.handleEnd),(" "+a.target.className+" ").replace(/[\n\t]/g," ").indexOf(this.options.handleClass)>-1)return!1;var b=this.getRelativePosition(this.$range[0],a),c=this.getPositionFromNode(this.$handle[0])-this.getPositionFromNode(this.$range[0]);this.setPosition(b-this.grabX),b>=c&&ba?b:a>c?c:a},f.prototype.setPosition=function(a){var b,c;b=this.cap(a,0,this.maxHandleX),c=this.getValueFromPosition(b)/this.step*this.step,b=this.getPositionFromValue(c),this.$fill[0].style.width=b+this.grabX+"px",this.$handle[0].style.left=b+"px",this.setValue(c),this.position=b,this.value=c,this.onSlide&&"function"==typeof this.onSlide&&this.onSlide(b,c)},f.prototype.getPositionFromNode=function(a){for(var b=0;null!==a;)b+=a.offsetLeft,a=a.offsetParent;return b},f.prototype.getRelativePosition=function(a,b){return(b.pageX||b.originalEvent.clientX||b.originalEvent.touches[0].clientX||b.currentPoint.x)-this.getPositionFromNode(a)},f.prototype.getPositionFromValue=function(a){var b,c;return b=(a-this.min)/(this.max-this.min),c=b*this.maxHandleX},f.prototype.getValueFromPosition=function(a){var b,c;return b=a/this.maxHandleX,c=this.step*Math.ceil((b*(this.max-this.min)+this.min)/this.step)},f.prototype.setValue=function(a){this.$element.val(a).trigger("change",{origin:g})},a.fn[g]=function(b){return this.each(function(){a.data(this,"plugin_"+g)||a.data(this,"plugin_"+g,new f(this,b))})}});
\ No newline at end of file
diff --git a/example/index.html b/example/index.html
index b81b0d1..461e3c7 100644
--- a/example/index.html
+++ b/example/index.html
@@ -17,28 +17,40 @@
margin: 0 auto;
max-width: 800px;
}
+
output {
display: block;
font-size: 30px;
font-weight: bold;
text-align: center;
margin: 30px 0;
+ width: 100%;
}
+
+
Programmatic value changes
+
+
+
+
+
+
+
+
+
-
+
-
-
+
@@ -46,10 +58,12 @@
diff --git a/package.json b/package.json
index b5bf6c1..3b8e6cc 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "rangeslider.js",
"title": "rangeslider.js",
"description": "Simple, small and fast JavaScript/jQuery polyfill for the HTML5 slider element",
- "version": "0.2.4",
+ "version": "0.2.5",
"homepage": "https://github.com/andreruffert/rangeslider.js",
"license": "MIT",
"keywords": [
diff --git a/src/rangeslider.js b/src/rangeslider.js
index 5e8c667..cf59392 100644
--- a/src/rangeslider.js
+++ b/src/rangeslider.js
@@ -38,8 +38,7 @@
inputrange = supportsRange(),
defaults = {
polyfill: true,
- baseClass: 'rangeslider',
- rangeClass: 'rangeslider__range',
+ rangeClass: 'rangeslider',
fillClass: 'rangeslider__fill',
handleClass: 'rangeslider__handle',
startEvent: ((!touchevents) ? 'mousedown' : 'touchstart') + '.' + pluginName,
@@ -108,14 +107,13 @@
}
this.identifier = 'js-' + pluginName + '-' +(+new Date());
- this.value = parseInt(this.$element[0].value) || 0;
- this.min = parseInt(this.$element[0].getAttribute('min')) || 0;
- this.max = parseInt(this.$element[0].getAttribute('max')) || 0;
- this.step = parseInt(this.$element[0].getAttribute('step')) || 1;
- this.$range = $('');
+ this.value = parseFloat(this.$element[0].value) || 0;
+ this.min = parseFloat(this.$element[0].getAttribute('min')) || 0;
+ this.max = parseFloat(this.$element[0].getAttribute('max')) || 100;
+ this.step = parseFloat(this.$element[0].getAttribute('step')) || 1;
this.$fill = $('');
this.$handle = $('');
- this.$base = $('').insertBefore(this.$element).prepend(this.$range, this.$fill, this.$handle, this.$element);
+ this.$range = $('').insertBefore(this.$element).prepend(this.$fill, this.$handle, this.$element);
// visually hide the input
this.$element.css({
@@ -135,11 +133,24 @@
// Attach Events
var _this = this;
+
this.$window.on('resize' + '.' + pluginName, debounce(function() {
// Simulate resizeEnd event.
delay(function() { _this.update(); }, 300);
}, 20));
+
this.$document.on(this.options.startEvent, '#' + this.identifier, this.handleDown);
+
+ // Listen to programmatic value changes
+ this.$element.on('change' + '.' + pluginName, function(e, data) {
+ if (data && data.origin === pluginName) {
+ return;
+ }
+
+ var value = e.target.value,
+ pos = _this.getPositionFromValue(value);
+ _this.setPosition(pos);
+ });
}
Plugin.prototype.init = function() {
@@ -151,7 +162,7 @@
};
Plugin.prototype.update = function() {
- this.handleWidth = this.$handle.width();
+ this.handleWidth = this.$handle[0].offsetWidth;
this.rangeWidth = this.$range[0].offsetWidth;
this.maxHandleX = this.rangeWidth - this.handleWidth;
this.grabX = this.handleWidth / 2;
@@ -165,8 +176,13 @@
this.$document.on(this.options.moveEvent, this.handleMove);
this.$document.on(this.options.endEvent, this.handleEnd);
- var posX = this.getRelativePosition(this.$base[0], e),
- handleX = this.getPositionFromNode(this.$handle[0]) - this.getPositionFromNode(this.$base[0]);
+ // If we click on the handle don't set the new position
+ if ((' ' + e.target.className + ' ').replace(/[\n\t]/g, ' ').indexOf(this.options.handleClass) > -1) {
+ return false;
+ }
+
+ var posX = this.getRelativePosition(this.$range[0], e),
+ handleX = this.getPositionFromNode(this.$handle[0]) - this.getPositionFromNode(this.$range[0]);
this.setPosition(posX - this.grabX);
@@ -177,7 +193,7 @@
Plugin.prototype.handleMove = function(e) {
e.preventDefault();
- var posX = this.getRelativePosition(this.$base[0], e);
+ var posX = this.getRelativePosition(this.$range[0], e);
this.setPosition(posX - this.grabX);
};
@@ -186,7 +202,7 @@
this.$document.off(this.options.moveEvent, this.handleMove);
this.$document.off(this.options.endEvent, this.handleEnd);
- var posX = this.getRelativePosition(this.$base[0], e);
+ var posX = this.getRelativePosition(this.$range[0], e);
if (this.onSlideEnd && typeof this.onSlideEnd === 'function') {
this.onSlideEnd(posX - this.grabX, this.value);
}
@@ -202,17 +218,12 @@
Plugin.prototype.setPosition = function(pos) {
var left, value;
left = this.cap(pos, 0, this.maxHandleX);
- value = this.getValueFromPosition(left);
// Snap steps
- if (this.step > 1) {
- value = Math.ceil((value) / this.step ) * this.step;
- left = this.getPositionFromValue(value);
- }
+ value = (this.getValueFromPosition(left) / this.step) * this.step;
+ left = this.getPositionFromValue(value);
- left = Math.ceil(left);
-
- this.$fill[0].style.width = (left + this.handleWidth) + 'px';
+ this.$fill[0].style.width = (left + this.grabX) + 'px';
this.$handle[0].style.left = left + 'px';
this.setValue(value);
@@ -235,27 +246,25 @@
};
Plugin.prototype.getRelativePosition = function(node, e) {
- return (e.pageX || e.originalEvent.changedTouches[0].pageX || 0) - this.getPositionFromNode(node);
+ return (e.pageX || e.originalEvent.clientX || e.originalEvent.touches[0].clientX || e.currentPoint.x) - this.getPositionFromNode(node);
};
Plugin.prototype.getPositionFromValue = function(value) {
var percentage, pos;
- percentage = ((value - this.min) / (this.max - this.min)) * 100;
- pos = (percentage/100) * this.maxHandleX;
-
+ percentage = (value - this.min)/(this.max - this.min);
+ pos = percentage * this.maxHandleX;
return pos;
};
Plugin.prototype.getValueFromPosition = function(pos) {
var percentage, value;
- percentage = ((pos) / (this.maxHandleX)) * 100;
- value = Math.ceil(((percentage/100) * (this.max - this.min)) + this.min);
-
+ percentage = (pos) / (this.maxHandleX);
+ value = this.step * Math.ceil((((percentage) * (this.max - this.min)) + this.min) / this.step);
return value;
};
Plugin.prototype.setValue = function(value) {
- this.$element.val(value).trigger('change');
+ this.$element.val(value).trigger('change', {origin: pluginName});
};
// A really lightweight plugin wrapper around the constructor,
diff --git a/src/rangeslider.scss b/src/rangeslider.scss
index 1ad6c22..1ff8848 100644
--- a/src/rangeslider.scss
+++ b/src/rangeslider.scss
@@ -1,10 +1,6 @@
@import "compass/css3";
-.rangeslider {
- position: relative;
-}
-
-.rangeslider__range,
+.rangeslider,
.rangeslider__fill {
background: #e6e6e6;
border: none;
@@ -16,6 +12,10 @@
@include border-radius(10px);
}
+.rangeslider {
+ position: relative;
+}
+
.rangeslider__fill {
background: #00ff00;
position: absolute;