Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added better feature test (Thanks to Mathias Bynens). Closes #1

  • Loading branch information...
commit 1112467e85234aa74ab5f0d22dbd60213b5e5ec5 1 parent 59e4d96
@manuelbieh authored
Showing with 33 additions and 2 deletions.
  1. +1 −1  details.polyfill.min.js
  2. +32 −1 details.polyfill.src.js
View
2  details.polyfill.min.js
@@ -1 +1 @@
-jQuery(function(a){(function(){var b=this;this.hideDetailChildren=function(c){var d=c instanceof jQuery?c[0].childNodes:c.childNodes,e=d.length;a(c).attr("open",false);if(a.browser.safari==true){for(var f=0;f<e;f++){if(d[f].nodeType==3&&d[f].textContent!=""){var g=a("<span />");g.text(d[f].textContent).hide();a(d[f]).after(g);d[f].textContent="";e++}}}a.each(d,function(d,e){if(a(e)[0].nodeType==1&&e==a(e).parent().find("> summary:first-of-type")[0]){if(a(e).data("processed")!=true){a(e).css({display:"block",cursor:"pointer"}).data("processed",true).addClass("detailHidden").bind("click",function(){b.toggleDetailChildren(a(this))});a(c).prepend(a(e))}}else if(a(e)[0].nodeType==3&&!e.isElementContentWhitespace&&!!a.browser.safari==false){var f=a("<span />");f.text(e.textContent).hide();a(e).after(f);e.textContent=""}else if(a(c).find("> summary").length==0){var g=a("<summary />").text("Details").css({display:"block",cursor:"pointer"}).data("processed",true).addClass("detailHidden").bind("click",function(){b.toggleDetailChildren(a(this))});a(c).prepend(g)}a(c).find("> :visible:not(summary:first-child)").hide()})};this.showDetailChildren=function(b){a(b).attr("open",true);a.each(a(b).find("> *"),function(b,c){a(c).show()})};this.toggleDetailChildren=function(a){if(a.hasClass("detailHidden")){a.removeClass("detailHidden");b.showDetailChildren(a.parents("details")[0])}else{a.addClass("detailHidden");b.hideDetailChildren(a.parents("details")[0])}};if("open"in document.createElement("details")==false){a.each(a("details"),function(c,d){b.hideDetailChildren(d);var e=a("<style />").text('summary {-webkit-text-size-adjust: none;} details > summary:first-child:before {content: "▼ "} details > summary.detailHidden:first-child:before {content: "► "}');a("head").append(e)})}})()})
+jQuery(function(a){(function(){var b=this;this.hideDetailChildren=function(c){var d=c instanceof jQuery?c[0].childNodes:c.childNodes,e=d.length;a(c).attr("open",false);if(a.browser.safari==true){for(var f=0;f<e;f++){if(d[f].nodeType==3&&d[f].textContent!=""){var g=a("<span />");g.text(d[f].textContent).hide();a(d[f]).after(g);d[f].textContent="";e++}}}a.each(d,function(d,e){if(a(e)[0].nodeType==1&&e==a(e).parent().find("> summary:first-of-type")[0]){if(a(e).data("processed")!=true){a(e).css({display:"block",cursor:"pointer"}).data("processed",true).addClass("detailHidden").bind("click",function(){b.toggleDetailChildren(a(this))});a(c).prepend(a(e))}}else if(a(e)[0].nodeType==3&&!e.isElementContentWhitespace&&!!a.browser.safari==false){var f=a("<span />");f.text(e.textContent).hide();a(e).after(f);e.textContent=""}else if(a(c).find("> summary").length==0){var g=a("<summary />").text("Details").css({display:"block",cursor:"pointer"}).data("processed",true).addClass("detailHidden").bind("click",function(){b.toggleDetailChildren(a(this))});a(c).prepend(g)}a(c).find("> :visible:not(summary:first-child)").hide()})};this.showDetailChildren=function(b){a(b).attr("open",true);a.each(a(b).find("> *"),function(b,c){a(c).show()})};this.toggleDetailChildren=function(a){if(a.hasClass("detailHidden")){a.removeClass("detailHidden");b.showDetailChildren(a.parents("details")[0])}else{a.addClass("detailHidden");b.hideDetailChildren(a.parents("details")[0])}};var c=function(a){var b=a.createElement("details"),c,d,e;if(!("open"in b)){return false}d=a.body||function(){var b=a.documentElement;c=true;return b.insertBefore(a.createElement("body"),b.firstElementChild||b.firstChild)}();b.innerHTML="<summary>a</summary>b";b.style.display="block";d.appendChild(b);e=b.offsetHeight;b.open=true;e=e!=b.offsetHeight;d.removeChild(b);if(c){d.parentNode.removeChild(d)}return e}(document);if(c==false){a.each(a("details"),function(c,d){b.hideDetailChildren(d);var e=a("<style />").text('summary {-webkit-text-size-adjust: none;} details > summary:first-child:before {content: "▼ "} details > summary.detailHidden:first-child:before {content: "► "}');a("head").append(e)})}})()})
View
33 details.polyfill.src.js
@@ -111,7 +111,38 @@ jQuery(function($) {
}
- if('open' in document.createElement('details') == false) {
+ var isDetailsSupported = (function(doc) {
+ var el = doc.createElement('details'),
+ fake,
+ root,
+ diff;
+ if (!('open' in el)) {
+ 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);
+ diff = el.offsetHeight;
+ el.open = true;
+ diff = diff != el.offsetHeight;
+ root.removeChild(el);
+
+ if (fake) {
+ root.parentNode.removeChild(root);
+ }
+
+ return diff;
+
+ }(document));
+
+ if(isDetailsSupported == false) {
$.each($('details'), function(dKey, detailElement) {
Please sign in to comment.
Something went wrong with that request. Please try again.