mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-19 17:15:24 +00:00
Add base from clarity theme from @Nijikokun
This commit is contained in:
Regular → Executable
+11
-16
@@ -7,14 +7,16 @@ require([
|
||||
"core/state",
|
||||
"core/keyboard",
|
||||
"core/exercise",
|
||||
"core/quiz",
|
||||
"core/progress",
|
||||
"core/sidebar",
|
||||
"core/search"
|
||||
], function($, storage, analytic, sharing, state, keyboard, exercise, quiz, progress, sidebar, search){
|
||||
], function($, storage, analytic, sharing, state, keyboard, exercise, progress, sidebar, search){
|
||||
$(document).ready(function() {
|
||||
var $book = state.$book;
|
||||
|
||||
// Initialize storage
|
||||
storage.setBaseKey(state.githubId);
|
||||
|
||||
// Init sidebar
|
||||
sidebar.init();
|
||||
|
||||
@@ -24,21 +26,14 @@ require([
|
||||
// Init keyboard
|
||||
keyboard.init();
|
||||
|
||||
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);
|
||||
});
|
||||
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
|
||||
// Bind exercises
|
||||
// Bind exercise
|
||||
exercise.init();
|
||||
quiz.init();
|
||||
|
||||
// Bind sharing button
|
||||
sharing.init();
|
||||
@@ -49,4 +44,4 @@ require([
|
||||
// Focus on content
|
||||
$(".book-body").focus();
|
||||
});
|
||||
});
|
||||
});
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
+60
-6
@@ -1,15 +1,69 @@
|
||||
define([
|
||||
"jQuery"
|
||||
], function($) {
|
||||
"jQuery",
|
||||
"core/progress"
|
||||
], function($, progress) {
|
||||
var prev, next;
|
||||
|
||||
// Prevent cache so that using the back button works
|
||||
// See: http://stackoverflow.com/a/15805399/983070
|
||||
$.ajaxSetup({
|
||||
cache: false
|
||||
});
|
||||
|
||||
// Recreate first page when the page loads.
|
||||
history.replaceState({ path: window.location.href }, '');
|
||||
|
||||
// Back Button Hijacking :(
|
||||
window.onpopstate = function (event) {
|
||||
if (event.state === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
return handleNavigation(event.state.path, false);
|
||||
};
|
||||
|
||||
function updateHistory (url, title) {
|
||||
history.pushState({ path: url }, title, url);
|
||||
}
|
||||
|
||||
function handleNavigation (url, push) {
|
||||
if (typeof history.pushState === "undefined") {
|
||||
// Refresh the page to the new URL if pushState not supported
|
||||
location.href = url;
|
||||
}
|
||||
|
||||
return $.get(url).done(function (data) {
|
||||
$('.book-body').html($(data).find('.book-body').html());
|
||||
$('.book-summary').html($(data).find('.book-summary').html());
|
||||
if (push) updateHistory(url, null);
|
||||
progress.show();
|
||||
}).fail(function () {
|
||||
location.href = url;
|
||||
});
|
||||
}
|
||||
|
||||
var handlePagination = function (e) {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
|
||||
var url = $(this).attr('href');
|
||||
if (url) handleNavigation(url, true);
|
||||
};
|
||||
|
||||
var goNext = function() {
|
||||
var url = $("link[rel='next']").attr("href");
|
||||
if (url) location.href = url;
|
||||
var url = $(".navigation-next").attr("href");
|
||||
if (url) handleNavigation(url, true);
|
||||
};
|
||||
|
||||
var goPrev = function() {
|
||||
var url = $("link[rel='prev']").attr("href");
|
||||
if (url) location.href = url;
|
||||
var url = $(".navigation-prev").attr("href");
|
||||
if (url) handleNavigation(url, true);
|
||||
};
|
||||
|
||||
$(document).on('click', ".navigation-prev", handlePagination);
|
||||
$(document).on('click', ".navigation-next", handlePagination);
|
||||
$(document).on('click', ".summary [data-path] a", handlePagination);
|
||||
|
||||
return {
|
||||
goNext: goNext,
|
||||
goPrev: goPrev
|
||||
|
||||
Regular → Executable
+18
-11
@@ -10,15 +10,16 @@ define([
|
||||
};
|
||||
|
||||
// Return all levels
|
||||
var getLevels = function() {
|
||||
var getLevels = function () {
|
||||
var levels = $(".book-summary li[data-level]");
|
||||
|
||||
return _.map(levels, function(level) {
|
||||
return $(level).data("level").toString();
|
||||
});
|
||||
};
|
||||
|
||||
// Return a map chapter -> number (timestamp)
|
||||
var getProgress = function() {
|
||||
var getProgress = function () {
|
||||
// Current level
|
||||
var progress = storage.get("progress", {});
|
||||
|
||||
@@ -33,27 +34,33 @@ define([
|
||||
};
|
||||
|
||||
// Change value of progress for a level
|
||||
var markProgress = function(level, state) {
|
||||
if (state == null) state = true;
|
||||
|
||||
var markProgress = function (level, state) {
|
||||
var progress = getProgress();
|
||||
progress[level] = state? Date.now() : 0;
|
||||
|
||||
if (state == null) {
|
||||
state = true;
|
||||
}
|
||||
|
||||
progress[level] = state
|
||||
? Date.now()
|
||||
: 0;
|
||||
|
||||
storage.set("progress", progress);
|
||||
};
|
||||
|
||||
// Show progress
|
||||
var showProgress = function() {
|
||||
// Update progress
|
||||
var showProgress = function () {
|
||||
var progress = getProgress();
|
||||
var $summary = $(".book-summary");
|
||||
|
||||
_.each(progress, function(value, level) {
|
||||
_.each(progress, function (value, level) {
|
||||
$summary.find("li[data-level='"+level+"']").toggleClass("done", value > 0);
|
||||
});
|
||||
|
||||
// Mark current progress
|
||||
markProgress(getCurrentLevel(), true);
|
||||
// Mark current progress if we have not already
|
||||
if (!progress[getCurrentLevel()]) {
|
||||
markProgress(getCurrentLevel(), true);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
define([
|
||||
"jQuery",
|
||||
"utils/execute",
|
||||
"utils/analytic",
|
||||
"core/state"
|
||||
], function($, execute, analytic, state){
|
||||
// Bind an exercise
|
||||
var prepareExercise = function($exercise) {
|
||||
|
||||
$exercise.find(".quiz-answers input").click(function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
// Submit: test code
|
||||
$exercise.find(".action-submit").click(function(e) {
|
||||
e.preventDefault();
|
||||
analytic.track("exercise.submit");
|
||||
$exercise.find("tr.alert-danger,li.alert-danger").removeClass("alert-danger");
|
||||
$exercise.find(".alert-success,.alert-danger").addClass("hidden");
|
||||
|
||||
$exercise.find(".quiz").each(function(q) {
|
||||
var result = true;
|
||||
var $answers = $exercise.find(".quiz-answers").slice(q).find("input[type=radio], input[type=checkbox]");
|
||||
$(this).find("input[type=radio],input[type=checkbox]").each(function(i) {
|
||||
var correct = $(this).is(":checked") === $answers.slice(i).first().is(":checked");
|
||||
result = result && correct;
|
||||
if (!correct) {
|
||||
$(this).closest("tr, li").addClass("alert-danger");
|
||||
}
|
||||
});
|
||||
$(this).find(result ? "div.alert-success" : "div.alert-danger").toggleClass("hidden");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$exercise.find(".action-solution").click(function(e) {
|
||||
$exercise.find(".quiz, .quiz-answers").toggleClass("hidden");
|
||||
});
|
||||
};
|
||||
|
||||
// Prepare all exercise
|
||||
var init = function() {
|
||||
state.$book.find("section.quiz").each(function() {
|
||||
prepareExercise($(this));
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
init: init,
|
||||
prepare: prepareExercise
|
||||
};
|
||||
});
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
+5
-5
@@ -4,11 +4,11 @@ define([
|
||||
var $book = $(".book");
|
||||
|
||||
return {
|
||||
'$book': $book,
|
||||
'$book': $book,
|
||||
|
||||
'githubId': $book.data("github"),
|
||||
'level': $book.data("level"),
|
||||
'basePath': $book.data("basepath"),
|
||||
'revision': $book.data("revision")
|
||||
'githubId': $book.data("github"),
|
||||
'level': $book.data("level"),
|
||||
'basePath': $book.data("basepath"),
|
||||
'revision': $book.data("revision")
|
||||
};
|
||||
});
|
||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Reference in New Issue
Block a user