summaryrefslogtreecommitdiffstats
path: root/theme/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'theme/javascript')
-rwxr-xr-x[-rw-r--r--]theme/javascript/app.js27
-rwxr-xr-x[-rw-r--r--]theme/javascript/core/exercise.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/core/keyboard.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/core/navigation.js66
-rwxr-xr-x[-rw-r--r--]theme/javascript/core/progress.js29
-rw-r--r--theme/javascript/core/quiz.js52
-rwxr-xr-x[-rw-r--r--]theme/javascript/core/search.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/core/sidebar.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/core/state.js10
-rwxr-xr-x[-rw-r--r--]theme/javascript/execute/javascript.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/utils/execute.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/utils/platform.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/utils/sharing.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/utils/storage.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/vendors/jquery.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/vendors/lodash.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/vendors/mixpanel.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/vendors/mousetrap.js0
-rwxr-xr-x[-rw-r--r--]theme/javascript/vendors/require.js0
19 files changed, 94 insertions, 90 deletions
diff --git a/theme/javascript/app.js b/theme/javascript/app.js
index f18ae24..3638092 100644..100755
--- a/theme/javascript/app.js
+++ b/theme/javascript/app.js
@@ -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();
});
-});
+}); \ No newline at end of file
diff --git a/theme/javascript/core/exercise.js b/theme/javascript/core/exercise.js
index 5219546..5219546 100644..100755
--- a/theme/javascript/core/exercise.js
+++ b/theme/javascript/core/exercise.js
diff --git a/theme/javascript/core/keyboard.js b/theme/javascript/core/keyboard.js
index 5bbdcf2..5bbdcf2 100644..100755
--- a/theme/javascript/core/keyboard.js
+++ b/theme/javascript/core/keyboard.js
diff --git a/theme/javascript/core/navigation.js b/theme/javascript/core/navigation.js
index bb3547c..c4a7971 100644..100755
--- a/theme/javascript/core/navigation.js
+++ b/theme/javascript/core/navigation.js
@@ -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
diff --git a/theme/javascript/core/progress.js b/theme/javascript/core/progress.js
index d074cae..a409a11 100644..100755
--- a/theme/javascript/core/progress.js
+++ b/theme/javascript/core/progress.js
@@ -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 {
diff --git a/theme/javascript/core/quiz.js b/theme/javascript/core/quiz.js
deleted file mode 100644
index 7043641..0000000
--- a/theme/javascript/core/quiz.js
+++ /dev/null
@@ -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
- };
-});
diff --git a/theme/javascript/core/search.js b/theme/javascript/core/search.js
index 4171660..4171660 100644..100755
--- a/theme/javascript/core/search.js
+++ b/theme/javascript/core/search.js
diff --git a/theme/javascript/core/sidebar.js b/theme/javascript/core/sidebar.js
index d318676..d318676 100644..100755
--- a/theme/javascript/core/sidebar.js
+++ b/theme/javascript/core/sidebar.js
diff --git a/theme/javascript/core/state.js b/theme/javascript/core/state.js
index 79876b9..34851c1 100644..100755
--- a/theme/javascript/core/state.js
+++ b/theme/javascript/core/state.js
@@ -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")
};
}); \ No newline at end of file
diff --git a/theme/javascript/execute/javascript.js b/theme/javascript/execute/javascript.js
index ddbc2c1..ddbc2c1 100644..100755
--- a/theme/javascript/execute/javascript.js
+++ b/theme/javascript/execute/javascript.js
diff --git a/theme/javascript/utils/execute.js b/theme/javascript/utils/execute.js
index eb2a19b..eb2a19b 100644..100755
--- a/theme/javascript/utils/execute.js
+++ b/theme/javascript/utils/execute.js
diff --git a/theme/javascript/utils/platform.js b/theme/javascript/utils/platform.js
index ad5f3b4..ad5f3b4 100644..100755
--- a/theme/javascript/utils/platform.js
+++ b/theme/javascript/utils/platform.js
diff --git a/theme/javascript/utils/sharing.js b/theme/javascript/utils/sharing.js
index f4354f1..f4354f1 100644..100755
--- a/theme/javascript/utils/sharing.js
+++ b/theme/javascript/utils/sharing.js
diff --git a/theme/javascript/utils/storage.js b/theme/javascript/utils/storage.js
index 57f5878..57f5878 100644..100755
--- a/theme/javascript/utils/storage.js
+++ b/theme/javascript/utils/storage.js
diff --git a/theme/javascript/vendors/jquery.js b/theme/javascript/vendors/jquery.js
index f7f4227..f7f4227 100644..100755
--- a/theme/javascript/vendors/jquery.js
+++ b/theme/javascript/vendors/jquery.js
diff --git a/theme/javascript/vendors/lodash.js b/theme/javascript/vendors/lodash.js
index d653e5a..d653e5a 100644..100755
--- a/theme/javascript/vendors/lodash.js
+++ b/theme/javascript/vendors/lodash.js
diff --git a/theme/javascript/vendors/mixpanel.js b/theme/javascript/vendors/mixpanel.js
index 763a573..763a573 100644..100755
--- a/theme/javascript/vendors/mixpanel.js
+++ b/theme/javascript/vendors/mixpanel.js
diff --git a/theme/javascript/vendors/mousetrap.js b/theme/javascript/vendors/mousetrap.js
index 66f2d5b..66f2d5b 100644..100755
--- a/theme/javascript/vendors/mousetrap.js
+++ b/theme/javascript/vendors/mousetrap.js
diff --git a/theme/javascript/vendors/require.js b/theme/javascript/vendors/require.js
index d95c608..d95c608 100644..100755
--- a/theme/javascript/vendors/require.js
+++ b/theme/javascript/vendors/require.js