{"version":3,"file":"TableRowAnchor-OmXXYA-B.js","sources":["../../js/behaviors/TableRowAnchor.ts"],"sourcesContent":["import Page from '../lib/Page';\n\nPage.registerBehavior('.tr-anchor', function (el) {\n    const anchor = el as HTMLAnchorElement;\n\n    const tr = anchor.closest('tr');\n    const target = anchor.getAttribute('target');\n    const href = anchor.getAttribute('href');\n    const action = anchor.getAttribute('action');\n    const isDisabled = !!anchor.getAttribute('disabled');\n        \n    if(!tr)\n        return;\n\n    if ((!href && !action) || isDisabled) {\n        tr.classList.remove('cursor-pointer');\n        return;\n    } else {\n        tr.classList.add('group');\n        tr.classList.add('cursor-pointer');\n        tr.classList.add('hover:bg-grey-100');\n    }\n    \n\n    tr\n        .addEventListener('mouseup', function (ev: MouseEvent) {\n            const isForwardButton = ev.which === 4;\n            const isBackButton = ev.which === 5;\n            const isRightClick = ev.which === 3;\n\n            const currentTarget = ev.target as HTMLElement;\n\n            const isNotLeftClick = isRightClick || isForwardButton || isBackButton;\n            const rowTargetIsNotALink = anchor.classList.contains('no-link');\n            const clickedElementHasItsOwnBehaviour = currentTarget?.classList.contains('excluded-from-click') || isAnchorOrContainedInAnchor(currentTarget);\n\n            if (isNotLeftClick || rowTargetIsNotALink || clickedElementHasItsOwnBehaviour)\n                return;\n\n            ev.preventDefault();\n            const middleMouseClick = ev.type === 'mouseup' && ev.which === 2;\n\n            if (middleMouseClick || target === \"_blank\")\n                return openInNewTab(anchor);\n\n            const controlKeyIsDown = ev.ctrlKey || ev.metaKey;\n\n            if (controlKeyIsDown || target === \"_blank\")\n                openInNewTab(anchor);\n            else\n                openInSameTab(anchor);\n        });\n});\n\nfunction openInNewTab(anchor: HTMLAnchorElement) {\n    const href = anchor.getAttribute('href')!;\n    const method = anchor.getAttribute('method');\n\n    if (method === 'post')\n        anchor.click();\n    else\n        window.open(href, '_blank');\n}\n\nfunction openInSameTab(anchor: HTMLAnchorElement) {\n    const href = anchor.getAttribute('href')!;\n    const method = anchor.getAttribute('method');\n\n    if (method === 'post')\n        anchor.click();\n    else\n        window.location.href = href;\n}\n\nfunction isAnchorOrContainedInAnchor(el: HTMLElement)\n{\n    for (; el.parentElement != null; el = el.parentElement)\n        if (el.tagName.toLowerCase() == 'a')\n            return true;\n    return false;\n}"],"names":["Page","el","anchor","tr","target","href","action","isDisabled","ev","isForwardButton","isBackButton","isRightClick","currentTarget","isNotLeftClick","rowTargetIsNotALink","clickedElementHasItsOwnBehaviour","isAnchorOrContainedInAnchor","openInNewTab","openInSameTab"],"mappings":"+pBAEAA,EAAK,iBAAiB,aAAc,SAAUC,EAAI,CAC9C,MAAMC,EAASD,EAETE,EAAKD,EAAO,QAAQ,IAAI,EACxBE,EAASF,EAAO,aAAa,QAAQ,EACrCG,EAAOH,EAAO,aAAa,MAAM,EACjCI,EAASJ,EAAO,aAAa,QAAQ,EACrCK,EAAa,CAAC,CAACL,EAAO,aAAa,UAAU,EAEnD,GAAIC,EAGJ,IAAK,CAACE,GAAQ,CAACC,GAAWC,EAAY,CAC/BJ,EAAA,UAAU,OAAO,gBAAgB,EACpC,MAAA,MAEGA,EAAA,UAAU,IAAI,OAAO,EACrBA,EAAA,UAAU,IAAI,gBAAgB,EAC9BA,EAAA,UAAU,IAAI,mBAAmB,EAKnCA,EAAA,iBAAiB,UAAW,SAAUK,EAAgB,CAC7C,MAAAC,EAAkBD,EAAG,QAAU,EAC/BE,EAAeF,EAAG,QAAU,EAC5BG,EAAeH,EAAG,QAAU,EAE5BI,EAAgBJ,EAAG,OAEnBK,EAAiBF,GAAgBF,GAAmBC,EACpDI,EAAsBZ,EAAO,UAAU,SAAS,SAAS,EACzDa,GAAmCH,GAAA,YAAAA,EAAe,UAAU,SAAS,yBAA0BI,EAA4BJ,CAAa,EAE9I,GAAIC,GAAkBC,GAAuBC,EACzC,OAKJ,GAHAP,EAAG,eAAe,EACOA,EAAG,OAAS,WAAaA,EAAG,QAAU,GAEvCJ,IAAW,SAC/B,OAAOa,EAAaf,CAAM,EAELM,EAAG,SAAWA,EAA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