From cf725ba5758d0fa37e40eb1343f0bf1df6d1f4e0 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Tue, 17 Jun 2014 10:10:00 +0200 Subject: [PATCH 1/5] =?UTF-8?q?set=20options=20based=20on=20input=20elem;?= =?UTF-8?q?=20don=E2=80=99t=20check=20for=20input=20elem=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main.js | 4 ++-- lib/powerange.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/main.js b/lib/main.js index bfc0d47..7903ac8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -30,7 +30,7 @@ function Powerange(element, options) { this.options = options || {}; this.slider = this.create('span', 'range-bar'); - if (this.element !== null && this.element.type === 'text') this.init(); + if (this.element !== null) this.init(); } /** @@ -295,4 +295,4 @@ Powerange.prototype.init = function() { this.checkValues(this.options.start); this.setRange(this.options.min, this.options.max); this.disable(); -}; \ No newline at end of file +}; diff --git a/lib/powerange.js b/lib/powerange.js index 569b0b3..4a23faa 100644 --- a/lib/powerange.js +++ b/lib/powerange.js @@ -33,6 +33,18 @@ var defaults = { module.exports = function(element, options) { options = options || {}; + // if we have an element, fill in some values based on that input element + if (element) { + if (typeof options.min === 'undefined') + options.min = element.min; + if (typeof options.max === 'undefined') + options.max = element.max; + if (typeof options.step === 'undefined') + options.step = element.step; + if (typeof options.start === 'undefined') + options.start = element.value; + } + for (var i in defaults) { if (options[i] == null) { options[i] = defaults[i]; @@ -44,4 +56,4 @@ module.exports = function(element, options) { } else { return new Horizontal(element, options); } -}; \ No newline at end of file +}; From 49aba238f295de280844125494d66d103c7a7a45 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Wed, 2 Jul 2014 11:39:32 +0200 Subject: [PATCH 2/5] use the build files in example, as to not rely on crappy grunt for development --- example/example.html | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/example/example.html b/example/example.html index 5bbadbe..b385b09 100644 --- a/example/example.html +++ b/example/example.html @@ -5,7 +5,7 @@ Powerange - iOS 7 style range slider - + @@ -391,9 +391,11 @@

Development

- + - \ No newline at end of file + From 57cb0232556f3c624fa7e700e466585893662318 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Wed, 2 Jul 2014 11:40:19 +0200 Subject: [PATCH 3/5] fix empty strings when the element has no min/max set --- lib/powerange.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/powerange.js b/lib/powerange.js index 4a23faa..339f2a2 100644 --- a/lib/powerange.js +++ b/lib/powerange.js @@ -35,13 +35,13 @@ module.exports = function(element, options) { // if we have an element, fill in some values based on that input element if (element) { - if (typeof options.min === 'undefined') + if (typeof options.min === 'undefined' && element.min) options.min = element.min; - if (typeof options.max === 'undefined') + if (typeof options.max === 'undefined' && element.max) options.max = element.max; - if (typeof options.step === 'undefined') + if (typeof options.step === 'undefined' && element.step) options.step = element.step; - if (typeof options.start === 'undefined') + if (typeof options.start === 'undefined' && element.value) options.start = element.value; } From fe5f2844e020fcbfa9c7483ea45ce8528f010238 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Wed, 2 Jul 2014 11:40:50 +0200 Subject: [PATCH 4/5] allow tapping anywhere on the slider, not just the handle --- lib/horizontal.js | 14 ++++++++++++-- lib/main.js | 11 +++++++---- lib/powerange.css | 14 ++++++++++++-- lib/vertical.js | 14 ++++++++++++-- 4 files changed, 43 insertions(+), 10 deletions(-) diff --git a/lib/horizontal.js b/lib/horizontal.js index d98a63e..4258cbc 100644 --- a/lib/horizontal.js +++ b/lib/horizontal.js @@ -75,10 +75,20 @@ Horizontal.prototype.setPosition = function(val) { Horizontal.prototype.onmousedown = function(e) { if (e.touches) e = e.touches[0]; - this.startX = e.clientX; + // snap to the touched position + if (e.target.className !== 'range-handle') { + var offset = 0; + var parent = this.handle; + while (parent = parent.offsetParent) + offset += parent.offsetLeft; + this.startX = offset - window.scrollX + this.handle.offsetLeft + this.handle.clientWidth / 2; + } else + this.startX = e.clientX; this.handleOffsetX = this.handle.offsetLeft; this.restrictHandleX = this.slider.offsetWidth - this.handle.offsetWidth; this.unselectable(this.slider, true); + // trigger a move right away, to reposition the handle + this.onmousemove(e); }; /** @@ -115,4 +125,4 @@ Horizontal.prototype.onmousemove = function(e) { Horizontal.prototype.onmouseup = function(e) { this.unselectable(this.slider, false); -}; \ No newline at end of file +}; diff --git a/lib/main.js b/lib/main.js index 7903ac8..acaddd8 100644 --- a/lib/main.js +++ b/lib/main.js @@ -28,7 +28,7 @@ function Powerange(element, options) { this.element = element; this.options = options || {}; - this.slider = this.create('span', 'range-bar'); + this.slider = this.create('div', 'range-container'); if (this.element !== null) this.init(); } @@ -41,11 +41,11 @@ function Powerange(element, options) { Powerange.prototype.bindEvents = function () { this.handle = this.slider.querySelector('.range-handle'); - this.touch = events(this.handle, this); + this.touch = events(this.slider, this); this.touch.bind('touchstart', 'onmousedown'); this.touch.bind('touchmove', 'onmousemove'); this.touch.bind('touchend', 'onmouseup'); - this.mouse = mouse(this.handle, this); + this.mouse = mouse(this.slider, this); this.mouse.bind(); }; @@ -97,10 +97,13 @@ Powerange.prototype.generate = function() { } }; + var bar = this.create('span', 'range-bar'); + this.slider.appendChild(bar); + for (var key in elems) { if (elems.hasOwnProperty(key)) { var temp = this.create(elems[key].type, elems[key].selector); - this.slider.appendChild(temp); + bar.appendChild(temp); } } diff --git a/lib/powerange.css b/lib/powerange.css index 7aebfa7..1d2a40c 100644 --- a/lib/powerange.css +++ b/lib/powerange.css @@ -9,6 +9,11 @@ * Horizontal slider style (default). */ +.range-container { + height: 4px; + padding: 13px 0px; +} + .range-bar { background-color: #a9acb1; border-radius: 15px; @@ -64,9 +69,14 @@ * Vertical slider style. */ -.vertical { +.vertical.range-container { + width: 4px; + padding: 0px 13px; height: 100%; +} +.vertical .range-bar { width: 4px; + height: 100%; } .vertical .range-quantity { @@ -116,4 +126,4 @@ .range-disabled { cursor: default; -} \ No newline at end of file +} diff --git a/lib/vertical.js b/lib/vertical.js index 68cc119..2c7df99 100644 --- a/lib/vertical.js +++ b/lib/vertical.js @@ -77,10 +77,20 @@ Vertical.prototype.setPosition = function(val) { Vertical.prototype.onmousedown = function(e) { if (e.touches) e = e.touches[0]; - this.startY = e.clientY; + // snap to the touched position + if (e.target.className !== 'range-handle') { + var offset = 0; + var parent = this.handle; + while (parent = parent.offsetParent) + offset += parent.offsetTop; + this.startY = offset - window.scrollY + this.handle.offsetTop + this.handle.clientHeight / 2; + } else + this.startY = e.clientY; this.handleOffsetY = this.slider.offsetHeight - this.handle.offsetHeight - this.handle.offsetTop; this.restrictHandleY = this.slider.offsetHeight - this.handle.offsetHeight; this.unselectable(this.slider, true); + // trigger a move right away, to reposition the handle + this.onmousemove(e); }; /** @@ -117,4 +127,4 @@ Vertical.prototype.onmousemove = function(e) { Vertical.prototype.onmouseup = function(e) { this.unselectable(this.slider, false); -}; \ No newline at end of file +}; From 62df99e669f2a1214ba9878f2f5a4786c86f6846 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Wed, 2 Jul 2014 11:42:08 +0200 Subject: [PATCH 5/5] Release 0.0.4 --- History.md | 9 ++++++++- bower.json | 2 +- component.json | 4 ++-- package.json | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/History.md b/History.md index 0093723..807fbe0 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,11 @@ +0.0.4 / 2014-07-02 +================== + + * allow tapping anywhere on the slider, not just the handle + * fix empty strings when the element has no min/max set + * use the build files in example, as to not rely on crappy grunt for development + 0.0.2 / 2014-04-26 ================== @@ -11,4 +18,4 @@ 0.0.1 / 2014-03-17 ================== - * Initial release \ No newline at end of file + * Initial release diff --git a/bower.json b/bower.json index 6d0c678..db1cc66 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "powerange" , "main": "dist/powerange.js" - , "version": "0.0.2" + , "version": "0.0.4" , "description": "iOS 7 style range slider" , "keywords": [ "range" diff --git a/component.json b/component.json index 5b1e699..18b4226 100644 --- a/component.json +++ b/component.json @@ -2,7 +2,7 @@ "name": "powerange" , "repo": "abpetkov/powerange" , "description": "iOS 7 style range slider" - , "version": "0.0.2" + , "version": "0.0.4" , "keywords": [ "range" , "slider" @@ -32,4 +32,4 @@ , "https://cdn.rawgit.com" , "https://rawgit.com" ] -} \ No newline at end of file +} diff --git a/package.json b/package.json index 7cbfe97..72a42f1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "powerange" - , "version": "0.0.2" + , "version": "0.0.4" , "description": "iOS 7 style range slider" , "main": "powerange.js" , "repository": {