fossasia/loklak_search

View on GitHub
scripts.1548ef9001acf0bc02b9.js

Summary

Maintainability
A
0 mins
Test Coverage
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t():"function"==typeof define&&define.amd?define(t):t()}(0,function(){"use strict";var e=function(e,t){var n=window.Element.prototype,r=n.matches||n.mozMatchesSelector||n.msMatchesSelector||n.oMatchesSelector||n.webkitMatchesSelector;if(!e||1!==e.nodeType)return!1;var i=e.parentNode;if(r)return r.call(e,t);for(var o=i.querySelectorAll(t),a=o.length,s=0;s<a;s++)if(o[s]===e)return!0;return!1},t=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},n=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}();!function(r){function i(e,t,n){if(e.nodeType==Node.ELEMENT_NODE){var r=e;t&&t(r);var o=r.shadowRoot||r.webkitShadowRoot;if(o)return void i(o,t,o);if("content"==r.localName){for(var a=r.getDistributedNodes?r.getDistributedNodes():[],s=0;s<a.length;s++)i(a[s],t,n);return}if("slot"==r.localName){for(var d=r.assignedNodes?r.assignedNodes({flatten:!0}):[],u=0;u<d.length;u++)i(d[u],t,n);return}}for(var l=e.firstChild;null!=l;)i(l,t,n),l=l.nextSibling}function o(e){if(!e.querySelector("style#inert-style")){var t=r.createElement("style");t.setAttribute("id","inert-style"),t.textContent="\n[inert] {\n  pointer-events: none;\n  cursor: default;\n}\n\n[inert], [inert] * {\n  user-select: none;\n  -webkit-user-select: none;\n  -moz-user-select: none;\n  -ms-user-select: none;\n}\n",e.appendChild(t)}}function a(e,t){return t&&(e===t||!!(16&e.compareDocumentPosition(t)))}var s=Array.prototype.slice,d=["a[href]","area[href]","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","button:not([disabled])","iframe","object","embed","[contenteditable]"].join(","),u=function(){function o(e,n){t(this,o),this._inertManager=n,this._rootElement=e,this._managedNodes=new Set([]),this._rootElement.hasAttribute("aria-hidden")&&(this._savedAriaHidden=this._rootElement.getAttribute("aria-hidden")),this._rootElement.setAttribute("aria-hidden","true"),this._makeSubtreeUnfocusable(this._rootElement),this._observer=new MutationObserver(this._onMutation.bind(this)),this._observer.observe(this._rootElement,{attributes:!0,childList:!0,subtree:!0})}return n(o,[{key:"destructor",value:function(){this._observer.disconnect(),this._observer=null,this._rootElement&&(this.hasSavedAriaHidden?this._rootElement.setAttribute("aria-hidden",this.savedAriaHidden):this._rootElement.removeAttribute("aria-hidden")),this._rootElement=null;var e=!0,t=!1,n=void 0;try{for(var r,i=this._managedNodes[Symbol.iterator]();!(e=(r=i.next()).done);e=!0)this._unmanageNode(r.value.node)}catch(e){t=!0,n=e}finally{try{!e&&i.return&&i.return()}finally{if(t)throw n}}this._managedNodes=null,this._inertManager=null}},{key:"_makeSubtreeUnfocusable",value:function(e){var t=this;i(e,function(e){return t._visitNode(e)});var n=r.activeElement;if(!a(r.body,e)){for(var o=e,s=void 0;o;){if(o.nodeType===Node.DOCUMENT_FRAGMENT_NODE){s=o;break}o=o.parentNode}s&&(n=s.activeElement)}a(e,n)&&n.blur()}},{key:"_visitNode",value:function(t){t.nodeType===Node.ELEMENT_NODE&&(t!==this._rootElement&&t.hasAttribute("inert")&&this._adoptInertRoot(t),(e(t,d)||t.hasAttribute("tabindex"))&&this._manageNode(t))}},{key:"_manageNode",value:function(e){var t=this._inertManager.register(e,this);this._managedNodes.add(t)}},{key:"_unmanageNode",value:function(e){var t=this._inertManager.deregister(e,this);t&&this._managedNodes.delete(t)}},{key:"_unmanageSubtree",value:function(e){var t=this;i(e,function(e){return t._unmanageNode(e)})}},{key:"_adoptInertRoot",value:function(e){var t=this._inertManager.getInertRoot(e);t||(this._inertManager.setInert(e,!0),t=this._inertManager.getInertRoot(e));var n=!0,r=!1,i=void 0;try{for(var o,a=t.managedNodes[Symbol.iterator]();!(n=(o=a.next()).done);n=!0)this._manageNode(o.value.node)}catch(e){r=!0,i=e}finally{try{!n&&a.return&&a.return()}finally{if(r)throw i}}}},{key:"_onMutation",value:function(e,t){var n=!0,r=!1,i=void 0;try{for(var o,d=e[Symbol.iterator]();!(n=(o=d.next()).done);n=!0){var u=o.value,l=u.target;if("childList"===u.type){var h=!0,f=!1,c=void 0;try{for(var v,y=s.call(u.addedNodes)[Symbol.iterator]();!(h=(v=y.next()).done);h=!0)this._makeSubtreeUnfocusable(v.value)}catch(e){f=!0,c=e}finally{try{!h&&y.return&&y.return()}finally{if(f)throw c}}var b=!0,_=!1,m=void 0;try{for(var g,N=s.call(u.removedNodes)[Symbol.iterator]();!(b=(g=N.next()).done);b=!0)this._unmanageSubtree(g.value)}catch(e){_=!0,m=e}finally{try{!b&&N.return&&N.return()}finally{if(_)throw m}}}else if("attributes"===u.type)if("tabindex"===u.attributeName)this._manageNode(l);else if(l!==this._rootElement&&"inert"===u.attributeName&&l.hasAttribute("inert")){this._adoptInertRoot(l);var w=this._inertManager.getInertRoot(l),E=!0,I=!1,p=void 0;try{for(var k,x=this._managedNodes[Symbol.iterator]();!(E=(k=x.next()).done);E=!0){var S=k.value;a(l,S.node)&&w._manageNode(S.node)}}catch(e){I=!0,p=e}finally{try{!E&&x.return&&x.return()}finally{if(I)throw p}}}}}catch(e){r=!0,i=e}finally{try{!n&&d.return&&d.return()}finally{if(r)throw i}}}},{key:"managedNodes",get:function(){return new Set(this._managedNodes)}},{key:"hasSavedAriaHidden",get:function(){return"_savedAriaHidden"in this}},{key:"savedAriaHidden",set:function(e){this._savedAriaHidden=e},get:function(){return this._savedAriaHidden}}]),o}(),l=function(){function r(e,n){t(this,r),this._node=e,this._overrodeFocusMethod=!1,this._inertRoots=new Set([n]),this._destroyed=!1,this.ensureUntabbable()}return n(r,[{key:"destructor",value:function(){this._throwIfDestroyed(),this._node&&(this.hasSavedTabIndex?this._node.setAttribute("tabindex",this.savedTabIndex):this._node.removeAttribute("tabindex"),this._overrodeFocusMethod&&delete this._node.focus),this._node=null,this._inertRoots=null,this._destroyed=!0}},{key:"_throwIfDestroyed",value:function(){if(this.destroyed)throw new Error("Trying to access destroyed InertNode")}},{key:"ensureUntabbable",value:function(){var t=this.node;if(e(t,d)){if(-1===t.tabIndex&&this.hasSavedTabIndex)return;t.hasAttribute("tabindex")&&(this._savedTabIndex=t.tabIndex),t.setAttribute("tabindex","-1"),t.nodeType===Node.ELEMENT_NODE&&(t.focus=function(){},this._overrodeFocusMethod=!0)}else t.hasAttribute("tabindex")&&(this._savedTabIndex=t.tabIndex,t.removeAttribute("tabindex"))}},{key:"addInertRoot",value:function(e){this._throwIfDestroyed(),this._inertRoots.add(e)}},{key:"removeInertRoot",value:function(e){this._throwIfDestroyed(),this._inertRoots.delete(e),0===this._inertRoots.size&&this.destructor()}},{key:"destroyed",get:function(){return this._destroyed}},{key:"hasSavedTabIndex",get:function(){return"_savedTabIndex"in this}},{key:"node",get:function(){return this._throwIfDestroyed(),this._node}},{key:"savedTabIndex",set:function(e){this._throwIfDestroyed(),this._savedTabIndex=e},get:function(){return this._throwIfDestroyed(),this._savedTabIndex}}]),r}(),h=new(function(){function r(e){if(t(this,r),!e)throw new Error("Missing required argument; InertManager needs to wrap a document.");this._document=e,this._managedNodes=new Map,this._inertRoots=new Map,this._observer=new MutationObserver(this._watchForInert.bind(this)),o(e.head||e.body||e.documentElement),"loading"===e.readyState?e.addEventListener("DOMContentLoaded",this._onDocumentLoaded.bind(this)):this._onDocumentLoaded()}return n(r,[{key:"setInert",value:function(e,t){if(t){if(this._inertRoots.has(e))return;var n=new u(e,this);if(e.setAttribute("inert",""),this._inertRoots.set(e,n),!a(this._document.body,e))for(var r=e.parentNode;r;)11===r.nodeType&&o(r),r=r.parentNode}else{if(!this._inertRoots.has(e))return;this._inertRoots.get(e).destructor(),this._inertRoots.delete(e),e.removeAttribute("inert")}}},{key:"getInertRoot",value:function(e){return this._inertRoots.get(e)}},{key:"register",value:function(e,t){var n=this._managedNodes.get(e);return void 0!==n?(n.addInertRoot(t),n.ensureUntabbable()):n=new l(e,t),this._managedNodes.set(e,n),n}},{key:"deregister",value:function(e,t){var n=this._managedNodes.get(e);return n?(n.removeInertRoot(t),n.destroyed&&this._managedNodes.delete(e),n):null}},{key:"_onDocumentLoaded",value:function(){var e=s.call(this._document.querySelectorAll("[inert]")),t=!0,n=!1,r=void 0;try{for(var i,o=e[Symbol.iterator]();!(t=(i=o.next()).done);t=!0)this.setInert(i.value,!0)}catch(e){n=!0,r=e}finally{try{!t&&o.return&&o.return()}finally{if(n)throw r}}this._observer.observe(this._document.body,{attributes:!0,subtree:!0,childList:!0})}},{key:"_watchForInert",value:function(t,n){var r=!0,i=!1,o=void 0;try{for(var a,d=t[Symbol.iterator]();!(r=(a=d.next()).done);r=!0){var u=a.value;switch(u.type){case"childList":var l=!0,h=!1,f=void 0;try{for(var c,v=s.call(u.addedNodes)[Symbol.iterator]();!(l=(c=v.next()).done);l=!0){var y=c.value;if(y.nodeType===Node.ELEMENT_NODE){var b=s.call(y.querySelectorAll("[inert]"));e(y,"[inert]")&&b.unshift(y);var _=!0,m=!1,g=void 0;try{for(var N,w=b[Symbol.iterator]();!(_=(N=w.next()).done);_=!0)this.setInert(N.value,!0)}catch(t){m=!0,g=t}finally{try{!_&&w.return&&w.return()}finally{if(m)throw g}}}}}catch(t){h=!0,f=t}finally{try{!l&&v.return&&v.return()}finally{if(h)throw f}}break;case"attributes":if("inert"!==u.attributeName)continue;var E=u.target,I=E.hasAttribute("inert");this.setInert(E,I)}}}catch(t){i=!0,o=t}finally{try{!r&&d.return&&d.return()}finally{if(i)throw o}}}}]),r}())(r);Object.defineProperty(Element.prototype,"inert",{enumerable:!0,get:function(){return this.hasAttribute("inert")},set:function(e){h.setInert(this,e)}})}(document)});