summaryrefslogtreecommitdiffstats
path: root/theme/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'theme/javascript')
-rwxr-xr-xtheme/javascript/app.js7
-rwxr-xr-xtheme/javascript/core/navigation.js23
-rwxr-xr-xtheme/javascript/core/search.js2
-rwxr-xr-xtheme/javascript/core/sidebar.js2
-rwxr-xr-xtheme/javascript/utils/sharing.js2
5 files changed, 25 insertions, 11 deletions
diff --git a/theme/javascript/app.js b/theme/javascript/app.js
index 6cf4120..38a9572 100755
--- a/theme/javascript/app.js
+++ b/theme/javascript/app.js
@@ -17,13 +17,6 @@ require([
if (state.githubId) {
// Initialize storage
storage.setBaseKey(state.githubId);
-
- // Star and watch count
- $.getJSON("https://api.github.com/repos/"+state.githubId)
- .done(function(repo) {
- $book.find(".count-star span").text(repo.stargazers_count);
- $book.find(".count-watch span").text(repo.subscribers_count);
- });
}
// Init sidebar
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();
});
diff --git a/theme/javascript/utils/sharing.js b/theme/javascript/utils/sharing.js
index f4354f1..caf97fb 100755
--- a/theme/javascript/utils/sharing.js
+++ b/theme/javascript/utils/sharing.js
@@ -19,7 +19,7 @@ define([
// Bind all sharing button
var init = function() {
- $("a[data-sharing]").click(function(e) {
+ $(document).on("click", "a[data-sharing]", function(e) {
if (e) e.preventDefault();
var type = $(this).data("sharing");