Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 28e1519

Browse files
committed
Merge pull request #96 from andreruffert/release-0.3.5
release: 0.3.5
2 parents f2bb1e7 + 99a3d60 commit 28e1519

8 files changed

+170
-14
lines changed

Gruntfile.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,17 @@ module.exports = function (grunt) {
9595
// Increment version
9696
bump: {
9797
options: {
98-
files: ['bower.json', 'package.json'],
98+
files: [
99+
'bower.json',
100+
'package.json',
101+
'rangeslider.jquery.json'
102+
],
99103
updateConfigs: ['pkg'],
100104
commitMessage: 'chore(release): v%VERSION%',
101105
commitFiles: [
102106
'bower.json',
103107
'package.json',
108+
'rangeslider.jquery.json',
104109
'dist'
105110
],
106111
createTag: false

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rangeslider.js",
3-
"version": "0.3.4",
3+
"version": "0.3.5",
44
"homepage": "https://github.com/andreruffert/rangeslider.js",
55
"authors": [
66
"André Ruffert <[email protected]>"

dist/rangeslider.js

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! rangeslider.js - v0.3.4 | (c) 2014 @andreruffert | MIT license | https://github.com/andreruffert/rangeslider.js */
1+
/*! rangeslider.js - v0.3.5 | (c) 2014 @andreruffert | MIT license | https://github.com/andreruffert/rangeslider.js */
22
(function(factory) {
33
'use strict';
44

@@ -78,6 +78,72 @@
7878
};
7979
}
8080

81+
/**
82+
* Check if a `element` is visible in the DOM
83+
*
84+
* @param {Element} element
85+
* @return {Boolean}
86+
*/
87+
function isHidden(element) {
88+
if (element.offsetWidth !== 0 || element.offsetHeight !== 0) {
89+
return false;
90+
}
91+
return true;
92+
}
93+
94+
/**
95+
* Get hidden parentNodes of an `element`
96+
*
97+
* @param {Element} element
98+
* @return {[type]}
99+
*/
100+
function getHiddenParentNodes(element) {
101+
var parents = [],
102+
node = element.parentNode;
103+
104+
while (isHidden(node)) {
105+
parents.push(node);
106+
node = node.parentNode;
107+
}
108+
return parents;
109+
}
110+
111+
/**
112+
* Returns dimensions for an element even if it is not visible in the DOM.
113+
*
114+
* @param {Element} element
115+
* @param {String} key (e.g. offsetWidth …)
116+
* @return {Number}
117+
*/
118+
function getDimension(element, key) {
119+
var hiddenParentNodes = getHiddenParentNodes(element),
120+
hiddenParentNodesLength = hiddenParentNodes.length,
121+
displayProperty = [],
122+
dimension = element[key];
123+
124+
if (hiddenParentNodesLength) {
125+
for (var i = 0; i < hiddenParentNodesLength; i++) {
126+
// Cache the display property to restore it later.
127+
displayProperty[i] = hiddenParentNodes[i].style.display;
128+
129+
hiddenParentNodes[i].style.display = 'block';
130+
hiddenParentNodes[i].style.height = '0';
131+
hiddenParentNodes[i].style.overflow = 'hidden';
132+
hiddenParentNodes[i].style.visibility = 'hidden';
133+
}
134+
135+
dimension = element[key];
136+
137+
for (var j = 0; j < hiddenParentNodesLength; j++) {
138+
hiddenParentNodes[j].style.display = displayProperty[j];
139+
hiddenParentNodes[j].style.height = '';
140+
hiddenParentNodes[j].style.overflow = '';
141+
hiddenParentNodes[j].style.visibility = '';
142+
}
143+
}
144+
return dimension;
145+
}
146+
81147
/**
82148
* Plugin
83149
* @param {String} element
@@ -158,8 +224,8 @@
158224
};
159225

160226
Plugin.prototype.update = function() {
161-
this.handleWidth = this.$handle[0].offsetWidth;
162-
this.rangeWidth = this.$range[0].offsetWidth;
227+
this.handleWidth = getDimension(this.$handle[0], 'offsetWidth');
228+
this.rangeWidth = getDimension(this.$range[0], 'offsetWidth');
163229
this.maxHandleX = this.rangeWidth - this.handleWidth;
164230
this.grabX = this.handleWidth / 2;
165231
this.position = this.getPositionFromValue(this.value);
@@ -264,7 +330,7 @@
264330
Plugin.prototype.getValueFromPosition = function(pos) {
265331
var percentage, value;
266332
percentage = ((pos) / (this.maxHandleX || 1));
267-
value = this.step * Math.ceil((((percentage) * (this.max - this.min)) + this.min) / this.step);
333+
value = this.step * Math.round(percentage * (this.max - this.min) / this.step) + this.min;
268334
return Number((value).toFixed(2));
269335
};
270336

dist/rangeslider.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/index.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,18 @@ <h2>Destroy a plugin instance</h2>
115115
<button data-behaviour="initialize">Initialize</button>
116116
</div>
117117

118+
<br>
119+
<br>
120+
121+
<div id="js-example-hidden">
122+
<h2>Consider initialization and update of hidden elements</h2>
123+
<div style="display:none">
124+
<input type="range" min="10" max="100" data-rangeslider>
125+
<output></output>
126+
</div>
127+
<button data-behaviour="toggle">Toggle visibility</button>
128+
</div>
129+
118130
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
119131
<script src="../dist/rangeslider.min.js"></script>
120132
<script>
@@ -167,6 +179,13 @@ <h2>Destroy a plugin instance</h2>
167179
$('input[type="range"]', e.target.parentNode).rangeslider({ polyfill: false });
168180
});
169181

182+
// Example functionality to test initialisation on hidden elements
183+
$document
184+
.on('click', '#js-example-hidden button[data-behaviour="toggle"]', function(e) {
185+
var $container = $(e.target.previousElementSibling);
186+
$container.toggle();
187+
});
188+
170189
// Basic rangeslider initialization
171190
$element.rangeslider({
172191

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "rangeslider.js",
33
"title": "rangeslider.js",
44
"description": "Simple, small and fast JavaScript/jQuery polyfill for the HTML5 <input type=\"range\"> slider element",
5-
"version": "0.3.4",
5+
"version": "0.3.5",
66
"homepage": "https://github.com/andreruffert/rangeslider.js",
77
"license": "MIT",
88
"keywords": [
@@ -41,5 +41,5 @@
4141
"load-grunt-tasks": "~0.2.1",
4242
"time-grunt": "~0.2.7"
4343
},
44-
"codename": "Red Orange"
44+
"codename": "Cadet Blue"
4545
}

rangeslider.jquery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "rangeslider",
33
"title": "rangeslider.js",
44
"description": "Simple, small and fast JavaScript/jQuery polyfill for the HTML5 <input type=\"range\"> slider element",
5-
"version": "0.3.3",
5+
"version": "0.3.5",
66
"homepage": "https://github.com/andreruffert/rangeslider.js",
77
"docs": "http://andreruffert.github.io/rangeslider.js/",
88
"license": "MIT",

0 commit comments

Comments
 (0)