forked from mathiasbynens/jquery-details
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.details.min.js
2 lines (2 loc) · 2.14 KB
/
jquery.details.min.js
1
2
/*! http://mths.be/details v0.1.0 by @mathias | includes http://mths.be/noselect v1.0.3 */
(function(e,t){var n=t.fn,r,i=Object.prototype.toString.call(window.opera)=="[object Opera]",s=function(e){var t=e.createElement("details"),n,r,i;if(!("open"in t)){return false}r=e.body||function(){var t=e.documentElement;n=true;return t.insertBefore(e.createElement("body"),t.firstElementChild||t.firstChild)}();t.innerHTML="<summary>a</summary>b";t.style.display="block";r.appendChild(t);i=t.offsetHeight;t.open=true;i=i!=t.offsetHeight;r.removeChild(t);if(n){r.parentNode.removeChild(r)}return i}(e),o=function(e,t,n,r){var i=e.prop("open"),s=i&&r||!i&&!r;if(s){e.removeClass("open").prop("open",false).triggerHandler("close.details");t.attr("aria-expanded",false);n.hide()}else{e.addClass("open").prop("open",true).triggerHandler("open.details");t.attr("aria-expanded",true);n.show()}};n.noSelect=function(){var e="none";return this.bind("selectstart dragstart mousedown",function(){return false}).css({MozUserSelect:e,msUserSelect:e,webkitUserSelect:e,userSelect:e})};if(s){r=n.details=function(){return this.each(function(e){var n=t(this),r=t("summary",n).first();if(!n.attr("id")){n.attr("id","details-id-"+e)}n.attr("role","group");r.attr({role:"button","aria-expanded":n.prop("open"),"aria-controls":n.attr("id")}).on("click",function(){var e=n.prop("open");r.attr("aria-expanded",!e);n.triggerHandler((e?"close":"open")+".details")})})};r.support=s}else{r=n.details=function(){return this.each(function(e){var n=t(this),r=t("summary",n).first(),s=n.children(":not(summary)"),u=n.contents(":not(summary)");if(!n.attr("id")){n.attr("id","details-id-"+e)}n.attr("role","group");if(!r.length){r=t("<summary>").text("Details").prependTo(n)}if(s.length!=u.length){u.filter(function(){return this.nodeType==3&&/[^ \t\n\f\r]/.test(this.data)}).wrap("<span>");s=n.children(":not(summary)")}n.prop("open",typeof n.attr("open")=="string");o(n,r,s);r.attr({role:"button","aria-controls":n.attr("id")}).noSelect().prop("tabIndex",0).on("click",function(){r.focus();o(n,r,s,true)}).keyup(function(e){if(32==e.keyCode||13==e.keyCode&&!i){e.preventDefault();r.click()}})})};r.support=s}})(document,jQuery)