summaryrefslogtreecommitdiffstats
path: root/theme/javascript/core/search.js
diff options
context:
space:
mode:
authorcodepiano <codepiano.li@gmail.com>2014-08-04 17:04:31 +0800
committercodepiano <codepiano.li@gmail.com>2014-08-05 15:14:10 +0800
commit7ba86539350937fea170586a744ab955cb99be57 (patch)
treed564b2b269d1cac89628d8bbf775022679016330 /theme/javascript/core/search.js
parent5692bdd229020f5b01ca9b24658d6a7b253b6515 (diff)
downloadgitbook-7ba86539350937fea170586a744ab955cb99be57.zip
gitbook-7ba86539350937fea170586a744ab955cb99be57.tar.gz
gitbook-7ba86539350937fea170586a744ab955cb99be57.tar.bz2
keep the search result list after user click a link
Record search keyword to LocalStorage, when navigate to a new url,fetch keyword from LocalStorage, init the search input element,then filter the sidebar menu. So User can iterator the result list without type the keyword every time.
Diffstat (limited to 'theme/javascript/core/search.js')
-rwxr-xr-xtheme/javascript/core/search.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/theme/javascript/core/search.js b/theme/javascript/core/search.js
index f17f746..4cbc3ed 100755
--- a/theme/javascript/core/search.js
+++ b/theme/javascript/core/search.js
@@ -81,18 +81,34 @@ define([
}
if (q.length == 0) {
sidebar.filter(null);
+ storage.remove("keyword");
} else {
var results = search(q);
sidebar.filter(
_.pluck(results, "path")
);
+ storage.set("keyword", q);
}
})
+
+ };
+
+ // filter sidebar menu with current search keyword
+ var recoverSearch = function() {
+ var keyword = storage.get("keyword", "");
+ if(keyword.length > 0) {
+ if(!isSearchOpen()){
+ toggleSearch();
+ }
+ sidebar.filter(_.pluck(search(keyword), "path"));
+ }
+ $(".book-search input").val(keyword);
};
return {
init: init,
search: search,
- toggle: toggleSearch
+ toggle: toggleSearch,
+ recover:recoverSearch
};
-}); \ No newline at end of file
+});