|
|
@@ -5,34 +5,145 @@ |
|
|
|
|
|
|
|
var advancedSearchDiv = $("div#advanced-search"); |
|
|
|
var advancedSearchButton = $("button#advanced-search"); |
|
|
|
advancedSearchButton.click(function(){ |
|
|
|
var searchField = $("div#search-field"); |
|
|
|
if(!advancedSearchDiv.hasClass("visible")){ |
|
|
|
searchField.addClass("partly-visible"); |
|
|
|
advancedSearchDiv.fadeIn(500).addClass("visible"); |
|
|
|
advancedSearchButton.addClass("clicked"); |
|
|
|
} |
|
|
|
else { |
|
|
|
advancedSearchDiv.fadeOut(300).removeClass("visible"); |
|
|
|
advancedSearchButton.removeClass("clicked"); |
|
|
|
if($("div#results .result").length == 0) |
|
|
|
searchField.removeClass("partly-visible"); |
|
|
|
FINISH_TYPING_INTERVAL = 650; |
|
|
|
var searchBar = $("form#search-bar input[type='text']")[0]; |
|
|
|
var resultsDiv = $("div#results")[0]; |
|
|
|
|
|
|
|
var typingTimer, scrollTimer, lastValue; |
|
|
|
var searchResultsPage = 1; |
|
|
|
|
|
|
|
/* |
|
|
|
* Set all page callbacks. |
|
|
|
*/ |
|
|
|
(function setHomePageCallbabacks(){ |
|
|
|
var results = $('#results').get(0); |
|
|
|
|
|
|
|
// Enable infinite scrolling down the results page. |
|
|
|
$(window).scroll(function(){ |
|
|
|
if($(window).scrollTop() + $(window).height() == $(document).height() && |
|
|
|
resultsDiv.querySelectorAll(".result").length > 0) |
|
|
|
loadMoreResults(); |
|
|
|
|
|
|
|
clearTimeout(scrollTimer); |
|
|
|
if (!results.classList.contains('disable-hover')) |
|
|
|
results.classList.add('disable-hover') |
|
|
|
|
|
|
|
scrollTimer = setTimeout(function(){ |
|
|
|
if (results.classList.contains('disable-hover')) |
|
|
|
results.classList.remove('disable-hover'); |
|
|
|
}, 200); |
|
|
|
}); |
|
|
|
|
|
|
|
// Toggle the advanced-search form's visibility. |
|
|
|
advancedSearchButton.click(function(){ |
|
|
|
var searchField = $("div#search-field"); |
|
|
|
if(!advancedSearchDiv.hasClass("visible")){ |
|
|
|
searchField.addClass("partly-visible"); |
|
|
|
advancedSearchDiv.fadeIn(500).addClass("visible"); |
|
|
|
advancedSearchButton.addClass("clicked"); |
|
|
|
} |
|
|
|
else { |
|
|
|
advancedSearchDiv.fadeOut(300).removeClass("visible"); |
|
|
|
advancedSearchButton.removeClass("clicked"); |
|
|
|
if($("div#results .result").length == 0) |
|
|
|
searchField.removeClass("partly-visible"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// Enable capturing the `enter` key. |
|
|
|
$("form#search-bar").submit(function(event){ |
|
|
|
event.preventDefault(); |
|
|
|
return false; |
|
|
|
}); |
|
|
|
searchBar.onkeyup = typingTimer; |
|
|
|
}()); |
|
|
|
|
|
|
|
/* |
|
|
|
* Set keyboard shortcut mappings. |
|
|
|
*/ |
|
|
|
(function resultsHotkeys(){ |
|
|
|
/* |
|
|
|
* If the currently viewed result is not the first, scroll to the previous |
|
|
|
* result. |
|
|
|
*/ |
|
|
|
var previousResult = function(){ |
|
|
|
var currResult = $(".display-all"); |
|
|
|
if(currResult.length) { |
|
|
|
currResult.removeClass("display-all"); |
|
|
|
currResult = currResult.closest(".result").prev(".result"); |
|
|
|
} else { |
|
|
|
currResult = $(document.querySelectorAll(".result")[0]); |
|
|
|
} |
|
|
|
|
|
|
|
currResult.addClass("display-all"); |
|
|
|
currResult.each(function(){ |
|
|
|
$('html,body').stop().animate({ |
|
|
|
scrollTop: $(this).offset().top - ( |
|
|
|
$(window).height() - $(this).outerHeight(true)) / 2 |
|
|
|
}, 140); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
/* |
|
|
|
* If the currently viewed result is not the last, scroll to the next |
|
|
|
* result. |
|
|
|
*/ |
|
|
|
var nextResult = function(){ |
|
|
|
var currResult = $(".display-all"); |
|
|
|
if(currResult.length) { |
|
|
|
currResult.removeClass("display-all"); |
|
|
|
currResult = currResult.closest(".result").next(".result"); |
|
|
|
} else { |
|
|
|
currResult = $(document.querySelectorAll(".result")[0]); |
|
|
|
} |
|
|
|
|
|
|
|
currResult.addClass('display-all'); |
|
|
|
currResult.each(function(){ |
|
|
|
$('html,body').stop().animate({ |
|
|
|
scrollTop: $(this).offset().top - ( |
|
|
|
$(window).height() - $(this).outerHeight(true)) / 2 |
|
|
|
}, 140); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
var displayHotkeyHelp = function(){ |
|
|
|
var help = $("div#hotkey-help"); |
|
|
|
console.log("H"); |
|
|
|
if(help.hasClass("hidden")) |
|
|
|
help.fadeIn(420); |
|
|
|
else |
|
|
|
help.fadeOut(420); |
|
|
|
|
|
|
|
$("div#body").toggleClass("faded"); |
|
|
|
help.toggleClass("hidden"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
FINISH_TYPING_INTERVAL = 650; |
|
|
|
searchBar = $("form#search-bar input[type='text']")[0]; |
|
|
|
resultsDiv = $("div#results")[0]; |
|
|
|
var hotkeyActions = { |
|
|
|
"k" : previousResult, |
|
|
|
"j" : nextResult, |
|
|
|
"h" : previousSymbolMatch, |
|
|
|
"l" : nextSymbolMatch, |
|
|
|
"?" : displayHotkeyHelp |
|
|
|
}; |
|
|
|
|
|
|
|
$(window).keypress(function(key){ |
|
|
|
for(var hotkey in hotkeyActions){ |
|
|
|
var keyChar = String.fromCharCode(key.keyCode); |
|
|
|
if(keyChar == hotkey && |
|
|
|
!($(key.target).is("textarea") || $(key.target).is("input"))) |
|
|
|
hotkeyActions[keyChar](); |
|
|
|
} |
|
|
|
}); |
|
|
|
}()); |
|
|
|
|
|
|
|
var typingTimer, lastValue; |
|
|
|
//Obtained by parsing python file with pygments |
|
|
|
var codeExample = '<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40</pre></div></td><td class="code"><div class="hll"><pre><span class="sd">"""</span>\n<span class="sd">Module to contain all the project's Flask server plumbing.</span>\n<span class="sd">"""</span>\n\n<span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">Flask</span>\n<span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">render_template</span><span class="p">,</span> <span class="n">session</span>\n\n<span class="kn">from</span> <span class="nn">bitshift</span> <span class="kn">import</span> <span class="n">assets</span>\n<span class="c"># from bitshift.database import Database</span>\n<span class="c"># from bitshift.query import parse_query</span>\n\n<span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>\n<span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_object</span><span class="p">(</span><span class="s">"bitshift.config"</span><span class="p">)</span>\n\n<span class="n">app_env</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">jinja_env</span>\n<span class="n">app_env</span><span class="o">.</span><span class="n">line_statement_prefix</span> <span class="o">=</span> <span class="s">"="</span>\n<span class="n">app_env</span><span class="o">.</span><span class="n">globals</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">assets</span><span class="o">=</span><span class="n">assets</span><span class="p">)</span>\n\n<span class="c"># database = Database()</span>\n\n<span class="nd">@app.route</span><span class="p">(</span><span class="s">"/"</span><span class="p">)</span>\n<span class="k">def</span> <span class="nf">index</span><span class="p">():</span>\n <span class="k">return</span> <span class="n">render_template</span><span class="p">(</span><span class="s">"index.html"</span><span class="p">)</span>\n\n<span class="nd">@app.route</span><span class="p">(</span><span class="s">"/search/<query>"</span><span class="p">)</span>\n<span class="k">def</span> <span class="nf">search</span><span class="p">(</span><span class="n">query</span><span class="p">):</span>\n <span class="c"># tree = parse_query(query)</span>\n <span class="c"># database.search(tree)</span>\n <span class="k">pass</span>\n\n<span class="nd">@app.route</span><span class="p">(</span><span class="s">"/about"</span><span class="p">)</span>\n<span class="k">def</span> <span class="nf">about</span><span class="p">():</span>\n <span class="k">return</span> <span class="n">render_template</span><span class="p">(</span><span class="s">"about.html"</span><span class="p">)</span>\n\n<span class="nd">@app.route</span><span class="p">(</span><span class="s">"/developers"</span><span class="p">)</span>\n<span class="k">def</span> <span class="nf">developers</span><span class="p">():</span>\n <span class="k">return</span> <span class="n">render_template</span><span class="p">(</span><span class="s">"developers.html"</span><span class="p">)</span>\n\n<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span>\n <span class="n">app</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">debug</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>\n</pre></div>\n</td></tr></table>' |
|
|
|
var codeExample = '<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre> 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40</pre></div></td><td class="code"><div class="highlight"><pre><span class="sd">"""</span>\n<span class="sd">Module to contain all the project's Flask server plumbing.</span>\n<span class="sd">"""</span>\n\n<span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">Flask</span>\n<span class="kn">from</span> <span class="nn">flask</span> <span class="kn">import</span> <span class="n">render_template</span><span class="p">,</span> <span class="n">session</span>\n\n<span class="kn">from</span> <span class="nn">bitshift</span> <span class="kn">import</span> <span class="n">assets</span>\n<span class="c"># from bitshift.database import Database</span>\n<span class="c"># from bitshift.query import parse_query</span>\n\n<span class="hll"><span class="n">app</span> <span class="o">=</span> <span class="n">Flask</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>\n</span><span class="hll"><span class="n">app</span><span class="o">.</span><span class="n">config</span><span class="o">.</span><span class="n">from_object</span><span class="p">(</span><span class="s">"bitshift.config"</span><span class="p">)</span>\n</span>\n<span class="hll"><span class="n">app_env</span> <span class="o">=</span> <span class="n">app</span><span class="o">.</span><span class="n">jinja_env</span>\n</span><span class="hll"><span class="n">app_env</span><span class="o">.</span><span class="n">line_statement_prefix</span> <span class="o">=</span> <span class="s">"="</span>\n</span><span class="hll"><span class="n">app_env</span><span class="o">.</span><span class="n">globals</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">assets</span><span class="o">=</span><span class="n">assets</span><span class="p">)</span>\n</span>\n<span class="c"># database = Database()</span>\n\n<span class="hll"><span class="nd">@app.route</span><span class="p">(</span><span class="s">"/"</span><span class="p">)</span>\n</span><span class="k">def</span> <span class="nf">index</span><span class="p">():</span>\n <span class="k">return</span> <span class="n">render_template</span><span class="p">(</span><span class="s">"index.html"</span><span class="p">)</span>\n\n<span class="hll"><span class="nd">@app.route</span><span class="p">(</span><span class="s">"/search/<query>"</span><span class="p">)</span>\n</span><span class="k">def</span> <span class="nf">search</span><span class="p">(</span><span class="n">query</span><span class="p">):</span>\n <span class="c"># tree = parse_query(query)</span>\n <span class="c"># database.search(tree)</span>\n <span class="k">pass</span>\n\n<span class="hll"><span class="nd">@app.route</span><span class="p">(</span><span class="s">"/about"</span><span class="p">)</span>\n</span><span class="k">def</span> <span class="nf">about</span><span class="p">():</span>\n <span class="k">return</span> <span class="n">render_template</span><span class="p">(</span><span class="s">"about.html"</span><span class="p">)</span>\n\n<span class="hll"><span class="nd">@app.route</span><span class="p">(</span><span class="s">"/developers"</span><span class="p">)</span>\n</span><span class="k">def</span> <span class="nf">developers</span><span class="p">():</span>\n <span class="k">return</span> <span class="n">render_template</span><span class="p">(</span><span class="s">"developers.html"</span><span class="p">)</span>\n\n<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">"__main__"</span><span class="p">:</span>\n<span class="hll"> <span class="n">app</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">debug</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>\n</span></pre></div>\n</td></tr></table>' |
|
|
|
searchBar.onkeyup = typingTimer; |
|
|
|
|
|
|
|
var testCodelet = { |
|
|
|
'url': 'https://github.com/earwig/bitshift/blob/develop/app.py', |
|
|
|
'filename': 'app.py', |
|
|
|
'language': 'Python', |
|
|
|
'language': 'python', |
|
|
|
'date_created': 'May 10, 2014', |
|
|
|
'date_modified': '2 days ago', |
|
|
|
'origin': ['GitHub', 'https://github.com', ''], |
|
|
@@ -43,17 +154,12 @@ var testCodelet = { |
|
|
|
// Enable infinite scrolling down the results page. |
|
|
|
$(window).scroll(function() { |
|
|
|
var searchField = $("div#search-field"); |
|
|
|
if($(window).scrollTop() + $(window).height() == $(document).height() && searchField.hasClass('partly-visible')){ |
|
|
|
if($(window).scrollTop() + $(window).height() == $(document).height() && |
|
|
|
searchField.hasClass('partly-visible')){ |
|
|
|
loadMoreResults(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
// Enable capturing the `enter` key. |
|
|
|
$("form#search-bar").submit(function(event){ |
|
|
|
event.preventDefault(); |
|
|
|
return false; |
|
|
|
}); |
|
|
|
|
|
|
|
/* |
|
|
|
* Clear the existing timer and set a new one the the user types text into the |
|
|
|
* search bar. |
|
|
@@ -109,6 +215,7 @@ function clearResults(){ |
|
|
|
* with its response. |
|
|
|
*/ |
|
|
|
function populateResults(){ |
|
|
|
searchResultsPage = 1; |
|
|
|
var results = queryServer(); |
|
|
|
|
|
|
|
for(var result = 0; result < results.length; result++){ |
|
|
@@ -135,74 +242,108 @@ function createResult(codelet) { |
|
|
|
row = document.createElement("tr"); |
|
|
|
//Level 2 |
|
|
|
var displayInfo = document.createElement("div"), |
|
|
|
sidebar = document.createElement("td"), |
|
|
|
codeElt = document.createElement("td"), |
|
|
|
displayButton = document.createElement("td"), |
|
|
|
hiddenInfoContainer = document.createElement("td"), |
|
|
|
hiddenInfo = document.createElement("div"); |
|
|
|
hiddenInfo = document.createElement("div"), |
|
|
|
cycle = document.createElement("div"); |
|
|
|
//Level 3 |
|
|
|
var title = document.createElement("span"), |
|
|
|
site = document.createElement("span"), |
|
|
|
dateModified = document.createElement("span"), |
|
|
|
language = document.createElement("span"), |
|
|
|
dateCreated = document.createElement("span"), |
|
|
|
nextMatch = document.createElement("a"), |
|
|
|
prevMatch = document.createElement("a"), |
|
|
|
dateModified = document.createElement("div"), |
|
|
|
language = document.createElement("div"), |
|
|
|
dateCreated = document.createElement("div"), |
|
|
|
authors = document.createElement("div"); |
|
|
|
|
|
|
|
//Classes and ID's |
|
|
|
newDiv.classList.add('result'); |
|
|
|
|
|
|
|
displayInfo.id = 'display-info'; |
|
|
|
sidebar.id = 'sidebar'; |
|
|
|
codeElt.id = 'code'; |
|
|
|
displayButton.id = 'display-button'; |
|
|
|
hiddenInfo.id = 'hidden-info'; |
|
|
|
cycle.id = 'cycle-matches' |
|
|
|
|
|
|
|
title.id = 'title'; |
|
|
|
site.id = 'site'; |
|
|
|
nextMatch.id = 'next-match'; |
|
|
|
nextMatch.href = '#'; |
|
|
|
prevMatch.id = 'prev-match'; |
|
|
|
prevMatch.href = '#'; |
|
|
|
dateModified.id = 'date-modified'; |
|
|
|
language.id = 'language'; |
|
|
|
dateCreated.id = 'date-created'; |
|
|
|
authors.id = 'authors'; |
|
|
|
|
|
|
|
//Add the bulk of the html |
|
|
|
title.innerHTML = 'File <a href="' + codelet.url + '">' |
|
|
|
title.innerHTML = ' » <a href="' + codelet.url + '">' |
|
|
|
+ codelet.filename + '</a>'; |
|
|
|
site.innerHTML = 'on <a href="' + codelet.origin[1] + '">' + codelet.origin[0] +'</a>'; |
|
|
|
dateModified.innerHTML = 'Last modified ' + codelet.date_modified; |
|
|
|
site.innerHTML = '<a href="' + codelet.origin[1] + '">' + codelet.origin[0] +'</a>'; |
|
|
|
nextMatch.innerHTML = 'next match'; |
|
|
|
prevMatch.innerHTML = 'prev match'; |
|
|
|
language.innerHTML = 'Language: <span>' + codelet.language + '</span>'; |
|
|
|
dateModified.innerHTML = 'Last modified: <span>' + codelet.date_modified + '</span>'; |
|
|
|
// Needs to be changed from int to string on the server |
|
|
|
language.innerHTML = codelet.language; |
|
|
|
dateCreated.innerHTML = 'Created ' + codelet.date_created; |
|
|
|
authors.innerHTML = 'Authors: '; |
|
|
|
$.each(codelet.authors, function(i, a) { |
|
|
|
authors.innerHTML += '<a href=#>' + a + ' </a>'; |
|
|
|
dateCreated.innerHTML = 'Created: <span>' + codelet.date_created + '</span>'; |
|
|
|
|
|
|
|
var authorsHtml = 'Authors: <span>'; |
|
|
|
codelet.authors.forEach(function(a, i) { |
|
|
|
if (i == codelet.authors.length - 1) |
|
|
|
authorsHtml += '<a href=#>' + a + ' </a>'; |
|
|
|
else |
|
|
|
authorsHtml += '<a href=#>' + a + ' </a>, '; |
|
|
|
}); |
|
|
|
authors.innerHTML = authorsHtml; |
|
|
|
|
|
|
|
sidebar.innerHTML = ''; |
|
|
|
// Needs to be processed on the server |
|
|
|
codeElt.innerHTML = '<div id=tablecontainer>' + codelet.html_code + '</div>'; |
|
|
|
|
|
|
|
//Event binding |
|
|
|
$(displayButton).click(function(e) { |
|
|
|
$(hiddenInfo).toggleClass('visible'); |
|
|
|
$(this).toggleClass('active'); |
|
|
|
$(newDiv).on('mousemove', function(e) { |
|
|
|
var holdCondition = $('.disable-hover'); |
|
|
|
|
|
|
|
if(holdCondition.length == 0) { |
|
|
|
$(this).siblings().removeClass('display-all'); |
|
|
|
$(this).addClass('display-all'); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
$(newDiv).on('mouseleave', function(e) { |
|
|
|
var holdCondition = $('.disable-hover'); |
|
|
|
|
|
|
|
if(holdCondition.length == 0) |
|
|
|
$(this).removeClass('display-all'); |
|
|
|
}); |
|
|
|
|
|
|
|
$(nextMatch).click(function(e) { |
|
|
|
e.stopPropagation(); |
|
|
|
e.preventDefault(); |
|
|
|
nextSymbolMatch(); |
|
|
|
}); |
|
|
|
|
|
|
|
$(prevMatch).click(function(e) { |
|
|
|
e.stopPropagation(); |
|
|
|
e.preventDefault(); |
|
|
|
previousSymbolMatch(); |
|
|
|
}); |
|
|
|
|
|
|
|
//Finish and append elements to parent elements |
|
|
|
hiddenInfo.appendChild(dateCreated); |
|
|
|
hiddenInfo.appendChild(dateModified); |
|
|
|
hiddenInfo.appendChild(authors); |
|
|
|
hiddenInfo.appendChild(language); |
|
|
|
hiddenInfo.appendChild(authors); |
|
|
|
|
|
|
|
hiddenInfoContainer.appendChild(hiddenInfo); |
|
|
|
|
|
|
|
row.appendChild(sidebar); |
|
|
|
row.appendChild(codeElt); |
|
|
|
row.appendChild(hiddenInfoContainer); |
|
|
|
row.appendChild(displayButton); |
|
|
|
table.appendChild(row); |
|
|
|
|
|
|
|
displayInfo.appendChild(title); |
|
|
|
displayInfo.appendChild(site); |
|
|
|
displayInfo.appendChild(title); |
|
|
|
|
|
|
|
cycle.appendChild(prevMatch); |
|
|
|
cycle.appendChild(nextMatch); |
|
|
|
|
|
|
|
newDiv.appendChild(displayInfo); |
|
|
|
newDiv.appendChild(table); |
|
|
@@ -210,6 +351,52 @@ function createResult(codelet) { |
|
|
|
return newDiv; |
|
|
|
} |
|
|
|
|
|
|
|
function previousSymbolMatch() { |
|
|
|
var currResult = $(".display-all"), |
|
|
|
currMatch = currResult.find(".hll.current"), |
|
|
|
matches = currResult.find(".hll"), |
|
|
|
scrollDiv = currResult.find("#tablecontainer"); |
|
|
|
|
|
|
|
if (currMatch.length == 0) |
|
|
|
currMatch = matches[0]; |
|
|
|
else |
|
|
|
currMatch.removeClass('current'); |
|
|
|
|
|
|
|
var index = matches.index(currMatch.get(0)) - 1; |
|
|
|
index = index <= 0 ? matches.length - 1 : index; |
|
|
|
var newMatch = $(matches[index]); |
|
|
|
|
|
|
|
scrollDiv.scrollTop(scrollDiv.scrollTop() |
|
|
|
- scrollDiv.height() / 2 |
|
|
|
+ newMatch.position().top + newMatch.height() / 2); |
|
|
|
|
|
|
|
newMatch.effect("highlight", {color: '#FFF'}, 750) |
|
|
|
newMatch.addClass('current'); |
|
|
|
}; |
|
|
|
|
|
|
|
function nextSymbolMatch() { |
|
|
|
var currResult = $(".display-all"), |
|
|
|
currMatch = currResult.find(".hll.current"), |
|
|
|
matches = currResult.find(".hll"), |
|
|
|
scrollDiv = currResult.find("#tablecontainer"); |
|
|
|
|
|
|
|
if (currMatch.length == 0) |
|
|
|
currMatch = $(matches[0]); |
|
|
|
else |
|
|
|
currMatch.removeClass("current"); |
|
|
|
|
|
|
|
var index = matches.index(currMatch.get(0)) + 1; |
|
|
|
index = index >= matches.length ? 0 : index; |
|
|
|
var newMatch = $(matches[index]); |
|
|
|
|
|
|
|
scrollDiv.scrollTop(scrollDiv.scrollTop() |
|
|
|
- scrollDiv.height() / 2 |
|
|
|
+ newMatch.position().top + newMatch.height() / 2); |
|
|
|
|
|
|
|
newMatch.effect("highlight", {color: "#FFF"}, 750) |
|
|
|
newMatch.addClass("current"); |
|
|
|
}; |
|
|
|
|
|
|
|
/* |
|
|
|
* AJAX the current query string to the server, and return its response. |
|
|
|
* |
|
|
@@ -217,10 +404,23 @@ function createResult(codelet) { |
|
|
|
* elements, to fill `div#results`. |
|
|
|
*/ |
|
|
|
function queryServer(){ |
|
|
|
var resultDivs = [] |
|
|
|
var queryUrl = document.URL + "search.json?" + $.param({ |
|
|
|
"q" : searchBar.value, |
|
|
|
"p" : searchResultsPage++ |
|
|
|
}); |
|
|
|
|
|
|
|
var resultDivs = []; |
|
|
|
$.getJSON(queryUrl, function(result){ |
|
|
|
if("error" in result) |
|
|
|
insertErrorMessage(result["error"]); |
|
|
|
else |
|
|
|
for(var codelet = 0; codelet < result["results"].length; codelet++) |
|
|
|
resultDivs.push(result["results"][codelet]); |
|
|
|
}); |
|
|
|
|
|
|
|
for(var result = 0; result < 20; result++){ |
|
|
|
var newDiv = createResult(testCodelet); |
|
|
|
resultDivs.push(newDiv); |
|
|
|
resultDivs.push(newDiv) |
|
|
|
} |
|
|
|
|
|
|
|
return resultDivs; |
|
|
@@ -230,7 +430,7 @@ function queryServer(){ |
|
|
|
* Adds more results to `div#results`. |
|
|
|
*/ |
|
|
|
function loadMoreResults(){ |
|
|
|
results = queryServer(); |
|
|
|
var results = queryServer(); |
|
|
|
for(var result = 0; result < results.length; result++){ |
|
|
|
var newDiv = results[result]; |
|
|
|
resultsDiv.appendChild(newDiv); |
|
|
@@ -243,3 +443,16 @@ function loadMoreResults(){ |
|
|
|
result * 20); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
|
* Displays a warning message in the UI. |
|
|
|
* |
|
|
|
* @param msg (str) The message string. |
|
|
|
*/ |
|
|
|
function insertErrorMessage(msg){ |
|
|
|
var error = $("<div id='error'><span>Error: </span></div>"); |
|
|
|
error.append(msg); |
|
|
|
resultsDiv.appendChild(error[0]); |
|
|
|
} |
|
|
|
|
|
|
|
// loadMoreResults(); |