diff options
Diffstat (limited to 'theme/javascript/core')
-rw-r--r-- | theme/javascript/core/exercise.js | 2 | ||||
-rw-r--r-- | theme/javascript/core/progress.js | 2 | ||||
-rw-r--r-- | theme/javascript/core/sidebar.js | 28 | ||||
-rw-r--r-- | theme/javascript/core/state.js | 12 |
4 files changed, 23 insertions, 21 deletions
diff --git a/theme/javascript/core/exercise.js b/theme/javascript/core/exercise.js index db278b8..f890f2a 100644 --- a/theme/javascript/core/exercise.js +++ b/theme/javascript/core/exercise.js @@ -38,7 +38,7 @@ define([ // Prepare all exercise var init = function() { - state().$book.find("section.exercise").each(function() { + state.$book.find("section.exercise").each(function() { prepareExercise($(this)); }); }; diff --git a/theme/javascript/core/progress.js b/theme/javascript/core/progress.js index 755f111..d074cae 100644 --- a/theme/javascript/core/progress.js +++ b/theme/javascript/core/progress.js @@ -6,7 +6,7 @@ define([ ], function(_, $, storage, state) { // Get current level var getCurrentLevel = function() { - return state().level; + return state.level; }; // Return all levels diff --git a/theme/javascript/core/sidebar.js b/theme/javascript/core/sidebar.js index 27a0abd..88ab639 100644 --- a/theme/javascript/core/sidebar.js +++ b/theme/javascript/core/sidebar.js @@ -4,15 +4,17 @@ define([ "core/state", "core/search" ], function(storage, platform, state, search) { + var $summary = state.$book.find(".book-summary"); + var $searchInput = $summary.find(".book-search input") + // Toggle sidebar with or withour animation var toggleSidebar = function(_state, animation) { if (state != null && isOpen() == _state) return; if (animation == null) animation = true; - var $book = state().$book; - $book.toggleClass("without-animation", !animation); - $book.toggleClass("with-summary", _state); + state.$book.toggleClass("without-animation", !animation); + state.$book.toggleClass("with-summary", _state); storage.set("sidebar", isOpen()); }; @@ -21,29 +23,31 @@ define([ var toggleSearch = function(_state) { if (state != null && isSearchOpen() == _state) return; - var $summary = state().$book.find(".book-summary"); + $summary.toggleClass("with-search", _state); // If search bar is open: focus input - if (isSearchOpen()) $summary.find(".book-search input").focus(); + if (isSearchOpen()) { + $searchInput.focus(); + } else { + + } }; // Return true if sidebar is open var isOpen = function() { - return state().$book.hasClass("with-summary"); + return state.$book.hasClass("with-summary"); }; // Return true if search bar is open var isSearchOpen = function() { - return state().$book.find(".book-summary").hasClass("with-search"); + return $summary.hasClass("with-search"); }; // Prepare sidebar: state and toggle button var init = function() { - var $book = state().$book; - // Toggle summary - $book.find(".book-header .toggle-summary").click(function(e) { + state.$book.find(".book-header .toggle-summary").click(function(e) { e.preventDefault(); toggleSidebar(); }); @@ -54,12 +58,12 @@ define([ } // Toggle search - $book.find(".book-header .toggle-search").click(function(e) { + state.$book.find(".book-header .toggle-search").click(function(e) { e.preventDefault(); toggleSearch(); }); - $book.find(".book-summary .book-search input").keyup(function(e) { + $searchInput.keyup(function(e) { var key = (e.keyCode ? e.keyCode : e.which); var q = $(this).val(); diff --git a/theme/javascript/core/state.js b/theme/javascript/core/state.js index fc67d7b..b219f5d 100644 --- a/theme/javascript/core/state.js +++ b/theme/javascript/core/state.js @@ -1,14 +1,12 @@ define([ "jQuery" ], function() { - return function() { - var $book = $(".book"); + var $book = $(".book"); - return { - '$book': $book, + return { + '$book': $book, - 'githubId': $book.data("github"), - 'level': $book.data("level") - }; + 'githubId': $book.data("github"), + 'level': $book.data("level") }; });
\ No newline at end of file |