-
Notifications
You must be signed in to change notification settings - Fork 6
/
embed-index.html
174 lines (163 loc) · 5.5 KB
/
embed-index.html
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<html>
<head>
<meta charset="utf-8">
<!-- NOTE: Don't change this Title -->
<title>Quizme App Inventor</title>
<link type="text/css" rel="stylesheet" href="../../css/main.css">
<style>
body {
background-color: white;
font-family: sans-serif;
}
h1 {
font-weight: normal;
font-size: 140%;
}
#dialogoverlay{
display: none;
opacity: .2;
position: fixed;
top: 0px;
left: 0px;
background: #FFF;
width: 100%;
z-index: 10;
}
#dialogbox{
display: none;
position: fixed;
background: #000;
border-radius:7px;
width:400px;
z-index: 10;
}
#dialogbox > div{ background:#FFF; margin:8px; }
#dialogbox > div > #dialogboxhead{ background: #666; font-size:19px; padding:10px; color:#CCC; }
#dialogbox > div > #dialogboxbody{ background:#333; padding:20px; color:#FFF; }
#dialogbox > div > #dialogboxfoot{ background: #666; padding:10px; text-align:right; }
</style>
<script>
// Based on: https://www.developphp.com/video/JavaScript/Custom-Alert-Box-Programming-Tutorial
// The variable doc is set based on where the dialogoverlay, which varies if index.html is embedded.
function JavaScriptAlert(){
this.render = function(dialog){
var winW = window.innerWidth;
var winH = window.innerHeight;
var dialogoverlay = window.parent.document.getElementById('dialogoverlay');
var doc;
if (dialogoverlay) {
doc = window.parent.document;
} else {
doc = window.document; // For embedded cases
}
dialogoverlay = doc.getElementById('dialogoverlay');
var dialogbox = doc.getElementById('dialogbox');
dialogoverlay.style.display = "block";
dialogoverlay.style.height = winH+"px";
dialogbox.style.left = winW - 550 +"px";
dialogbox.style.top = "100px";
dialogbox.style.display = "block";
doc.getElementById('dialogboxhead').innerHTML = "Javascript Code";
doc.getElementById('dialogboxbody').innerHTML = "<pre>" + dialog + "</pre>";
doc.getElementById('dialogboxfoot').innerHTML = '<button onclick="Alert.ok()">OK</button>';
}
this.ok = function(){
var dialogoverlay = window.parent.document.getElementById('dialogoverlay');
if (dialogoverlay) {
doc = window.parent.document;
} else {
doc = window.document; // For embedded cases
}
doc.getElementById('dialogbox').style.display = "none";
doc.getElementById('dialogoverlay').style.display = "none";
}
}
var Alert = new JavaScriptAlert();
var DEBUG = false;
function showJavascript() {
if (DEBUG) console.log("ShowJavaScript");
Blockly.hello('showjavascript');
}
/**
Handler for the Quizly submit button. It
evaluates the user's solution and posts
the result (true or false) on window.parent.quizlies
where it can be retrieved by the GCB quiz object.
*/
function checkAnswer() {
console.log("checkAnswer -- GCB");
document.getElementById('show_javascript').disabled = true;
var result = Blockly.Quizme.evaluateUserAnswer();
var quizName = Blockly.Quizme.quizName
window.parent.quizlies['quizname']=quizName;
var thisQuiz = window.parent.quizlies[quizName];
thisQuiz.result = result[0];
thisQuiz.workspace = result[1];
// Comment this out if there is separate GCB button for submitting the result.
window.parent.checkAnswer(); // This parent script is in modules/quizly/quizly.py
}
function giveHint() {
if (DEBUG) console.log("giveHint");
Blockly.hello('hint');
}
function showQuiz(quizname) {
if (DEBUG) console.log("showQuiz");
Blockly.hello('showquiz', quizname);
}
function giveNewQuestion(quizname) {
if (DEBUG) console.log("giveNewQuestion");
Blockly.hello('showquiz', quizname);
}
</script>
</head>
<body>
<div id="dialogoverlay"></div>
<div id="dialogbox">
<div>
<div id="dialogboxhead"></div>
<div id="dialogboxbody"></div>
<div id="dialogboxfoot"></div>
</div>
</div>
<input type="hidden" id="quizname" value="">
<h1 hidden="true" id="heading">Quizly: Live Coding Exercises for App Inventor</h1>
<table width="100%" height="100%" cellspacing="0" cellpadding="0" style="border:0px">
<tr>
<td>
<div id="quiz_question">Here is where the quiz question goes.</div>
<input hidden="true" id="quiz_answer" width="80" font-size="14px" type="text"></input>
<div id="hint_html">Here is where the hint goes. </div>
<table style="border:0px" >
<tr>
<td>
<button class="gcb-button gcb-button-primary" id="hint_button" onclick="giveHint()">Hint</button>
</td>
<td>
<button class="gcb-button gcb-button-primary" id="gcb_check_answer" onclick="checkAnswer()">Check Answer</button>
</td>
<td>
<button class="gcb-button gcb-button-primary" id="show_javascript" onclick="showJavascript()" style="visibility:hidden" disabled>Show Javascript</button>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td><div contenteditable="true" width="300px" height="100px" id="quiz_result" readonly="readonly"> </div></td>
</tr>
<tr>
<td height="99%">
<script>
// Called once Blockly is fully loaded. Puts Blockly on the top-level Window
function blocklyLoaded(blockly) {
window.Blockly = blockly;
}
</script>
<iframe style="width: 100%; height: 100%; border: 0px; padding: 1px; margin: 2px;" src="blockly.html"></iframe>
</td>
</tr>
</table>
</body>
</html>