mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-03 12:10:34 +00:00
Add global js interface for plugins and remove mixpanel
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
require([
|
||||
"jQuery",
|
||||
"utils/storage",
|
||||
"utils/analytic",
|
||||
"utils/sharing",
|
||||
|
||||
"core/global",
|
||||
"core/state",
|
||||
"core/keyboard",
|
||||
"core/navigation",
|
||||
"core/progress",
|
||||
"core/sidebar",
|
||||
"core/search"
|
||||
], function($, storage, analytic, sharing, state, keyboard, navigation, progress, sidebar, search){
|
||||
], function($, storage, sharing, global, state, keyboard, navigation, progress, sidebar, search){
|
||||
$(document).ready(function() {
|
||||
var $book;
|
||||
$book = state.$book;
|
||||
@@ -34,5 +34,7 @@ require([
|
||||
|
||||
// Init navigation
|
||||
navigation.init();
|
||||
|
||||
global.trigger("init");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
define([
|
||||
"jQuery",
|
||||
"utils/execute",
|
||||
"utils/analytic",
|
||||
"core/global",
|
||||
"core/state"
|
||||
], function($, execute, analytic, state){
|
||||
], function($, execute, global, 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"});
|
||||
global.trigger("exercise.submit", {type: "code"});
|
||||
|
||||
execute("javascript", editor.getValue(), codeValidation, codeContext, function(err, result) {
|
||||
$exercise.toggleClass("return-error", err != null);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
define([
|
||||
"jQuery"
|
||||
], function($) {
|
||||
// Interface for plugins
|
||||
window.gitbook = $({});
|
||||
|
||||
return window.gitbook;
|
||||
});
|
||||
@@ -1,12 +1,12 @@
|
||||
define([
|
||||
"jQuery",
|
||||
"utils/analytic",
|
||||
"core/global",
|
||||
"core/state",
|
||||
"core/search",
|
||||
"core/progress",
|
||||
"core/exercise",
|
||||
"core/quiz"
|
||||
], function($, analytic, state, search, progress, exercises, quiz) {
|
||||
], function($, global, state, search, progress, exercises, quiz) {
|
||||
var prev, next;
|
||||
var githubCountStars, githubCountWatch;
|
||||
|
||||
@@ -110,7 +110,7 @@ define([
|
||||
}
|
||||
|
||||
// Send to mixpanel
|
||||
analytic.track("page.view");
|
||||
global.trigger("page.change");
|
||||
};
|
||||
|
||||
var handlePagination = function (e) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
define([
|
||||
"jQuery",
|
||||
"utils/execute",
|
||||
"utils/analytic",
|
||||
"core/global",
|
||||
"core/state"
|
||||
], function($, execute, analytic, state){
|
||||
], function($, execute, global, 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"});
|
||||
global.trigger("exercise.submit", {type: "quiz"});
|
||||
$quiz.find("tr.alert-danger,li.alert-danger").removeClass("alert-danger");
|
||||
$quiz.find(".alert-success,.alert-danger").addClass("hidden");
|
||||
|
||||
|
||||
@@ -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
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user