607A Yorktown Place, Statesboro, GA 30461
http://www.chrissterling.me — chris@chrissterling.me
770-689-6679

Return to Resume


$('#searchBox').on('change keyup paste keydown', function(event) {
	//first I capture what key is being pressed so I can act upon it
	var key = event.keyCode || event.charCode;
	//unhide all the panels
	if (key == 8 || key == 46) {
		$('.panel').each(function() { $(this).show(); });
	}
	//the search is wrapped inside a form, so I prevent the enter key
	if (key == 13) {
		event.preventDefault();
	}
	//get the actual search value
	var searchValue = $('#searchBox').val();
	//send the event to google analytics so we can see what people are searching for
	//so we can see if we need to tweak anything
	if (event.type == "change") {
		//function I wrote that I can call to send analytic events to google
		googleAlertEvent("Search", searchValue);
	}
	//actually do the search
	doSearch(searchValue);
});
function doSearch(searchString) {
	//only fire off the search if the search string is more then 2 characters
    if (searchString.length > 2) {
    	//get the number of panels we are searching
        var numItems = $('.panel').length;
        //loop through all the panels
        $('.panel').each(function () {
            var searchTags = "";
            var panelTitle = "";
            
            //we've added the ability to tag panels and links with extra data
            //so we can tag stuff with different search terms
            if ($(this).data('searchtags') != undefined) {
                searchTags += $(this).data('searchtags').toUpperCase();
            }
            //grab the panel title as well
            $(this).find('.panel-heading').each(function() {
                panelTitle = $(this).text().trim().toUpperCase();
            });
            //next chuck of code sees if the user has hidden the tile, but maybe the term we are looking for
            // is located in this hidden tile, lets open the tile, but keep track that we opened it
            var panelCollapsed;
            $(this).find('.panel-collapse').each(function () {
                if (!$(this).hasClass('in')) {
                    panelCollapsed = $(this);
                    hiddenPanels.push(panelCollapsed);
                }
            });
            var queryFound = false;
            //at this point, i start to look through each link inside the tile
            $(this).find('a').each(function () {
                var adjSearchString = searchString.toUpperCase()
                var linkText = $(this).text().trim().toUpperCase();
                
                var linkTags = "";
                if ($(this).data('searchtags') != undefined) {
                    searchTags += $(this).data('searchtags').toUpperCase();
                    linkTags = $(this).data('searchtags').toUpperCase();
                }
                //look at a number of different sections to look for the search string in
                if (linkText.indexOf(adjSearchString) > -1 || panelTitle.indexOf(adjSearchString) > -1 || searchTags.indexOf(adjSearchString) > -1) {
                	//found a result
                    queryFound = true;
                    //if it's a link, lets go and add a highlight to point it out to the user
                    if (linkText.indexOf(adjSearchString) > -1 || linkTags.indexOf(adjSearchString) > -1) {
                        $(this).addClass("highlight");
                    }
					//is the link tagged, if so, lets add a tooltip to the link to show why we highlighted it
                    if (linkTags.indexOf(adjSearchString) > -1) {
                        var tags = linkTags.split(',');
                        var toolTipTag = "";
                        for (i = 0; i < tags.length; i++) {
                            if (tags[i].indexOf(searchString) > -1) {
                                toolTipTag += tags[i] + ",";
                            }
                        }
                        //add a tool tip to the link
                        if (toolTipTag != "") {
                            $(this).tooltip({ title: toolTipTag.substring(0, toolTipTag.length - 1), placement: "auto", trigger: "manual" }).tooltip('show');
                        }
                    }
                    //is this panel currently collapsed? if so, lets go and show it
                    if (panelCollapsed != undefined) {
                        panelCollapsed.collapse('show');
                    }
                }
            });
            //if we didn't find anything, lets hide the whole panel
            if (!queryFound) {
                $(this).hide();
                numItems--;
            }
        });
        //we've searched everything, can't find anything, lets show that we didn't find anything
        if (numItems == 0) {
            $('#searchFail').show();
        } else {
            $('#searchFail').hide();
        }
    } else {
    	//lets go and hide the search fail div
        $('#searchFail').hide();
        //lets remove the highlight and show all the tiles again
        $('.panel').each(function () {
            $(this).show(); 
            $(this).find('a').each(function () {
                $(this).removeClass("highlight");
            });
        });
		//lets go and rehide any tiles that we had to show
        rehidePanels();
    }
}
Return to Resume