Created
July 10, 2011 18:43
-
-
Save gaurish/1074829 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Variables | |
var ids = {}; | |
//Start up with document | |
$(document).ready(init); | |
//Initilize some stuff. | |
function init(){ | |
setUpMenu(); | |
setUpSearch(); | |
} | |
//Set up the menu on the left. Pretty intricate in terms of what it does. | |
function setUpMenu(){ | |
$('#pages >p') | |
.data('open',false) | |
.each( | |
function(index,value){ | |
$(this).click( | |
function(){ | |
$(this).parent().contents().css('font-weight',''); | |
$('.innards').addClass('hidden'); | |
scrollTo(0,0); | |
if(!$(this).data('open')){ | |
showById(this.id); | |
$(this).css('font-weight','bold'); | |
$('.innards',this).toggleClass('hidden'); | |
$(this).data('open',true); | |
} | |
else | |
$(this).data('open',false); | |
}); | |
$('<div>') | |
.hide() | |
.attr('id',value.id) | |
.load('search/'+$(value).attr('id'), | |
function(){ | |
var id = this.id; | |
console.log(id); | |
ids[id] = []; | |
$('h3',this).each(function(index,header){ | |
ids[id].push($(header).text()); | |
}); | |
$('h2',this).each(function(index,header){ | |
if(0==index) | |
$('#pages >p#'+id).append($('<span>').addClass('header').text($(header).text())); | |
else | |
ids[id].push($(header).text()); | |
}); | |
var innards = $('<span>').addClass('innards'); | |
for(var i = 0; i < ids[id].length;i++){ | |
innards.append($('<p>').text(ids[id][i]).attr('id',ids[id][i])); | |
} | |
$('#pages > p#'+$(value).attr('id')).append(innards); | |
innards.contents(':even').css('background-color','#EDF3FE'); | |
innards.contents(':odd').css('background-color','white'); | |
innards.addClass('hidden').contents().each(function(index,innard){ $(innard).click(resultsByText(id,innard.id)); | |
}); | |
}) | |
.appendTo('#results'); | |
}); | |
} | |
//Set up the search box to look for certain key words. | |
function setUpSearch(){ | |
$('#searchInput').focus().keyup(function(event){ | |
var text= $(this).val(); | |
var notRemade = true; | |
if(text != ""){ | |
$('.innards').removeClass('hidden'); | |
$('#pages').contents().addClass('hidden').each(function(index1,page){ | |
$('p', page).addClass('hidden').each(function(index2, paragraph){ | |
if(paragraph.id.toLowerCase().indexOf(text.toLowerCase()) !=-1){ | |
$(paragraph).removeClass('hidden').parent().parent().removeClass('hidden'); | |
$(page).removeClass('hidden'); | |
if(notRemade){ | |
resultsByText(page.id,paragraph.id)(null); | |
notRemade = false; | |
} | |
} | |
}); | |
}); | |
} | |
else{ | |
resetMenu(); | |
} | |
}) | |
.bind('search', function(event){ | |
console.log('text'); | |
if($(this).val() == "") | |
resetMenu(); | |
}); | |
} | |
function resetMenu(){ | |
$('.innards').addClass('hidden'); | |
$('#pages >p').removeClass('hidden'); | |
} | |
// | |
function resultsByText(page,text){ | |
return function(event){ | |
if(event) | |
event.stopPropagation(); | |
showById(page); | |
$('h3,h2',$('#results > #'+page)).each(function(index,value){ | |
if($(value).text().indexOf(text) != -1) | |
scrollTo(0,$(this).offset().top); | |
}); | |
}; | |
} | |
//Pass an id and it adjusts the results section to look at everything. | |
function showById(id){ | |
$('#results > div').hide(); | |
$('#results > #'+id).show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment