Skip to content
Snippets Groups Projects
Commit 57c9ebfd authored by Brett Bieber's avatar Brett Bieber
Browse files

Merge branch 'four' into 'master'

Improve UI for empty filtered Directory results
parents 0211b5e9 843ac685
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@
resultSel = '.search-results',
googleSel = '.google-results',
evtStateChange = 'statechange',
wrapperMain = '#search_wrapper',
wrapperWeb = '#search_results',
wrapperDir = '#directory_results',
......@@ -71,14 +72,28 @@
};
Directory.prototype._renderState = function(duration) {
var $innerRes = $('.results', $(this._renderTo)),
$showRes, failState,
depFilter = '.departments';
if (!$innerRes.length) {
return;
}
$innerRes.slideUp(duration);
if (this._viewState === 0) {
$innerRes.not(depFilter).slideDown();
$showRes = $innerRes.not(depFilter);
failState = 1;
} 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() {
this._searchCanceled = true;
......@@ -106,8 +121,12 @@
return;
}
var prevState = this._viewState;
this._viewState = state;
this._renderState();
$(this._renderTo).trigger(evtStateChange, [state, prevState]);
};
Directory.prototype.clearAllResults = function() {
$(this._renderTo).empty();
......@@ -205,11 +224,22 @@
$(function() {
var $q = $(inputSel),
resSel = '.results-group',
tabsSel = '.result-tab',
selCls = 'selected',
stateClsPfx = 'state-',
$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$/,
......@@ -247,21 +277,13 @@
return;
}
var i = $(this).index(),
j = $(this).siblings('.' + selCls).index(),
$tab = $(this).closest(tabsSel),
$par = $(this).parents('.results-group');
$tab.removeClass(stateClsPfx + j);
$tab.addClass(stateClsPfx + i);
$(this).siblings().removeClass(selCls);
$(this).addClass(selCls);
var i = $(this).index(),
$par = $(this).parents(resSel);
if ($par.is(wrapperDir)) {
directorySearch.changeViewState(i);
} else if ($par.is(wrapperWeb)) {
$(activeSearch.root).closest(googleSel).slideUp();
$(activeSearch.root).closest(googleSel).slideUp().trigger(evtStateChange, [i, 0 + !i]);
if (i === 0) {
activeSearch = localSearch;
} else {
......@@ -272,6 +294,8 @@
}
});
$(resSel).on(evtStateChange, tabStateChange);
// listen for the submit event
$(formSel).submit(function(e) {
e.preventDefault();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment