mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-17 16:15:22 +00:00
Fix header interractive actions: buttons and github
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user