diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-08-05 09:44:54 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-08-05 09:44:54 -0700 |
commit | 388c7ffd3270038a544f88bea69b5b9428557411 (patch) | |
tree | 0b64c748d9bd1a3cbe9884e75ab481498a67dab2 | |
parent | a4403aad1e9fc74cfe8e5129b04ebfe39a1c927f (diff) | |
parent | 7ba86539350937fea170586a744ab955cb99be57 (diff) | |
download | gitbook-388c7ffd3270038a544f88bea69b5b9428557411.zip gitbook-388c7ffd3270038a544f88bea69b5b9428557411.tar.gz gitbook-388c7ffd3270038a544f88bea69b5b9428557411.tar.bz2 |
Merge pull request #396 from codepiano/hold-search-keyword
keep the search result list after user click a link
-rwxr-xr-x | theme/javascript/core/navigation.js | 10 | ||||
-rwxr-xr-x | theme/javascript/core/search.js | 20 |
2 files changed, 25 insertions, 5 deletions
diff --git a/theme/javascript/core/navigation.js b/theme/javascript/core/navigation.js index c1018e0..bcf7e65 100755 --- a/theme/javascript/core/navigation.js +++ b/theme/javascript/core/navigation.js @@ -6,8 +6,9 @@ define([ "core/progress", "core/exercise", "core/quiz", - "core/loading" -], function($, URL, events, state, progress, exercises, quiz, loading) { + "core/loading", + "core/search" +], function($, URL, events, state, progress, exercises, quiz, loading, search) { var prev, next; var usePushState = (typeof history.pushState !== "undefined"); @@ -55,6 +56,8 @@ define([ // Update state state.update($("html")); + // recover search keyword + search.recover(); preparePage(); }) .fail(function (e) { @@ -146,4 +149,5 @@ define([ goNext: goNext, goPrev: goPrev }; -});
\ No newline at end of file +}); + 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 +}); |