Browse Source

Fix #23. Slightly index.js refactor.

Add:
    static/js/index.js
        -Fix #23.
        -Move callbacks to an function that gets executed on definition, for
        more aesthetically modular code.

Rem:
    static/js/lib/typeahead.bundle.min.js
        -Remove the `typeahead` plugin, which is not longer used for
        autocompletion.
tags/v1.0^2
Severyn Kozak 10 years ago
parent
commit
c8cc7d7ecf
4 changed files with 38 additions and 39 deletions
  1. +1
    -1
      app.py
  2. +36
    -29
      static/js/index.js
  3. +0
    -7
      static/js/lib/typeahead.bundle.min.js
  4. +1
    -2
      templates/index.html

+ 1
- 1
app.py View File

@@ -21,7 +21,7 @@ app_env.globals.update(assets=assets)

@app.route("/")
def index():
return render_template("index.html", typeahead_languages=languages.LANGS)
return render_template("index.html", autocomplete_languages=languages.LANGS)

@app.route("/search/<query>")
def search(query):


+ 36
- 29
static/js/index.js View File

@@ -5,40 +5,47 @@

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;
searchBar = $("form#search-bar input[type='text']")[0];
resultsDiv = $("div#results")[0];
var searchBar = $("form#search-bar input[type='text']")[0];
var resultsDiv = $("div#results")[0];

var typingTimer, lastValue;
searchBar.onkeyup = typingTimer;

// Enable infinite scrolling down the results page.
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()){
loadMoreResults();
}
});
/*
* Set all page callbacks.
*/
(function setHomePageCallbabacks(){
// Enable infinite scrolling down the results page.
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() == $(document).height() &&
resultsDiv.querySelectorAll(".result").length > 0)
loadMoreResults();
});

// 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;
});

// Enable capturing the `enter` key.
$("form#search-bar").submit(function(event){
event.preventDefault();
return false;
});
searchBar.onkeyup = typingTimer;
}());

/*
* Clear the existing timer and set a new one the the user types text into the


+ 0
- 7
static/js/lib/typeahead.bundle.min.js
File diff suppressed because it is too large
View File


+ 1
- 2
templates/index.html View File

@@ -8,7 +8,6 @@
{{ assets.tag("lib/jqueryui.custom.min.css") }}
{{ assets.tag("lib/jquery.min.js") }}
{{ assets.tag("lib/jquery-ui.min.js") }}
{{ assets.tag("lib/typeahead.bundle.min.js") }}

{{ assets.tag("index.css") }}

@@ -29,7 +28,7 @@

<form id="search-bar">
<input type="text" name="query"
><button id="advanced-search" title="advanced search">
><button id="advanced-search" title="advanced search" type="button">
<img src="static/img/search_bar_magnifying_glass.png">
</button>



Loading…
Cancel
Save