blob: c6197df17676bad6e976aab9f6a55c50d9ddc6a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
require([
"jQuery",
"core/state",
"core/progress"
], function($, _state, progress){
$(document).ready(function() {
var state = _state();
var $book = state.$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/"+state.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);
});
});
// Show progress
progress.show();
});
});
|