From 5fdc51b23e72458d56e62186f476989ece8dddb7 Mon Sep 17 00:00:00 2001 From: Manan Jethwani Date: Fri, 9 Apr 2021 12:11:29 +0530 Subject: [PATCH] fixed suggestion system --- static/skin/taskbar.js | 157 +++++++++++++++-------------- static/templates/head_taskbar.html | 6 +- 2 files changed, 83 insertions(+), 80 deletions(-) diff --git a/static/skin/taskbar.js b/static/skin/taskbar.js index 358e1c9e6..448b6faf8 100644 --- a/static/skin/taskbar.js +++ b/static/skin/taskbar.js @@ -3,83 +3,86 @@ function htmlDecode(input) { return doc.documentElement.textContent; } -(function ($) { - const root = $( `link[type='root']` ).attr("href"); - const bookName = window.location.pathname.split(`${root}/`)[1].split('/')[0]; - - $( "#kiwixsearchbox" ).autocomplete({ - - source: `${root}/suggest?content=${bookName}`, - dataType: "json", - cache: false, - - response: function( event, ui ) { - for(const item of ui.content) { - item.label = htmlDecode(item.label); - item.value = htmlDecode(item.value); - if (item.path) item.path = htmlDecode(item.path); - } - }, - - select: function(event, ui) { - if (ui.item.kind === 'path') { - window.location.href = `${root}/${bookName}/${encodeURI(ui.item.path)}`; - } else { - $( "#kiwixsearchbox" ).val(ui.item.value); - $( "#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; +const jq = jQuery.noConflict(true); +jq(document).ready(() => { + (function ($) { + const root = $( `link[type='root']` ).attr("href"); + const bookName = window.location.pathname.split(`${root}/`)[1].split('/')[0]; + + $( "#kiwixsearchbox" ).autocomplete({ + + source: `${root}/suggest?content=${bookName}`, + dataType: "json", + cache: false, + + response: function( event, ui ) { + for(const item of ui.content) { + item.label = htmlDecode(item.label); + item.value = htmlDecode(item.value); + if (item.path) item.path = htmlDecode(item.path); + } + }, + + select: function(event, ui) { + if (ui.item.kind === 'path') { + window.location.href = `${root}/${bookName}/${encodeURI(ui.item.path)}`; + } else { + $( "#kiwixsearchbox" ).val(ui.item.value); + $( "#kiwixsearchform" ).submit(); + } + }, }); - // 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; + + /* cybook hack */ + if (navigator.userAgent.indexOf("bookeen/cybook") != -1) { + $("html").addClass("cybook"); } - } - - $('#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'); + + 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 + 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); \ No newline at end of file + + $('#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); +}) \ No newline at end of file diff --git a/static/templates/head_taskbar.html b/static/templates/head_taskbar.html index ac56d4117..1ed843638 100644 --- a/static/templates/head_taskbar.html +++ b/static/templates/head_taskbar.html @@ -1,6 +1,6 @@ - - - + + +