@xiee/utils 1.3.19 → 1.3.20
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/js/fuse-search.js +3 -4
- package/js/fuse-search.min.js +1 -1
- package/package.json +1 -1
package/js/fuse-search.js
CHANGED
|
@@ -70,12 +70,11 @@
|
|
|
70
70
|
output.innerHTML = '';
|
|
71
71
|
function search() {
|
|
72
72
|
if (!fuse) return;
|
|
73
|
-
let res, sec, u;
|
|
74
73
|
output.innerHTML = '';
|
|
75
74
|
// display search results in <section> and highlight keywords
|
|
76
|
-
for (res of fuse.search(input.value, {'limit': lim})) {
|
|
77
|
-
sec = tpl.cloneNode(true);
|
|
78
|
-
a = sec.querySelector('a');
|
|
75
|
+
for (let res of fuse.search(input.value, {'limit': lim})) {
|
|
76
|
+
const sec = tpl.cloneNode(true);
|
|
77
|
+
const a = sec.querySelector('a');
|
|
79
78
|
a.href = res.item.uri;
|
|
80
79
|
a.innerHTML = highlight(res, 'title', len);
|
|
81
80
|
sec.querySelector('.search-preview').innerHTML = highlight(res, 'content', len);
|
package/js/fuse-search.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e){const t=e.querySelector("#search-input"),n=e.querySelector(".search-results");if(!t||!n)return;const i=t.dataset;let
|
|
1
|
+
!function(e){const t=e.querySelector("#search-input"),n=e.querySelector(".search-results");if(!t||!n)return;const i=t.dataset;let o;function r(e,t,n){let i;for(let n of e.matches)n.key===t&&(i=n.indices);const o=e.item[t];if(!i)return o.substr(0,n);let r,s,c=0,l=Math.ceil(n/2);for(;s=i.shift();)s[1]-s[0]>=c&&(r=s,c=r[1]-r[0]);return(r[0]-l>0?"[...] ":"")+o.substring(r[0]-l,r[0])+"<b>"+o.substring(r[0],r[1]+1)+"</b>"+o.substring(r[1]+1,r[1]+1+l)+(r[1]+1+l<o.length?" [...] ":"")}t.addEventListener("focus",(e=>{if(o)return;t.placeholder=i.infoInit||"Loading search index... Please hold on.";const n=new XMLHttpRequest;n.responseType="json",n.addEventListener("load",(e=>{const r=n.response;r&&0!==r.length?(t.placeholder=i.infoOk||"Type to search:",t.focus(),o=new Fuse(r,{keys:[{name:"title",weight:5},"content"],useExtendedSearch:!0,includeMatches:!0,ignoreLocation:!0,threshold:.1})):t.placeholder=i.infoFail||"Failed to load search index!"}),!1),n.open("GET",i.indexUrl||"/index.json"),n.send(null)}));const s=i.textLength||300,c=i.limit||50,l=i.delay||500,a=n.firstElementChild.cloneNode(!0);function u(){if(o){n.innerHTML="";for(let e of o.search(t.value,{limit:c})){const t=a.cloneNode(!0),i=t.querySelector("a");i.href=e.item.uri,i.innerHTML=r(e,"title",s),t.querySelector(".search-preview").innerHTML=r(e,"content",s),n.appendChild(t)}}}n.innerHTML="";const d=/Mobi/i.test(navigator.userAgent);t.addEventListener(d?"change":"input",d?u:function(e,t){let n;return function(...i){clearTimeout(n),n=setTimeout((()=>e(...i)),t)}}(u,l))}(document);
|