Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #96 from andreruffert/release-0.3.5
Browse files Browse the repository at this point in the history
release: 0.3.5
  • Loading branch information
andreruffert committed Sep 28, 2014
2 parents f2bb1e7 + 99a3d60 commit 28e1519
Show file tree
Hide file tree
Showing 8 changed files with 170 additions and 14 deletions.
7 changes: 6 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,17 @@ module.exports = function (grunt) {
// Increment version
bump: {
options: {
files: ['bower.json', 'package.json'],
files: [
'bower.json',
'package.json',
'rangeslider.jquery.json'
],
updateConfigs: ['pkg'],
commitMessage: 'chore(release): v%VERSION%',
commitFiles: [
'bower.json',
'package.json',
'rangeslider.jquery.json',
'dist'
],
createTag: false
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rangeslider.js",
"version": "0.3.4",
"version": "0.3.5",
"homepage": "https://github.com/andreruffert/rangeslider.js",
"authors": [
"André Ruffert <[email protected]>"
Expand Down
74 changes: 70 additions & 4 deletions dist/rangeslider.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! rangeslider.js - v0.3.4 | (c) 2014 @andreruffert | MIT license | https://github.com/andreruffert/rangeslider.js */
/*! rangeslider.js - v0.3.5 | (c) 2014 @andreruffert | MIT license | https://github.com/andreruffert/rangeslider.js */
(function(factory) {
'use strict';

Expand Down Expand Up @@ -78,6 +78,72 @@
};
}

/**
* Check if a `element` is visible in the DOM
*
* @param {Element} element
* @return {Boolean}
*/
function isHidden(element) {
if (element.offsetWidth !== 0 || element.offsetHeight !== 0) {
return false;
}
return true;
}

/**
* Get hidden parentNodes of an `element`
*
* @param {Element} element
* @return {[type]}
*/
function getHiddenParentNodes(element) {
var parents = [],
node = element.parentNode;

while (isHidden(node)) {
parents.push(node);
node = node.parentNode;
}
return parents;
}

/**
* Returns dimensions for an element even if it is not visible in the DOM.
*
* @param {Element} element
* @param {String} key (e.g. offsetWidth …)
* @return {Number}
*/
function getDimension(element, key) {
var hiddenParentNodes = getHiddenParentNodes(element),
hiddenParentNodesLength = hiddenParentNodes.length,
displayProperty = [],
dimension = element[key];

if (hiddenParentNodesLength) {
for (var i = 0; i < hiddenParentNodesLength; i++) {
// Cache the display property to restore it later.
displayProperty[i] = hiddenParentNodes[i].style.display;

hiddenParentNodes[i].style.display = 'block';
hiddenParentNodes[i].style.height = '0';
hiddenParentNodes[i].style.overflow = 'hidden';
hiddenParentNodes[i].style.visibility = 'hidden';
}

dimension = element[key];

for (var j = 0; j < hiddenParentNodesLength; j++) {
hiddenParentNodes[j].style.display = displayProperty[j];
hiddenParentNodes[j].style.height = '';
hiddenParentNodes[j].style.overflow = '';
hiddenParentNodes[j].style.visibility = '';
}
}
return dimension;
}

/**
* Plugin
* @param {String} element
Expand Down Expand Up @@ -158,8 +224,8 @@
};

Plugin.prototype.update = function() {
this.handleWidth = this.$handle[0].offsetWidth;
this.rangeWidth = this.$range[0].offsetWidth;
this.handleWidth = getDimension(this.$handle[0], 'offsetWidth');
this.rangeWidth = getDimension(this.$range[0], 'offsetWidth');
this.maxHandleX = this.rangeWidth - this.handleWidth;
this.grabX = this.handleWidth / 2;
this.position = this.getPositionFromValue(this.value);
Expand Down Expand Up @@ -264,7 +330,7 @@
Plugin.prototype.getValueFromPosition = function(pos) {
var percentage, value;
percentage = ((pos) / (this.maxHandleX || 1));
value = this.step * Math.ceil((((percentage) * (this.max - this.min)) + this.min) / this.step);
value = this.step * Math.round(percentage * (this.max - this.min) / this.step) + this.min;
return Number((value).toFixed(2));
};

Expand Down
4 changes: 2 additions & 2 deletions dist/rangeslider.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ <h2>Destroy a plugin instance</h2>
<button data-behaviour="initialize">Initialize</button>
</div>

<br>
<br>

<div id="js-example-hidden">
<h2>Consider initialization and update of hidden elements</h2>
<div style="display:none">
<input type="range" min="10" max="100" data-rangeslider>
<output></output>
</div>
<button data-behaviour="toggle">Toggle visibility</button>
</div>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="../dist/rangeslider.min.js"></script>
<script>
Expand Down Expand Up @@ -167,6 +179,13 @@ <h2>Destroy a plugin instance</h2>
$('input[type="range"]', e.target.parentNode).rangeslider({ polyfill: false });
});

// Example functionality to test initialisation on hidden elements
$document
.on('click', '#js-example-hidden button[data-behaviour="toggle"]', function(e) {
var $container = $(e.target.previousElementSibling);
$container.toggle();
});

// Basic rangeslider initialization
$element.rangeslider({

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "rangeslider.js",
"title": "rangeslider.js",
"description": "Simple, small and fast JavaScript/jQuery polyfill for the HTML5 <input type=\"range\"> slider element",
"version": "0.3.4",
"version": "0.3.5",
"homepage": "https://github.com/andreruffert/rangeslider.js",
"license": "MIT",
"keywords": [
Expand Down Expand Up @@ -41,5 +41,5 @@
"load-grunt-tasks": "~0.2.1",
"time-grunt": "~0.2.7"
},
"codename": "Red Orange"
"codename": "Cadet Blue"
}
2 changes: 1 addition & 1 deletion rangeslider.jquery.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "rangeslider",
"title": "rangeslider.js",
"description": "Simple, small and fast JavaScript/jQuery polyfill for the HTML5 <input type=\"range\"> slider element",
"version": "0.3.3",
"version": "0.3.5",
"homepage": "https://github.com/andreruffert/rangeslider.js",
"docs": "http://andreruffert.github.io/rangeslider.js/",
"license": "MIT",
Expand Down
Loading

0 comments on commit 28e1519

Please sign in to comment.