diff --git a/src/server/response.cpp b/src/server/response.cpp index 4b53914c2..d1ceda998 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -337,34 +337,6 @@ void print_response_info(int retCode, MHD_Response* response) } -void ContentResponse::introduce_taskbar(const std::string& lang) -{ - i18n::GetTranslatedString t(lang); - kainjow::mustache::object data{ - {"root", m_root}, - {"content", m_bookName}, - {"hascontent", (!m_bookName.empty() && !m_bookTitle.empty())}, - {"title", m_bookTitle}, - {"withlibrarybutton", m_withLibraryButton}, - {"LIBRARY_BUTTON_TEXT", t("library-button-text")}, - {"HOME_BUTTON_TEXT", t("home-button-text", {{"BOOK_TITLE", m_bookTitle}}) }, - {"RANDOM_PAGE_BUTTON_TEXT", t("random-page-button-text") }, - {"SEARCHBOX_TOOLTIP", t("searchbox-tooltip", {{"BOOK_TITLE", m_bookTitle}}) }, - }; - auto head_content = render_template(RESOURCE::templates::head_taskbar_html, data); - m_content = prependToFirstOccurence( - m_content, - "", - head_content); - - auto taskbar_part = render_template(RESOURCE::templates::taskbar_part_html, data); - m_content = appendToFirstOccurence( - m_content, - "]*>", - taskbar_part); -} - - void ContentResponse::inject_externallinks_blocker() { kainjow::mustache::data data; @@ -414,9 +386,6 @@ ContentResponse::create_mhd_response(const RequestContext& request) if (contentDecorationAllowed()) { inject_root_link(); - if (m_withTaskbar) { - introduce_taskbar(request.get_user_language()); - } if (m_blockExternalLinks) { inject_externallinks_blocker(); } @@ -468,14 +437,12 @@ void ContentResponse::set_taskbar(const std::string& bookName, const zim::Archiv } -ContentResponse::ContentResponse(const std::string& root, bool verbose, bool raw, bool withTaskbar, bool withLibraryButton, bool blockExternalLinks, const std::string& content, const std::string& mimetype) : +ContentResponse::ContentResponse(const std::string& root, bool verbose, bool raw, bool /*withTaskbar*/, bool /*withLibraryButton*/, bool blockExternalLinks, const std::string& content, const std::string& mimetype) : Response(verbose), m_root(root), m_content(content), m_mimeType(mimetype), m_raw(raw), - m_withTaskbar(withTaskbar), - m_withLibraryButton(withLibraryButton), m_blockExternalLinks(blockExternalLinks), m_bookName(""), m_bookTitle("") @@ -494,8 +461,8 @@ std::unique_ptr ContentResponse::build( server.m_root, server.m_verbose.load(), raw, - server.m_withTaskbar && !isHomePage, - server.m_withLibraryButton, + /*server.m_withTaskbar && !isHomePage*/ false, // XXX + /*server.m_withLibraryButton*/ false, // XXX server.m_blockExternalLinks, content, mimetype)); diff --git a/src/server/response.h b/src/server/response.h index 85dc8cb8f..9c66f7baf 100644 --- a/src/server/response.h +++ b/src/server/response.h @@ -107,7 +107,6 @@ class ContentResponse : public Response { private: MHD_Response* create_mhd_response(const RequestContext& request); - void introduce_taskbar(const std::string& lang); void inject_externallinks_blocker(); void inject_root_link(); bool can_compress(const RequestContext& request) const; @@ -119,8 +118,6 @@ class ContentResponse : public Response { std::string m_content; std::string m_mimeType; bool m_raw; - bool m_withTaskbar; - bool m_withLibraryButton; bool m_blockExternalLinks; std::string m_bookName; std::string m_bookTitle; diff --git a/static/resources_list.txt b/static/resources_list.txt index 179cd97e3..6696343f8 100644 --- a/static/resources_list.txt +++ b/static/resources_list.txt @@ -4,7 +4,6 @@ skin/magnet.png skin/download.png skin/hash.png skin/search-icon.svg -skin/taskbar.js skin/iso6391To3.js skin/isotope.pkgd.min.js skin/index.js @@ -24,8 +23,6 @@ templates/error.html templates/error.xml templates/index.html templates/suggestion.json -templates/head_taskbar.html -templates/taskbar_part.html templates/external_blocker_part.html templates/captured_external.html templates/catalog_entries.xml diff --git a/static/skin/taskbar.js b/static/skin/taskbar.js deleted file mode 100644 index bedc93281..000000000 --- a/static/skin/taskbar.js +++ /dev/null @@ -1,122 +0,0 @@ -function htmlDecode(input) { - var doc = new DOMParser().parseFromString(input, "text/html"); - return doc.documentElement.textContent; -} - -function setupAutoHidingOfTheToolbar() { - let lastScrollTop = 0; - const delta = 5; - let didScroll = false; - const kiwixToolBar = document.querySelector('#kiwixtoolbar'); - - window.addEventListener('scroll', () => { - didScroll = true; - }); - - setInterval(function() { - if (didScroll) { - hasScrolled(); - didScroll = false; - } - }, 250); - - function hasScrolled() { - const st = document.documentElement.scrollTop || document.body.scrollTop; - if (Math.abs(lastScrollTop - st) <= delta) - return; - - if (st > lastScrollTop) { - kiwixToolBar.style.top = '-100%'; - } else { - kiwixToolBar.style.top = '0'; - } - - lastScrollTop = st; - } - -} - -document.addEventListener('DOMContentLoaded', function () { - const root = document.querySelector(`link[type='root']`).getAttribute("href"); - const bookName = (window.location.pathname == `${root}/search`) - ? (new URLSearchParams(window.location.search)).get('content') - : window.location.pathname.split(`${root}/`)[1].split('/')[0]; - - const autoCompleteJS = new autoComplete( - { - selector: "#kiwixsearchbox", - placeHolder: document.querySelector("#kiwixsearchbox").title, - threshold: 1, - debounce: 300, - data : { - src: async (query) => { - try { - // Fetch Data from external Source - const source = await fetch(`${root}/suggest?content=${encodeURIComponent(bookName)}&term=${encodeURIComponent(query)}`); - const data = await source.json(); - return data; - } catch (error) { - return error; - } - }, - keys: ['label'], - }, - submit: true, - searchEngine: (query, record) => { - // We accept all records - return true; - }, - resultsList: { - noResults: true, - /* We must display 10 results (requested) + 1 potential link to do a full text search. */ - maxResults: 11, - }, - resultItem: { - element: (item, data) => { - let searchLink; - if (data.value.kind == "path") { - searchLink = `${root}/${bookName}/${htmlDecode(data.value.path)}`; - } else { - searchLink = `${root}/search?content=${encodeURIComponent(bookName)}&pattern=${encodeURIComponent(htmlDecode(data.value.value))}`; - } - item.innerHTML = `${htmlDecode(data.value.label)}`; - }, - highlight: "autoComplete_highlight", - selected: "autoComplete_selected" - } - } - ); - - document.querySelector('#kiwixsearchform').addEventListener('submit', function(event) { - try { - const selectedElemLink = document.querySelector('.autoComplete_selected > a').href; - if (selectedElemLink) { - event.preventDefault(); - window.location = selectedElemLink; - } - } catch (err) {} - }); - - const kiwixSearchBox = document.querySelector('#kiwixsearchbox'); - const kiwixSearchForm = document.querySelector('.kiwix_searchform'); - kiwixSearchBox.addEventListener('focus', () => { - kiwixSearchForm.classList.add('full_width'); - document.querySelector('label[for="kiwix_button_show_toggle"]').classList.add('searching'); - document.querySelector('.kiwix_button_cont').classList.add('searching'); - }); - kiwixSearchBox.addEventListener('blur', () => { - kiwixSearchForm.classList.remove('full_width'); - document.querySelector('label[for="kiwix_button_show_toggle"]').classList.remove('searching'); - document.querySelector('.kiwix_button_cont').classList.remove('searching'); - }); - - // cybook hack - if (navigator.userAgent.indexOf("bookeen/cybook") != -1) { - document.querySelector('html').classList.add('cybook'); - } - - if (document.body.clientWidth < 520) { - setupAutoHidingOfTheToolbar(); - } - -}); diff --git a/static/templates/head_taskbar.html b/static/templates/head_taskbar.html deleted file mode 100644 index 52384b547..000000000 --- a/static/templates/head_taskbar.html +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/static/templates/taskbar_part.html b/static/templates/taskbar_part.html deleted file mode 100644 index fab98abe3..000000000 --- a/static/templates/taskbar_part.html +++ /dev/null @@ -1,25 +0,0 @@ - - -
-
-
- {{#hascontent}}{{/hascontent}} - - -
-
- - -
- {{#withlibrarybutton}} - - {{/withlibrarybutton}} - {{#hascontent}} - - - {{/hascontent}} -
-
-
-
diff --git a/test/server.cpp b/test/server.cpp index 93bd9f4b5..234890d2a 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -43,7 +43,6 @@ typedef std::vector ResourceCollection; const ResourceCollection resources200Compressible{ { WITH_ETAG, "/ROOT/" }, - { WITH_ETAG, "/ROOT/skin/taskbar.js" }, { WITH_ETAG, "/ROOT/skin/autoComplete.min.js" }, { WITH_ETAG, "/ROOT/skin/css/autoComplete.css" }, { WITH_ETAG, "/ROOT/skin/taskbar.css" }, @@ -55,8 +54,6 @@ const ResourceCollection resources200Compressible{ { NO_ETAG, "/ROOT/suggest?content=zimfile&term=ray" }, - { NO_ETAG, "/ROOT/catch/external?source=www.example.com" }, - { WITH_ETAG, "/ROOT/content/zimfile/A/index" }, { WITH_ETAG, "/ROOT/content/zimfile/A/Ray_Charles" }, @@ -79,6 +76,8 @@ const ResourceCollection resources200Uncompressible{ { NO_ETAG, "/ROOT/catalog/v2/illustration/6f1d19d0-633f-087b-fb55-7ac324ff9baf?size=48" }, + { NO_ETAG, "/ROOT/catch/external?source=www.example.com" }, + { WITH_ETAG, "/ROOT/content/zimfile/I/m/Ray_Charles_classic_piano_pose.jpg" }, { WITH_ETAG, "/ROOT/content/corner_cases/A/empty.html" }, @@ -210,23 +209,13 @@ R"EXPECTEDRESULT( - - - - -)EXPECTEDRESULT" + "" }, { // Searching in a ZIM file without a full-text index returns // a page rendered from static/templates/no_search_result_html /* url */ "/ROOT/search?content=poor&pattern=whatever", R"EXPECTEDRESULT( - - - - - )EXPECTEDRESULT" }, }; @@ -442,13 +431,8 @@ public: std::string expectedResponse() const; private: - bool isTranslatedVersion() const; virtual std::string pageTitle() const; std::string pageCssLink() const; - std::string hiddenBookNameInput() const; - std::string searchPatternInput() const; - std::string taskbarLinks() const; - std::string goToWelcomePageText() const; }; std::string TestContentIn404HtmlResponse::expectedResponse() const @@ -464,40 +448,8 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const )FRAG", R"FRAG( - - - - - - - -
-
-
- )FRAG", - - R"FRAG( - -)FRAG", - - R"FRAG(
-
- - -
- - )FRAG", - - R"FRAG( -
-
-
-
-)FRAG", + + )FRAG", R"FRAG( @@ -509,18 +461,8 @@ std::string TestContentIn404HtmlResponse::expectedResponse() const + frag[1] + pageCssLink() + frag[2] - + hiddenBookNameInput() - + frag[3] - + searchPatternInput() - + frag[4] - + goToWelcomePageText() - + frag[5] - + goToWelcomePageText() - + frag[6] - + taskbarLinks() - + frag[7] + expectedBody - + frag[8]; + + frag[3]; } std::string TestContentIn404HtmlResponse::pageTitle() const @@ -540,71 +482,6 @@ std::string TestContentIn404HtmlResponse::pageCssLink() const + R"(" rel="Stylesheet" />)"; } -std::string TestContentIn404HtmlResponse::hiddenBookNameInput() const -{ - return bookName.empty() - ? "" - : R"()"; -} - -std::string TestContentIn404HtmlResponse::searchPatternInput() const -{ - const std::string searchboxTooltip = isTranslatedVersion() - ? "Որոնել '" + bookTitle + "'֊ում" - : "Search '" + bookTitle + "'"; - return R"( -)"; -} - -std::string TestContentIn404HtmlResponse::taskbarLinks() const -{ - if ( bookName.empty() ) - return ""; - - const auto goToMainPageOfBook = isTranslatedVersion() - ? "Դեպի '" + bookTitle + "'֊ի գլխավոր էջը" - : "Go to the main page of '" + bookTitle + "'"; - - const std::string goToRandomPage = isTranslatedVersion() - ? "Բացել պատահական էջ" - : "Go to a randomly selected page"; - - return R"( - )"; -} - -bool TestContentIn404HtmlResponse::isTranslatedVersion() const -{ - return url.find("userlang=hy") != std::string::npos; -} - -std::string TestContentIn404HtmlResponse::goToWelcomePageText() const -{ - return isTranslatedVersion() - ? "Գրադարանի էջ" - : "Go to welcome page"; -} - - class TestContentIn400HtmlResponse : public TestContentIn404HtmlResponse { public: @@ -1156,7 +1033,7 @@ TEST_F(ServerTest, RawEntry) p = zfs1_->GET("/ROOT/content/zimfile/A/Ray_Charles"); EXPECT_EQ(200, p->status); EXPECT_NE(std::string(p->body), std::string(entry.getItem(true).getData())); - EXPECT_TRUE(p->body.find("taskbar") != std::string::npos); + EXPECT_TRUE(p->body.find("") != std::string::npos); } TEST_F(ServerTest, HeadMethodIsSupported)