Change js interface for plugins and add configuration

This commit is contained in:
Samy Pessé
2014-04-21 22:20:41 +02:00
parent dd395edae1
commit 5beff86548
11 changed files with 42 additions and 27 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ module.exports = function (grunt) {
requirejs: {
compile: {
options: {
name: "app",
name: "gitbook",
baseUrl: "theme/javascript/",
out: "theme/assets/app.js",
preserveLicenseComments: false,
+5 -1
View File
@@ -43,7 +43,11 @@ var generate = function(options) {
githubHost: 'https://github.com/',
// Theming
theme: path.resolve(__dirname, '../../theme')
theme: path.resolve(__dirname, '../../theme'),
// Plugins
plugins: [],
pluginsConfig: {test:1}
});
if (!options.input) {
+2 -1
View File
@@ -71,7 +71,8 @@ Generator.prototype._writeTemplate = function(tpl, options, output) {
summary: that.options.summary,
allNavigation: that.options.navigation,
plugins: that.plugins
plugins: that.plugins,
pluginsConfig: JSON.stringify(that.options.pluginsConfig)
}, options));
})
.then(function(html) {
+1 -1
View File
File diff suppressed because one or more lines are too long
+7
View File
@@ -0,0 +1,7 @@
define([
"jQuery"
], function($) {
var events = $({});
return events;
});
+3 -3
View File
@@ -1,9 +1,9 @@
define([
"jQuery",
"utils/execute",
"core/global",
"core/events",
"core/state"
], function($, execute, global, 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();
global.trigger("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);
-8
View File
@@ -1,8 +0,0 @@
define([
"jQuery"
], function($) {
// Interface for plugins
window.gitbook = $({});
return window.gitbook;
});
+3 -3
View File
@@ -1,12 +1,12 @@
define([
"jQuery",
"core/global",
"core/events",
"core/state",
"core/search",
"core/progress",
"core/exercise",
"core/quiz"
], function($, global, 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
global.trigger("page.change");
events.trigger("page.change");
};
var handlePagination = function (e) {
+3 -3
View File
@@ -1,9 +1,9 @@
define([
"jQuery",
"utils/execute",
"core/global",
"core/events",
"core/state"
], function($, execute, global, 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();
global.trigger("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");
@@ -1,17 +1,17 @@
require([
define([
"jQuery",
"utils/storage",
"utils/sharing",
"core/global",
"core/events",
"core/state",
"core/keyboard",
"core/navigation",
"core/progress",
"core/sidebar",
"core/search"
], function($, storage, sharing, global, 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;
@@ -37,6 +37,11 @@ require([
$(document).trigger("bookReady");
global.trigger("init");
});
events.trigger("start", config);
}
return {
start: start,
events: events
};
});
+6
View File
@@ -45,6 +45,12 @@
<script src="{{ staticBase }}/plugins/{{ resource.path }}"></script>
{% endif %}
{% endfor %}
<script>
require(["gitbook"], function(gitbook) {
var config = {% autoescape false %}{{ pluginsConfig }}{% endautoescape %};
gitbook.start(config);
});
</script>
{% endblock %}
{% block style %}