diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-14 16:29:02 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-14 16:29:02 +0200 |
commit | 6da48764e89dc7cdf050126624ea23ba1dad5d76 (patch) | |
tree | d8a88d51b7f71019a10689af09e0b9776ee709e1 /theme/javascript/core | |
parent | 8c4cfed6092f69df81e1999944638595e03edb9c (diff) | |
download | gitbook-6da48764e89dc7cdf050126624ea23ba1dad5d76.zip gitbook-6da48764e89dc7cdf050126624ea23ba1dad5d76.tar.gz gitbook-6da48764e89dc7cdf050126624ea23ba1dad5d76.tar.bz2 |
Fix header interractive actions: buttons and github
Diffstat (limited to 'theme/javascript/core')
-rwxr-xr-x | theme/javascript/core/navigation.js | 23 | ||||
-rwxr-xr-x | theme/javascript/core/search.js | 2 | ||||
-rwxr-xr-x | theme/javascript/core/sidebar.js | 2 |
3 files changed, 24 insertions, 3 deletions
diff --git a/theme/javascript/core/navigation.js b/theme/javascript/core/navigation.js index 2a6d1df..31a7cd6 100755 --- a/theme/javascript/core/navigation.js +++ b/theme/javascript/core/navigation.js @@ -1,10 +1,12 @@ define([ "jQuery", + "core/state", "core/progress", "core/exercise", "core/quiz" -], function($, progress, exercises, quiz) { +], function($, state, progress, exercises, quiz) { var prev, next; + var githubCountStars, githubCountWatch; var updateHistory = function(url, title) { history.pushState({ path: url }, title, url); @@ -39,6 +41,11 @@ define([ }); }; + var updateGitHubCounts = function() { + $(".book-header .count-star span").text(githubCountStars); + $(".book-header .count-watch span").text(githubCountWatch); + } + var preparePage = function() { // Bind exercises/quiz exercises.init(); @@ -52,6 +59,20 @@ define([ // Focus on content $(".book-body").focus(); + + // Update GitHub count + if (state.githubId) { + if (githubCountStars) { + updateGitHubCounts(); + } else { + $.getJSON("https://api.github.com/repos/"+state.githubId) + .done(function(repo) { + githubCountStars = repo.stargazers_count; + githubCountWatch = repo.subscribers_count; + updateGitHubCounts(); + }); + } + } }; var handlePagination = function (e) { diff --git a/theme/javascript/core/search.js b/theme/javascript/core/search.js index 4171660..d8ddc2e 100755 --- a/theme/javascript/core/search.js +++ b/theme/javascript/core/search.js @@ -64,7 +64,7 @@ define([ loadIndex(); // Toggle search - state.$book.find(".book-header .toggle-search").click(function(e) { + $(document).on("click", ".book-header .toggle-search", function(e) { e.preventDefault(); toggleSearch(); }); diff --git a/theme/javascript/core/sidebar.js b/theme/javascript/core/sidebar.js index d318676..0d09b58 100755 --- a/theme/javascript/core/sidebar.js +++ b/theme/javascript/core/sidebar.js @@ -25,7 +25,7 @@ define([ // Prepare sidebar: state and toggle button var init = function() { // Toggle summary - state.$book.find(".book-header .toggle-summary").click(function(e) { + $(document).on("click", ".book-header .toggle-summary", function(e) { e.preventDefault(); toggleSidebar(); }); |