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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
$(document).ready(function() {
/* Code Mirror Controls */
$fullscreen_code = $("#fullscreen-code");
$toggle_code = $("#toggle-code");
$fullscreen_code.click(function(e) {
editor.setOption("fullScreen", !editor.getOption("fullScreen"));
editor.focus();
});
$toggle_code.click(function() {
if(editor.getOption("theme") == "monokai") {
editor.setOption("theme", "default");
} else{
editor.setOption("theme", "monokai");
}
});
$fullscreen_result = $("#fullscreen-result");
$toggle_result = $("#toggle-result");
$fullscreen_result.click(function(e) {
result.setOption("fullScreen", !result.getOption("fullScreen"));
result.focus();
});
$toggle_result.click(function() {
if(result.getOption("theme") == "monokai") {
result.setOption("theme", "default");
} else{
result.setOption("theme", "monokai");
}
});
/*
* Selectors function
* Write the queries using live
*/
$("#categories").change(function() {
$("#books-wrapper").html("");
$("#chapters-wrapper").html("");
$("#examples-wrapper").html("");
$.ajax({
url: "/ajax-books/",
type: "POST",
data: {
category_id: $(this).val()
},
dataType: "html",
success: function(data) {
$("#books-wrapper").html(data);
}
});
});
$(document).on("change", "#books", function(){
$("#chapters-wrapper").html("");
$("#examples-wrapper").html("");
$.ajax({
url: "/ajax-chapters/",
type: "POST",
data: {
book_id: $("#books").val()
},
dataType: "html",
success: function(data) {
$("#chapters-wrapper").html(data);
}
});
});
$(document).on("change", "#chapters", function(){
$("#examples-wrapper").html("");
$.ajax({
url: "/ajax-examples/",
type: "POST",
data: {
chapter_id: $("#chapters").val()
},
dataType: "html",
success: function(data) {
$("#examples-wrapper").html(data);
}
});
});
/* Execute the code */
$("#execute").click(function() {
var csrfmiddlewaretoken = $("[name='csrfmiddlewaretoken']").val();
var code = editor.getValue();
$("body").css("cursor", "wait");
$.ajax({
url:"/ajax-execute/",
type: "POST",
data: {
csrfmiddlewaretoken: csrfmiddlewaretoken,
code: code
},
dataType: "text",
success: function(data) {
$("body").css("cursor", "auto");
result.setValue(data);
}
});
});
});
|