clean-jsdoc-theme 4.1.6 → 4.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +1 -1
- package/.eslintrc.js +2 -2
- package/.prettierignore +0 -1
- package/.stylelintignore +2 -2
- package/.stylelintrc +9 -14
- package/CHANGELOG.md +56 -35
- package/CODE_OF_CONDUCT.md +4 -4
- package/CODE_OF_CONDUCT_HINDI.md +25 -10
- package/CONTRIBUTING.md +19 -7
- package/README.md +104 -64
- package/SECURITY.md +2 -2
- package/css.js +124 -0
- package/jsdoc-config.json +1 -0
- package/minify.js +31 -23
- package/package.json +50 -48
- package/publish.js +798 -797
- package/static/scripts/core.js +401 -383
- package/static/scripts/core.min.js +2 -2
- package/static/scripts/resize.js +2 -2
- package/static/scripts/search.js +81 -108
- package/static/scripts/search.min.js +5 -10
- package/static/scripts/third-party/hljs-line-num-original.js +369 -0
- package/static/scripts/third-party/hljs-line-num.js +1 -1
- package/static/scripts/third-party/tocbot.js +672 -1
- package/static/scripts/third-party/tocbot.min.js +1 -0
- package/static/styles/clean-jsdoc-theme-base.css +29 -12
- package/static/styles/clean-jsdoc-theme.min.css +1 -1
- package/tmpl/layout.tmpl +4 -2
- package/tmpl/members.tmpl +1 -1
- package/tmpl/method.tmpl +1 -1
- package/tmpl/search.tmpl +1 -1
- package/tmpl/type.tmpl +8 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var accordionLocalStorageKey="accordion-id",themeLocalStorageKey="theme",fontSizeLocalStorageKey="font-size",html=document.querySelector("html"),MAX_FONT_SIZE=30,MIN_FONT_SIZE=10,localStorage=window.localStorage;function getTheme(){return document.body.getAttribute("data-theme")}function updateTheme(e){var t=document.body,o=document.querySelectorAll(".theme-svg-use"),n="dark"===e?"#light-theme-icon":"#dark-theme-icon";t.setAttribute("data-theme",e),t.classList.remove("dark","light"),t.classList.add(e),o.forEach(function(e){e.setAttribute("xlink:href",n)}),localStorage.setItem(themeLocalStorageKey,e)}function toggleTheme(){updateTheme("dark"===document.body.getAttribute("data-theme")?"light":"dark")}function setAccordionIdToLocalStorage(e){var t=JSON.parse(localStorage.getItem(accordionLocalStorageKey));t[e]=e,localStorage.setItem(accordionLocalStorageKey,JSON.stringify(t))}function removeAccordionIdFromLocalStorage(e){var t=JSON.parse(localStorage.getItem(accordionLocalStorageKey));delete t[e],localStorage.setItem(accordionLocalStorageKey,JSON.stringify(t))}function getAccordionIdsFromLocalStorage(){return JSON.parse(localStorage.getItem(accordionLocalStorageKey))||{}}function toggleAccordion(e){"false"===e.getAttribute("data-isopen")?(e.setAttribute("data-isopen","true"),setAccordionIdToLocalStorage(e.id)):(e.setAttribute("data-isopen","false"),removeAccordionIdFromLocalStorage(e.id))}function initAccordion(){void 0!==localStorage.getItem(accordionLocalStorageKey)&&null!==localStorage.getItem(accordionLocalStorageKey)||localStorage.setItem(accordionLocalStorageKey,"{}");var e=document.querySelectorAll(".sidebar-section-title"),t=getAccordionIdsFromLocalStorage();e.forEach(function(e){e.addEventListener("click",function(){toggleAccordion(e)}),e.id in t&&toggleAccordion(e)})}function isSourcePage(){return Boolean(document.querySelector("#source-page"))}function bringElementIntoView(e,t=!0){var o,n,i,c;e&&(o=document.querySelector(".navbar-container"),n=document.querySelector(".main-content"),i=e.getBoundingClientRect().top,c=16,o&&(c+=o.scrollHeight),n&&n.scrollBy(0,i-c),t&&history.pushState(null,null,"#"+e.id))}function bringLinkToView(e){e.preventDefault(),e.stopPropagation();var e=e.currentTarget.getAttribute("href");!e||(e=document.getElementById(e.slice(1)))&&bringElementIntoView(e)}function bringIdToViewOnMount(){var e,t;isSourcePage()||""!==(e=window.location.hash)&&((t=document.getElementById(e.slice(1)))||(e=decodeURI(e),t=document.getElementById(e.slice(1))),t&&bringElementIntoView(t,!1))}function createAnchorElement(e){var t=document.createElement("a");return t.textContent="#",t.href="#"+e,t.classList.add("link-anchor"),t.onclick=bringLinkToView,t}function addAnchor(){var e=document.querySelector(".main-content").querySelector("section");[e.querySelectorAll("h1"),e.querySelectorAll("h2"),e.querySelectorAll("h3"),e.querySelectorAll("h4")].forEach(function(e){e.forEach(function(e){var t=createAnchorElement(e.id);e.classList.add("has-anchor"),e.append(t)})})}function copy(e){const t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}function showTooltip(e){var t=document.getElementById(e);t.classList.add("show-tooltip"),setTimeout(function(){t.classList.remove("show-tooltip")},3e3)}function copyFunction(e){var t=document.getElementById(e);copy((t.querySelector(".linenums")||t.querySelector("code")).innerText),showTooltip("tooltip-"+e)}function hideTocOnSourcePage(){isSourcePage()&&(document.querySelector(".toc-container").style.display="none")}function getPreTopBar(e,t=""){e='<button aria-label="copy code" class="icon-button copy-code" onclick="copyFunction(\''+e+'\')"><svg class="sm-icon" alt="click to copy"><use xlink:href="#copy-icon"></use></svg>'+('<div class="tooltip" id="tooltip-'+e+'">Copied!</div>')+"</button>";return'<div class="pre-top-bar-container">'+('<div class="code-lang-name-container"><div class="code-lang-name">'+t.toLocaleUpperCase()+"</div></div>")+e+"</div>"}function getPreDiv(){var e=document.createElement("div");return e.classList.add("pre-div"),e}function processAllPre(){var e=document.querySelectorAll("pre"),t=document.querySelector("#PeOAagUepe"),o=document.querySelector("#VuAckcnZhf"),n=0,i=0,c=(t&&(i=t.getBoundingClientRect().height),o&&(n=o.getBoundingClientRect().height),window.innerHeight-n-i-250);e.forEach(function(e,t){var o,n=e.parentNode;n&&"true"===n.getAttribute("data-skip-pre-process")||(n=getPreDiv(),o=getPreTopBar(t="ScDloZOMdL"+t,e.getAttribute("data-lang")||"code"),n.innerHTML=o,e.style.maxHeight=c+"px",e.id=t,e.classList.add("prettyprint"),e.parentNode.insertBefore(n,e),n.appendChild(e))})}function highlightAndBringLineIntoView(){var e=window.location.hash.replace("#line","");try{var t='[data-line-number="'+e+'"',o=document.querySelector(t);o.scrollIntoView(),o.parentNode.classList.add("selected")}catch(e){console.error(e)}}function getFontSize(){var e=16;try{e=Number.parseInt(html.style.fontSize.split("px")[0],10)}catch(e){console.log(e)}return e}function updateFontSize(e){html.style.fontSize=e+"px",localStorage.setItem(fontSizeLocalStorageKey,e);var t=document.querySelector("#b77a68a492f343baabea06fad81f651e");t&&(t.innerHTML=e)}function incrementFont(e){var t=getFontSize();t<MAX_FONT_SIZE&&updateFontSize(t+1)}function decrementFont(e){var t=getFontSize();MIN_FONT_SIZE<t&&updateFontSize(t-1)}function fontSizeTooltip(){var e=getFontSize();return`
|
|
1
|
+
var accordionLocalStorageKey="accordion-id",themeLocalStorageKey="theme",fontSizeLocalStorageKey="font-size",html=document.querySelector("html"),MAX_FONT_SIZE=30,MIN_FONT_SIZE=10,localStorage=window.localStorage;function getTheme(){return document.body.getAttribute("data-theme")}function updateTheme(e){var t=document.body,o=document.querySelectorAll(".theme-svg-use"),n="dark"===e?"#light-theme-icon":"#dark-theme-icon";t.setAttribute("data-theme",e),t.classList.remove("dark","light"),t.classList.add(e),o.forEach(function(e){e.setAttribute("xlink:href",n)}),localStorage.setItem(themeLocalStorageKey,e)}function toggleTheme(){updateTheme("dark"===document.body.getAttribute("data-theme")?"light":"dark")}function setAccordionIdToLocalStorage(e){var t=JSON.parse(localStorage.getItem(accordionLocalStorageKey));t[e]=e,localStorage.setItem(accordionLocalStorageKey,JSON.stringify(t))}function removeAccordionIdFromLocalStorage(e){var t=JSON.parse(localStorage.getItem(accordionLocalStorageKey));delete t[e],localStorage.setItem(accordionLocalStorageKey,JSON.stringify(t))}function getAccordionIdsFromLocalStorage(){return JSON.parse(localStorage.getItem(accordionLocalStorageKey))||{}}function toggleAccordion(e){"false"===e.getAttribute("data-isopen")?(e.setAttribute("data-isopen","true"),setAccordionIdToLocalStorage(e.id)):(e.setAttribute("data-isopen","false"),removeAccordionIdFromLocalStorage(e.id))}function initAccordion(){void 0!==localStorage.getItem(accordionLocalStorageKey)&&null!==localStorage.getItem(accordionLocalStorageKey)||localStorage.setItem(accordionLocalStorageKey,"{}");var e=document.querySelectorAll(".sidebar-section-title"),t=getAccordionIdsFromLocalStorage();e.forEach(function(e){e.addEventListener("click",function(){toggleAccordion(e)}),e.id in t&&toggleAccordion(e)})}function isSourcePage(){return Boolean(document.querySelector("#source-page"))}function bringElementIntoView(e,t=!0){var o,n,i,c;e&&(tocbotInstance&&setTimeout(()=>tocbotInstance.updateTocListActiveElement(e),60),o=document.querySelector(".navbar-container"),n=document.querySelector(".main-content"),i=e.getBoundingClientRect().top,c=16,o&&(c+=o.scrollHeight),n&&n.scrollBy(0,i-c),t&&history.pushState(null,null,"#"+e.id))}function bringLinkToView(e){e.preventDefault(),e.stopPropagation();var e=e.currentTarget.getAttribute("href");!e||(e=document.getElementById(e.slice(1)))&&bringElementIntoView(e)}function bringIdToViewOnMount(){var e,t;isSourcePage()||""!==(e=window.location.hash)&&((t=document.getElementById(e.slice(1)))||(e=decodeURI(e),t=document.getElementById(e.slice(1))),t&&bringElementIntoView(t,!1))}function createAnchorElement(e){var t=document.createElement("a");return t.textContent="#",t.href="#"+e,t.classList.add("link-anchor"),t.onclick=bringLinkToView,t}function addAnchor(){var e=document.querySelector(".main-content").querySelector("section");[e.querySelectorAll("h1"),e.querySelectorAll("h2"),e.querySelectorAll("h3"),e.querySelectorAll("h4")].forEach(function(e){e.forEach(function(e){var t=createAnchorElement(e.id);e.classList.add("has-anchor"),e.append(t)})})}function copy(e){console.log(e);const t=document.createElement("textarea");t.value=e,document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}function showTooltip(e){var t=document.getElementById(e);t.classList.add("show-tooltip"),setTimeout(function(){t.classList.remove("show-tooltip")},3e3)}function copyFunction(e){var t=document.getElementById(e);copy((t.querySelector(".linenums")||t.querySelector("code")).innerText.trim().replace(/(^\t)/gm,"")),showTooltip("tooltip-"+e)}function hideTocOnSourcePage(){isSourcePage()&&(document.querySelector(".toc-container").style.display="none")}function getPreTopBar(e,t=""){e='<button aria-label="copy code" class="icon-button copy-code" onclick="copyFunction(\''+e+'\')"><svg class="sm-icon" alt="click to copy"><use xlink:href="#copy-icon"></use></svg>'+('<div class="tooltip" id="tooltip-'+e+'">Copied!</div>')+"</button>";return'<div class="pre-top-bar-container">'+('<div class="code-lang-name-container"><div class="code-lang-name">'+t.toLocaleUpperCase()+"</div></div>")+e+"</div>"}function getPreDiv(){var e=document.createElement("div");return e.classList.add("pre-div"),e}function processAllPre(){var e=document.querySelectorAll("pre"),t=document.querySelector("#PeOAagUepe"),o=document.querySelector("#VuAckcnZhf"),n=0,i=0,c=(t&&(i=t.getBoundingClientRect().height),o&&(n=o.getBoundingClientRect().height),window.innerHeight-n-i-250);e.forEach(function(e,t){var o,n=e.parentNode;n&&"true"===n.getAttribute("data-skip-pre-process")||(n=getPreDiv(),o=getPreTopBar(t="ScDloZOMdL"+t,e.getAttribute("data-lang")||"code"),n.innerHTML=o,e.style.maxHeight=c+"px",e.id=t,e.classList.add("prettyprint"),e.parentNode.insertBefore(n,e),n.appendChild(e))})}function highlightAndBringLineIntoView(){var e=window.location.hash.replace("#line","");try{var t='[data-line-number="'+e+'"',o=document.querySelector(t);o.scrollIntoView(),o.parentNode.classList.add("selected")}catch(e){console.error(e)}}function getFontSize(){var e=16;try{e=Number.parseInt(html.style.fontSize.split("px")[0],10)}catch(e){console.log(e)}return e}function updateFontSize(e){html.style.fontSize=e+"px",localStorage.setItem(fontSizeLocalStorageKey,e);var t=document.querySelector("#b77a68a492f343baabea06fad81f651e");t&&(t.innerHTML=e)}function incrementFont(e){var t=getFontSize();t<MAX_FONT_SIZE&&updateFontSize(t+1)}function decrementFont(e){var t=getFontSize();MIN_FONT_SIZE<t&&updateFontSize(t-1)}function fontSizeTooltip(){var e=getFontSize();return`
|
|
2
2
|
<div class="font-size-tooltip">
|
|
3
3
|
<button aria-label="decrease-font-size" class="icon-button ${MAX_FONT_SIZE<=e?"disabled":""}" onclick="decrementFont(event)">
|
|
4
4
|
<svg>
|
|
@@ -20,4 +20,4 @@ var accordionLocalStorageKey="accordion-id",themeLocalStorageKey="theme",fontSiz
|
|
|
20
20
|
</button>
|
|
21
21
|
</div>
|
|
22
22
|
|
|
23
|
-
`}function initTooltip(){tippy(".theme-toggle",{content:"Toggle Theme",delay:500}),tippy(".search-button",{content:"Search",delay:500}),tippy(".font-size",{content:"Change font size",delay:500}),tippy(".codepen-button",{content:"Open code in CodePen",placement:"left"}),tippy(".copy-code",{content:"Copy this code",placement:"left"}),tippy(".font-size",{content:fontSizeTooltip(),trigger:"click",interactive:!0,allowHTML:!0,placement:"left"})}function fixTable(){var e,t=document.querySelectorAll("table");if(!(900<window.innerWidth))for(e of t){if(e.classList.contains("hljs-ln"))return;var o=document.createElement("div");o.classList.add("table-div"),e.parentNode.insertBefore(o,e),o.appendChild(e)}}function hideMobileMenu(){var e=document.querySelector("#mobile-sidebar"),t=document.querySelector("#mobile-menu"),o=t.querySelector("use");e&&e.classList.remove("show"),t&&t.setAttribute("data-isopen","false"),o&&o.setAttribute("xlink:href","#menu-icon")}function showMobileMenu(){var e=document.querySelector("#mobile-sidebar"),t=document.querySelector("#mobile-menu"),o=t.querySelector("use");e&&e.classList.add("show"),t&&t.setAttribute("data-isopen","true"),o&&o.setAttribute("xlink:href","#close-icon")}function onMobileMenuClick(){("true"===document.querySelector("#mobile-menu").getAttribute("data-isopen")?hideMobileMenu:showMobileMenu)()}function initMobileMenu(){var e=document.querySelector("#mobile-menu");e&&e.addEventListener("click",onMobileMenuClick)}function addHrefToSidebarTitle(){document.querySelectorAll(".sidebar-title-anchor").forEach(function(e){e.setAttribute("href",baseURL)})}function onDomContentLoaded(){var e=document.querySelectorAll(".theme-toggle");initMobileMenu(),e&&e.forEach(function(e){e.addEventListener("click",toggleTheme)}),hljs.addPlugin({"after:highlightElement":function(e){e.el.parentNode.setAttribute("data-lang","code")}}),hljs.highlightAll(),hljs.initLineNumbersOnLoad({singleLine:!0}),initAccordion(),addAnchor(),processAllPre(),hideTocOnSourcePage(),setTimeout(function(){bringIdToViewOnMount(),isSourcePage()&&highlightAndBringLineIntoView()},1e3),initTooltip(),fixTable(),addHrefToSidebarTitle()}!function(){var e=getTheme(),t=localStorage.getItem(themeLocalStorageKey);t?e!==t&&updateTheme(t):localStorage.setItem(themeLocalStorageKey,e)}(),function(){var e=getFontSize(),t=localStorage.getItem(fontSizeLocalStorageKey);t?(t=Number.parseInt(t,10))!==e&&updateFontSize(t):updateFontSize(e)}(),window.addEventListener("DOMContentLoaded",onDomContentLoaded);
|
|
23
|
+
`}function initTooltip(){tippy(".theme-toggle",{content:"Toggle Theme",delay:500}),tippy(".search-button",{content:"Search",delay:500}),tippy(".font-size",{content:"Change font size",delay:500}),tippy(".codepen-button",{content:"Open code in CodePen",placement:"left"}),tippy(".copy-code",{content:"Copy this code",placement:"left"}),tippy(".font-size",{content:fontSizeTooltip(),trigger:"click",interactive:!0,allowHTML:!0,placement:"left"})}function fixTable(){var e,t=document.querySelectorAll("table");if(!(900<window.innerWidth))for(e of t){if(e.classList.contains("hljs-ln"))return;var o=document.createElement("div");o.classList.add("table-div"),e.parentNode.insertBefore(o,e),o.appendChild(e)}}function hideMobileMenu(){var e=document.querySelector("#mobile-sidebar"),t=document.querySelector("#mobile-menu"),o=t.querySelector("use");e&&e.classList.remove("show"),t&&t.setAttribute("data-isopen","false"),o&&o.setAttribute("xlink:href","#menu-icon")}function showMobileMenu(){var e=document.querySelector("#mobile-sidebar"),t=document.querySelector("#mobile-menu"),o=t.querySelector("use");e&&e.classList.add("show"),t&&t.setAttribute("data-isopen","true"),o&&o.setAttribute("xlink:href","#close-icon")}function onMobileMenuClick(){("true"===document.querySelector("#mobile-menu").getAttribute("data-isopen")?hideMobileMenu:showMobileMenu)()}function initMobileMenu(){var e=document.querySelector("#mobile-menu");e&&e.addEventListener("click",onMobileMenuClick)}function addHrefToSidebarTitle(){document.querySelectorAll(".sidebar-title-anchor").forEach(function(e){e.setAttribute("href",baseURL)})}function onDomContentLoaded(){var e=document.querySelectorAll(".theme-toggle");initMobileMenu(),e&&e.forEach(function(e){e.addEventListener("click",toggleTheme)}),hljs.addPlugin({"after:highlightElement":function(e){e.el.parentNode.setAttribute("data-lang","code")}}),hljs.highlightAll(),hljs.initLineNumbersOnLoad({singleLine:!0}),initAccordion(),addAnchor(),processAllPre(),hideTocOnSourcePage(),setTimeout(function(){bringIdToViewOnMount(),isSourcePage()&&highlightAndBringLineIntoView()},1e3),initTooltip(),fixTable(),addHrefToSidebarTitle()}!function(){var e=getTheme(),t=localStorage.getItem(themeLocalStorageKey);t?e!==t&&updateTheme(t):localStorage.setItem(themeLocalStorageKey,e)}(),function(){var e=getFontSize(),t=localStorage.getItem(fontSizeLocalStorageKey);t?(t=Number.parseInt(t,10))!==e&&updateFontSize(t):updateFontSize(e)}(),window.addEventListener("DOMContentLoaded",onDomContentLoaded),window.addEventListener("hashchange",e=>{e=new URL(e.newURL);""!==e.hash&&bringIdToViewOnMount(e.hash)});
|
package/static/scripts/resize.js
CHANGED
|
@@ -9,8 +9,8 @@ var NAVBAR_OPTIONS = {};
|
|
|
9
9
|
var navbar = document.querySelector('#navbar');
|
|
10
10
|
var footer = document.querySelector('#footer');
|
|
11
11
|
var mainSection = document.querySelector('#main');
|
|
12
|
-
// eslint-disable-next-line no-undef
|
|
13
12
|
var localStorageResizeObject = JSON.parse(
|
|
13
|
+
// eslint-disable-next-line no-undef
|
|
14
14
|
localStorage.getItem(NAVBAR_RESIZE_LOCAL_STORAGE_KEY)
|
|
15
15
|
);
|
|
16
16
|
|
|
@@ -33,7 +33,7 @@ var NAVBAR_OPTIONS = {};
|
|
|
33
33
|
max = Number.parseInt(NAVBAR_OPTIONS.max, 10) || 600;
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
|
-
* Just to add some checks. If min is smaller
|
|
36
|
+
* Just to add some checks. If min is smaller than 10 then
|
|
37
37
|
* user may accidentally end up reducing the size of navbar
|
|
38
38
|
* less than 10. In that case user will not able to resize navbar
|
|
39
39
|
* because navbar slider will be hidden.
|
package/static/scripts/search.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
/* global document */
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
const searchId = 'LiBfqbJVcV';
|
|
4
|
+
const searchHash = '#' + searchId;
|
|
5
|
+
const searchContainer = document.querySelector('#PkfLWpAbet');
|
|
6
|
+
const searchWrapper = document.querySelector('#iCxFxjkHbP');
|
|
7
|
+
const searchCloseButton = document.querySelector('#VjLlGakifb');
|
|
8
|
+
const searchInput = document.querySelector('#vpcKVYIppa');
|
|
9
|
+
const resultBox = document.querySelector('#fWwVHRuDuN');
|
|
10
|
+
|
|
11
|
+
function showResultText(text) {
|
|
12
|
+
resultBox.innerHTML = `<span class="search-result-c-text">${text}</span>`;
|
|
13
|
+
}
|
|
11
14
|
|
|
12
15
|
function hideSearch() {
|
|
13
|
-
var container = document.querySelector(searchContainerID);
|
|
14
|
-
|
|
15
16
|
// eslint-disable-next-line no-undef
|
|
16
17
|
if (window.location.hash === searchHash) {
|
|
17
18
|
// eslint-disable-next-line no-undef
|
|
@@ -21,16 +22,16 @@ function hideSearch() {
|
|
|
21
22
|
// eslint-disable-next-line no-undef
|
|
22
23
|
window.onhashchange = null;
|
|
23
24
|
|
|
24
|
-
if (
|
|
25
|
-
|
|
25
|
+
if (searchContainer) {
|
|
26
|
+
searchContainer.style.display = 'none';
|
|
26
27
|
}
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
function
|
|
30
|
+
function listenCloseKey(event) {
|
|
30
31
|
if (event.key === 'Escape') {
|
|
31
32
|
hideSearch();
|
|
32
33
|
// eslint-disable-next-line no-undef
|
|
33
|
-
window.removeEventListener('keyup',
|
|
34
|
+
window.removeEventListener('keyup', listenCloseKey);
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -45,9 +46,6 @@ function showSearch() {
|
|
|
45
46
|
console.error(error);
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
var container = document.querySelector(searchContainerID);
|
|
49
|
-
var input = document.querySelector(searchInputID);
|
|
50
|
-
|
|
51
49
|
// eslint-disable-next-line no-undef
|
|
52
50
|
window.onhashchange = hideSearch;
|
|
53
51
|
|
|
@@ -57,51 +55,43 @@ function showSearch() {
|
|
|
57
55
|
history.pushState(null, null, searchHash);
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
if (
|
|
61
|
-
|
|
58
|
+
if (searchContainer) {
|
|
59
|
+
searchContainer.style.display = 'flex';
|
|
62
60
|
// eslint-disable-next-line no-undef
|
|
63
|
-
window.addEventListener('keyup',
|
|
61
|
+
window.addEventListener('keyup', listenCloseKey);
|
|
64
62
|
}
|
|
65
63
|
|
|
66
|
-
if (
|
|
67
|
-
|
|
64
|
+
if (searchInput) {
|
|
65
|
+
searchInput.focus();
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
function fetchAllData(
|
|
69
|
+
async function fetchAllData() {
|
|
72
70
|
// eslint-disable-next-line no-undef
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
.catch(function(error) {
|
|
86
|
-
console.error(error);
|
|
87
|
-
if (typeof obj.onError === 'function') {
|
|
88
|
-
obj.onError();
|
|
89
|
-
}
|
|
90
|
-
});
|
|
71
|
+
const { hostname, protocol, port } = location;
|
|
72
|
+
|
|
73
|
+
// eslint-disable-next-line no-undef
|
|
74
|
+
const base = protocol + '//' + hostname + (port !== '' ? ':' + port : '') + baseURL;
|
|
75
|
+
// eslint-disable-next-line no-undef
|
|
76
|
+
const url = new URL('data/search.json', base);
|
|
77
|
+
const result = await fetch(url);
|
|
78
|
+
const { list } = await result.json();
|
|
79
|
+
|
|
80
|
+
return list;
|
|
91
81
|
}
|
|
92
82
|
|
|
93
83
|
// eslint-disable-next-line no-unused-vars
|
|
94
84
|
function onClickSearchItem(event) {
|
|
95
|
-
|
|
85
|
+
const target = event.currentTarget;
|
|
96
86
|
|
|
97
87
|
if (target) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
88
|
+
const href = target.getAttribute('href') || '';
|
|
89
|
+
let elementId = href.split('#')[1] || '';
|
|
90
|
+
let element = document.getElementById(elementId);
|
|
101
91
|
|
|
102
92
|
if (!element) {
|
|
103
|
-
|
|
104
|
-
element = document.getElementById(
|
|
93
|
+
elementId = decodeURI(elementId);
|
|
94
|
+
element = document.getElementById(elementId);
|
|
105
95
|
}
|
|
106
96
|
|
|
107
97
|
if (element) {
|
|
@@ -114,22 +104,17 @@ function onClickSearchItem(event) {
|
|
|
114
104
|
}
|
|
115
105
|
|
|
116
106
|
function buildSearchResult(result) {
|
|
117
|
-
|
|
107
|
+
let output = '';
|
|
118
108
|
|
|
119
109
|
for (const res of result) {
|
|
120
|
-
|
|
110
|
+
const { title, description } = res.item;
|
|
121
111
|
|
|
122
|
-
|
|
112
|
+
const link = res.item.link.replace('<a href="', '').replace(/">.*/, '');
|
|
123
113
|
|
|
124
114
|
output += `
|
|
125
|
-
|
|
126
115
|
<a onclick="onClickSearchItem(event)" href="${link}" class="search-result-item">
|
|
127
|
-
<div class="search-result-item-title">
|
|
128
|
-
|
|
129
|
-
</div>
|
|
130
|
-
<div class="search-result-item-p">
|
|
131
|
-
${data.description ? data.description : 'No description available.'}
|
|
132
|
-
</div>
|
|
116
|
+
<div class="search-result-item-title">${title}</div>
|
|
117
|
+
<div class="search-result-item-p">${description || 'No description available.'}</div>
|
|
133
118
|
</a>
|
|
134
119
|
`;
|
|
135
120
|
}
|
|
@@ -138,7 +123,7 @@ function buildSearchResult(result) {
|
|
|
138
123
|
}
|
|
139
124
|
|
|
140
125
|
function getSearchResult(list, keys, searchKey) {
|
|
141
|
-
|
|
126
|
+
const defaultOptions = {
|
|
142
127
|
shouldSort: true,
|
|
143
128
|
threshold: 0.4,
|
|
144
129
|
location: 0,
|
|
@@ -148,49 +133,50 @@ function getSearchResult(list, keys, searchKey) {
|
|
|
148
133
|
keys: keys
|
|
149
134
|
};
|
|
150
135
|
|
|
151
|
-
|
|
152
|
-
var op = defaultOptions;
|
|
136
|
+
const options = { ...defaultOptions };
|
|
153
137
|
|
|
154
138
|
// eslint-disable-next-line no-undef
|
|
155
|
-
|
|
139
|
+
const searchIndex = Fuse.createIndex(options.keys, list);
|
|
156
140
|
|
|
157
|
-
|
|
158
|
-
|
|
141
|
+
// eslint-disable-next-line no-undef
|
|
142
|
+
const fuse = new Fuse(list, options, searchIndex);
|
|
159
143
|
|
|
160
|
-
|
|
144
|
+
const result = fuse.search(searchKey);
|
|
161
145
|
|
|
162
146
|
if (result.length > 20) {
|
|
163
|
-
|
|
147
|
+
return result.slice(0, 20);
|
|
164
148
|
}
|
|
165
149
|
|
|
166
150
|
return result;
|
|
167
151
|
}
|
|
168
152
|
|
|
169
153
|
function debounce(func, wait, immediate) {
|
|
170
|
-
|
|
154
|
+
let timeout;
|
|
171
155
|
|
|
172
156
|
return function() {
|
|
173
|
-
|
|
174
|
-
var context = this,
|
|
175
|
-
args = arguments;
|
|
157
|
+
const args = arguments;
|
|
176
158
|
|
|
177
159
|
clearTimeout(timeout);
|
|
178
|
-
timeout = setTimeout(
|
|
160
|
+
timeout = setTimeout(() => {
|
|
179
161
|
timeout = null;
|
|
180
162
|
if (!immediate) {
|
|
181
|
-
|
|
163
|
+
// eslint-disable-next-line consistent-this, no-invalid-this
|
|
164
|
+
func.apply(this, args);
|
|
182
165
|
}
|
|
183
166
|
}, wait);
|
|
167
|
+
|
|
184
168
|
if (immediate && !timeout) {
|
|
185
|
-
|
|
169
|
+
// eslint-disable-next-line consistent-this, no-invalid-this
|
|
170
|
+
func.apply(this, args);
|
|
186
171
|
}
|
|
187
172
|
};
|
|
188
173
|
}
|
|
189
174
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
175
|
+
let searchData;
|
|
176
|
+
|
|
177
|
+
async function search(event) {
|
|
178
|
+
const value = event.target.value;
|
|
179
|
+
const keys = ['title', 'description'];
|
|
194
180
|
|
|
195
181
|
if (!resultBox) {
|
|
196
182
|
console.error('Search result container not found');
|
|
@@ -199,53 +185,40 @@ function search(event) {
|
|
|
199
185
|
}
|
|
200
186
|
|
|
201
187
|
if (!value) {
|
|
202
|
-
|
|
188
|
+
showResultText('Type anything to view search result');
|
|
203
189
|
|
|
204
190
|
return;
|
|
205
191
|
}
|
|
206
192
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
193
|
+
if (!searchData) {
|
|
194
|
+
showResultText('Loading...');
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
// eslint-disable-next-line require-atomic-updates
|
|
198
|
+
searchData = await fetchAllData();
|
|
199
|
+
} catch (e) {
|
|
200
|
+
console.log(e);
|
|
201
|
+
showResultText('Failed to load result.');
|
|
211
202
|
|
|
212
203
|
return;
|
|
213
204
|
}
|
|
214
|
-
var output = buildSearchResult(res);
|
|
215
|
-
|
|
216
|
-
resultBox.innerHTML = output;
|
|
217
205
|
}
|
|
218
206
|
|
|
219
|
-
|
|
220
|
-
resultBox.innerHTML = 'Loading...';
|
|
221
|
-
|
|
222
|
-
fetchAllData({
|
|
223
|
-
onSuccess: function(list) {
|
|
224
|
-
var result = getSearchResult(list, keys, value);
|
|
207
|
+
const result = getSearchResult(searchData, keys, value);
|
|
225
208
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
onError: function() {
|
|
229
|
-
resultBox.innerHTML = 'Failed to load result.';
|
|
230
|
-
}
|
|
231
|
-
});
|
|
209
|
+
if (!result.length) {
|
|
210
|
+
showResultText('No result found! Try some different combination.');
|
|
232
211
|
|
|
233
212
|
return;
|
|
234
213
|
}
|
|
235
214
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
onSuccess(result);
|
|
215
|
+
// eslint-disable-next-line require-atomic-updates
|
|
216
|
+
resultBox.innerHTML = buildSearchResult(result);
|
|
239
217
|
}
|
|
240
218
|
|
|
241
219
|
function onDomContentLoaded() {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var searchContainer = document.querySelector(searchContainerID);
|
|
245
|
-
var searchWrapper = document.querySelector(searchWrapperID);
|
|
246
|
-
var searchCloseButton = document.querySelector(searchCloseButtonID);
|
|
247
|
-
|
|
248
|
-
var debouncedSearch = debounce(search, 300);
|
|
220
|
+
const searchButton = document.querySelectorAll('.search-button');
|
|
221
|
+
const debouncedSearch = debounce(search, 300);
|
|
249
222
|
|
|
250
223
|
if (searchCloseButton) {
|
|
251
224
|
searchCloseButton.addEventListener('click', hideSearch);
|
|
@@ -267,8 +240,8 @@ function onDomContentLoaded() {
|
|
|
267
240
|
});
|
|
268
241
|
}
|
|
269
242
|
|
|
270
|
-
if (
|
|
271
|
-
|
|
243
|
+
if (searchInput) {
|
|
244
|
+
searchInput.addEventListener('keyup', debouncedSearch);
|
|
272
245
|
}
|
|
273
246
|
|
|
274
247
|
// eslint-disable-next-line no-undef
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
<div class="search-result-item-
|
|
5
|
-
${n.title}
|
|
6
|
-
</div>
|
|
7
|
-
<div class="search-result-item-p">
|
|
8
|
-
${n.description||"No description available."}
|
|
9
|
-
</div>
|
|
1
|
+
const searchId="LiBfqbJVcV",searchHash="#"+searchId,searchContainer=document.querySelector("#PkfLWpAbet"),searchWrapper=document.querySelector("#iCxFxjkHbP"),searchCloseButton=document.querySelector("#VjLlGakifb"),searchInput=document.querySelector("#vpcKVYIppa"),resultBox=document.querySelector("#fWwVHRuDuN");function showResultText(e){resultBox.innerHTML=`<span class="search-result-c-text">${e}</span>`}function hideSearch(){window.location.hash===searchHash&&history.go(-1),window.onhashchange=null,searchContainer&&(searchContainer.style.display="none")}function listenCloseKey(e){"Escape"===e.key&&(hideSearch(),window.removeEventListener("keyup",listenCloseKey))}function showSearch(){try{hideMobileMenu()}catch(e){console.error(e)}window.onhashchange=hideSearch,window.location.hash!==searchHash&&history.pushState(null,null,searchHash),searchContainer&&(searchContainer.style.display="flex",window.addEventListener("keyup",listenCloseKey)),searchInput&&searchInput.focus()}async function fetchAllData(){var{hostname:e,protocol:t,port:n}=location,t=t+"//"+e+(""!==n?":"+n:"")+baseURL,e=new URL("data/search.json",t);const a=await fetch(e);n=(await a.json()).list;return n}function onClickSearchItem(t){const n=t.currentTarget;if(n){const a=n.getAttribute("href")||"";t=a.split("#")[1]||"";let e=document.getElementById(t);e||(t=decodeURI(t),e=document.getElementById(t)),e&&setTimeout(function(){bringElementIntoView(e)},100)}}function buildSearchResult(e){let t="";for(const s of e){var{title:n,description:a}=s.item,o=s.item.link.replace('<a href="',"").replace(/">.*/,"");t+=`
|
|
2
|
+
<a onclick="onClickSearchItem(event)" href="${o}" class="search-result-item">
|
|
3
|
+
<div class="search-result-item-title">${n}</div>
|
|
4
|
+
<div class="search-result-item-p">${a||"No description available."}</div>
|
|
10
5
|
</a>
|
|
11
|
-
`}return t}function getSearchResult(e,t,n){var t={shouldSort:!0,threshold:.4,location:0,distance:100,maxPatternLength:32,minMatchCharLength:1,keys:t},
|
|
6
|
+
`}return t}function getSearchResult(e,t,n){var t={...{shouldSort:!0,threshold:.4,location:0,distance:100,maxPatternLength:32,minMatchCharLength:1,keys:t}},a=Fuse.createIndex(t.keys,e);const o=new Fuse(e,t,a),s=o.search(n);return 20<s.length?s.slice(0,20):s}function debounce(t,n,a){let o;return function(){const e=arguments;clearTimeout(o),o=setTimeout(()=>{o=null,a||t.apply(this,e)},n),a&&!o&&t.apply(this,e)}}let searchData;async function search(e){e=e.target.value;if(resultBox)if(e){if(!searchData){showResultText("Loading...");try{searchData=await fetchAllData()}catch(e){return console.log(e),void showResultText("Failed to load result.")}}e=getSearchResult(searchData,["title","description"],e);e.length?resultBox.innerHTML=buildSearchResult(e):showResultText("No result found! Try some different combination.")}else showResultText("Type anything to view search result");else console.error("Search result container not found")}function onDomContentLoaded(){const e=document.querySelectorAll(".search-button");var t=debounce(search,300);searchCloseButton&&searchCloseButton.addEventListener("click",hideSearch),e&&e.forEach(function(e){e.addEventListener("click",showSearch)}),searchContainer&&searchContainer.addEventListener("click",hideSearch),searchWrapper&&searchWrapper.addEventListener("click",function(e){e.stopPropagation()}),searchInput&&searchInput.addEventListener("keyup",t),window.location.hash===searchHash&&showSearch()}window.addEventListener("DOMContentLoaded",onDomContentLoaded),window.addEventListener("hashchange",function(){window.location.hash===searchHash&&showSearch()});
|