fixed suggestion system

This commit is contained in:
Manan Jethwani 2021-04-09 12:11:29 +05:30 committed by Matthieu Gautier
parent 32cc6b0dcb
commit 5fdc51b23e
2 changed files with 83 additions and 80 deletions

View File

@ -3,83 +3,86 @@ function htmlDecode(input) {
return doc.documentElement.textContent; return doc.documentElement.textContent;
} }
(function ($) { const jq = jQuery.noConflict(true);
const root = $( `link[type='root']` ).attr("href"); jq(document).ready(() => {
const bookName = window.location.pathname.split(`${root}/`)[1].split('/')[0]; (function ($) {
const root = $( `link[type='root']` ).attr("href");
const bookName = window.location.pathname.split(`${root}/`)[1].split('/')[0];
$( "#kiwixsearchbox" ).autocomplete({ $( "#kiwixsearchbox" ).autocomplete({
source: `${root}/suggest?content=${bookName}`, source: `${root}/suggest?content=${bookName}`,
dataType: "json", dataType: "json",
cache: false, cache: false,
response: function( event, ui ) { response: function( event, ui ) {
for(const item of ui.content) { for(const item of ui.content) {
item.label = htmlDecode(item.label); item.label = htmlDecode(item.label);
item.value = htmlDecode(item.value); item.value = htmlDecode(item.value);
if (item.path) item.path = htmlDecode(item.path); if (item.path) item.path = htmlDecode(item.path);
} }
}, },
select: function(event, ui) { select: function(event, ui) {
if (ui.item.kind === 'path') { if (ui.item.kind === 'path') {
window.location.href = `${root}/${bookName}/${encodeURI(ui.item.path)}`; window.location.href = `${root}/${bookName}/${encodeURI(ui.item.path)}`;
} else { } else {
$( "#kiwixsearchbox" ).val(ui.item.value); $( "#kiwixsearchbox" ).val(ui.item.value);
$( "#kiwixsearchform" ).submit(); $( "#kiwixsearchform" ).submit();
} }
}, },
});
/* cybook hack */
if (navigator.userAgent.indexOf("bookeen/cybook") != -1) {
$("html").addClass("cybook");
}
if ($(window).width() < 520) {
var didScroll;
var lastScrollTop = 0;
var delta = 5;
// on scroll, let the interval function know the user has scrolled
$(window).scroll(function (event) {
didScroll = true;
}); });
// run hasScrolled() and reset didScroll status
setInterval(function () {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
function hasScrolled() {
var st = $(this).scrollTop();
// Make sure they scroll more than delta /* cybook hack */
if (Math.abs(lastScrollTop - st) <= delta) if (navigator.userAgent.indexOf("bookeen/cybook") != -1) {
return; $("html").addClass("cybook");
// If they scrolled down and are past the navbar, add class .nav-up.
// This is necessary so you never see what is "behind" the navbar.
if (st > lastScrollTop) {
// Scroll Down
$('#kiwixtoolbar').css({ top: '-100%' });
} else {
// Scroll Up
$('#kiwixtoolbar').css({ top: '0' });
}
lastScrollTop = st;
} }
}
$('#kiwixsearchbox').on({ if ($(window).width() < 520) {
focus: function () { var didScroll;
$('.kiwix_searchform').addClass('full_width'); var lastScrollTop = 0;
$('label[for="kiwix_button_show_toggle"], .kiwix_button_cont').addClass('searching'); var delta = 5;
}, // on scroll, let the interval function know the user has scrolled
blur: function () { $(window).scroll(function (event) {
$('.kiwix_searchform').removeClass('full_width'); didScroll = true;
$('label[for="kiwix_button_show_toggle"], .kiwix_button_cont').removeClass('searching'); });
// run hasScrolled() and reset didScroll status
setInterval(function () {
if (didScroll) {
hasScrolled();
didScroll = false;
}
}, 250);
function hasScrolled() {
var st = $(this).scrollTop();
// Make sure they scroll more than delta
if (Math.abs(lastScrollTop - st) <= delta)
return;
// If they scrolled down and are past the navbar, add class .nav-up.
// This is necessary so you never see what is "behind" the navbar.
if (st > lastScrollTop) {
// Scroll Down
$('#kiwixtoolbar').css({ top: '-100%' });
} else {
// Scroll Up
$('#kiwixtoolbar').css({ top: '0' });
}
lastScrollTop = st;
}
} }
});
})(jQuery); $('#kiwixsearchbox').on({
focus: function () {
$('.kiwix_searchform').addClass('full_width');
$('label[for="kiwix_button_show_toggle"], .kiwix_button_cont').addClass('searching');
},
blur: function () {
$('.kiwix_searchform').removeClass('full_width');
$('label[for="kiwix_button_show_toggle"], .kiwix_button_cont').removeClass('searching');
}
});
})(jq);
})

View File

@ -1,6 +1,6 @@
<link type="text/css" href="{{root}}/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" /> <link type="text/css" href="{{root}}/skin/jquery-ui/jquery-ui.min.css" rel="Stylesheet" />
<link type="text/css" href="{{root}}/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" /> <link type="text/css" href="{{root}}/skin/jquery-ui/jquery-ui.theme.min.css" rel="Stylesheet" />
<link type="text/css" href="{{root}}/skin/taskbar.css" rel="Stylesheet" /> <link type="text/css" href="{{root}}/skin/taskbar.css" rel="Stylesheet" />
<script type="text/javascript" src="{{root}}/skin/jquery-ui/external/jquery/jquery.js"></script> <script type="text/javascript" src="{{root}}/skin/jquery-ui/external/jquery/jquery.js" defer></script>
<script type="text/javascript" src="{{root}}/skin/jquery-ui/jquery-ui.min.js"></script> <script type="text/javascript" src="{{root}}/skin/jquery-ui/jquery-ui.min.js" defer></script>
<script type="text/javascript" src="{{root}}/skin/taskbar.js" async></script> <script type="text/javascript" src="{{root}}/skin/taskbar.js" defer></script>