Adopt new article search logic from Kiwix JS

Former-commit-id: a076b7a332fc7c6b2d23ed769c4c97f71db28aaa [formerly b5bc463fbcd69ed1ef07dadc36efa596e5f53db8]
Former-commit-id: 3a77460f4e1f88f749fc3f9146baa621b9bdaedd
This commit is contained in:
Jaifroid 2019-05-18 11:25:53 +01:00
parent cb15c17438
commit 80f7bc9c65

View File

@ -51,8 +51,6 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
function resizeIFrame() { function resizeIFrame() {
var height = $(window).outerHeight() var height = $(window).outerHeight()
//- $("#top").outerHeight(true) //- $("#top").outerHeight(true)
-
$("#articleListWithHeader").outerHeight(true)
// TODO : this 5 should be dynamically computed, and not hard-coded // TODO : this 5 should be dynamically computed, and not hard-coded
//- 5; //- 5;
+ +
@ -132,17 +130,26 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
} }
} }
if (e.which == 27) { if (e.which == 27) {
//Esc, so hide the list behind article //User pressed Esc, so hide the article list
document.getElementById('articleContent').style.position = "fixed"; $('#articleListWithHeader').hide();
document.getElementById('articleContent').style.position = 'fixed';
$('#articleContent').focus();
$("#myModal").modal('hide'); // This is in case the modal box is showing with an index search $("#myModal").modal('hide'); // This is in case the modal box is showing with an index search
return; return;
} }
onKeyUpPrefix(e); onKeyUpPrefix(e);
} }
}); });
// This is touch equivalent of Esc above $('#prefix').on('focus', function(e) {
document.getElementById('prefix').addEventListener('blur', function (e) { if ($('#prefix').val() !== '') {
document.getElementById('articleContent').style.position = "fixed"; $('#articleListWithHeader').show();
document.getElementById('articleContent').style.position = 'static';
}
});
$('#prefix').on('blur', function() {
$('#articleListWithHeader').hide();
document.getElementById('articleContent').style.position = 'fixed';
}); });
//Add keyboard shortcuts //Add keyboard shortcuts
@ -1989,13 +1996,10 @@ define(['jquery', 'zimArchiveLoader', 'util', 'uiUtil', 'cookies', 'q', 'module'
'" class="list-group-item">' + dirEntry.getTitleOrUrl() + '</a>'; '" class="list-group-item">' + dirEntry.getTitleOrUrl() + '</a>';
} }
articleListDiv.html(articleListDivHtml); articleListDiv.html(articleListDivHtml);
// @TODO - why doesn't this work?
//Array.prototype.slice.call(document.querySelectorAll('articleList a')).forEach(function (el) {
// el.addEventListener('click', function () { handleTitleClick(); });
//});
// Needed so that results show on top of article // Needed so that results show on top of article
document.getElementById('articleContent').style.position = 'static'; document.getElementById('articleContent').style.position = 'static';
// We have to use mousedown instead of click as otherwise the blur event fires first and prevents this event from firing // We have to use mousedown below instead of click as otherwise the prefix blur event fires first
// and prevents this event from firing; note that touch also triggers mousedown
$('#articleList a').on('mousedown', function (e) { $('#articleList a').on('mousedown', function (e) {
handleTitleClick(e); handleTitleClick(e);
return false; return false;