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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
<!DOCTYPE html>
<html lang="de">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, user-scalable=no, maximum-scale=1, shrink-to-fit=no">
    {{#if title }}
        <title>Jugendwettbewerb Informatik – {{title}}</title>
    {{else}}
        <title>Jugendwettbewerb Informatik: Programmieren – leichter, als du denkst!</title>
    {{/if}}

    <script src="/static/lib/jquery/jquery-3.2.1.min.js"></script>
    <script src="/static/lib/fioipem/jschannel-190528.js"></script>
    <script src="/static/lib/fioipem/task-xd-pr-190528.js"></script>
    <script src="/static/lib/medal/medal-1.0.0.js"></script>

    <link rel="icon" href="/static/images/favicon.png" type="image/png">
<style>
body{
  margin: 0px;
  padding: 0px;
  overflow: hidden;
  font-family: sans-serif;
}

:root {
  --vh: 100vh;
}

#bar, #bar>div {
display:inline-block;
padding: 8px;
margin:0px;
background: #8ca405;
color:white;
font-size:12pt;
{{#if preview}}
height: 0px;
{{else}}
height: 35px;
{{/if}}
overflow-y:hidden;
}

#bar {
display:block;
padding:0px;
width:100vw;
}

#bar>.nav {
float:right;
}
#bar>#time {
float:right;
padding:0px 8px;
text-align:right;
}
#timetext{
padding:0px;
margin:0px;
font-size:8pt;
}
#timetime{
padding:0px;
margin:0px;
margin-top:-8px;
font-size:18pt;
}
#ttsec {
font-size:8pt;
}

#bar>#hamburger, #bar>#menu, #bar>#time {
background: #6d8004;
font-weight:bold;
padding-left: 10px;
padding-right: 10px;
}

#bar>div.highlight {
background: #f5fbe8;
  color:#334900;
  font-size: 10pt;
}

.max10 {
  max-width: 10vw;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

.max20 {
  max-width: 20vw;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

iframe {
width: 100vw;
border: 0px;
{{#if preview}}
min-height: 100vh; /* Fallback for browsers that do not support Custom Properties */
{{else}}
min-height: calc(100vh - 35px); /* Fallback for browsers that do not support Custom Properties */
min-height: calc(var(--vh) - 35px);
{{/if}}
}

a {
color: #eee;
text-decoration: none;
}

 /* The Modal (background) */
.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1; /* Sit on top */
  left: 0;
  top: 35px;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content/Box */
.modal-content {
  background-color: #fefefe;
  margin: 15% auto; /* 15% from the top and centered */
  padding: 20px;
  border: 1px solid #888;
  width: 30%; /* Could be more or less, depending on screen size */
}


{{#if readonly}}
#bar, #bar>div {
background: #a48c05
}

#bar>#hamburger, #bar>#menu, #bar>#time {
background: #806d04;
}

#bar>div.highlight {
    background: #fbf5e8;
    color:#493300;

}
{{/if}}
</style>
</head><body style="">

<div id="bar">

{{#if contestname}}
<div id="menu" class="max20" title="{{contestname}}">
{{#if contestid}}
<a href="/contest/{{contestid}}">{{contestname}}</a>
{{else}}
{{contestname}}
{{/if}}
</div>
{{/if}}
<div class="max20" title="{{name}}">
{{name}}
</div>

{{#each subtasks}}
  {{#if active}}
    <div class="highlight max10" title="{{linktext}}">
      {{linktext}}
    </div>
  {{else}}
    <div class="max10" title="{{linktext}}">
      <a href="/task/{{id}}">{{linktext}}</a>
   </div>
  {{/if}}
{{/each}}

{{#if readonly}}
<div class="max10" title="Review-Modus">
<em>Review-Modus</em>
</div>
{{/if}}

{{#unless readonly}}
{{#if time_info.has_timelimit}}
<div id="time" class="max10" title="Verbleibende Zeit">
<div id="timetext">
Verbleibende Zeit
</div>
<div id="timetime">
{{time_left_mh_formatted}}<span id="ttsec">{{time_left_sec_formatted}}</span>
</div>
<script>
  var seconds_left_at_start = {{time_info.left_secs_total}};
  var timerStart = Date.now();

  function lz(a) {
    var b = a.toString();
    if (b.length < 2) {
      return "0" + b;
    }
    return b;
  }

  function updateTimer() {
    var seconds_passed = (Date.now() - timerStart) / 1000;
    var seconds_left = seconds_left_at_start - seconds_passed;

    var timer_sign = "";
    {{#if time_info.exempt_from_timelimit}}
      // Workaround for teachers to allow them to stay in the task even if
      // the time has run out.
      if (seconds_left < 0) {
        seconds_left = -seconds_left;
        timer_sign = "";
      }
    {{/if}}

    if (seconds_left > 0) {
      var hour = seconds_left / 3600 | 0;
      var min = (seconds_left / 60 | 0) % 60 | 0;
      var sec = seconds_left % 60 | 0;

      text = timer_sign + hour.toString() + ":" + lz(min) + "<span id=\"ttsec\">:" + lz(sec) + "</span>";
      document.getElementById("timetime").innerHTML = text;
    }
    else if (seconds_left > -10) {
       document.getElementById("timetime").innerHTML = "0:00<span id=\"ttsec\">:00</span>";
    }
    else {
       document.getElementById("contestpage").click()
    }
  }

  setInterval(updateTimer, 300);
</script>
</div>
{{/if}}
{{/unless}}

<script>
function redirectOverview() {
  window.location.href = "{{#unless standalone_task}}{{#if category}}/contest/{{category}}/{{contestid}}{{else}}/contest/{{contestid}}{{/if}}{{else}}/contest/standalone_task{{/unless}}";
}

function updateIframeHeight() {
  var vh = window.innerHeight;
  document.documentElement.style.setProperty('--vh', vh + "px");

  // do it again after 1 s
  setTimeout(function() {
    var vh = window.innerHeight;
    document.documentElement.style.setProperty('--vh', vh + "px");
  }, 1000)
}

// Update initially and on resize
updateIframeHeight();
window.addEventListener("resize", updateIframeHeight);

function enterFullscreen(element) {
  if(element.requestFullscreen) {
    element.requestFullscreen();
  } else if(element.mozRequestFullScreen) {
    element.mozRequestFullScreen();
  } else if(element.msRequestFullscreen) {
    element.msRequestFullscreen();
  } else if(element.webkitRequestFullscreen) {
    element.webkitRequestFullscreen();
  }
}
function exitFullscreen() {
  if(document.exitFullscreen) {
    document.exitFullscreen();
  } else if(document.mozCancelFullScreen) {
    document.mozCancelFullScreen();
  } else if(document.webkitExitFullscreen) {
    document.webkitExitFullscreen();
  }
}
var fullscreen = false;
function toggleFullscreen(element) {
if (fullscreen) {
  exitFullscreen();
fullscreen = false;
    document.getElementById("tgfs").innerText = "";
}
else {
  enterFullscreen(element);
  fullscreen = true;
    document.getElementById("tgfs").innerText = "";
  }
}
</script>
<div class="nav max10" onclick="toggleFullscreen(document.documentElement);" title="Vollbild">
<a href="javascript:;"><span id="tgfs"></span> Vollbild</a>
</div>

{{#if contestid}}
<div class="nav max10" title="Übersicht">
  <a href="{{#unless standalone_task}}{{#if category}}/contest/{{category}}/{{contestid}}{{else}}/contest/{{contestid}}{{/if}}{{else}}/contest/standalone_task{{/unless}}" id="contestpage">⇧ Übersicht</a>
</div>
{{/if}}
{{#if nexttask}}
<div class="nav max10" title="Nächste Aufgabe">
<a href="{{ nexttask }}">⇨ Nächste Aufgabe</a>
</div>
{{/if}}
{{#if prevtask}}
<div class="nav max10" title="Vorherige Aufgabe">
<a href="{{ prevtask }}">⇦ Vorherige Aufgabe</a>
</div>
{{/if}}

</div>
</div>

<div id="save-submission-modal" class="modal">
  <div class="modal-content">
    <p>Deine Einsendung wird gespeichert. Dies scheint etwas länger zu dauern als üblich …</p>
    <p>Möglicherweise liegt ein Problem mit der Netzwerkverbindung vor. Du kannst versuchen, deine Einsendung erneut zu speichern: <button id="save-again">Erneut speichern</button>.</p>
  </div>
</div>

<iframe src="/{{taskpath}}?{{#if tasklang}}language={{tasklang}}&{{/if}}channelId=task" id="ifr" style="border: 0px; margin:0px; padding:0px; "></iframe>

<script>
// Magic: This sets some internal state of the medal js lib that is usually read from the url fragment identifier
window.hashdict["taskid"] = "{{taskid}}";
window.hashdict["csrftoken"] = "{{csrf_token}}";
{{#if readonly}}
  window.hashdict["readonly"] = "true";
{{/if}} //

var options = {
  minScore:0,
  maxScore:100,
  noScore:0,
  randomSeed:0,
  readOnly:false,
  options:{difficulty:"easy", log:1},
}

var myLoadViews = {
  editor: true,
  forum: true,
  hints: true,
  submission: true,
  task: true,
  grader: true,
  metadata: true,
}

var myViews = {
  task: true,
}

function ec(name) {
  return function(e){
    console.log(name + " error:");
    console.log(e);
  }
}

function noop(){}

var previous_answer = "";
var best_score = 0;
var best_unsaved_score = 0;

function getTaskProxyCallback(task) {
  function reloadAnswerCallback() {
    task.gradeAnswer("", {}, noop, ec("task.gradeAnswer"));
  }

  function reloadStateCallback() {
    function load_task_callback(data) {
      if ("text" in data) {
        task.reloadAnswer(data["text"], reloadAnswerCallback, ec("task.reloadAnswer"));
      } else {
        task.reloadAnswer('', reloadAnswerCallback, ec("task.reloadAnswer"));
      }
    }
    function load_task_error() {
      task.reloadAnswer('', reloadAnswerCallback, ec("task.reloadAnswer"));
      alert("Laden fehlgeschlagen");
    }

    {{#if submission}}
      window.load_submission_object({{submission}}, load_task_callback, load_task_error);
    {{else}}
      {{#if preview}}
        // Directly load an empty task without asking the server first
        load_task_callback({});
      {{else}}
        window.load_task_object(load_task_callback, load_task_error);
      {{/if}}
    {{/if}} //
  }

  function showViewsCallback(){
    task.reloadState('', reloadStateCallback, ec("task.reloadState"));
  }

  function loadCallback(){
    task.showViews(myViews, showViewsCallback, ec("task.showViews"));
  }

  function getViewsCallback(views){
    task.load(myLoadViews, loadCallback, ec("task.load"))
  }

  function getAnswerCallback(answer, save_message, autosave) {
    if (window.hashdict["readonly"] == "true") {
      return;
    }

    // If the answer did not change since last save, there is nothing to do
    if (answer == previous_answer) {
      return;
    }

    console.log("In task.gradeAnswer callback:");
    console.log(answer);

    function gradeAnswerCallback(score, message, scoreToken){
      var not_saved_yet = true;
      var needs_message = false;
      if (score > best_score) {
        needs_message = true;
      }
      if (score > best_unsaved_score) {
        best_unsaved_score = score;
      }
      function save_task_callback() {
        not_saved_yet = false;
        console.log("OK transmission");

        // Now we know that the answer has been saved
        previous_answer = answer;
        if (score > best_score) {
          best_score = score;
        }

        if (best_unsaved_score <= best_score) {
          document.getElementById("save-submission-modal").style.display = "none";
          document.getElementById("save-again").onclick = function() {}
        }
      };
      function save_task_error() {
        console.log("ERROR transmission");
        alert("Speichern fehlgeschlagen");
      };

      if (score > best_score && save_message) {
        setTimeout(function(){
          if (not_saved_yet && best_unsaved_score > best_score) {
            document.getElementById("save-submission-modal").style.display = "block";
            document.getElementById("save-again").disabled = true;
            setTimeout(function(){document.getElementById("save-again").disabled = false;}, 3000);
            document.getElementById("save-again").onclick = function() {
              document.getElementById("save-again").disabled = true;
              setTimeout(function(){document.getElementById("save-again").disabled = false;}, 3000);
              window.save_task_object({"text": answer}, score, save_task_callback, save_task_error);
            };
          }
        }, 200);
      }
      window.save_task_object({"text": answer}, score, autosave, save_task_callback, save_task_error);
    }

    task.gradeAnswer(answer, {}, gradeAnswerCallback, ec("task.gradeAnswer"));
  }

  var platform = {
    getTaskParams: function(key, def, cb, ecb) {
      if (!key && !def) {
        cb(options);
      }
      else {
        cb();
      }
    },
    validate: function(mode, cb, ecb) {
      if (mode == 'done') {
        task.getAnswer(function(answer) {return getAnswerCallback(answer, true, false);}, ec("task.getAnswer"));
        if (cb) {cb();}
      }
      else if (mode == 'next' || mode == 'nextImmediate') {
        window.parent.redirectOverview();
      }
      if (mode == 'log') {
          task.getAnswer(function(answer) {return getAnswerCallback(answer, false, false);}, ec("task.getAnswer"));
        if (cb) {cb();}
      }
      else {
        console.error("Unknown mode: '" + mode + "'");
        if (ecb) {ecb();}
      }
    },
    showViews: function(views, cb, ecb) {
      cb(options);
    },
    openUrl: function(textId, cb, ecb) {
      cb();
    },
    askHint: function(ht, cb, ecb) {
      cb();
    },
    updateDisplay: function(opt, cb, ecb) {
      cb();
    },
    initWithTask: function(t, cb, ecb) {
      cb(options);
    },
    log: function(l, cb, ecb) {
      cb();
    }
  };

  TaskProxyManager.setPlatform(task, platform);

  task.getViews(getViewsCallback, ec("task.getViews"));

  if (window.hashdict["readonly"] != "true" && {{auto_save_interval_ms}} > 0) {
    setInterval(function(){
      task.getAnswer(function(answer) {return getAnswerCallback(answer, false, true);}, ec("task.getAnswer"));
    }, {{auto_save_interval_ms}});
  }
}

function main() {
  TaskProxyManager.getTaskProxy("ifr", getTaskProxyCallback, false, ec("task.getTaskProxy"));
}

setTimeout(main, 1);

    </script>
</body></html>