element-closest
Version:
Return the closest element matching a selector up the DOM tree
1 lines • 2.22 kB
Source Map (JSON)
{"version":3,"file":"index.mjs","sources":["src/index.js"],"sourcesContent":["export default function polyfill(window) {\n\tconst ElementPrototype = window.Element.prototype;\n\n\tif (typeof ElementPrototype.matches !== 'function') {\n\t\tElementPrototype.matches = ElementPrototype.msMatchesSelector || ElementPrototype.mozMatchesSelector || ElementPrototype.webkitMatchesSelector || function matches(selector) {\n\t\t\tlet element = this;\n\t\t\tconst elements = (element.document || element.ownerDocument).querySelectorAll(selector);\n\t\t\tlet index = 0;\n\n\t\t\twhile (elements[index] && elements[index] !== element) {\n\t\t\t\t++index;\n\t\t\t}\n\n\t\t\treturn Boolean(elements[index]);\n\t\t};\n\t}\n\n\tif (typeof ElementPrototype.closest !== 'function') {\n\t\tElementPrototype.closest = function closest(selector) {\n\t\t\tlet element = this;\n\n\t\t\twhile (element && element.nodeType === 1) {\n\t\t\t\tif (element.matches(selector)) {\n\t\t\t\t\treturn element;\n\t\t\t\t}\n\n\t\t\t\telement = element.parentNode;\n\t\t\t}\n\n\t\t\treturn null;\n\t\t};\n\t}\n}\n"],"names":["polyfill","window","ElementPrototype","Element","prototype","matches","msMatchesSelector","mozMatchesSelector","webkitMatchesSelector","selector","element","elements","document","ownerDocument","querySelectorAll","index","Boolean","closest","nodeType","parentNode"],"mappings":"AAAe,SAASA,QAAT,CAAkBC,MAAlB,EAA0B;MAClCC,gBAAgB,GAAGD,MAAM,CAACE,OAAP,CAAeC,SAAxC;;MAEI,OAAOF,gBAAgB,CAACG,OAAxB,KAAoC,UAAxC,EAAoD;IACnDH,gBAAgB,CAACG,OAAjB,GAA2BH,gBAAgB,CAACI,iBAAjB,IAAsCJ,gBAAgB,CAACK,kBAAvD,IAA6EL,gBAAgB,CAACM,qBAA9F,IAAuH,SAASH,OAAT,CAAiBI,QAAjB,EAA2B;UACxKC,OAAO,GAAG,IAAd;UACMC,QAAQ,GAAG,CAACD,OAAO,CAACE,QAAR,IAAoBF,OAAO,CAACG,aAA7B,EAA4CC,gBAA5C,CAA6DL,QAA7D,CAAjB;UACIM,KAAK,GAAG,CAAZ;;aAEOJ,QAAQ,CAACI,KAAD,CAAR,IAAmBJ,QAAQ,CAACI,KAAD,CAAR,KAAoBL,OAA9C,EAAuD;UACpDK,KAAF;;;aAGMC,OAAO,CAACL,QAAQ,CAACI,KAAD,CAAT,CAAd;KATD;;;MAaG,OAAOb,gBAAgB,CAACe,OAAxB,KAAoC,UAAxC,EAAoD;IACnDf,gBAAgB,CAACe,OAAjB,GAA2B,SAASA,OAAT,CAAiBR,QAAjB,EAA2B;UACjDC,OAAO,GAAG,IAAd;;aAEOA,OAAO,IAAIA,OAAO,CAACQ,QAAR,KAAqB,CAAvC,EAA0C;YACrCR,OAAO,CAACL,OAAR,CAAgBI,QAAhB,CAAJ,EAA+B;iBACvBC,OAAP;;;QAGDA,OAAO,GAAGA,OAAO,CAACS,UAAlB;;;aAGM,IAAP;KAXD;;;;;;"}