返回 reveal.js
search.mjs
根目录 / dist / plugin / search.mjs
1 //#endregion
2 //#region plugin/search/index.ts
3 var e = () => {
4 let e, t, n, r, i, a, o;
5 function s() {
6 t = document.createElement("div"), t.classList.add("searchbox"), t.style.position = "absolute", t.style.top = "10px", t.style.right = "10px", t.style.zIndex = 10, t.innerHTML = "<input type=\"search\" class=\"searchinput\" placeholder=\"Search...\" style=\"vertical-align: top;\"/>\n </span>", n = t.querySelector(".searchinput"), n.style.width = "240px", n.style.fontSize = "14px", n.style.padding = "4px 6px", n.style.color = "#000", n.style.background = "#fff", n.style.borderRadius = "2px", n.style.border = "0", n.style.outline = "0", n.style.boxShadow = "0 2px 18px rgba(0, 0, 0, 0.2)", n.style["-webkit-appearance"] = "none", e.getRevealElement().appendChild(t), n.addEventListener("keyup", function(e) {
7 switch (e.keyCode) {
8 case 13:
9 e.preventDefault(), d(), a = !1;
10 break;
11 default: a = !0;
12 }
13 }, !1), l();
14 }
15 function c() {
16 t || s(), t.style.display = "inline", n.focus(), n.select();
17 }
18 function l() {
19 t || s(), t.style.display = "none", o && o.remove();
20 }
21 function u() {
22 t || s(), t.style.display === "inline" ? l() : c();
23 }
24 function d() {
25 if (a) {
26 var t = n.value;
27 t === "" ? (o && o.remove(), r = null) : (o = new f("slidecontent"), r = o.apply(t), i = 0);
28 }
29 r && (r.length && r.length <= i && (i = 0), r.length > i && (e.slide(r[i].h, r[i].v), i++));
30 }
31 function f(t, n) {
32 var r = document.getElementById(t) || document.body, i = n || "EM", a = RegExp("^(?:" + i + "|SCRIPT|FORM)$"), o = [
33 "#ff6",
34 "#a0ffff",
35 "#9f9",
36 "#f99",
37 "#f6f"
38 ], s = [], c = 0, l = "", u = [];
39 this.setRegex = function(e) {
40 e = e.trim(), l = RegExp("(" + e + ")", "i");
41 }, this.getRegex = function() {
42 return l.toString().replace(/^\/\\b\(|\)\\b\/i$/g, "").replace(/\|/g, " ");
43 }, this.hiliteWords = function(t) {
44 if (!(t == null || !t) && l && !a.test(t.nodeName)) {
45 if (t.hasChildNodes()) for (var n = 0; n < t.childNodes.length; n++) this.hiliteWords(t.childNodes[n]);
46 if (t.nodeType == 3) {
47 var r, d;
48 if ((r = t.nodeValue) && (d = l.exec(r))) {
49 for (var f = t; f != null && f.nodeName != "SECTION";) f = f.parentNode;
50 for (var p = e.getIndices(f), m = u.length, h = !1, n = 0; n < m; n++) u[n].h === p.h && u[n].v === p.v && (h = !0);
51 h || u.push(p), s[d[0].toLowerCase()] || (s[d[0].toLowerCase()] = o[c++ % o.length]);
52 var g = document.createElement(i);
53 g.appendChild(document.createTextNode(d[0])), g.style.backgroundColor = s[d[0].toLowerCase()], g.style.fontStyle = "inherit", g.style.color = "#000";
54 var _ = t.splitText(d.index);
55 _.nodeValue = _.nodeValue.substring(d[0].length), t.parentNode.insertBefore(g, _);
56 }
57 }
58 }
59 }, this.remove = function() {
60 for (var e = document.getElementsByTagName(i), t; e.length && (t = e[0]);) t.parentNode.replaceChild(t.firstChild, t);
61 }, this.apply = function(e) {
62 if (!(e == null || !e)) return this.remove(), this.setRegex(e), this.hiliteWords(r), u;
63 };
64 }
65 return {
66 id: "search",
67 init: (t) => {
68 e = t, e.registerKeyboardShortcut("CTRL + Shift + F", "Search"), document.addEventListener("keydown", function(e) {
69 e.key == "F" && (e.ctrlKey || e.metaKey) && (e.preventDefault(), u());
70 }, !1);
71 },
72 open: c,
73 close: l,
74 toggle: u
75 };
76 };
77 //#endregion
78 export { e as default };
79
79 lines Plain Text