Skip to content
Snippets Groups Projects
Commit c3e421a2 authored by Kevin Abel's avatar Kevin Abel
Browse files

Move the tab filter UI changing into separate event handler.

This allows other objects (namely the Directory controller) to trigger
an interface change.

The Directory controller triggers a UI change when their are no results
for the current filtered view state.
parent 0211b5e9
No related branches found
No related tags found
1 merge request!3Improve UI for empty filtered Directory results
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
resultSel = '.search-results', resultSel = '.search-results',
googleSel = '.google-results', googleSel = '.google-results',
evtStateChange = 'statechange',
wrapperMain = '#search_wrapper', wrapperMain = '#search_wrapper',
wrapperWeb = '#search_results', wrapperWeb = '#search_results',
wrapperDir = '#directory_results', wrapperDir = '#directory_results',
...@@ -71,14 +72,28 @@ ...@@ -71,14 +72,28 @@
}; };
Directory.prototype._renderState = function(duration) { Directory.prototype._renderState = function(duration) {
var $innerRes = $('.results', $(this._renderTo)), var $innerRes = $('.results', $(this._renderTo)),
$showRes, failState,
depFilter = '.departments'; depFilter = '.departments';
if (!$innerRes.length) {
return;
}
$innerRes.slideUp(duration); $innerRes.slideUp(duration);
if (this._viewState === 0) { if (this._viewState === 0) {
$innerRes.not(depFilter).slideDown(); $showRes = $innerRes.not(depFilter);
failState = 1;
} else { } else {
$innerRes.filter(depFilter).slideDown(); $showRes = $innerRes.filter(depFilter);
failState = 0;
}
if (!$showRes.length && typeof duration !== "undefined") {
this.changeViewState(failState);
return;
} }
$showRes.slideDown();
}; };
Directory.prototype.cancelSearch = function() { Directory.prototype.cancelSearch = function() {
this._searchCanceled = true; this._searchCanceled = true;
...@@ -106,8 +121,12 @@ ...@@ -106,8 +121,12 @@
return; return;
} }
var prevState = this._viewState;
this._viewState = state; this._viewState = state;
this._renderState(); this._renderState();
$(this._renderTo).trigger(evtStateChange, [state, prevState]);
}; };
Directory.prototype.clearAllResults = function() { Directory.prototype.clearAllResults = function() {
$(this._renderTo).empty(); $(this._renderTo).empty();
...@@ -205,11 +224,22 @@ ...@@ -205,11 +224,22 @@
$(function() { $(function() {
var $q = $(inputSel), var $q = $(inputSel),
resSel = '.results-group',
tabsSel = '.result-tab', tabsSel = '.result-tab',
selCls = 'selected', selCls = 'selected',
stateClsPfx = 'state-', stateClsPfx = 'state-',
$resTabs = $('.result-tab'), $resTabs = $('.result-tab'),
tabStateChange = function(e, state, prevState) {
var $tab = $(this).find(tabsSel);
e.stopPropagation();
$tab.removeClass(stateClsPfx + prevState);
$tab.addClass(stateClsPfx + state);
$tab.children().removeClass(selCls).eq(state).addClass(selCls);
},
googleOrigin = /^https?:\/\/www\.google\.com$/, googleOrigin = /^https?:\/\/www\.google\.com$/,
...@@ -248,20 +278,12 @@ ...@@ -248,20 +278,12 @@
} }
var i = $(this).index(), var i = $(this).index(),
j = $(this).siblings('.' + selCls).index(), $par = $(this).parents(resSel);
$tab = $(this).closest(tabsSel),
$par = $(this).parents('.results-group');
$tab.removeClass(stateClsPfx + j);
$tab.addClass(stateClsPfx + i);
$(this).siblings().removeClass(selCls);
$(this).addClass(selCls);
if ($par.is(wrapperDir)) { if ($par.is(wrapperDir)) {
directorySearch.changeViewState(i); directorySearch.changeViewState(i);
} else if ($par.is(wrapperWeb)) { } else if ($par.is(wrapperWeb)) {
$(activeSearch.root).closest(googleSel).slideUp(); $(activeSearch.root).closest(googleSel).slideUp().trigger(evtStateChange, [i, !i]);
if (i === 0) { if (i === 0) {
activeSearch = localSearch; activeSearch = localSearch;
} else { } else {
...@@ -272,6 +294,8 @@ ...@@ -272,6 +294,8 @@
} }
}); });
$(resSel).on(evtStateChange, tabStateChange);
// listen for the submit event // listen for the submit event
$(formSel).submit(function(e) { $(formSel).submit(function(e) {
e.preventDefault(); e.preventDefault();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment