@xiee/utils
Advanced tools
Comparing version 1.3.19 to 1.3.20
@@ -73,8 +73,7 @@ // perform searching via Fuse.js with data from /index.json | ||
if (!fuse) return; | ||
let res, sec, u; | ||
output.innerHTML = ''; | ||
// display search results in <section> and highlight keywords | ||
for (res of fuse.search(input.value, {'limit': lim})) { | ||
sec = tpl.cloneNode(true); | ||
a = sec.querySelector('a'); | ||
for (let res of fuse.search(input.value, {'limit': lim})) { | ||
const sec = tpl.cloneNode(true); | ||
const a = sec.querySelector('a'); | ||
a.href = res.item.uri; | ||
@@ -81,0 +80,0 @@ a.innerHTML = highlight(res, 'title', len); |
@@ -1,1 +0,1 @@ | ||
!function(e){const t=e.querySelector("#search-input"),n=e.querySelector(".search-results");if(!t||!n)return;const i=t.dataset;let r;function o(e,t,n){let i;for(let n of e.matches)n.key===t&&(i=n.indices);const r=e.item[t];if(!i)return r.substr(0,n);let o,s,l=0,c=Math.ceil(n/2);for(;s=i.shift();)s[1]-s[0]>=l&&(o=s,l=o[1]-o[0]);return(o[0]-c>0?"[...] ":"")+r.substring(o[0]-c,o[0])+"<b>"+r.substring(o[0],o[1]+1)+"</b>"+r.substring(o[1]+1,o[1]+1+c)+(o[1]+1+c<r.length?" [...] ":"")}t.addEventListener("focus",(e=>{if(r)return;t.placeholder=i.infoInit||"Loading search index... Please hold on.";const n=new XMLHttpRequest;n.responseType="json",n.addEventListener("load",(e=>{const o=n.response;o&&0!==o.length?(t.placeholder=i.infoOk||"Type to search:",t.focus(),r=new Fuse(o,{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,l=i.limit||50,c=i.delay||500,u=n.firstElementChild.cloneNode(!0);function d(){if(!r)return;let e,i;for(e of(n.innerHTML="",r.search(t.value,{limit:l})))i=u.cloneNode(!0),a=i.querySelector("a"),a.href=e.item.uri,a.innerHTML=o(e,"title",s),i.querySelector(".search-preview").innerHTML=o(e,"content",s),n.appendChild(i)}n.innerHTML="";const h=/Mobi/i.test(navigator.userAgent);t.addEventListener(h?"change":"input",h?d:function(e,t){let n;return function(...i){clearTimeout(n),n=setTimeout((()=>e(...i)),t)}}(d,c))}(document); | ||
!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); |
{ | ||
"name": "@xiee/utils", | ||
"version": "1.3.19", | ||
"version": "1.3.20", | ||
"description": "Miscellaneous tools and utilities to manipulate HTML pages", | ||
@@ -5,0 +5,0 @@ "scripts": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58142
903