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 #111 from andreruffert/feature/consider-details-el…
Browse files Browse the repository at this point in the history
…ement

feature: consider range inside `<details>`
  • Loading branch information
andreruffert committed Jan 23, 2015
2 parents 53d763c + 6d0cdf4 commit 57ae2e5
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
18 changes: 15 additions & 3 deletions dist/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@
* @return {Boolean}
*/
function isHidden(element) {
if (element.offsetWidth !== 0 || element.offsetHeight !== 0) {
return false;
if (element.offsetWidth === 0 ||
element.offsetHeight === 0 ||
// Also Consider native `<details>` elements.
element.open === false) {
return true;
}
return true;
return false;
}

/**
Expand Down Expand Up @@ -121,6 +124,13 @@
displayProperty = [],
dimension = element[key];

// Used for native `<details>` elements
function toggleOpenProperty(element) {
if (typeof element.open !== 'undefined') {
element.open = (element.open) ? false : true;
}
}

if (hiddenParentNodesLength) {
for (var i = 0; i < hiddenParentNodesLength; i++) {
// Cache the display property to restore it later.
Expand All @@ -130,11 +140,13 @@
hiddenParentNodes[i].style.height = '0';
hiddenParentNodes[i].style.overflow = 'hidden';
hiddenParentNodes[i].style.visibility = 'hidden';
toggleOpenProperty(hiddenParentNodes[i]);
}

dimension = element[key];

for (var j = 0; j < hiddenParentNodesLength; j++) {
toggleOpenProperty(hiddenParentNodes[j]);
hiddenParentNodes[j].style.display = displayProperty[j];
hiddenParentNodes[j].style.height = '';
hiddenParentNodes[j].style.overflow = '';
Expand Down
2 changes: 1 addition & 1 deletion dist/rangeslider.min.js

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

14 changes: 14 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ <h2>Consider initialization and update of hidden elements</h2>
<button data-behaviour="toggle">Toggle visibility</button>
</div>

<br>
<br>

<div id="js-example-hidden">
<h2>Combination with native <code>&lt;details&gt;</code> element</h2>
<details>
<summary>Toggle</summary>
<br>
<br>
<input type="range" min="10" max="100" value="20" data-rangeslider>
<output></output>
</details>
</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
18 changes: 15 additions & 3 deletions src/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,13 @@
* @return {Boolean}
*/
function isHidden(element) {
if (element.offsetWidth !== 0 || element.offsetHeight !== 0) {
return false;
if (element.offsetWidth === 0 ||
element.offsetHeight === 0 ||
// Also Consider native `<details>` elements.
element.open === false) {
return true;
}
return true;
return false;
}

/**
Expand Down Expand Up @@ -120,6 +123,13 @@
displayProperty = [],
dimension = element[key];

// Used for native `<details>` elements
function toggleOpenProperty(element) {
if (typeof element.open !== 'undefined') {
element.open = (element.open) ? false : true;
}
}

if (hiddenParentNodesLength) {
for (var i = 0; i < hiddenParentNodesLength; i++) {
// Cache the display property to restore it later.
Expand All @@ -129,11 +139,13 @@
hiddenParentNodes[i].style.height = '0';
hiddenParentNodes[i].style.overflow = 'hidden';
hiddenParentNodes[i].style.visibility = 'hidden';
toggleOpenProperty(hiddenParentNodes[i]);
}

dimension = element[key];

for (var j = 0; j < hiddenParentNodesLength; j++) {
toggleOpenProperty(hiddenParentNodes[j]);
hiddenParentNodes[j].style.display = displayProperty[j];
hiddenParentNodes[j].style.height = '';
hiddenParentNodes[j].style.overflow = '';
Expand Down

0 comments on commit 57ae2e5

Please sign in to comment.