From 5252793df99e0c31fad6ccf7827f3c94727897ef Mon Sep 17 00:00:00 2001 From: Kevin Abel <kevin.abel.0@gmail.com> Date: Mon, 2 Jun 2014 17:35:23 -0500 Subject: [PATCH] Implement automatic web search tab switching on empty local result When a local search occurs (not triggered by explict tab click), automatically switch to the "All of UNL" tab if no result are detected. --- www/js/search.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/www/js/search.js b/www/js/search.js index 4b6c0e3..ac2efe1 100644 --- a/www/js/search.js +++ b/www/js/search.js @@ -146,6 +146,7 @@ directorySearch, localContext = window['LOCAL_SEARCH_CONTEXT'], drawOp = new google.search.DrawOptions(), + searchToggleLock = false, trackQuery = function(q) { var loc = window.location, @@ -175,8 +176,15 @@ }); $('img.gcsc-branding-img-noclear', $root).attr('alt', 'Googleâ„¢'); + if (!searchToggleLock && control == localSearch && $('.gs-no-results-result').length) { + $root.closest('.results-group').find('.result-tab li:last-child').click(); + return; + } + $root.closest(resultSel).addClass(actCls); $root.closest(googleSel).slideDown(); + + searchToggleLock = false; }, fullQuery = function(q, track) { if (track !== false) { @@ -288,6 +296,7 @@ if ($par.is(wrapperDir)) { directorySearch.changeViewState(i); } else if ($par.is(wrapperWeb)) { + searchToggleLock = true; $(activeSearch.root).closest(googleSel).slideUp().trigger(evtStateChange, [i, 0 + !i]); if (i === 0) { activeSearch = localSearch; -- GitLab