|
5 | 5 | <meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6 | 6 | <link href="css/bootstrap.min.css" rel="stylesheet" media="screen" />
|
7 | 7 | <link href="css/app.css" rel="stylesheet" media="screen" />
|
8 |
| - <meta http-equiv="refresh" content="60"> |
| 8 | + <script src=" https://cdn.jsdelivr.net/npm/[email protected]/src-min-noconflict/ace.min.js " ></script> |
| 9 | + <link href=" https://cdn.jsdelivr.net/npm/[email protected]/css/ace.min.css " rel=" stylesheet" > |
9 | 10 | </head>
|
10 | 11 | <body>
|
11 | 12 | <div class="container">
|
@@ -75,8 +76,30 @@ <h4>Oops, your entry is incorrect</h4>
|
75 | 76 | onchange="javascript:this.form.submit();"
|
76 | 77 | />
|
77 | 78 | <input type="hidden" name="key" value="{{session.key}}" />
|
| 79 | + <input type="hidden" name="code" value="" /> |
| 80 | + <div id="editor-container" class="editor-container" style="display: none"> |
| 81 | + <div id="editor" class="editor"></div> |
| 82 | + <div class="right"> |
| 83 | + <div class="controls"> |
| 84 | + <button type="submit" class="btn btn-lg btn-info" id="submit">Submit Entry</button> |
| 85 | + <div> |
| 86 | + Write your code in the editor. Hit "Submit Entry" to submit your entry to the leaderboard. Use the test field to try out your code and the results will appear below. If you reload the page we will remember the last code you entered. |
| 87 | + </div> |
| 88 | + </div> |
| 89 | + <div id="console" class="console"></div> |
| 90 | + <div class="test-container"> |
| 91 | + <input id="test" value="{{ challenge.exampleTest }}{{ ^challenge.exampleTest }}play() {{/challenge.exampleTest}}"/> |
| 92 | + <button class="btn btn-lg btn-info" id="run-test">Run Test</button> |
| 93 | + </div> |
| 94 | + |
| 95 | + </div> |
| 96 | + </div> |
78 | 97 | <div class="footer">
|
79 |
| - <a href="#" class="btn btn-lg btn-info">Choose File</a> |
| 98 | + <div> |
| 99 | + You can upload a file from your computer with "Choose File" or you can edit online (or copy/paste) with "Web Editor" |
| 100 | + </div> |
| 101 | + <a href="#" class="btn btn-lg btn-info" id="choose">Choose File</a> |
| 102 | + <a href="#" class="btn btn-lg btn-info" id="open-editor">Web Editor</a> |
80 | 103 | </div>
|
81 | 104 | </form>
|
82 | 105 | {{/game.running}} {{^game.running}}
|
@@ -110,7 +133,7 @@ <h4>You can now view other solutions by clicking on them.</h4>
|
110 | 133 | offsetAddEntryHeight();
|
111 | 134 | $(window).on('resize', offsetAddEntryHeight);
|
112 | 135 |
|
113 |
| - $('.submit-form a').click(function(e) { |
| 136 | + $('#choose').click(function(e) { |
114 | 137 | e.preventDefault();
|
115 | 138 | $('.submit-form input[type="file"]').click();
|
116 | 139 | });
|
@@ -147,6 +170,59 @@ <h4>You can now view other solutions by clicking on them.</h4>
|
147 | 170 | clock.text([min, sec].join(':'));
|
148 | 171 | }, 1000);
|
149 | 172 | });
|
| 173 | + |
| 174 | + |
| 175 | + |
| 176 | + const editor = ace.edit("editor"); |
| 177 | + editor.setTheme("ace/theme/monokai"); |
| 178 | + editor.session.setMode("ace/mode/javascript"); |
| 179 | + editor.setValue(localStorage["code"] || "let play = () => {}"); |
| 180 | + function updateCode () { |
| 181 | + localStorage["code"] = editor.getValue(); |
| 182 | + $('[name="code"]').val(editor.getValue()); |
| 183 | + } |
| 184 | + updateCode(); |
| 185 | + editor.session.on('change', updateCode); |
| 186 | + |
| 187 | + $('#open-editor').click(function(e) { |
| 188 | + e.preventDefault(); |
| 189 | + if (!$('[name="email"]').val() || !$('[name="team"]').val()) { |
| 190 | + alert("Please fill in a name and email first"); |
| 191 | + return; |
| 192 | + } |
| 193 | + $('[name="file"]').remove(); |
| 194 | + $('#editor-container').show(); |
| 195 | + }); |
| 196 | + |
| 197 | + function runTest() { |
| 198 | + const oldConsoleLog = console.log; |
| 199 | + console.log = function (...args) { |
| 200 | + const output = args.join(""); |
| 201 | + const pre = document.createElement("pre"); |
| 202 | + pre.innerText = output; |
| 203 | + $('#console').append(pre); |
| 204 | + pre.scrollIntoView(); |
| 205 | + }; |
| 206 | + try { |
| 207 | + console.log(eval(editor.getValue() + "\n;\n" + $('#test').val())); |
| 208 | + } catch (e) { |
| 209 | + console.log(e) |
| 210 | + } |
| 211 | + console.log = oldConsoleLog; |
| 212 | + } |
| 213 | + |
| 214 | + $('#test').keypress(function(e) { |
| 215 | + if (e.which === 13) { |
| 216 | + e.preventDefault(); |
| 217 | + runTest(); |
| 218 | + } |
| 219 | + }); |
| 220 | + |
| 221 | + $('#run-test').click(function(e) { |
| 222 | + e.preventDefault(); |
| 223 | + runTest(); |
| 224 | + }); |
| 225 | + |
150 | 226 | });
|
151 | 227 | </script>
|
152 | 228 | </body>
|
|
0 commit comments