浏览代码

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 年前
父节点
当前提交
c8cc7d7ecf
共有 4 个文件被更改,包括 38 次插入39 次删除
  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 查看文件

@@ -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 查看文件

@@ -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
文件差异内容过多而无法显示
查看文件


+ 1
- 2
templates/index.html 查看文件

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



正在加载...
取消
保存