summaryrefslogtreecommitdiffstats
path: root/theme/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'theme/javascript')
-rw-r--r--theme/javascript/core/events.js7
-rwxr-xr-xtheme/javascript/core/exercise.js6
-rwxr-xr-xtheme/javascript/core/navigation.js6
-rw-r--r--theme/javascript/core/quiz.js6
-rwxr-xr-xtheme/javascript/gitbook.js (renamed from theme/javascript/app.js)19
-rw-r--r--theme/javascript/utils/analytic.js36
6 files changed, 30 insertions, 50 deletions
diff --git a/theme/javascript/core/events.js b/theme/javascript/core/events.js
new file mode 100644
index 0000000..855755f
--- /dev/null
+++ b/theme/javascript/core/events.js
@@ -0,0 +1,7 @@
+define([
+ "jQuery"
+], function($) {
+ var events = $({});
+
+ return events;
+}); \ No newline at end of file
diff --git a/theme/javascript/core/exercise.js b/theme/javascript/core/exercise.js
index e24ae0a..7dbe982 100755
--- a/theme/javascript/core/exercise.js
+++ b/theme/javascript/core/exercise.js
@@ -1,9 +1,9 @@
define([
"jQuery",
"utils/execute",
- "utils/analytic",
+ "core/events",
"core/state"
-], function($, execute, analytic, state){
+], function($, execute, events, state){
// Bind an exercise
var prepareExercise = function($exercise) {
var codeSolution = $exercise.find(".code-solution").text();
@@ -19,7 +19,7 @@ define([
$exercise.find(".action-submit").click(function(e) {
e.preventDefault();
- analytic.track("exercise.submit", {type: "code"});
+ events.trigger("exercise.submit", {type: "code"});
execute("javascript", editor.getValue(), codeValidation, codeContext, function(err, result) {
$exercise.toggleClass("return-error", err != null);
diff --git a/theme/javascript/core/navigation.js b/theme/javascript/core/navigation.js
index 1796fc1..8f8b0a6 100755
--- a/theme/javascript/core/navigation.js
+++ b/theme/javascript/core/navigation.js
@@ -1,12 +1,12 @@
define([
"jQuery",
- "utils/analytic",
+ "core/events",
"core/state",
"core/search",
"core/progress",
"core/exercise",
"core/quiz"
-], function($, analytic, state, search, progress, exercises, quiz) {
+], function($, events, state, search, progress, exercises, quiz) {
var prev, next;
var githubCountStars, githubCountWatch;
@@ -110,7 +110,7 @@ define([
}
// Send to mixpanel
- analytic.track("page.view");
+ events.trigger("page.change");
};
var handlePagination = function (e) {
diff --git a/theme/javascript/core/quiz.js b/theme/javascript/core/quiz.js
index 4e30fea..d34af48 100644
--- a/theme/javascript/core/quiz.js
+++ b/theme/javascript/core/quiz.js
@@ -1,9 +1,9 @@
define([
"jQuery",
"utils/execute",
- "utils/analytic",
+ "core/events",
"core/state"
-], function($, execute, analytic, state){
+], function($, execute, events, state){
// Bind an exercise
var prepareQuiz = function($quiz) {
@@ -14,7 +14,7 @@ define([
// Submit: test code
$quiz.find(".action-submit").click(function(e) {
e.preventDefault();
- analytic.track("exercise.submit", {type: "quiz"});
+ events.trigger("exercise.submit", {type: "quiz"});
$quiz.find("tr.alert-danger,li.alert-danger").removeClass("alert-danger");
$quiz.find(".alert-success,.alert-danger").addClass("hidden");
diff --git a/theme/javascript/app.js b/theme/javascript/gitbook.js
index 3829a42..713a734 100755
--- a/theme/javascript/app.js
+++ b/theme/javascript/gitbook.js
@@ -1,17 +1,17 @@
-require([
+define([
"jQuery",
"utils/storage",
- "utils/analytic",
"utils/sharing",
+ "core/events",
"core/state",
"core/keyboard",
"core/navigation",
"core/progress",
"core/sidebar",
"core/search"
-], function($, storage, analytic, sharing, state, keyboard, navigation, progress, sidebar, search){
- $(document).ready(function() {
+], function($, storage, sharing, events, state, keyboard, navigation, progress, sidebar, search){
+ var start = function(config) {
var $book;
$book = state.$book;
@@ -34,5 +34,14 @@ require([
// Init navigation
navigation.init();
- });
+
+ $(document).trigger("bookReady");
+
+ events.trigger("start", config);
+ }
+
+ return {
+ start: start,
+ events: events
+ };
});
diff --git a/theme/javascript/utils/analytic.js b/theme/javascript/utils/analytic.js
deleted file mode 100644
index f90dd95..0000000
--- a/theme/javascript/utils/analytic.js
+++ /dev/null
@@ -1,36 +0,0 @@
-define([
- "lodash"
-], function(_) {
- var isAvailable = function() {
- return (
- typeof mixpanel !== "undefined" &&
- typeof mixpanel.track === "function"
- );
- };
-
- var track = function(e, data, t) {
- if (!isAvailable()) {
- console.warn("tracking not available!");
- t = t || 500;
- setTimeout(function() {
- console.log(" -> retest tracking");
- track(e, data, t*2);
- }, t);
- return;
- }
- console.log("track", e);
- mixpanel.track(e, _.extend(data || {}, {
- 'domain': window.location.host
- }));
- };
-
- setTimeout(function() {
- mixpanel.init("01eb2b950ae09a5fdb15a98dcc5ff20e");
- track("page.start");
- }, 0);
-
- return {
- isAvailable: isAvailable,
- track: track
- };
-}); \ No newline at end of file