Skip to content

Commit

Permalink
Fix issue with Element.visible reading only inline style. [closes #131
Browse files Browse the repository at this point in the history
]
  • Loading branch information
savetheclocktower committed Apr 22, 2014
1 parent d9411e5 commit 548580c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/prototype/dom/dom.js
Expand Up @@ -290,7 +290,7 @@
* // -> true
**/
function visible(element) {
return $(element).style.display !== 'none';
return $(element).getStyle('display') !== 'none';
}

/**
Expand Down
4 changes: 4 additions & 0 deletions test/unit/dom_test.js
Expand Up @@ -290,6 +290,10 @@ new Test.Unit.Runner({
testElementVisible: function(){
this.assertNotEqual('none', $('test-visible').style.display);
this.assertEqual('none', $('test-hidden').style.display);

this.assert($('test-visible').visible());
this.assert(!$('test-invisible').visible());
this.assert(!$('test-hidden').visible());
},

testElementToggle: function(){
Expand Down
5 changes: 5 additions & 0 deletions test/unit/fixtures/dom.html
Expand Up @@ -2,7 +2,12 @@
<p id="scroll_test_2">Scroll test</p>
</div>

<style type="text/css">
#test-invisible { display: none; }
</style>

<div id="test-visible">visible</div>
<div id="test-invisible">invisible</div>
<div id="test-hidden" style="display:none;">hidden</div>
<div id="test-toggle-visible">visible</div>
<div id="test-toggle-hidden" style="display:none;">hidden</div>
Expand Down

3 comments on commit 548580c

@yunosh
Copy link

@yunosh yunosh commented on 548580c Jul 5, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks if calling this code on an element from a different document, e.g. some embedded iframe. In that case $() doesn't return a fully extended Element object for some reason, and getStyle() ist not available.

@jwestbrook
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yunosh Can you post an example as an issue?

@yunosh
Copy link

@yunosh yunosh commented on 548580c Jul 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See issue #319

Please sign in to comment.