Browse files

Improved variable assignment in <details> feature test.

  • Loading branch information...
1 parent 3b11792 commit 98f8d6510a385458dc813a3d119ed588a75a9089 @mathiasbynens mathiasbynens committed Aug 13, 2011
Showing with 11 additions and 12 deletions.
  1. +11 −12 feature-detects/elem-details.js
View
23 feature-detects/elem-details.js
@@ -1,19 +1,18 @@
// By @mathias, based on http://mths.be/axh
Modernizr.addTest('details', function() {
var doc = document,
- el = doc.createElement('details');
- //test fast API implementation
- if( !('open' in el) ){
- return false;
- }
- //interface implemented, detected UI implementation
- var de = doc.documentElement,
+ el = doc.createElement('details'),
fake,
- root = doc.body || (function() {
- fake = true;
- return de.insertBefore(doc.createElement('body'), de.firstElementChild || de.firstChild);
- }()),
+ root,
diff;
+ if (!('open' in el)) { // return early if possible; thanks @aFarkas!
+ return false;
+ }
+ root = doc.body || (function() {
+ var de = doc.documentElement;
+ fake = true;
+ return de.insertBefore(doc.createElement('body'), de.firstElementChild || de.firstChild);
+ }());
el.innerHTML = '<summary>a</summary>b';
el.style.display = 'block';
root.appendChild(el);
@@ -23,4 +22,4 @@ Modernizr.addTest('details', function() {
root.removeChild(el);
fake && root.parentNode.removeChild(root);
return diff;
-});
+}(document));

0 comments on commit 98f8d65

Please sign in to comment.