forked from abaevdict/abaev-basex
fixed quick filter
This commit is contained in:
parent
e808e2877c
commit
7b35bf2e83
3 changed files with 52 additions and 42 deletions
|
@ -98,6 +98,34 @@ $( document ).ready(function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
// ENTRY LIST SIDE PANEL
|
// ENTRY LIST SIDE PANEL
|
||||||
|
|
||||||
|
// Function to produce HTML for the entry list
|
||||||
|
function filterEntryList(list, filter, showSubentries) {
|
||||||
|
let listHtml = "";
|
||||||
|
for (entry of list) {
|
||||||
|
let entryID = entry.xmlid;
|
||||||
|
let entryForm = entry.form;
|
||||||
|
if (entryForm.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").startsWith(filter)
|
||||||
|
&& (!entry.subentry || showSubentries)
|
||||||
|
) {
|
||||||
|
listHtml += `<li id="link_${entryID}"${entry.subentry ? ' class="abv-menu-re"' : ''}"><a href="./dict/${entryID}">${entryForm}</a></li>`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
listHtml = $(`<ul>${listHtml}</ul>`);
|
||||||
|
$("#entrylist").append(listHtml);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch entries from the server when page loads
|
||||||
|
var entries = [];
|
||||||
|
|
||||||
|
fetch('./api/entries')
|
||||||
|
.then(res => res.json())
|
||||||
|
.then(out => {
|
||||||
|
entries = out;
|
||||||
|
filterEntryList(entries, '', false);
|
||||||
|
})
|
||||||
|
.then(err => console.log(err));
|
||||||
|
|
||||||
// Function to scroll the entry list to the selected entry OR to the first entry displayed on the current page if there is no hash in the URL
|
// Function to scroll the entry list to the selected entry OR to the first entry displayed on the current page if there is no hash in the URL
|
||||||
function scrollView() {
|
function scrollView() {
|
||||||
var $container = $('#entrylist')
|
var $container = $('#entrylist')
|
||||||
|
@ -113,10 +141,7 @@ $( document ).ready(function() {
|
||||||
|
|
||||||
// Click to open the offcanvas entry list
|
// Click to open the offcanvas entry list
|
||||||
$( '#open-leftbar' ).on('click', function() {
|
$( '#open-leftbar' ).on('click', function() {
|
||||||
// $("#leftbar")[0].style.width = "250px";
|
|
||||||
$("#leftbar").show();
|
$("#leftbar").show();
|
||||||
// $("#leftbar")[0].style.paddingLeft = "10px";
|
|
||||||
|
|
||||||
$("main")[0].style.marginLeft = "250px";
|
$("main")[0].style.marginLeft = "250px";
|
||||||
$("header nav")[0].style.marginLeft = "250px";
|
$("header nav")[0].style.marginLeft = "250px";
|
||||||
$("footer nav")[0].style.marginLeft = "250px";
|
$("footer nav")[0].style.marginLeft = "250px";
|
||||||
|
@ -139,27 +164,26 @@ $( document ).ready(function() {
|
||||||
|
|
||||||
// Quick filter functionality
|
// Quick filter functionality
|
||||||
$('#filter-entries').on("keyup", function () {
|
$('#filter-entries').on("keyup", function () {
|
||||||
|
$("#entrylist > ul").remove();
|
||||||
var value = $(this).val().toLowerCase();
|
var value = $(this).val().toLowerCase();
|
||||||
if (value.length > 0) {
|
filterEntryList(entries, value, $('#show-re').prop('checked'))
|
||||||
$("#entrylist > ul > li:not([hidden])").filter(function () {
|
// var value = $(this).val().toLowerCase();
|
||||||
return $(this).toggle($(this).children('a').text().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").startsWith(value))
|
// if (value.length > 0) {
|
||||||
});
|
// $("#entrylist > ul > li:not([hidden])").filter(function () {
|
||||||
}
|
// return $(this).toggle($(this).children('a').text().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").startsWith(value))
|
||||||
else {
|
// });
|
||||||
$("#entrylist > ul > li").show();
|
// }
|
||||||
}
|
// else {
|
||||||
|
// $("#entrylist > ul > li").show();
|
||||||
return false;
|
// }
|
||||||
|
//
|
||||||
|
// return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Event handler to show subentries
|
// Event handler to show subentries
|
||||||
$('#show-re').on("change", function () {
|
$('#show-re').on("change", function () {
|
||||||
if($(this).prop('checked')) {
|
$("#entrylist > ul").remove();
|
||||||
console.log('haha')
|
filterEntryList(entries, $("#filter-entries").val().toLowerCase(), $(this).prop('checked'));
|
||||||
$('li.abv-menu-re').removeAttr('hidden');
|
scrollView();
|
||||||
}
|
|
||||||
else {
|
|
||||||
$('li.abv-menu-re').prop('hidden',true);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,9 +23,11 @@ declare function api:ment-index($db-lang as xs:string) {
|
||||||
some Unicode characters very well in this system :)
|
some Unicode characters very well in this system :)
|
||||||
declare function api:entry-info-short($n as node())
|
declare function api:entry-info-short($n as node())
|
||||||
as map(xs:string, item()) {
|
as map(xs:string, item()) {
|
||||||
map{'id': string(hash($n/@xml:id)),
|
let $id := if (name($n) = 're') then string($n/@corresp) else string($n/@xml:id)
|
||||||
'xmlid': string($n/@xml:id),
|
return map{'id': hash($id),
|
||||||
'form': $n/text()
|
'xmlid': $id,
|
||||||
|
'form': $n/text(),
|
||||||
|
'subentry': if (name($n) = 're') then true() else false()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -173,7 +175,7 @@ declare %rest:path("{$db-lang}/api/entries")
|
||||||
%rest:GET
|
%rest:GET
|
||||||
function api:entries($db-lang as xs:string) {
|
function api:entries($db-lang as xs:string) {
|
||||||
array:build(
|
array:build(
|
||||||
$lookup/tei:table[1]/tei:entry,
|
$lookup/tei:table[1]/*,
|
||||||
api:entry-info-short#1
|
api:entry-info-short#1
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
@ -183,7 +185,7 @@ declare %rest:path("{$db-lang}/api/entries/{$entry-id}")
|
||||||
function api:entries($db-lang as xs:string,
|
function api:entries($db-lang as xs:string,
|
||||||
$entry-id as xs:string) {
|
$entry-id as xs:string) {
|
||||||
api:entry-info-long(
|
api:entry-info-long(
|
||||||
$lookup/tei:table[1]/tei:entry[string(hash(@xml:id))=$entry-id],
|
$lookup/tei:table[1]/*[string(hash(@xml:id))=$entry-id],
|
||||||
$db-lang)
|
$db-lang)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -503,23 +503,7 @@ declare %rest:path("{$lang}/dict")
|
||||||
{if ($lang = 'ru') then 'Производные' else 'Show subentries'}
|
{if ($lang = 'ru') then 'Производные' else 'Show subentries'}
|
||||||
</label>
|
</label>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<nav id="entrylist">
|
<nav id="entrylist"></nav> <!-- To be filled dynamically in js -->
|
||||||
<ul>
|
|
||||||
{for $doc in $page:lookup-all
|
|
||||||
let $id := if ($doc/name() = 'entry') then $doc/@xml:id
|
|
||||||
else $doc/@corresp
|
|
||||||
return element li {
|
|
||||||
if ($doc/name() = 're') then
|
|
||||||
(attribute hidden {'true'},
|
|
||||||
attribute class {'abv-menu-re'}) else (),
|
|
||||||
attribute id {`link_{$id}`},
|
|
||||||
<a href="./dict/{$id}">
|
|
||||||
{$doc/text()}
|
|
||||||
</a>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<!-- The dictionary itself. The entries are displayed as articles retrieved
|
<!-- The dictionary itself. The entries are displayed as articles retrieved
|
||||||
|
|
Loading…
Add table
Reference in a new issue