|
@@ -5,10 +5,17 @@ |
|
|
|
|
|
|
|
|
FINISH_TYPING_INTERVAL = 650; |
|
|
FINISH_TYPING_INTERVAL = 650; |
|
|
searchBar = document.querySelectorAll("form#search-bar input[type='text']")[0]; |
|
|
searchBar = document.querySelectorAll("form#search-bar input[type='text']")[0]; |
|
|
|
|
|
resultsDiv = document.querySelectorAll("div#results")[0]; |
|
|
|
|
|
|
|
|
var typingTimer, lastValue; |
|
|
var typingTimer, lastValue; |
|
|
searchBar.onkeyup = typingTimer; |
|
|
searchBar.onkeyup = typingTimer; |
|
|
|
|
|
|
|
|
|
|
|
$(window).scroll(function() { |
|
|
|
|
|
if($(window).scrollTop() + $(window).height() == $(document).height()) { |
|
|
|
|
|
loadMoreResults(); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Clear the existing timer and set a new one the the user types text into the |
|
|
* Clear the existing timer and set a new one the the user types text into the |
|
|
* search bar. |
|
|
* search bar. |
|
@@ -32,9 +39,10 @@ function finishedTyping(){ |
|
|
|
|
|
|
|
|
clearResults(); |
|
|
clearResults(); |
|
|
if(searchBar.value){ |
|
|
if(searchBar.value){ |
|
|
populateResults(); |
|
|
|
|
|
if(!searchField.classList.contains("partly-visible")) |
|
|
if(!searchField.classList.contains("partly-visible")) |
|
|
searchField.classList.add("partly-visible"); |
|
|
searchField.classList.add("partly-visible"); |
|
|
|
|
|
|
|
|
|
|
|
populateResults(); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
searchField.classList.remove("partly-visible"); |
|
|
searchField.classList.remove("partly-visible"); |
|
@@ -44,10 +52,8 @@ function finishedTyping(){ |
|
|
* Removes any child elements of `div#results`. |
|
|
* Removes any child elements of `div#results`. |
|
|
*/ |
|
|
*/ |
|
|
function clearResults(){ |
|
|
function clearResults(){ |
|
|
var resultsPage = document.querySelectorAll("div#results")[0]; |
|
|
|
|
|
|
|
|
|
|
|
while(resultsPage.firstChild) |
|
|
|
|
|
resultsPage.removeChild(resultsPage.firstChild); |
|
|
|
|
|
|
|
|
while(resultsDiv.firstChild) |
|
|
|
|
|
resultsDiv.removeChild(resultsDiv.firstChild); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
@@ -55,18 +61,17 @@ function clearResults(){ |
|
|
* with its response. |
|
|
* with its response. |
|
|
*/ |
|
|
*/ |
|
|
function populateResults(){ |
|
|
function populateResults(){ |
|
|
var resultsPage = document.querySelectorAll("div#results")[0]; |
|
|
|
|
|
var results = queryServer(); |
|
|
var results = queryServer(); |
|
|
|
|
|
|
|
|
for(var result = 0; result < results.length; result++){ |
|
|
for(var result = 0; result < results.length; result++){ |
|
|
var newDiv = results[result]; |
|
|
var newDiv = results[result]; |
|
|
resultsPage.appendChild(newDiv); |
|
|
|
|
|
|
|
|
resultsDiv.appendChild(newDiv); |
|
|
setTimeout( |
|
|
setTimeout( |
|
|
(function(divReference){ |
|
|
|
|
|
return function(){ |
|
|
|
|
|
divReference.classList.add("cascade"); |
|
|
|
|
|
}; |
|
|
|
|
|
}(newDiv)), result * 20); |
|
|
|
|
|
|
|
|
(function(divReference){ |
|
|
|
|
|
return function(){ |
|
|
|
|
|
divReference.classList.add("cascade"); |
|
|
|
|
|
}; |
|
|
|
|
|
}(newDiv)), result * 20); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for(var result = 0; result < results.length; result++); |
|
|
for(var result = 0; result < results.length; result++); |
|
@@ -80,7 +85,7 @@ function populateResults(){ |
|
|
*/ |
|
|
*/ |
|
|
function queryServer(){ |
|
|
function queryServer(){ |
|
|
var resultDivs = [] |
|
|
var resultDivs = [] |
|
|
for(var result = 0; result < 200; result++){ |
|
|
|
|
|
|
|
|
for(var result = 0; result < 20; result++){ |
|
|
var newDiv = document.createElement("div"); |
|
|
var newDiv = document.createElement("div"); |
|
|
newDiv.classList.add("result"); |
|
|
newDiv.classList.add("result"); |
|
|
newDiv.innerHTML = Math.random(); |
|
|
newDiv.innerHTML = Math.random(); |
|
@@ -92,3 +97,20 @@ function queryServer(){ |
|
|
|
|
|
|
|
|
return resultDivs; |
|
|
return resultDivs; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* Adds more results to `div#results`. |
|
|
|
|
|
*/ |
|
|
|
|
|
function loadMoreResults(){ |
|
|
|
|
|
results = queryServer(); |
|
|
|
|
|
for(var result = 0; result < results.length; result++){ |
|
|
|
|
|
var newDiv = results[result]; |
|
|
|
|
|
resultsDiv.appendChild(newDiv); |
|
|
|
|
|
setTimeout( |
|
|
|
|
|
(function(divReference){ |
|
|
|
|
|
return function(){ |
|
|
|
|
|
divReference.classList.add("cascade"); |
|
|
|
|
|
}; |
|
|
|
|
|
}(newDiv)), result * 20); |
|
|
|
|
|
} |
|
|
|
|
|
} |