From 58f003392a72a7e4bd0db6c04d045787279756e0 Mon Sep 17 00:00:00 2001 From: derv82 Date: Sun, 3 Dec 2017 23:27:55 -0800 Subject: [PATCH] Scroll up when search results options are clicked (find/next/prev) --- popup/popup.css | 2 -- popup/search-results.css | 5 +++++ popup/search-results.js | 34 ++++++++++++++++------------------ 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/popup/popup.css b/popup/popup.css index 73f5bc1b..b9e6f2a0 100644 --- a/popup/popup.css +++ b/popup/popup.css @@ -1,7 +1,5 @@ html, body { height: min-content; - overflow-y: auto; - overflow-x: hidden; } body { diff --git a/popup/search-results.css b/popup/search-results.css index 4facbcc6..363a19e0 100755 --- a/popup/search-results.css +++ b/popup/search-results.css @@ -1,3 +1,8 @@ +body.search-results-shown { + overflow-y: auto; + overflow-x: hidden; +} + #disable-all-wrapper { border-bottom: solid 1px #000; margin-bottom: 5px; diff --git a/popup/search-results.js b/popup/search-results.js index 846a966a..3b45a8e4 100755 --- a/popup/search-results.js +++ b/popup/search-results.js @@ -9,14 +9,23 @@ $('#find-styles-link').onclick = event => { // Only load search results inline if option is selected. if ($('#find-styles-inline').checked) { + // Hide 'inline' checkbox. $('#find-styles-inline-group').classList.add('hidden'); $('#find-styles-inline').checked = false; + const searchResults = searchResultsController(); $('#searchResultsNav-prev').onclick = searchResults.prev; $('#searchResultsNav-next').onclick = searchResults.next; - // Intercept event to avoid opening the search page. - return searchResults.load(event); + searchResults.load(); + document.body.classList.add('search-results-shown'); + + window.scrollTo(0, 0); + + // Avoid propagating click to anchor/href + event.preventDefault(); + return false; } else { + // Open anchor href in new tab. handleEvent.openURLandHide.call($('#find-styles-link'), event); } }; @@ -99,22 +108,18 @@ } /** Increments currentDisplayedPage and loads results. */ - function next(event) { - if (event) { - event.preventDefault(); - } + function next() { currentDisplayedPage += 1; render(); + window.scrollTo(0, 0); loadMoreIfNeeded(); } /** Decrements currentPage and loads results. */ - function prev(event) { - if (event) { - event.preventDefault(); - } + function prev() { currentDisplayedPage = Math.max(1, currentDisplayedPage - 1); render(); + window.scrollTo(0, 0); } /** @@ -136,13 +141,8 @@ /** * Initializes search results container, starts fetching results. - * @param {Object} event The click event */ - function load(event) { - if (event) { - event.preventDefault(); - } - + function load() { loading = true; render(); @@ -175,8 +175,6 @@ }) .catch(error); }); - // Find styles for the current active tab - return true; } /**