menupro
Version:
Custom menu like OS but better
81 lines (78 loc) • 5.76 kB
JavaScript
;(()=>{const s=document.createElement("style");s.textContent="@layer menupro {.menupro{position:relative;margin:0;padding:0;}.menupro ul,.menupro li,.menupro ul{background-color:#000;list-style:none;margin:0;padding:0;}.menupro img,.menupro svg{max-width:20px;}.menupro li:hover{transition:0s;transition-delay:0s;}.menupro ul,.menupro ul,.menupro ul:hover,.menupro ul:hover{transition:0s;transition-delay:0.5s;}.menupro hr{border:1px solid !important;height:0 !important;color:#333 !important;background-color:#333 !important;margin:0;padding:0;}.menupro a{padding:4px 10px;display:block;text-align:left;white-space:nowrap;}.menupro:hover{background-color:#0b86bf;}.menupro li{float:left;position:relative;}.menupro li:hover,.menupro li:active{background-color:#0b86bf;}.menupro li:hover > ul,.menupro li:focus-within > ul{opacity:1;visibility:visible;transition-delay:visibility 0s;}.menupro li > span.icon{position:absolute;left:5px;top:8px;width:13px;height:auto;filter:invert(0.5);}.menupro li > span.arrow:before{content:\u0022\\203a\u0022;position:absolute;right:5px;top:0;font-size:1.5em;line-height:1em;}.menupro li > ul{position:absolute;width:auto;float:left;opacity:0;visibility:hidden;transition-delay:visibility 0s;box-shadow:0 10px 12px -8px black;padding:0;}.menupro li > ul li{float:left;position:relative;width:100%;padding:0;}.menupro li > ul li:hover > ul,.menupro li > ul li:focus-within > ul{opacity:1;pointer-events:auto;}.menupro li > ul li:not(:visible){pointer-events:none;}.menupro li > ul li > ul{position:absolute;margin:0 auto;top:0px;left:99%;}.menupro li > ul li a{padding:4px 20px 4px 30px;}}";document.head.appendChild(s)})();"use strict";
Object.defineProperty(window, "menupro", {
value: {
start: {}
},
writable: !1,
configurable: !1,
enumerable: !1
});
var e = new Set([ "eval", "Function", "exec", "spawn", "execSync", "fetch", "XMLHttpRequest", "WebSocket", "importScripts", "setTimeout", "setInterval", "setImmediate", "document.write", "document.writeln", "innerHTML", "outerHTML", "location", "location.href", "location.assign", "location.replace", "history.pushState", "history.replaceState", "localStorage", "sessionStorage", "cookie", "postMessage", "import", "require" ]), t = t => /^[a-zA-Z_$][a-zA-Z0-9_$.]*$/.test(t) && !e.has(t) && !t.includes("__");
menupro.start = e => {
const {element: n, name: i = e.name || "menupro", nav: s = e.nav || []} = e;
let o, c;
const a = e => document.createElement(e), l = (e, n = "." + i) => {
const s = "string" == typeof n ? document.querySelector(n) : n;
s && e?.map(e => {
if (e.name) {
o = a("li");
const t = a("a");
t.textContent = e.name, o.appendChild(t), s.appendChild(o);
}
if (e.onclick && 0 === e.sub?.length) {
let n;
if ("function" == typeof e.onclick) n = e.onclick; else if ("string" == typeof e.onclick) {
const i = e.onclick.trim();
if (i.includes("(") && i.endsWith(")")) {
const e = i.match(/^(\w+)\((.*)\)$/);
if (e) {
const [, i, s] = e;
if (t(i)) {
const e = window[i];
if (e && "function" == typeof e) {
const t = e => {
const t = e.trim();
return t.startsWith('"') && t.endsWith('"') || t.startsWith("'") && t.endsWith("'") ? t.slice(1, -1) : isNaN(Number(t)) ? "true" === t || "false" !== t && ("null" === t ? null : void 0) : Number(t);
}, i = [];
if (s.trim()) {
let e = "", n = 0, o = !1, c = "";
for (const a of s) '"' !== a && "'" !== a || "\\" === e.slice(-1) || (o ? a === c && (o = !1,
c = "") : (o = !0, c = a)), o || "(" !== a || n++, o || ")" !== a || n--, o || 0 !== n || "," !== a ? e += a : (i.push(t(e)),
e = "");
e.trim() && i.push(t(e));
}
n = () => {
try {
e(...i);
} catch (e) {}
};
} else n = () => {};
} else n = () => {};
} else n = () => {};
} else if (t(i)) {
const e = window[i];
n = e || (() => {});
} else n = () => {};
} else n = () => {};
o.addEventListener("click", n);
}
if ("" === e.name && (o = a("hr"), s.appendChild(o)), n != "." + i) {
if (e.icon) {
const t = a("span");
t.className = "icon", t.innerHTML = e.icon, o.appendChild(t);
}
if (e.sub?.length > 0) {
const e = a("span");
e.className = "arrow", o.appendChild(e);
}
}
e.sub?.length > 0 && (c = a("ul"), o.appendChild(c), l(e.sub, c));
});
};
setTimeout(() => {
const e = a("ul");
e.className = i;
const t = "string" == typeof n ? document.querySelector(n) : n;
t && (t.appendChild(e), l(s, e));
}, 0);
};