Compare commits
No commits in common. "ad87bf327ee93cc1e84400862150eb2ace7bd40e" and "e808e2877c25189602bed978948c2a0d4c521554" have entirely different histories.
ad87bf327e
...
e808e2877c
4 changed files with 72 additions and 86 deletions
|
@ -98,34 +98,6 @@ $( 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')
|
||||||
|
@ -141,7 +113,10 @@ $( 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";
|
||||||
|
@ -164,26 +139,27 @@ $( 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();
|
||||||
filterEntryList(entries, value, $('#show-re').prop('checked'))
|
if (value.length > 0) {
|
||||||
// var value = $(this).val().toLowerCase();
|
$("#entrylist > ul > li:not([hidden])").filter(function () {
|
||||||
// if (value.length > 0) {
|
return $(this).toggle($(this).children('a').text().toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "").startsWith(value))
|
||||||
// $("#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 () {
|
||||||
$("#entrylist > ul").remove();
|
if($(this).prop('checked')) {
|
||||||
filterEntryList(entries, $("#filter-entries").val().toLowerCase(), $(this).prop('checked'));
|
console.log('haha')
|
||||||
scrollView();
|
$('li.abv-menu-re').removeAttr('hidden');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$('li.abv-menu-re').prop('hidden',true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -282,21 +282,25 @@ declare function abv-m:mark-element($doc as document-node(), $path as xs:string)
|
||||||
declare function abv-m:search($db-lang as xs:string,
|
declare function abv-m:search($db-lang as xs:string,
|
||||||
$type as xs:string,
|
$type as xs:string,
|
||||||
$query as xs:string) {
|
$query as xs:string) {
|
||||||
let $db-name := `abaevdict_{$db-lang}`
|
let $pexpr := string-join(
|
||||||
let $docs := collection(`{$db-name}/xml`)
|
('declare namespace tei = "http://www.tei-c.org/ns/1.0";',
|
||||||
let $hits := switch($type)
|
switch($type)
|
||||||
case "full" return $docs//text()[. contains text {$query}]
|
case "full" return "//text()"
|
||||||
case "form" return $docs/tei:entry[1]/tei:form[./tei:orth contains text {$query}]
|
case "form" return "/tei:entry[1]/tei:form/tei:orth"
|
||||||
case "sense" return $docs/tei:entry[1]//tei:sense[./tei:cit[@type='translationEquivalent'] contains text {$query}]
|
case "sense" return "/tei:entry[1]/tei:sense"
|
||||||
case "example" return $docs/tei:entry[1]//tei:cit[@type='example']/tei:quote[. contains text {$query}]
|
case "example" return "/tei:entry[1]//tei:cit[@type='example']/tei:quote"
|
||||||
case "translation" return $docs/tei:entry[1]//tei:cit[@type='translation' and . contains text {$query}]
|
case "translation" return "/tei:entry[1]//tei:cit[@type='translation']"
|
||||||
case "mentioned" return $docs/tei:entry[1]//tei:mentioned/(tei:m|tei:w|tei:phr|tei:s)[. contains text {$query}]
|
case "mentioned" return "/tei:entry[1]//tei:mentioned/(tei:m|tei:w|tei:phr|tei:s)"
|
||||||
case "gloss" return $docs/tei:entry[1]//tei:gloss[. contains text {$query}]
|
case "gloss" return "tei:entry[1]//tei:gloss"
|
||||||
case "etym" return $docs/tei:entry[1]/tei:etym[1][. contains text {$query}]
|
case "etym" return "tei:entry[1]/tei:etym[1]//text()"
|
||||||
default return $docs//text()[. contains text {$query}]
|
default return "//text()")
|
||||||
return array:build(for $hit in $hits
|
)
|
||||||
let $entry-id := db:get($db-name,db:path($hit))/tei:entry[1]/string(@xml:id)
|
return array{for $doc in collection(`abaevdict_{$db-lang}/xml`)
|
||||||
group by $entry-id
|
let $hits := for $node in xquery:eval($pexpr, {'': $doc})
|
||||||
order by abv-m:sortKey(abv-m:entry-form-by-id($entry-id))
|
where $node contains text {$query}
|
||||||
return {'entry': $entry-id, 'nodes': array:build(for $node in $hit return path($node))})
|
return path($node)
|
||||||
|
where count($hits) > 0
|
||||||
|
order by abv-m:sortKey($doc/tei:entry[1]/tei:form[1]/tei:orth[1])
|
||||||
|
return {'entry_id': string($doc/tei:entry[1]/@xml:id),
|
||||||
|
'path': array:build($hits)}}
|
||||||
};
|
};
|
|
@ -23,11 +23,9 @@ 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()) {
|
||||||
let $id := if (name($n) = 're') then string($n/@corresp) else string($n/@xml:id)
|
map{'id': string(hash($n/@xml:id)),
|
||||||
return map{'id': hash($id),
|
'xmlid': string($n/@xml:id),
|
||||||
'xmlid': $id,
|
'form': $n/text()
|
||||||
'form': $n/text(),
|
|
||||||
'subentry': if (name($n) = 're') then true() else false()
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -175,7 +173,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]/*,
|
$lookup/tei:table[1]/tei:entry,
|
||||||
api:entry-info-short#1
|
api:entry-info-short#1
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
@ -185,7 +183,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]/*[string(hash(@xml:id))=$entry-id],
|
$lookup/tei:table[1]/tei:entry[string(hash(@xml:id))=$entry-id],
|
||||||
$db-lang)
|
$db-lang)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -174,10 +174,6 @@ declare %rest:path("/favicon.ico")
|
||||||
(: ======================= SEARCH ENTRYPOINT ===================== :)
|
(: ======================= SEARCH ENTRYPOINT ===================== :)
|
||||||
(: =============================================================== :)
|
(: =============================================================== :)
|
||||||
|
|
||||||
declare function page:entry-for-node($lang as xs:string, $node as node()) {
|
|
||||||
db:get(`abaevdict_{$lang}`,db:path($node))/tei:entry[1]/string(@xml:id)
|
|
||||||
};
|
|
||||||
|
|
||||||
declare %rest:path("/search/{$path=.+}")
|
declare %rest:path("/search/{$path=.+}")
|
||||||
%rest:GET
|
%rest:GET
|
||||||
function page:search-default($path as xs:string) {
|
function page:search-default($path as xs:string) {
|
||||||
|
@ -195,11 +191,10 @@ declare %rest:path("{$lang}/search/new")
|
||||||
let $r2 := session:set('searchQuery', $searchQuery)
|
let $r2 := session:set('searchQuery', $searchQuery)
|
||||||
let $r3 := session:set('searchN', 1)
|
let $r3 := session:set('searchN', 1)
|
||||||
let $r4 := session:set('searchData', $sd)
|
let $r4 := session:set('searchData', $sd)
|
||||||
return
|
return if(array:size($sd) > 0) then
|
||||||
if(array:size($sd) > 0) then
|
|
||||||
page:by-id($lang,
|
page:by-id($lang,
|
||||||
$sd(1)('entry'),
|
$sd(1)('entry_id'),
|
||||||
string-join($sd(1)('nodes'),'|'))
|
string-join($sd(1)('path')?*,"|"))
|
||||||
else
|
else
|
||||||
web:redirect('../search/clear')
|
web:redirect('../search/clear')
|
||||||
};
|
};
|
||||||
|
@ -211,7 +206,7 @@ declare %rest:path("{$lang}/search/next")
|
||||||
let $n as xs:integer := session:get('searchN')+1
|
let $n as xs:integer := session:get('searchN')+1
|
||||||
let $r1 := session:set('searchN', $n)
|
let $r1 := session:set('searchN', $n)
|
||||||
let $sd := session:get('searchData')
|
let $sd := session:get('searchData')
|
||||||
return page:by-id($lang, $sd($n)('entry'), string-join($sd($n)('nodes'),'|'))
|
return page:by-id($lang, $sd($n)('entry_id'), string-join($sd($n)('path')?*,"|"))
|
||||||
};
|
};
|
||||||
|
|
||||||
declare %rest:path("{$lang}/search/prev")
|
declare %rest:path("{$lang}/search/prev")
|
||||||
|
@ -221,8 +216,7 @@ declare %rest:path("{$lang}/search/prev")
|
||||||
let $n as xs:integer := session:get('searchN')-1
|
let $n as xs:integer := session:get('searchN')-1
|
||||||
let $r1 := session:set('searchN', $n)
|
let $r1 := session:set('searchN', $n)
|
||||||
let $sd := session:get('searchData')
|
let $sd := session:get('searchData')
|
||||||
let $node := db:get-id(`abaevdict_{$lang}`,$sd[$n])
|
return page:by-id($lang, $sd($n)('entry_id'), string-join($sd($n)('path')?*,"|"))
|
||||||
return page:by-id($lang, $sd($n)('entry'), string-join($sd($n)('nodes'),'|'))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
declare %rest:path("{$lang}/search/position")
|
declare %rest:path("{$lang}/search/position")
|
||||||
|
@ -232,8 +226,7 @@ declare %rest:path("{$lang}/search/position")
|
||||||
function page:search-position($lang, $p as xs:integer) {
|
function page:search-position($lang, $p as xs:integer) {
|
||||||
let $r1 := session:set('searchN', $p)
|
let $r1 := session:set('searchN', $p)
|
||||||
let $sd := session:get('searchData')
|
let $sd := session:get('searchData')
|
||||||
let $node := db:get-id(`abaevdict_{$lang}`,$sd[$p])
|
return page:by-id($lang, $sd($p)('entry_id'), string-join($sd($p)('path')?*,"|"))
|
||||||
return page:by-id($lang, $sd($p)('entry'), string-join($sd($p)('nodes'),'|'))
|
|
||||||
};
|
};
|
||||||
|
|
||||||
declare %rest:path("{$lang}/search/clear")
|
declare %rest:path("{$lang}/search/clear")
|
||||||
|
@ -510,7 +503,23 @@ 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> <!-- To be filled dynamically in js -->
|
<nav id="entrylist">
|
||||||
|
<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
|
||||||
|
@ -591,14 +600,13 @@ declare %rest:path("{$lang}/dict")
|
||||||
<td>
|
<td>
|
||||||
<a href="./search/position?p={$pos}">
|
<a href="./search/position?p={$pos}">
|
||||||
{
|
{
|
||||||
abv-m:entry-form-by-id($res('entry'))
|
abv-m:entry-form-by-id($res('entry_id'))
|
||||||
}
|
}
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{
|
{
|
||||||
xquery:eval($res('nodes')(1),
|
xquery:eval($res('path')(1), {'': doc(`abaevdict_{$lang}/xml/{$res('entry_id')}.xml`)})
|
||||||
{'': doc(`abaevdict_{$lang}/xml/{$res('entry')}.xml`)})
|
|
||||||
}
|
}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue