Fix header interractive actions: buttons and github

This commit is contained in:
Samy Pessé
2014-04-14 16:29:02 +02:00
parent 8c4cfed609
commit 6da48764e8
6 changed files with 26 additions and 12 deletions
-7
View File
@@ -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
+22 -1
View File
@@ -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) {
+1 -1
View File
@@ -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();
});
+1 -1
View File
@@ -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();
});
+1 -1
View File
@@ -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");