Quellcode durchsuchen

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 vor 10 Jahren
Ursprung
Commit
c8cc7d7ecf
4 geänderte Dateien mit 38 neuen und 39 gelöschten Zeilen
  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 Datei anzeigen

@@ -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 Datei anzeigen

@@ -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
Datei-Diff unterdrückt, da er zu groß ist
Datei anzeigen


+ 1
- 2
templates/index.html Datei anzeigen

@@ -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>



Laden…
Abbrechen
Speichern