summaryrefslogtreecommitdiffstats
path: root/assets/javascript/app.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2014-03-31 19:04:26 -0700
committerSamy Pessé <samypesse@gmail.com>2014-03-31 19:04:26 -0700
commit5ff6896ee55e6bc735214e0df33d6e004372a03e (patch)
treee13f401848c6ecc7b5f548823d806da20aa2ded8 /assets/javascript/app.js
parent68e35758c33168e9b3fe1c678e07d52b42879720 (diff)
downloadgitbook-5ff6896ee55e6bc735214e0df33d6e004372a03e.zip
gitbook-5ff6896ee55e6bc735214e0df33d6e004372a03e.tar.gz
gitbook-5ff6896ee55e6bc735214e0df33d6e004372a03e.tar.bz2
Move all javascript to the bundle
Diffstat (limited to 'assets/javascript/app.js')
-rw-r--r--assets/javascript/app.js44
1 files changed, 41 insertions, 3 deletions
diff --git a/assets/javascript/app.js b/assets/javascript/app.js
index cc17c90..55a711a 100644
--- a/assets/javascript/app.js
+++ b/assets/javascript/app.js
@@ -1,5 +1,43 @@
require([
-
-], function(){
-
+ "jQuery"
+], function($){
+ $(document).ready(function() {
+ var $book = $(".book");
+
+ // Toggle summary
+ $book.find(".book-header .toggle-summary").click(function(e) {
+ e.preventDefault();
+ $book.toggleClass("with-summary");
+ });
+
+ // Star and watch count
+ $.getJSON("https://api.github.com/repos/{{ githubId }}")
+ .done(function(repo) {
+ $book.find(".count-star span").text(repo.stargazers_count);
+ $book.find(".count-watch span").text(repo.subscribers_count);
+ });
+
+ // Bind exercises
+ $book.find("section.exercise").each(function() {
+ var $exercise = $(this);
+
+ var codeSolution = $exercise.find(".code-solution").html();
+ var codeValidation = $exercise.find(".code-validation").html();
+
+ var editor = ace.edit($exercise.find(".editor").get(0));
+ editor.setTheme("ace/theme/tomorrow");
+ editor.getSession().setMode("ace/mode/javascript");
+
+ $exercise.find(".action-submit").click(function(e) {
+ e.preventDefault();
+
+ alert("submit");
+ });
+ $exercise.find(".action-solution").click(function(e) {
+ e.preventDefault();
+
+ editor.setValue(codeSolution);
+ });
+ });
+ });
}); \ No newline at end of file