-
Notifications
You must be signed in to change notification settings - Fork 0
/
details.polyfill.min.js
1 lines (1 loc) · 1.94 KB
/
details.polyfill.min.js
1
(function(a){"use strict";var b,c,d,e=0,f=a.documentElement,g=a.getElementsByTagName("head")[0]||f,h=a.getElementsByTagName("body")[0]||f,i=a.createElement("style"),j="details { display: block; overflow:hidden; } \n"+"details[open] { height: auto; } \n"+"summary { display:inline-block; } \n"+"details * { visibility: hidden; } \n"+"summary:first-child { visibility: visible; cursor: pointer; } \n"+"details[open] * { visibility: visible } \n"+"details[open] summary { margin-bottom: 0; }",k=function(b,c){if(b.nodeName.toLowerCase()==="style"){if(!!b["styleSheet"]&&b.styleSheet["cssText"]!==undefined){b.styleSheet.cssText+="\n"+c}else{b.appendChild(a.createTextNode("\n"+c))}}},l=function(a,b,c){if(a.addEventListener){a.addEventListener(b,c)}else if(a.attachEvent){a.attachEvent("on"+b,c)}else if(a["on"+b]===null){a["on"+b]=c}},m=function(a){var b,c=a.target||a.srcElement;if(c.nodeName.toLowerCase()==="summary"){b=c;while(b.nodeName.toLowerCase()!=="details"){b=b.parentNode;if(b===h){b=null;break}}if(b){if(b.getAttribute("open")){b.removeAttribute("open")}else{b.setAttribute("open","open")}h.className=h.className}}},n=function(){var f,g,h,j,l=a.getElementsByTagName("details");for(b=0;b<l.length;b++){g=l[b];if(!g.getAttribute("data-detailsid")){f="d"+e++;g.className+=" "+f;g.setAttribute("data-detailsID",f);h=g.getElementsByTagName("summary")[0];if(!h){h=a.createElement("summary");h.appendChild(a.createTextNode("Details"));g.insertBefore(h,g.firstChild)}else if(h!==g.firstChild){g.removeChild(h);g.insertBefore(h,g.firstChild)}j=h.offsetHeight;k(i,"details."+f+" { height: "+j+"px; }\n"+"details."+f+"[open] { height: auto; }");for(c=0;c<g.childNodes.length;c++){if(g.childNodes[c].nodeName==="#text"&&(g.childNodes[c].nodeValue||"").replace(/\s/g,"").length){d=document.createElement("text");d.appendChild(g.childNodes[c]);g.insertBefore(d,g.childNodes[c])}}}}};g.insertBefore(i,g.firstChild);n();k(i,j);l(h,"click",m);l(h,"DOMSubtreeModified",n)})(document,undefined)