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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
$(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);
}
});
});
$(document).on("change", "#examples", function(){
$.ajax({
url: "/ajax-code/",
type: "POST",
data: {
example_id: $("#examples").val()
},
dataType: "html",
success: function(data) {
editor.setValue(data);
}
});
});
/* Execute the code */
$lightbox_wrapper = $("#lightbox-me-wrapper");
$lightbox = $("#lightbox-me");
$("#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,
book_id: $("#books").val(),
chapter_id: $("#chapters").val(),
example_id: $("#examples").val()
},
dataType: "text",
success: function(data) {
$("body").css("cursor", "auto");
$data = $(data);
var output = $data.find("#output").html();
var plot = $data.find("#plot").html();
result.setValue(output);
if(plot) {
$lightbox.html(plot);
$lightbox_wrapper.lightbox_me({centered: true});
}
}
});
});
});
|