mirror of https://github.com/kiwix/libkiwix.git
added dynamic loading of data using OPDS
This commit is contained in:
parent
b82fff9855
commit
1dbed28499
|
@ -19,6 +19,7 @@ skin/jquery-ui/jquery-ui.theme.min.css
|
|||
skin/jquery-ui/jquery-ui.min.css
|
||||
skin/caret.png
|
||||
skin/taskbar.js
|
||||
skin/index.js
|
||||
skin/taskbar.css
|
||||
skin/block_external.js
|
||||
templates/search_result.html
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
window.onload = async (event) => {
|
||||
const root = $( `link[type='root']` ).attr("href");
|
||||
await fetch(`${root}/catalog/search`)
|
||||
.then(async (resp) => {
|
||||
const data = new window.DOMParser().parseFromString(await resp.text(), 'application/xml');
|
||||
const entries = data.querySelectorAll("entry");
|
||||
displayBooks(entries);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
function getInnerHtml(node, query) {
|
||||
return node.querySelector(query).innerHTML;
|
||||
}
|
||||
|
||||
function displayBooks(books) {
|
||||
let bookHtml = '';
|
||||
books.forEach((book) => {
|
||||
const link = book.querySelector('link').getAttribute('href');
|
||||
const title = getInnerHtml(book, 'title');
|
||||
const description = getInnerHtml(book, 'summary');
|
||||
|
||||
bookHtml += `<a href='${link}'><div class='book'>
|
||||
<div class='book__background' style="background-image: url('${getInnerHtml(book, 'icon')}');">
|
||||
<div class='book__title' title='${title}'>${title}</div>
|
||||
<div class='book__description' title='${description}'>${description}</div>
|
||||
<div class='book__info'>${getInnerHtml(book, 'articleCount')} articles, ${getInnerHtml(book, 'mediaCount')} medias</div>
|
||||
</div>
|
||||
</div></a>`;
|
||||
});
|
||||
document.querySelector('.book__list').innerHTML = bookHtml;
|
||||
}
|
|
@ -40,22 +40,12 @@
|
|||
}
|
||||
.book__info { color: #777; font-weight: bold; font-size: 13px; line-height: 1em; }
|
||||
</style>
|
||||
<script type="text/javascript" src="{{root}}/skin/taskbar.js" async></script>
|
||||
<script type="text/javascript" src="{{root}}/skin/index.js" defer></script>
|
||||
</head>
|
||||
<body class="kiwix">
|
||||
|
||||
<div class="kiwix">
|
||||
<div class='book__list'>
|
||||
{{#books}}
|
||||
<a href="{{root}}/{{name}}"><div class='book'>
|
||||
<div class='book__background' style="background-image: url('{{root}}/meta?content={{#urlencoded}}{{{name}}}{{/urlencoded}}&name=favicon');">
|
||||
<div class='book__title' title='{{title}}'>{{title}}</div>
|
||||
<div class='book__description' title='{{description}}'>{{description}}</div>
|
||||
<div class='book__info'>{{articleCount}} articles, {{mediaCount}} medias</div>
|
||||
</div>
|
||||
</div></a>
|
||||
{{/books}}
|
||||
</div>
|
||||
<div class='book__list'></div>
|
||||
</div>
|
||||
|
||||
<div id="kiwixfooter">
|
||||
|
|
Loading…
Reference in New Issue