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

Refactored the searchInit function to utilize a standard form rather than...

Refactored the searchInit function to utilize a standard form rather than google's deprecated gSearchForm. Uses the onSearchStart callback to chain the peoplefinder and local searches. Removed unused functions.
parent 6261ae21
No related branches found
No related tags found
No related merge requests found
......@@ -6,42 +6,66 @@ function searchInit() {
UNL_Search.peoplefinderCache = new UNL_Search.Cache();
//Parse the querystring for q
var qs = location.search.substring(1,location.search.length);
qs = qs.replace(/\+/g, ' ');
var qs = window.location.search.substr(1);
var args = qs.split('&');
UNL_Search.query = "";
for (var i=0;i<args.length;i++) {
for (var i = 0; i < args.length; i++) {
var pair = args[i].split('=');
var name = unescape(pair[0]);
if (name == "q") {
if (decodeURIComponent(pair[0]) == "q") {
if (pair.length == 2) {
UNL_Search.query = unescape(pair[1])
UNL_Search.query = decodeURIComponent(pair[1].replace(/\+/g, ' '));
}
break;
}
}
UNL_Search.unl_search = new google.search.CustomSearchControl("015236299699564929946:nk1siew10ie");
var unl_search = new google.search.CustomSearchControl("015236299699564929946:nk1siew10ie");
unl_search.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
unl_search.setSearchCompleteCallback(UNL_Search, UNL_Search.onSearchComplete);
unl_search.setSearchStartingCallback(UNL_Search, UNL_Search.onSearchStart);
UNL_Search.unl_search.draw('unl_results');
UNL_Search.unl_search = unl_search;
drawOp = new google.search.DrawOptions();
drawOp.enableSearchResultsOnly();
unl_search.draw('unl_results', drawOp);
if (UNL_Search.do_local_search) {
UNL_Search.local_search = new google.search.CustomSearchControl(UNL_Search.local_search_context);
UNL_Search.local_search.setResultSetSize('small');
UNL_Search.local_search.draw('local_results');
var local_search = new google.search.CustomSearchControl(UNL_Search.local_search_context);
local_search.setResultSetSize('small');
local_search.setSearchCompleteCallback(UNL_Search, UNL_Search.onSearchComplete);
local_search.draw('local_results', drawOp);
UNL_Search.local_search = local_search;
}
var gSearchForm = new GSearchForm(false, document.getElementById("searchform"));
gSearchForm.setOnSubmitCallback(UNL_Search, UNL_Search.doQuery);
gSearchForm.input.value = (UNL_Search.query ? UNL_Search.query : "");
WDN.loadJQuery(function() {
var $ = WDN.jQuery;
$('#search_q').attr('autocomplete', 'off').val(UNL_Search.query);
$('#searchform form').submit(function() {
var q = $.trim($('#search_q').val());
UNL_Search.query = q;
UNL_Search.pfCancelFlag = false;
if (q !== '') {
unl_search.execute(q);
} else {
unl_search.cancelSearch();
unl_search.clearAllResults();
if (UNL_Search.do_local_search) {
local_search.cancelSearch();
local_search.clearAllResults();
}
UNL_Search.pfCancelFlag = true;
$('#ppl_results').empty();
}
return false;
});
});
// Execute an inital search
if (UNL_Search.query && UNL_Search.query != "") {
UNL_Search.doPeoplefinderQuery(UNL_Search.query);
UNL_Search.unl_search.execute(UNL_Search.query);
if (UNL_Search.do_local_search) {
UNL_Search.local_search.execute(UNL_Search.query);
}
if (UNL_Search.query) {
unl_search.execute(UNL_Search.query);
}
}
......@@ -60,8 +84,8 @@ UNL_Search.do_local_search = false;
UNL_Search.unl_search = null;
UNL_Search.local_search = null;
UNL_Search.local_search_context = null;
UNL_Search.scrolldelay = null;
UNL_Search.peoplefinderCache = null;
UNL_Search.pfCancelFlag = false;
//Caching Class
//
......@@ -84,62 +108,61 @@ UNL_Search.Cache.prototype.get = function (key) {
return val;
};
UNL_Search.handleUNLResults = function () {
UNL_Search.handleResults('unl_results', UNL_Search.unl_search);
UNL_Search.onSearchStart = function(control, searcher, query) {
UNL_Search.doPeoplefinderQuery(query);
if (UNL_Search.do_local_search) {
UNL_Search.local_search.execute(query);
}
UNL_Search.trackQuery(control, searcher, query);
};
UNL_Search.handleLocalResults = function () {
UNL_Search.handleResults('local_results', UNL_Search.local_search);
};
UNL_Search.onSearchComplete = function(control, searcher) {
var $ = WDN.jQuery;
/* The more URL no longer works on google's host
if (searcher && searcher.cursor && searcher.cursor.pages.length >= 8) {
var $moreDiv = $("<div />").html('More&hellip;').addClass('gsc-cursor-page').click(function() {
window.location.href = searcher.cursor.moreResultsUrl;
return false;
});
$('.gsc-cursor-box .gsc-cursor', control.root).append($moreDiv);
}
*/
if (searcher.cursor.estimatedResultCount) {
var $resultHead = $("<div />").addClass('result_head').text('About ' + searcher.cursor.estimatedResultCount + ' results');
$('.gsc-results', control.root).before($resultHead);
}
if (mobileSearch) { //if we're doing a mobile search, rewrite link URLs to use mobile proxy
$('a.gs-title', control.root).each(function() {
$(this).attr('href', function(i, val) {
return 'http://m.unl.edu/?view=proxy&u=' + encodeURIComponent(val);
})
});
}
}
UNL_Search.handleResults = function (result_div, searchobj) {
var resultsDIV = document.getElementById(result_div);
UNL_Search.trackQuery = function(control, searcher, query) {
var loc = document.location;
var url = [
loc.pathname,
loc.search,
loc.search ? '&' : '?',
'q=',
encodeURIComponent(query)
].join('');
if (searchobj.results && searchobj.results.length > 0) {
resultsDIV.innerHTML = '';
WDN.jQuery(resultsDIV).css('background', 'none');
//var resultHead = '<p>Results <strong>' + (1 + 8 * searchobj.cursor.currentPageIndex) + '</strong> - <strong>' + (8 + 8 * searchobj.cursor.currentPageIndex) + '</strong> of about <strong>' + searchobj.cursor.estimatedResultCount + '</strong> for <em>' + query + '</em></p>';
//resultsDIV.innerHTML += resultHead;
for (var i = 0; i < searchobj.results.length; i++) {
if (i % 2 != 0) {
searchobj.results[i].html.className += " alt";
}
resultsDIV.appendChild(searchobj.results[i].html);
}
if (mobileSearch) { //if we're doing a mobile search, rewrite link URLs to use mobile proxy
WDN.jQuery(resultsDIV).find('a.gs-title').each(function(){
//href= WDN.jQuery(this).attr('href');
WDN.jQuery(this).attr('href', function(i, val){
return 'http://m.unl.edu/?view=proxy&u='+val;
});
});
}
var nav = document.createElement("ul");
nav.className = "wdn_pagination";
var search_name = 'unl_search';
if (result_div.substring(0,5) == 'local') {
search_name = 'local_search';
}
for (var i = 0; i < searchobj.cursor.pages.length; i++) {
WDN.loadCSS('/wdn/templates_3.0/css/content/pagination.css');
var pageText = '';
if (searchobj.cursor.currentPageIndex != i) {
pageText += '<li><a onclick="UNL_Search.'+search_name+'.gotoPage(' + i + '); return false;" href="#">' + searchobj.cursor.pages[i].label + '</a></li>';
} else {
pageText += '<li class="selected">'+searchobj.cursor.pages[i].label + '</li>';
}
nav.innerHTML += pageText;
}
if (searchobj.cursor.pages.length >= 8) {
nav.innerHTML += '<li><a href="' + searchobj.cursor.moreResultsUrl + '">More Results &gt;&gt;</a></li>';
try {
if (typeof WDN.analytics !== 'undefined') {
WDN.analytics.callTrackPageview(url);
} else {
_gaq.push(["_trackPageview", url]);
}
resultsDIV.appendChild(nav);
} else {
WDN.jQuery(resultsDIV).html('<p>No results found.</p>');
} catch (e) {
// do nothing
}
};
UNL_Search.doPeoplefinderQuery = function (val) {
var cacheData = this.peoplefinderCache.get(val)
if (cacheData) {
......@@ -156,23 +179,7 @@ UNL_Search.doPeoplefinderQuery = function (val) {
};
UNL_Search.handlePeoplefinderResults = function (peoplefinderText) {
document.getElementById("ppl_results").innerHTML = peoplefinderText;
};
UNL_Search.doQuery = function (form) {
if (form.input.value != "") {
this.query = form.input.value;
this.doPeoplefinderQuery(form.input.value);
if (this.do_local_search) {
this.local_search.execute(form.input.value);
}
this.unl_search.execute(form.input.value);
} else {
document.getElementById("searchcontrol").innerHTML = '';
document.getElementById("ppl_results").innerHTML = '';
if (!UNL_Search.pfCancelFlag) {
document.getElementById("ppl_results").innerHTML = peoplefinderText;
}
return false;
};
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