UNPKG

dk-plus

Version:
35 lines (34 loc) 1.41 kB
var f = Object.defineProperty; var p = (e, t, o) => t in e ? f(e, t, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[t] = o; var i = (e, t, o) => (p(e, typeof t != "symbol" ? t + "" : t, o), o); class T { constructor(t) { i(this, "dom"); i(this, "open", !1); i(this, "getDom", (t, o) => { const r = o.childNodes, n = Array.from(r); let s = 0; for (; t !== n[s].className && s < n.length; ) s++; return n[s]; }); i(this, "setStyle", () => { try { const t = this.dom.value, o = window.innerHeight, r = this.getDom("dk-shadow", t), n = this.getDom("dk-box", r), s = this.getDom("dkcodedisplay_code", n), c = this.getDom("dkcodedisplay_open", n), d = window.pageYOffset || document.documentElement.scrollTop, m = t.offsetTop + t.clientHeight - d > o; if (t.offsetTop - d + s.clientHeight - t.clientHeight / 2 < o && m) { const a = t.parentNode.parentNode, l = a.parentNode.parentNode.parentNode.parentNode.parentNode; c.style.position = "fixed", c.style.left = a.offsetLeft + l.offsetLeft + "px", c.style.width = t.clientWidth + "px"; } else c.style.position = "absolute", c.style.left = 0 + "px"; } catch { } }); i(this, "init", (t, o) => { this.open = o, this.dom = t, this.setStyle(); }); this.dom = t; } } export { T as SetPosition };