UNPKG

alpineuse

Version:

Collection of Alpine, Extending Plugins.

2 lines (1 loc) 1.41 kB
const e=e=>{window.Alpine.directive("use-longpress",((e,{value:n,expression:t},{evaluateLater:o,cleanup:s})=>{const r=n||500;let a;const i=o(t),u=document.createElement("style");u.textContent="\n .useLongpress, .useLongpress * {\n margin: 0;\n padding: 0;\n -webkit-tap-highlight-color: transparent !important;\n user-select: none !important;\n -webkit-user-select: none !important;\n -moz-user-select: none !important;\n -ms-user-select: none !important;\n -o-user-select: none !important;\n -webkit-user-drag: none !important;\n -webkit-overflow-scrolling: touch;\n scroll-behavior: smooth;\n }\n ",document.head.appendChild(u),e.classList.add("useLongpress");const c=e=>{e.preventDefault()},m=()=>{a=setTimeout((()=>{i()}),r)},d=()=>{clearTimeout(a)};e.addEventListener("contextmenu",c),e.addEventListener("mousedown",m),e.addEventListener("touchstart",m),e.addEventListener("mouseup",d),e.addEventListener("mouseleave",d),e.addEventListener("touchend",d),e.addEventListener("touchcancel",d),s((()=>{e.removeEventListener("contextmenu",c),e.removeEventListener("mousedown",m),e.removeEventListener("touchstart",m),e.removeEventListener("mouseup",d),e.removeEventListener("mouseleave",d),e.removeEventListener("touchend",d),e.removeEventListener("touchcancel",d)}))}))};export{e as u};