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.
@@ -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)});
@@ -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 then 10 then
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.
@@ -1,17 +1,18 @@
1
1
  /* global document */
2
2
 
3
- var searchData;
4
- var searchId = 'LiBfqbJVcV';
5
- var searchHash = '#' + searchId;
6
- var searchContainerID = '#PkfLWpAbet';
7
- var searchWrapperID = '#iCxFxjkHbP';
8
- var searchCloseButtonID = '#VjLlGakifb';
9
- var searchInputID = '#vpcKVYIppa';
10
- var searchResultCID = '#fWwVHRuDuN';
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 (container) {
25
- container.style.display = 'none';
25
+ if (searchContainer) {
26
+ searchContainer.style.display = 'none';
26
27
  }
27
28
  }
28
29
 
29
- function listenKey(event) {
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', listenKey);
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 (container) {
61
- container.style.display = 'flex';
58
+ if (searchContainer) {
59
+ searchContainer.style.display = 'flex';
62
60
  // eslint-disable-next-line no-undef
63
- window.addEventListener('keyup', listenKey);
61
+ window.addEventListener('keyup', listenCloseKey);
64
62
  }
65
63
 
66
- if (input) {
67
- input.focus();
64
+ if (searchInput) {
65
+ searchInput.focus();
68
66
  }
69
67
  }
70
68
 
71
- function fetchAllData(obj = {}) {
69
+ async function fetchAllData() {
72
70
  // eslint-disable-next-line no-undef
73
- var url = baseURL + 'data/search.json';
74
-
75
- fetch(url)
76
- .then(function(d) {
77
- return d.json();
78
- })
79
- .then(function(d) {
80
- searchData = d.list;
81
- if (typeof obj.onSuccess === 'function') {
82
- obj.onSuccess(d.list);
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
- var target = event.currentTarget;
85
+ const target = event.currentTarget;
96
86
 
97
87
  if (target) {
98
- var href = target.getAttribute('href') || '';
99
- var id = href.split('#')[1] || '';
100
- var element = document.getElementById(id);
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
- id = decodeURI(id);
104
- element = document.getElementById(id);
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
- var output = '';
107
+ let output = '';
118
108
 
119
109
  for (const res of result) {
120
- var data = res.item;
110
+ const { title, description } = res.item;
121
111
 
122
- var link = res.item.link.replace('<a href="', '').replace(/">.*/, '');
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
- ${data.title}
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
- var defaultOptions = {
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
- // var op = Object.assign({}, defaultOptions, options);
152
- var op = defaultOptions;
136
+ const options = { ...defaultOptions };
153
137
 
154
138
  // eslint-disable-next-line no-undef
155
- var searchIndex = Fuse.createIndex(op.keys, list);
139
+ const searchIndex = Fuse.createIndex(options.keys, list);
156
140
 
157
- /* eslint-disable-next-line */
158
- var fuse = new Fuse(list, op, searchIndex);
141
+ // eslint-disable-next-line no-undef
142
+ const fuse = new Fuse(list, options, searchIndex);
159
143
 
160
- var result = fuse.search(searchKey);
144
+ const result = fuse.search(searchKey);
161
145
 
162
146
  if (result.length > 20) {
163
- result = result.slice(0, 20);
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
- var timeout;
154
+ let timeout;
171
155
 
172
156
  return function() {
173
- // eslint-disable-next-line consistent-this, no-invalid-this
174
- var context = this,
175
- args = arguments;
157
+ const args = arguments;
176
158
 
177
159
  clearTimeout(timeout);
178
- timeout = setTimeout(function() {
160
+ timeout = setTimeout(() => {
179
161
  timeout = null;
180
162
  if (!immediate) {
181
- func.apply(context, args);
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
- func.apply(context, args);
169
+ // eslint-disable-next-line consistent-this, no-invalid-this
170
+ func.apply(this, args);
186
171
  }
187
172
  };
188
173
  }
189
174
 
190
- function search(event) {
191
- var value = event.target.value;
192
- var resultBox = document.querySelector(searchResultCID);
193
- var keys = ['title', 'description'];
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
- resultBox.innerHTML = 'Type anything to view search result';
188
+ showResultText('Type anything to view search result');
203
189
 
204
190
  return;
205
191
  }
206
192
 
207
- function onSuccess(res) {
208
- if (res.length === 0) {
209
- resultBox.innerHTML =
210
- 'No result found! Try some different combination.';
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
- if (!searchData) {
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
- onSuccess(result);
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
- var result = getSearchResult(searchData, keys, value);
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
- var input = document.querySelector(searchInputID);
243
- var searchButton = document.querySelectorAll('.search-button');
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 (input) {
271
- input.addEventListener('keyup', debouncedSearch);
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
- var searchData,searchId="LiBfqbJVcV",searchHash="#"+searchId,searchContainerID="#PkfLWpAbet",searchWrapperID="#iCxFxjkHbP",searchCloseButtonID="#VjLlGakifb",searchInputID="#vpcKVYIppa",searchResultCID="#fWwVHRuDuN";function hideSearch(){var e=document.querySelector(searchContainerID);window.location.hash===searchHash&&history.go(-1),window.onhashchange=null,e&&(e.style.display="none")}function listenKey(e){"Escape"===e.key&&(hideSearch(),window.removeEventListener("keyup",listenKey))}function showSearch(){try{hideMobileMenu()}catch(e){console.error(e)}var e=document.querySelector(searchContainerID),t=document.querySelector(searchInputID);window.onhashchange=hideSearch,window.location.hash!==searchHash&&history.pushState(null,null,searchHash),e&&(e.style.display="flex",window.addEventListener("keyup",listenKey)),t&&t.focus()}function fetchAllData(t={}){var e=baseURL+"data/search.json";fetch(e).then(function(e){return e.json()}).then(function(e){searchData=e.list,"function"==typeof t.onSuccess&&t.onSuccess(e.list)}).catch(function(e){console.error(e),"function"==typeof t.onError&&t.onError()})}function onClickSearchItem(e){var t,e=e.currentTarget;e&&(e=(e.getAttribute("href")||"").split("#")[1]||"",(t=document.getElementById(e))||(e=decodeURI(e),t=document.getElementById(e)),t&&setTimeout(function(){bringElementIntoView(t)},100))}function buildSearchResult(e){var t="";for(const r of e){var n=r.item;t+=`
2
-
3
- <a onclick="onClickSearchItem(event)" href="${r.item.link.replace('<a href="',"").replace(/">.*/,"")}" class="search-result-item">
4
- <div class="search-result-item-title">
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},r=Fuse.createIndex(t.keys,e),e=new Fuse(e,t,r).search(n);return e=20<e.length?e.slice(0,20):e}function debounce(n,r,a){var c;return function(){var e=this,t=arguments;clearTimeout(c),c=setTimeout(function(){c=null,a||n.apply(e,t)},r),a&&!c&&n.apply(e,t)}}function search(e){var t=e.target.value,n=document.querySelector(searchResultCID),r=["title","description"];if(n)if(t){if(!searchData)return n.innerHTML="Loading...",void fetchAllData({onSuccess:function(e){a(getSearchResult(e,r,t))},onError:function(){n.innerHTML="Failed to load result."}});a(getSearchResult(searchData,r,t))}else n.innerHTML="Type anything to view search result";else console.error("Search result container not found");function a(e){0===e.length?n.innerHTML="No result found! Try some different combination.":(e=buildSearchResult(e),n.innerHTML=e)}}function onDomContentLoaded(){var e=document.querySelector(searchInputID),t=document.querySelectorAll(".search-button"),n=document.querySelector(searchContainerID),r=document.querySelector(searchWrapperID),a=document.querySelector(searchCloseButtonID),c=debounce(search,300);a&&a.addEventListener("click",hideSearch),t&&t.forEach(function(e){e.addEventListener("click",showSearch)}),n&&n.addEventListener("click",hideSearch),r&&r.addEventListener("click",function(e){e.stopPropagation()}),e&&e.addEventListener("keyup",c),window.location.hash===searchHash&&showSearch()}window.addEventListener("DOMContentLoaded",onDomContentLoaded),window.addEventListener("hashchange",function(){window.location.hash===searchHash&&showSearch()});
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()});