diff --git a/static/skin/index.js b/static/skin/index.js index 42947919a..67745d911 100644 --- a/static/skin/index.js +++ b/static/skin/index.js @@ -1,14 +1,10 @@ -const viewPortHeight = window.innerHeight; const root = $( `link[type='root']` ).attr("href"); -const count = Math.floor(viewPortHeight/100 + 1) * 3; +let viewPortHeight = window.innerHeight; +let count = Math.floor(viewPortHeight/100 + 1) * 3; let isFetching = false; let isEnd = false; let prevStart = 0; -function htmlEncode(str) { - return str.replace(/[\u00A0-\u9999<>\&]/gim, (i) => `&#${i.charCodeAt(0)};`); -} - async function loadAndDisplay(query, append = false) { isFetching = true; await fetch(`${root}/catalog/search${query}`) @@ -23,9 +19,9 @@ async function loadAndDisplay(query, append = false) { bookHtml += `
-
${htmlEncode(title)}
-
${htmlEncode(description)}
-
${htmlEncode(getInnerHtml(book, 'articleCount'))} articles, ${htmlEncode(getInnerHtml(book, 'mediaCount'))} medias
+
${title}
+
${description}
+
${getInnerHtml(book, 'articleCount')} articles, ${getInnerHtml(book, 'mediaCount')} medias
`; }); @@ -39,6 +35,15 @@ function getInnerHtml(node, query) { return node.querySelector(query).innerHTML; } +window.addEventListener('resize', async () => { + if (isFetching || isEnd) return; + viewPortHeight = window.innerHeight; + count = Math.floor(viewPortHeight/100 + 1) * 3; + start = prevStart + count; + loadAndDisplay(`?start=${start}&count=${count}`, true); + prevStart = start; +}) + window.addEventListener('scroll', async () => { if (isFetching || isEnd) return; if (viewPortHeight + window.scrollY >= document.body.offsetHeight) {