Skip to content

Commit

Permalink
refactoring(js): コードをbrowserifyに対応
Browse files Browse the repository at this point in the history
 
fixes #18
  • Loading branch information
azu committed Jun 11, 2014
1 parent 12a11b6 commit afd2d42
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 26 deletions.
9 changes: 4 additions & 5 deletions docinfo.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<script type="text/javascript" src="public/js/google-analytics.js"></script>
<link rel="canonical" href="http://azu.github.io/promises-book/">
<link href="public/img/favicon.ico" rel="shortcut icon" type="image/x-icon">
<link rel="icon" sizes="16x16 32x32" href="public/img/favicon.ico">
<link rel="stylesheet" type="text/css" href="public/css/overload.css"/>
<script type="text/javascript" src="public/js/sync-toc.js"></script>
<script type="text/javascript" src="public/js/google-analytics.js"></script>
<script type="text/javascript" src="public/js/bug-report.js"></script>
<link rel="stylesheet" type="text/css" href="node_modules/codemirror-console-ui/components/mirror-console-compoenent.css"/>
<link rel="stylesheet" type="text/css"
href="node_modules/codemirror-console-ui/components/mirror-console-compoenent.css"/>
<link rel="stylesheet" type="text/css" href="node_modules/codemirror/lib/codemirror.css">
<script type="text/javascript" src="public/js/app.js"></script>
<script type="text/javascript" src="public/js/app.js" async defer></script>
3 changes: 3 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ var path = require("path");
var rename = require("gulp-rename");
var inlining = require("gulp-inlining-node-require");
var removeUseString = require("gulp-remove-use-strict");
gulp.task("build-js", function () {

});
gulp.task("embed", function () {
return gulp.src(["./Ch*/src/**/*.js", "./Ch*/lib/*.js", "./Ch3_Testing/test/*.js"], {base: './'})
.pipe(inlining())
Expand Down
20 changes: 10 additions & 10 deletions public/js/bug-report.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
"use strict";
var TOCHighlighter = require("./sync-toc");
function quoteText(text) {
return text.split("\n").map(function (line) {
return "> " + line;
}).join("\n");
}

function BugReporter() {
var highLightLevel = ["h1", "h2", "h3"];
var sections = document.querySelectorAll(".sect2");
Expand Down Expand Up @@ -36,14 +43,8 @@ BugReporter.prototype.report = function () {
+ "&labels=" + encodeURIComponent(this.github_issue_labels);
window.open(url, "_blank");
};
window.addEventListener("load", function (event) {

function quoteText(text) {
return text.split("\n").map(function (line) {
return "> " + line;
}).join("\n");
}

module.exports = BugReporter;
module.exports.initilize = function () {
var reportElement = document.createElement("button");
reportElement.textContent = "バグ報告";
reportElement.setAttribute("style", "position:fixed; right:0;bottom:0;");
Expand All @@ -59,5 +60,4 @@ window.addEventListener("load", function (event) {
bug.report();
});
document.body.appendChild(reportElement);
});

};
16 changes: 16 additions & 0 deletions public/js/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Created by azu on 2014/06/11.
* LICENSE : MIT
*/
"use strict";
module.exports.initilize = function () {
var consoleUI = require("codemirror-console-ui");
var codeBlocks = document.querySelectorAll("div.listingblock");
for (var i = 0; i < codeBlocks.length; i++) {
var codeBlock = codeBlocks[i];
var code = codeBlock.getElementsByTagName("code")[0];
if (code) {
consoleUI(codeBlock, code.textContent);
}
}
}
12 changes: 3 additions & 9 deletions public/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@
*/
"use strict";
function windowOnload() {
var consoleUI = require("codemirror-console-ui");
var codeBlocks = document.querySelectorAll("div.listingblock");
for (var i = 0; i < codeBlocks.length; i++) {
var codeBlock = codeBlocks[i];
var code = codeBlock.getElementsByTagName("code")[0];
if (code) {
consoleUI(codeBlock, code.textContent);
}
}
require("./editor").initilize();
require("./sync-toc").initilize();
require("./bug-report").initilize();
}
window.addEventListener("load", windowOnload);
5 changes: 3 additions & 2 deletions public/js/sync-toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ TOCHighlighter.prototype.findAllChildHeader = function (parent) {
}
return [];
};
window.addEventListener("load", function onLoad() {
module.exports = TOCHighlighter;
module.exports.initilize = function initilize() {
var highLightLevel = ["h1", "h2", "h3"];
var chapters = document.querySelectorAll(".sect1");
var sections = document.querySelectorAll(".sect2");
Expand All @@ -78,4 +79,4 @@ window.addEventListener("load", function onLoad() {
}

window.addEventListener("scroll", onScroll);
});
};

0 comments on commit afd2d42

Please sign in to comment.