UNPKG

@haxtheweb/haxcms-nodejs

Version:

HAXcms single and multisite nodejs server, api, and administration

1 lines 1.19 kB
import{fireRouterEvent as t}from"../utils.js";function vaadinRouterGlobalClickHandler(e){if(e.defaultPrevented)return;if(0!==e.button)return;if(e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)return;let o=e.target;const a=e.composedPath?e.composedPath():e.path||[];for(let t=0;t<a.length;t++){const e=a[t];if(e.nodeName&&"a"===e.nodeName.toLowerCase()){o=e;break}}for(;o&&"a"!==o.nodeName.toLowerCase();)o=o.parentNode;if(!o||"a"!==o.nodeName.toLowerCase())return;if(o.target&&"_self"!==o.target.toLowerCase())return;if(o.hasAttribute("download"))return;if(o.hasAttribute("router-ignore"))return;if(o.pathname===window.location.pathname&&""!==o.hash)return;const n=o.origin||function getAnchorOrigin(t){const e=t.port,o=t.protocol;return`${o}//${"http:"===o&&"80"===e||"https:"===o&&"443"===e?t.hostname:t.host}`}(o);if(n!==window.location.origin)return;const{pathname:r,search:i,hash:c}=o;t("go",{pathname:r,search:i,hash:c})&&(e.preventDefault(),e&&"click"===e.type&&window.scrollTo(0,0))}const e={activate(){window.document.addEventListener("click",vaadinRouterGlobalClickHandler)},inactivate(){window.document.removeEventListener("click",vaadinRouterGlobalClickHandler)}};export default e;