/*
FILE ARCHIVED ON 21:22:46 Mar 23, 2011 AND RETRIEVED FROM THE
AN OPENWAYBACK INSTANCE ON 23:52:03 Sep 17, 2024.
JAVASCRIPT APPENDED BY OPENWAYBACK, COPYRIGHT INTERNET ARCHIVE.
ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
SECTION 108(a)(3)).
*/
dojo.require("dojo.string");
function TypeAhead(opts)
{
var defaultOpts = {
searchBox: '',
resultsDiv: document.getElementById('typeahead'),
dbObject: 'ta_data',
dbUrl: '',
resultsPerCategory: 5,
minChars: 2,
lagTime: 50,
debug: false
};
var templates = {
resultsStart: "
",
resultsEnd: "",
categoryStart: "",
entry: {
video: "${entry.view}",
Default: "${entry.view}"
},
highlight: "${match}"
};
var buildUrl = {
categories : function(e) {
var seo = (e.A+"-"+e.T).replace(/[ >]+/g,'-').replace(/^-+/,'');
return "https://webarchive.library.unt.edu/web/20110323212246/http://www.homedepot.com/"+seo+"/h_d1/N-5yc1vZ1xg1Z"+e.N+"/h_d2/Navigation?langId=-1&storeId=10051&catalogId=10053";
},
brands : function(e) {
return "https://webarchive.library.unt.edu/web/20110323212246/http://www.homedepot.com/"+e.T.replace(/[ ]+/g,'-')+"/h_d1/N-5yc1vZ1xg1Z"+e.N+"/h_d2/Navigation?langId=-1&storeId=10051&catalogId=10053";
},
Default: function(e){
return e.L;
}
};
var buildLog = {
categories : function(e) {
return (e.A+" > "+e.T).replace(/^[ >]+/,'');
},
Default: function(e) {
return e.T;
}
};
var buildView = {
Default: function(e) {
return e.T;
}
};
var headers = {
categories: 'Shop by Category',
brands: 'Shop by Brand',
projects: 'How to: Project Guides',
buying: 'How to: Buying Guides',
Community: 'Community',
InstallationServices: 'Installation Services'
};
var searchTimer = null;
var debug;
if(opts.debug !== true || !window.console)
{
var firebugFunctions = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
function noop(){}
debug = {};
for (var i = 0; i < firebugFunctions.length; ++i)
debug[firebugFunctions[i]] = noop;
}
else
{
debug = console;
}
function init()
{
debug.group("Initializing TypeAhead Widget");
opts = dojo.mixin(defaultOpts,opts);
debug.log(opts);
prepDom();
getDbObject();
debug.groupEnd();
}
function prepDom()
{
debug.log("Preparing Dom");
if('string' == typeof(opts.resultsDiv))
opts.resultsDiv = dojo.query(opts.resultsDiv);
dojo.style(opts.resultsDiv,'display','none');
if('string' == typeof(opts.searchBox))
opts.searchBox = dojo.query(opts.searchBox);
dojo.connect(opts.searchBox,'onkeyup',TypeAhead,scheduleSearch);
dojo.connect(opts.searchBox,'onblur',TypeAhead,scheduleClearSearchResults);
dojo.attr(opts.searchBox,'autocomplete','off');
}
function getDbObject()
{
if('string' == typeof(opts.dbObject))
{
if( '' != opts.dbUrl)
downloadDbObject();
checkForDbObject();
}
else
{
prepDbObject();
}
}
function downloadDbObject()
{
debug.log("Downloading json database from url: "+opts.dbUrl);
loadFile(opts.dbUrl);
}
function loadFile(url)
{
var script=document.createElement('script');
script.setAttribute("type","text/javascript");
script.setAttribute("src", url);
document.getElementsByTagName("head")[0].appendChild(script);
}
function checkForDbObject()
{
debug.log('Checking for Db Object');
if('object' != typeof(window[opts.dbObject]))
{
debug.log('dbObject not yet available');
setTimeout(dojo.hitch(TypeAhead,checkForDbObject),200);
}
else
{
opts.dbObject = window[opts.dbObject];
prepDbObject();
}
}
function prepDbObject()
{
debug.group("Preparing Search Object");
debug.log("Registered Db object: ",opts.dbObject);
debug.time("Search Object Preparation Time");
for(category in opts.dbObject)
{
if( ! opts.dbObject.hasOwnProperty(category)) continue;
for(entry in opts.dbObject[category])
{
if( ! opts.dbObject[category].hasOwnProperty(entry)) continue;
for(property in opts.dbObject[category][entry])
{
if( ! opts.dbObject[category][entry].hasOwnProperty(property)) continue;
if(property.indexOf('lower') == -1)
opts.dbObject[category][entry][property+"lower"] = opts.dbObject[category][entry][property].toLowerCase();
}
}
}
mergeVideosAndProjects();
debug.timeEnd("Search Object Preparation Time");
debug.groupEnd();
debug.log(opts.dbObject);
}
function mergeVideosAndProjects()
{
for(entry in opts.dbObject.video){
if( ! opts.dbObject.video.hasOwnProperty(entry) ) continue;
opts.dbObject.video[entry].V = true;
opts.dbObject.video[entry].category = 'video';
}
for(entry in opts.dbObject.projects){
if( ! opts.dbObject.projects.hasOwnProperty(entry) ) continue;
opts.dbObject.projects[entry].V = false;
}
opts.dbObject.projects = opts.dbObject.projects.concat(opts.dbObject.video);
delete(opts.dbObject.video);
}
function scheduleSearch(e)
{
clearTimeout(searchTimer);
if(((e.keyCode > 64 && e.keyCode < 91) || dojo.keys.BACKSPACE ))
searchTimer = setTimeout(performSearch,opts.lagTime);
}
function performSearch()
{
var term = opts.searchBox.value.toLowerCase();
if(term.length >= opts.minChars)
{
debug.group("Performing Search on Term: "+term);
debug.time("Search Time");
var matches = {};
var total = 0;
for( var category in opts.dbObject)
{
if( ! opts.dbObject.hasOwnProperty(category) ) continue;
matches[category] = [];
var entries = opts.dbObject[category];
var cnt = 0;
for(entry in entries)
{
if( ! entries.hasOwnProperty(entry) ) continue;
if(cnt == opts.resultsPerCategory) break;
entry = entries[entry];
if(entry['Tlower'].indexOf(term) > -1)
{
cnt++;
total++;
if('undefined'==typeof(entry.category))
{
entry.category = category;
}
matches[category].push(prepareEntry(entry,term));
}
}
}
debug.timeEnd("Search Time");
debug.log("Matches: ",matches);
debug.groupEnd();
updateSearchResults(matches,total);
}
else
{
clearSearchResults();
}
}
function updateSearchResults(matches,numResults)
{
debug.log("Updating Search Results");
var output = "";
var col = [ "", "", "" ];
if(numResults > 0)
{
output += dojo.string.substitute(templates.resultsStart,{
count:numResults
});
var i = 0;
for(category in matches)
{
if( ! matches.hasOwnProperty(category) ) continue;
if(matches[category].length > 0)
{
col[i%3] += addSearchResultsCategory(category,matches[category]);
i++;
}
}
output += ""+col[0]+"
"+col[1]+"
"+col[2]+"
";
output += dojo.string.substitute(templates.resultsEnd,{
count:numResults
});
opts.resultsDiv.innerHTML = output;
showSearchResults();
}
else
{
clearSearchResults();
}
}
function addSearchResultsCategory(category, matches)
{
var output = "";
output += dojo.string.substitute(templates.categoryStart,{
category:category,
header:headers[category],
count:matches.length
});
for(entry in matches)
{
if( ! matches.hasOwnProperty(entry) ) continue;
entry = matches[entry];
if('undefined' != typeof(templates.entry[entry.category]) )
{
output += dojo.string.substitute(templates.entry[entry.category],{
entry:entry
});
}
else
{
output += dojo.string.substitute(templates.entry.Default,{
entry:entry
});
}
}
output += dojo.string.substitute(templates.categoryEnd,{
category:category,
header:headers[category],
count:matches.length
});
return output;
}
function clearSearchResults()
{
opts.resultsDiv.innerHTML = "";
dojo.style(opts.resultsDiv,'display','none');
var colS2 = document.getElementsByTagName("SELECT");
if (colS2!=null){
for (i=0; i