|
| 1 | +<html> |
| 2 | + |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <!-- NOTE: Don't change this Title --> |
| 6 | + <title>Quizme App Inventor</title> |
| 7 | + <link type="text/css" rel="stylesheet" href="../../css/main.css"> |
| 8 | + <style> |
| 9 | + body { |
| 10 | + background-color: white; |
| 11 | + font-family: sans-serif; |
| 12 | + } |
| 13 | + h1 { |
| 14 | + font-weight: normal; |
| 15 | + font-size: 140%; |
| 16 | + } |
| 17 | + |
| 18 | + #dialogoverlay{ |
| 19 | + display: none; |
| 20 | + opacity: .2; |
| 21 | + position: fixed; |
| 22 | + top: 0px; |
| 23 | + left: 0px; |
| 24 | + background: #FFF; |
| 25 | + width: 100%; |
| 26 | + z-index: 10; |
| 27 | + } |
| 28 | + #dialogbox{ |
| 29 | + display: none; |
| 30 | + position: fixed; |
| 31 | + background: #000; |
| 32 | + border-radius:7px; |
| 33 | + width:400px; |
| 34 | + z-index: 10; |
| 35 | + } |
| 36 | + #dialogbox > div{ background:#FFF; margin:8px; } |
| 37 | + #dialogbox > div > #dialogboxhead{ background: #666; font-size:19px; padding:10px; color:#CCC; } |
| 38 | + #dialogbox > div > #dialogboxbody{ background:#333; padding:20px; color:#FFF; } |
| 39 | + #dialogbox > div > #dialogboxfoot{ background: #666; padding:10px; text-align:right; } |
| 40 | + </style> |
| 41 | + |
| 42 | +<script> |
| 43 | + // Event listener and handler for quiz result |
| 44 | + window.addEventListener('message', handleMessage, false); |
| 45 | + |
| 46 | + function handleMessage(event) { |
| 47 | +// if (event.origin != "http://localhost:85") { return; } |
| 48 | + console.log("handleMessage result: " + event.data) |
| 49 | + this.window.quizly_result = event.data; |
| 50 | + console.log("handleMessage window result: " + this.window.quizly_result); |
| 51 | + } |
| 52 | + |
| 53 | +// Based on: https://www.developphp.com/video/JavaScript/Custom-Alert-Box-Programming-Tutorial |
| 54 | +// The variable doc is set based on where the dialogoverlay, which varies if index.html is embedded. |
| 55 | +function JavaScriptAlert(){ |
| 56 | + this.render = function(dialog){ |
| 57 | + var winW = window.innerWidth; |
| 58 | + var winH = window.innerHeight; |
| 59 | + var dialogoverlay = window.parent.document.getElementById('dialogoverlay'); |
| 60 | + var doc; |
| 61 | + if (dialogoverlay) { |
| 62 | + doc = window.parent.document; |
| 63 | + } else { |
| 64 | + doc = window.document; // For embedded cases |
| 65 | + } |
| 66 | + dialogoverlay = doc.getElementById('dialogoverlay'); |
| 67 | + var dialogbox = doc.getElementById('dialogbox'); |
| 68 | + dialogoverlay.style.display = "block"; |
| 69 | + dialogoverlay.style.height = winH+"px"; |
| 70 | + dialogbox.style.left = winW - 550 +"px"; |
| 71 | + dialogbox.style.top = "100px"; |
| 72 | + dialogbox.style.display = "block"; |
| 73 | + doc.getElementById('dialogboxhead').innerHTML = "Javascript Code"; |
| 74 | + doc.getElementById('dialogboxbody').innerHTML = "<pre>" + dialog + "</pre>"; |
| 75 | + doc.getElementById('dialogboxfoot').innerHTML = '<button onclick="Alert.ok()">OK</button>'; |
| 76 | + } |
| 77 | + this.ok = function(){ |
| 78 | + var dialogoverlay = window.parent.document.getElementById('dialogoverlay'); |
| 79 | + if (dialogoverlay) { |
| 80 | + doc = window.parent.document; |
| 81 | + } else { |
| 82 | + doc = window.document; // For embedded cases |
| 83 | + } |
| 84 | + doc.getElementById('dialogbox').style.display = "none"; |
| 85 | + doc.getElementById('dialogoverlay').style.display = "none"; |
| 86 | + } |
| 87 | +} |
| 88 | +var Alert = new JavaScriptAlert(); |
| 89 | +var DEBUG = false; |
| 90 | + |
| 91 | +function showJavascript() { |
| 92 | + if (DEBUG) console.log("ShowJavaScript"); |
| 93 | + Blockly.hello('showjavascript'); |
| 94 | +} |
| 95 | + |
| 96 | +/** |
| 97 | + Handler for the Quizly submit button. It |
| 98 | + evaluates the user's solution and posts |
| 99 | + the result (true or false) on window.parent.quizlies |
| 100 | + where it can be retrieved by the GCB quiz object. |
| 101 | +*/ |
| 102 | +function checkAnswer() { |
| 103 | + console.log("checkAnswer -- RAM"); |
| 104 | + document.getElementById('show_javascript').disabled = true; |
| 105 | + var result = Blockly.Quizme.evaluateUserAnswer(); |
| 106 | + var quizName = Blockly.Quizme.quizName |
| 107 | + window.postMessage("Result=" + result, 'http://localhost:85'); |
| 108 | + |
| 109 | +// window.parent.quizlies['quizname']=quizName; |
| 110 | +// var thisQuiz = window.parent.quizlies[quizName]; |
| 111 | +// thisQuiz.result = result[0]; |
| 112 | +// thisQuiz.workspace = result[1]; |
| 113 | + |
| 114 | + |
| 115 | + // Comment this out if there is separate GCB button for submitting the result. |
| 116 | +// window.parent.checkAnswer(); // This parent script is in modules/quizly/quizly.py |
| 117 | +} |
| 118 | + |
| 119 | +function giveHint() { |
| 120 | + if (DEBUG) console.log("giveHint"); |
| 121 | + Blockly.hello('hint'); |
| 122 | +} |
| 123 | + |
| 124 | +function showQuiz(quizname) { |
| 125 | + if (DEBUG) console.log("showQuiz"); |
| 126 | + Blockly.hello('showquiz', quizname); |
| 127 | +} |
| 128 | + |
| 129 | +function giveNewQuestion(quizname) { |
| 130 | + if (DEBUG) console.log("giveNewQuestion"); |
| 131 | + Blockly.hello('showquiz', quizname); |
| 132 | +} |
| 133 | + |
| 134 | +</script> |
| 135 | + |
| 136 | +</head> |
| 137 | +<body> |
| 138 | +<div id="dialogoverlay"></div> |
| 139 | +<div id="dialogbox"> |
| 140 | + <div> |
| 141 | + <div id="dialogboxhead"></div> |
| 142 | + <div id="dialogboxbody"></div> |
| 143 | + <div id="dialogboxfoot"></div> |
| 144 | + </div> |
| 145 | +</div> |
| 146 | + |
| 147 | + <input type="hidden" id="quizname" value=""> |
| 148 | + <h1 hidden="true" id="heading">Quizly: Live Coding Exercises for App Inventor</h1> |
| 149 | + <table width="100%" height="100%" cellspacing="0" cellpadding="0" style="border:0px"> |
| 150 | + <tr> |
| 151 | + <td> |
| 152 | + <div id="quiz_question">Here is where the quiz question goes.</div> |
| 153 | + <input hidden="true" id="quiz_answer" width="80" font-size="14px" type="text"></input> |
| 154 | + <div id="hint_html">Here is where the hint goes. </div> |
| 155 | + |
| 156 | + |
| 157 | + <table style="border:0px" > |
| 158 | + <tr> |
| 159 | + <td> |
| 160 | + <button class="gcb-button gcb-button-primary" id="hint_button" onclick="giveHint()">Hint</button> |
| 161 | + </td> |
| 162 | + <td> |
| 163 | + <button class="gcb-button gcb-button-primary" id="gcb_check_answer" onclick="checkAnswer()">Check Answer</button> |
| 164 | + </td> |
| 165 | + <td> |
| 166 | + <button class="gcb-button gcb-button-primary" id="show_javascript" onclick="showJavascript()" style="visibility:hidden" disabled>Show Javascript</button> |
| 167 | + </td> |
| 168 | + </tr> |
| 169 | + </table> |
| 170 | + </td> |
| 171 | + </tr> |
| 172 | + <tr> |
| 173 | + <td><div contenteditable="true" width="300px" height="100px" id="quiz_result" readonly="readonly"> </div></td> |
| 174 | + </tr> |
| 175 | + <tr> |
| 176 | + <td height="99%"> |
| 177 | + <script> |
| 178 | + // Called once Blockly is fully loaded. Puts Blockly on the top-level Window |
| 179 | + function blocklyLoaded(blockly) { |
| 180 | + window.Blockly = blockly; |
| 181 | + } |
| 182 | + </script> |
| 183 | + <iframe style="width: 100%; height: 100%; border: 0px; padding: 1px; margin: 2px;" src="blockly.html"></iframe> |
| 184 | + </td> |
| 185 | + </tr> |
| 186 | + </table> |
| 187 | + |
| 188 | +</body> |
| 189 | + |
| 190 | +<!-- Mirrored from course.mobilecsp.org/mobilecsp/assets/lib/quizly/gcb-index.html?backpack=hidden&selector=hidden&quizname=quiz_pause_the_player&hints=true&repeatable=false by HTTrack Website Copier/3.x [XR&CO'2014], Fri, 26 Feb 2021 01:25:30 GMT --> |
| 191 | +</html> |
0 commit comments