-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.php
4598 lines (4163 loc) · 152 KB
/
renderer.php
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Render an attempt at a HotPot quiz
* Output format: hp_6
*
* @package mod
* @subpackage hotpot
* @copyright 2010 Gordon Bateson (gordon.bateson@gmail.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
*/
/** Prevent direct access to this script */
defined('MOODLE_INTERNAL') || die();
/** Include required files */
require_once($CFG->dirroot.'/mod/hotpot/attempt/hp/renderer.php');
/**
* mod_hotpot_attempt_hp_6_renderer
*
* @copyright 2010 Gordon Bateson (gordon.bateson@gmail.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.0
* @package mod
* @subpackage hotpot
*/
class mod_hotpot_attempt_hp_6_renderer extends mod_hotpot_attempt_hp_renderer {
/**
* init
*
* @param xxx $hotpot
*/
function init($hotpot) {
parent::init($hotpot);
array_unshift($this->templatesfolders, 'mod/hotpot/attempt/hp/6/templates');
}
/**
* fix_headcontent_DragAndDrop for JMix and JMatch
*/
function fix_headcontent_DragAndDrop() {
// replace one line functions that get and set positions of positionable elements
$search = array(
'/(?<=function CardGetL).*/',
'/(?<=function CardGetT).*/',
'/(?<=function CardGetW).*/',
'/(?<=function CardGetH).*/',
'/(?<=function CardGetB).*/',
'/(?<=function CardGetR).*/',
'/(?<=function CardSetL).*/',
'/(?<=function CardSetT).*/',
'/(?<=function CardSetW).*/',
'/(?<=function CardSetH).*/',
);
$replace = array(
"(){return getOffset(this.elm, 'Left')}",
"(){return getOffset(this.elm, 'Top')}",
"(){return getOffset(this.elm, 'Width')}",
"(){return getOffset(this.elm, 'Height')}",
"(){return getOffset(this.elm, 'Bottom')}",
"(){return getOffset(this.elm, 'Right')}",
"(NewL){setOffset(this.elm, 'Left', NewL)}",
"(NewT){setOffset(this.elm, 'Top', NewT)}",
"(NewW){setOffset(this.elm, 'Width', NewW)}",
"(NewH){setOffset(this.elm, 'Height', NewH)}"
);
$this->headcontent = preg_replace($search, $replace, $this->headcontent, 1);
}
/**
* fix_headcontent_rottmeier
*
* @param xxx $type (optional, default='')
*/
function fix_headcontent_rottmeier($type='') {
switch ($type) {
case 'dropdown':
// adding missing brackets to call to Is_ExerciseFinished() in CheckAnswers()
$search = '/(Finished\s*=\s*Is_ExerciseFinished)(;)/';
$this->headcontent = preg_replace($search, '$1()$2', $this->headcontent);
break;
case 'findit':
// get position of last </style> tag and
// insert CSS to make <b> and <em> tags bold
// even within GapSpans added by javascript
$search = '</style>';
if ($pos = strrpos($this->headcontent, $search)) {
$insert = "\n"
.'<!--[if IE 6]><style type="text/css">'."\n"
.'span.GapSpan{'."\n"
.' font-size:24px;'."\n"
.'}'."\n"
.'</style><![endif]-->'."\n"
.'<style type="text/css">'."\n"
.'b span.GapSpan,'."\n"
.'em span.GapSpan{'."\n"
.' font-weight:inherit;'."\n"
.'}'."\n"
.'</style>'."\n"
;
$this->headcontent = substr_replace($this->headcontent, $insert, $pos + strlen($search), 0);
}
break;
case 'jintro':
// add TimeOver variable, so we can use standard detection of quiz completion
if ($pos = strpos($this->headcontent, 'var Score = 0;')) {
$insert = "var TimeOver = false;\n";
$this->headcontent = substr_replace($this->headcontent, $insert, $pos, 0);
}
break;
case 'jmemori':
// add TimeOver variable, so we can use standard detection of quiz completion
if ($pos = strpos($this->headcontent, 'var Score = 0;')) {
$insert = "var TimeOver = false;\n";
$this->headcontent = substr_replace($this->headcontent, $insert, $pos, 0);
}
// override table border collapse from standard Moodle styles
if ($pos = strrpos($this->headcontent, '</style>')) {
$insert = ''
.'#'.$this->themecontainer.' form table'."\n"
.'{'."\n"
.' border-collapse: separate;'."\n"
.' border-spacing: 2px;'."\n"
.'}'."\n"
;
$this->headcontent = substr_replace($this->headcontent, $insert, $pos, 0);
}
break;
}
}
/**
* fix_bodycontent_rottmeier
*
* @param xxx $hideclozeform (optional, default=false)
*/
function fix_bodycontent_rottmeier($hideclozeform=false) {
// fix left aligned instructions in Rottmeier-based formats
// JCloze: DropDown, FindIt(a)+(b), JGloss
// JMatch: JMemori
$search = '/<p id="Instructions">(.*?)<\/p>/is';
$replace = '<div id="Instructions">$1</div>';
$this->bodycontent = preg_replace($search, $replace, $this->bodycontent);
if ($hideclozeform) {
// initially hide the Cloze text (so gaps are not revealed)
$search = '/<(form id="Cloze" [^>]*)>/is';
$replace = '<$1 style="display:none;">';
$this->bodycontent = preg_replace($search, $replace, $this->bodycontent);
}
}
/**
* get_js_functionnames
*
* @return xxx
*/
function get_js_functionnames() {
// return a comma-separated list of js functions to be "fixed".
// Each function name requires an corresponding function called:
// fix_js_{$name}
return 'Client,ShowElements,GetViewportHeight,SuppressBackspace,PageDim,TrimString,RemoveBottomNavBarForIE,StartUp,GetUserName,PreloadImages,ShowMessage,HideFeedback,SendResults,Finish,WriteToInstructions,ShowSpecialReadingForQuestion';
}
/**
* fix_js_Client
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
*/
function fix_js_Client(&$str, $start, $length) {
$substr = substr($str, $start, $length);
// refine detection of Chrome browser
$search = 'this.geckoVer < 20020000';
if ($pos = strpos($substr, $search)) {
$substr = substr_replace($substr, 'this.geckoVer > 10000000 && ', $pos, 0);
}
// add detection of Chrome browser
$search = '/(\s*)if \(this\.min == false\)\{/s';
$replace = '$1'
."this.chrome = (this.ua.indexOf('Chrome') > 0);".'$1'
."if (this.chrome) {".'$1'
." this.geckoVer = 0;".'$1'
." this.safari = false;".'$1'
." this.min = true;".'$1'
."}$0"
;
$substr = preg_replace($search, $replace, $substr, 1);
$str = substr_replace($str, $substr, $start, $length);
}
/**
* fix_js_ShowElements
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
*/
function fix_js_ShowElements(&$str, $start, $length) {
$substr = substr($str, $start, $length);
// hide <embed> tags (required for Chrome browser)
if ($pos = strpos($substr, 'TagName == "object"')) {
$substr = substr_replace($substr, 'TagName == "embed" || ', $pos, 0);
}
$str = substr_replace($str, $substr, $start, $length);
}
/**
* fix_js_PageDim
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
* @return xxx
*/
function fix_js_PageDim(&$str, $start, $length) {
if ($this->usemoodletheme) {
$obj = "document.getElementById('$this->themecontainer')"; // moodle
} else {
$obj = "document.getElementsByTagName('body')[0]"; // original
}
$replace = ''
."function getStyleValue(obj, property_name, propertyName){\n"
." var value = 0;\n"
." // Watch out for HTMLDocument which has no style property\n"
." // as this causes errors later in getComputedStyle() in FF\n"
." if (obj && obj.style){\n"
." // based on http://www.quirksmode.org/dom/getstyles.html\n"
." if (document.defaultView && document.defaultView.getComputedStyle){\n"
." // Firefox, Opera, Safari\n"
." value = document.defaultView.getComputedStyle(obj, null).getPropertyValue(property_name);\n"
." } else if (obj.currentStyle) {"
." // IE (and Opera)\n"
." value = obj.currentStyle[propertyName];\n"
." }\n"
." if (typeof(value)=='string'){\n"
." var r = new RegExp('([0-9.]*)([a-z]+)');\n"
." var m = value.match(r);\n"
." if (m){\n"
." switch (m[2]){\n"
." case 'em':\n"
." // as far as I can see, only IE needs this\n"
." // other browsers have getComputedStyle() in px\n"
." if (typeof(obj.EmInPx)=='undefined'){\n"
." var div = obj.parentNode.appendChild(document.createElement('div'));\n"
." div.style.margin = '0px';\n"
." div.style.padding = '0px';\n"
." div.style.border = 'none';\n"
." div.style.height = '1em';\n"
." obj.EmInPx = getOffset(div, 'Height');\n"
." obj.parentNode.removeChild(div);\n"
." }\n"
." value = parseFloat(m[1] * obj.EmInPx);\n"
." break;\n"
." case 'px':\n"
." value = parseFloat(m[1]);\n"
." break;\n"
." default:\n"
." value = 0;\n"
." }\n"
." } else {\n"
." value = 0 ;\n"
." }\n"
." } else {\n"
." value = 0;\n"
." }\n"
." }\n"
." return value;\n"
."}\n"
."function isStrict(){\n"
." return false;\n"
." if (typeof(window.cache_isStrict)=='undefined'){\n"
." if (document.compatMode) { // ie6+\n"
." window.cache_isStrict = (document.compatMode=='CSS1Compat');\n"
." } else if (document.doctype){\n"
." var s = document.doctype.systemId || document.doctype.name; // n6 OR ie5mac\n"
." window.cache_isStrict = (s && s.indexOf('strict.dtd') >= 0);\n"
." } else {\n"
." window.cache_isStrict = false;\n"
." }\n"
." }\n"
." return window.cache_isStrict;\n"
."}\n"
."function setOffset(obj, type, value){\n"
." if (! obj){\n"
." return false;\n"
." }\n"
."\n"
." switch (type){\n"
." case 'Right':\n"
." return setOffset(obj, 'Width', value - getOffset(obj, 'Left'));\n"
." case 'Bottom':\n"
." return setOffset(obj, 'Height', value - getOffset(obj, 'Top'));\n"
." }\n"
."\n"
." if (isStrict()){\n"
." // set arrays of p(roperties) and s(ub-properties)\n"
." var properties = new Array('margin', 'border', 'padding');\n"
." switch (type){\n"
." case 'Top':\n"
." var sides = new Array('Top');\n"
." break;\n"
." case 'Left':\n"
." var sides = new Array('Left');\n"
." break;\n"
." case 'Width':\n"
." var sides = new Array('Left', 'Right');\n"
." break;\n"
." case 'Height':\n"
." var sides = new Array('Top', 'Bottom');\n"
." break;\n"
." default:\n"
." return 0;\n"
." }\n"
." for (var p=0; p<properties.length; p++){\n"
." for (var s=0; s<sides.length; s++){\n"
." var propertyName = properties[p] + sides[s];\n"
." var property_name = properties[p] + '-' + sides[s].toLowerCase();\n"
." value -= getStyleValue(obj, property_name, propertyName);\n"
." }\n"
." }\n"
." value = Math.floor(value);\n"
." }\n"
." if (type=='Top' || type=='Left') {\n"
." value -= getOffset(obj.offsetParent, type);\n"
." }\n"
." if (obj.style) {\n"
." obj.style[type.toLowerCase()] = value + 'px';\n"
." }\n"
."}\n"
."function getOffset(obj, type){\n"
." if (! obj){\n"
." return 0;\n"
." }\n"
." switch (type){\n"
." case 'Width':\n"
." case 'Height':\n"
." return (obj['offset'+type]||0);\n"
."\n"
." case 'Top':\n"
." case 'Left':\n"
." return (obj['offset'+type]||0) + getOffset(obj.offsetParent, type);\n"
."\n"
." case 'Right':\n"
." return getOffset(obj, 'Left') + getOffset(obj, 'Width');\n"
."\n"
." case 'Bottom':\n"
." return getOffset(obj, 'Top') + getOffset(obj, 'Height');\n"
."\n"
." default:\n"
." return 0;\n"
." } // end switch\n"
."}\n"
."function PageDim(){\n"
." var obj = $obj;\n"
." this.W = getOffset(obj, 'Width');\n"
." this.H = getOffset(obj, 'Height');\n"
." this.Top = getOffset(obj, 'Top');\n"
." this.Left = getOffset(obj, 'Left');\n"
."}\n"
."function getClassAttribute(className, attributeName){\n"
." //based on http://www.shawnolson.net/a/503/\n"
." if (! document.styleSheets){\n"
." return null; // old browser\n"
." }\n"
." var css = document.styleSheets;\n"
." var rules = (document.all ? 'rules' : 'cssRules');\n"
." var regexp = new RegExp('\\\\.'+className+'\\\\b');\n"
." try {\n"
." var i_max = css.length;\n"
." } catch(err) {\n"
." var i_max = 0; // shouldn't happen !!\n"
." }\n"
." for (var i=0; i<i_max; i++){\n"
." try {\n"
." var ii_max = css[i][rules].length;\n"
." } catch(err) {\n"
." var ii_max = 0; // shouldn't happen !!\n"
." }\n"
." for (var ii=0; ii<ii_max; ii++){\n"
." if (! css[i][rules][ii].selectorText){\n"
." continue;\n"
." }\n"
." if (css[i][rules][ii].selectorText.match(regexp)){\n"
." if (css[i][rules][ii].style[attributeName]){\n"
." // class/attribute found\n"
." return css[i][rules][ii].style[attributeName];\n"
." }\n"
." }\n"
." }\n"
." }\n"
." // class/attribute not found\n"
." return null;\n"
."}\n"
;
$str = substr_replace($str, $replace, $start, $length);
}
/**
* fix_js_GetViewportHeight
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
* @return xxx
*/
function fix_js_GetViewportHeight(&$str, $start, $length) {
$replace = ''
."function GetViewportSize(type){\n"
." if (eval('window.inner' + type)){\n"
." return eval('window.inner' + type);\n"
." }\n"
." if (document.documentElement){\n"
." if (eval('document.documentElement.client' + type)){\n"
." return eval('document.documentElement.client' + type);\n"
." }\n"
." }\n"
." if (document.body){\n"
." if (eval('document.body.client' + type)){\n"
." return eval('document.body.client' + type);\n"
." }\n"
." }\n"
." return 0;\n"
."}\n"
."function GetViewportHeight(){\n"
." return GetViewportSize('Height');\n"
."}\n"
."function GetViewportWidth(){\n"
." return GetViewportSize('Width');\n"
."}"
;
$str = substr_replace($str, $replace, $start, $length);
}
/**
* fix_js_SuppressBackspace
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
* @return xxx
*/
function fix_js_SuppressBackspace(&$str, $start, $length) {
// could also check "window.InTextBox" which is HP's standard way of detecting INPUT and TEXTAREA
$replace = ''
."function SuppressBackspace(evt) {\n"
." if (evt==null) {\n"
." evt = window.event;\n"
." }\n"
." if (evt.target) {\n"
." var evtTarget = evt.target;\n"
." } else if (evt.srcElement) {\n"
." var evtTarget = evt.srcElement;\n"
." } else {\n"
." return true;\n" // shouldn't happen !!
." }\n"
." if (evt.keyCode != 8) {\n"
." return true;\n" // not the delete key
." }\n"
." if (evtTarget.nodeType==3) {\n" // Safari quirk
." evtTarget = evtTarget.parentNode;\n"
." }\n"
." if (evtTarget.tagName=='INPUT' || evtTarget.tagName=='TEXTAREA') {\n"
." return true;\n" // allow delete key in text input / textarea
." }\n"
." if (evt.preventDefault) {\n"
." evt.preventDefault();\n"
." } else if (window.event) {\n"
." window.event.returnValue = false;\n"
." window.event.cancelBubble = true;\n"
." }\n"
." return false;\n"
."}\n"
;
$str = substr_replace($str, $replace, $start, $length);
// remove standard HP code that assigns event keypress/keydown handler
$offset = $start + strlen($replace);
list($start, $finish) = $this->locate_js_block('if', 'C.ie', $str, true, $offset);
if ($finish) {
$length = $finish - $start;
$str = substr_replace($str, '', $start, $length);
}
}
/**
* remove_js_function
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
* @param xxx $function
*/
function remove_js_function(&$str, $start, $length, $function) {
// remove this function
$str = substr_replace($str, '', $start, $length);
// remove all direct calls to this function
$search = '/\s*'.$function.'\([^)]*\);/s';
$str = preg_replace($search, '', $str);
}
/**
* fix_js_TrimString
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
* @return xxx
*/
function fix_js_TrimString(&$str, $start, $length) {
$replace = ''
."function TrimString(InString){\n"
." if (typeof(InString)=='string'){\n"
." InString = InString.replace(new RegExp('^\\\\s+', 'g'), ''); // left\n"
." InString = InString.replace(new RegExp('\\\\s+$', 'g'), ''); // right\n"
." InString = InString.replace(new RegExp('\\\\s+', 'g'), ' '); // inner\n"
." }\n"
." return InString;\n"
."}"
;
$str = substr_replace($str, $replace, $start, $length);
}
/**
* fix_js_TypeChars
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
*/
function fix_js_TypeChars(&$str, $start, $length) {
if ($obj = $this->fix_js_TypeChars_obj()) {
$substr = substr($str, $start, $length);
if (strpos($substr, 'document.selection')===false) {
$replace = ''
."function TypeChars(Chars){\n"
.$this->fix_js_TypeChars_init()
." if ($obj==null || $obj.style.display=='none') {\n"
." return;\n"
." }\n"
." $obj.focus();\n"
." if (typeof($obj.selectionStart)=='number') {\n"
." // FF, Safari, Chrome, Opera\n"
." var startPos = $obj.selectionStart;\n"
." var endPos = $obj.selectionEnd;\n"
." $obj.value = $obj.value.substring(0, startPos) + Chars + $obj.value.substring(endPos);\n"
." var newPos = startPos + Chars.length;\n"
." $obj.setSelectionRange(newPos, newPos);\n"
." } else if (document.selection) {\n"
." // IE (tested on IE6, IE7, IE8)\n"
." var rng = document.selection.createRange();\n"
." rng.text = Chars;\n"
." rng = null; // prevent memory leak\n"
." } else {\n"
." // this browser can't insert text, so append instead\n"
." $obj.value += Chars;\n"
." }\n"
."}"
;
$str = substr_replace($str, $replace, $start, $length);
}
}
}
/**
* fix_js_TypeChars_init
*
* @return xxx
*/
function fix_js_TypeChars_init() {
return '';
}
/**
* fix_js_TypeChars_obj
*
* @return xxx
*/
function fix_js_TypeChars_obj() {
return '';
}
/**
* fix_js_SendResults
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
*/
function fix_js_SendResults(&$str, $start, $length) {
$this->remove_js_function($str, $start, $length, 'SendResults');
}
/**
* fix_js_GetUserName
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
*/
function fix_js_GetUserName(&$str, $start, $length) {
$this->remove_js_function($str, $start, $length, 'GetUserName');
}
/**
* fix_js_Finish
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
*/
function fix_js_Finish(&$str, $start, $length) {
$this->remove_js_function($str, $start, $length, 'Finish');
}
/**
* fix_js_PreloadImages
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
*/
function fix_js_PreloadImages(&$str, $start, $length) {
$substr = substr($str, $start, $length);
// fix issue in IE8 which sometimes doesn't have Image object in popups
// http://moodle.org/mod/forum/discuss.php?d=134510
$search = "Imgs[i] = new Image();";
if ($pos = strpos($substr, $search)) {
$replace = "Imgs[i] = (window.Image ? new Image() : document.createElement('img'));";
$substr = substr_replace($substr, $replace, $pos, strlen($search));
}
$str = substr_replace($str, $substr, $start, $length);
}
/**
* fix_js_WriteToInstructions
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
* @return xxx
*/
function fix_js_WriteToInstructions(&$str, $start, $length) {
$substr = substr($str, $start, $length);
if ($pos = strpos($substr, '{')) {
$insert = "\n"
." // check required HTML element exists\n"
." if (! document.getElementById('InstructionsDiv')) return false;\n"
;
$substr = substr_replace($substr, $insert, $pos+1, 0);
}
if ($pos = strrpos($substr, '}')) {
$append = "\n"
." StretchCanvasToCoverContent(true);\n"
;
$substr = substr_replace($substr, $append, $pos, 0);
}
$str = substr_replace($str, $substr, $start, $length);
}
/**
* fix_js_ShowMessage
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
* @return xxx
*/
function fix_js_ShowMessage(&$str, $start, $length) {
// the ShowMessage function is used by all HP6 quizzes
$substr = substr($str, $start, $length);
// only show feedback if the required HTML elements exist
// this prevents JavaScript errors which block the returning of the quiz results to Moodle
if ($pos = strpos($substr, '{')) {
$insert = "\n"
." // check required HTML elements exist\n"
." if (! document.getElementById('FeedbackDiv')) return false;\n"
." if (! document.getElementById('FeedbackContent')) return false;\n"
." if (! document.getElementById('FeedbackOKButton')) return false;\n"
;
$substr = substr_replace($substr, $insert, $pos+1, 0);
}
// hide <embed> elements on Chrome browser
$search = "/(\s*)ShowElements\(true, 'object', 'FeedbackContent'\);/s";
$replace = ''
."$0".'$1'
."if (C.chrome) {".'$1'
." ShowElements(false, 'embed');".'$1'
." ShowElements(true, 'embed', 'FeedbackContent');".'$1'
."}"
;
$substr = preg_replace($search, $replace, $substr, 1);
// fix "top" setting to position FeedbackDiv
if ($this->usemoodletheme) {
$canvas = "document.getElementById('$this->themecontainer')"; // moodle
} else {
$canvas = "document.getElementsByTagName('body')[0]"; // original
}
$search = "/FDiv.style.top = [^;]*;(\s*)(FDiv.style.display = [^;]*;)/s";
$replace = ''
.'$1$2'
.'$1'."var t = getOffset($canvas, 'Top');"
.'$1'."setOffset(FDiv, 'Top', Math.max(t, TopSettingWithScrollOffset(30)));"
;
$substr = preg_replace($search, $replace, $substr, 1);
// append link to student feedback form, if necessary
if ($this->hotpot->studentfeedback) {
$search = '/(\s*)var Output = [^;]*;/';
$replace = ''
."$0".'$1'
."if (window.FEEDBACK) {".'$1'
." Output += '".'<a href="javascript:hpFeedback();">'."' + FEEDBACK[6] + '</a>';".'$1'
."}"
;
$substr = preg_replace($search, $replace, $substr, 1);
}
$str = substr_replace($str, $substr, $start, $length);
}
/**
* fix_js_RemoveBottomNavBarForIE
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
*/
function fix_js_RemoveBottomNavBarForIE(&$str, $start, $length) {
$replace = ''
."function RemoveBottomNavBarForIE(){\n"
." if (C.ie) {\n"
." if (document.getElementById('Reading')){\n"
." var obj = document.getElementById('BottomNavBar');\n"
." if (obj){\n"
." obj.parentNode.removeChild(obj);\n"
." }\n"
." }\n"
." }\n"
."}"
;
$str = substr_replace($str, $replace, $start, $length);
}
/**
* fix_js_StartUp_DragAndDrop
*
* @param xxx $substr (passed by reference)
*/
function fix_js_StartUp_DragAndDrop(&$substr) {
// fixes for Drag and Drop (JMatch and JMix)
}
/**
* fix_js_StartUp_DragAndDrop_DragArea
*
* @param xxx $substr (passed by reference)
*/
function fix_js_StartUp_DragAndDrop_DragArea(&$substr) {
// fix LeftCol (=left side of drag area)
$search = '/(LeftColPos = [^;]+);/';
$replace = '$1 + pg.Left;';
$substr = preg_replace($search, $replace, $substr, 1);
// fix DragTop (=top side of Drag area)
$search = '/DragTop = [^;]+;/';
$replace = "DragTop = getOffset(document.getElementById('CheckButtonDiv'),'Bottom') + 10;";
$substr = preg_replace($search, $replace, $substr, 1);
}
/**
* fix_js_StartUp
*
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
*/
function fix_js_StartUp(&$str, $start, $length) {
$substr = substr($str, $start, $length);
// ensure StartUp is not called more than once
if ($pos = strpos($substr, '{')) {
$insert = "\n"
." if (window.StartedUp) {\n"
." return;\n"
." }\n"
." window.StartedUp = true;"
;
$substr = substr_replace($substr, $insert, $pos+1, 0);
}
// if necessary, fix drag area for JMatch or JMix drag-and-drop
$this->fix_js_StartUp_DragAndDrop($substr);
if ($pos = strrpos($substr, '}')) {
if ($this->hotpot->delay3==hotpot::TIME_DISABLE) {
$ajax = 1;
} else {
$ajax = 0;
}
if ($this->can_clickreport()) {
$sendallclicks = 1;
} else {
$sendallclicks = 0;
}
if ($this->can_continue()==hotpot::CONTINUE_RESUMEQUIZ) {
$onunload_status = hotpot::STATUS_INPROGRESS;
} else {
$onunload_status = hotpot::STATUS_ABANDONED;
}
$append = "\n"
."// adjust size and position of Feedback DIV\n"
." if (! window.pg){\n"
." window.pg = new PageDim();\n"
." }\n"
." var FDiv = document.getElementById('FeedbackDiv');\n"
." if (FDiv){\n"
." var w = getOffset(FDiv, 'Width') || FDiv.style.width || getClassAttribute(FDiv.className, 'width');\n"
." if (w){\n"
." if (typeof(w)=='string' && w.indexOf('%')>=0){\n"
." var percent = parseInt(w);\n"
." } else {\n"
." var percent = Math.floor(100 * parseInt(w) / pg.W);\n"
." }\n"
." } else if (window.FeedbackWidth && window.DivWidth){\n"
." var percent = Math.floor(100 * FeedbackWidth / DivWidth);\n"
." } else {\n"
." var percent = 34; // default width as percentage\n"
." }\n"
." FDiv.style.display = 'block';\n"
." setOffset(FDiv, 'Left', pg.Left + Math.floor(pg.W * (50 - percent/2) / 100));\n"
." setOffset(FDiv, 'Width', Math.floor(pg.W * percent / 100));\n"
." FDiv.style.display = 'none';\n"
." }\n"
."\n"
." // create HP object (to collect and send responses)\n"
." window.HP = new ".$this->js_object_type."($sendallclicks,$ajax);\n"
."\n"
." // define event handlers to try to send results if quiz finishes unexpectedly\n"
." HP_add_listener(window, 'beforeunload', HP_send_results);\n" // modern browsers
." HP_add_listener(window, 'pagehide', HP_send_results);\n" // modern browsers that don't allow actions in "onbeforeunload"
." HP_add_listener(window, 'unload', HP_send_results);\n" // old browsers that don't have "onbeforeunload" or "pagehide"
."\n"
;
$substr = substr_replace($substr, $append, $pos, 0);
}
// stretch the canvas vertically down, if there is a reading
if ($pos = strrpos($substr, '}')) {
// Reading is contained in <div class="LeftContainer">
// MainDiv is contained in <div class="RightContainer">
// when there is a reading. Otherwise, MainDiv is not contained.
// ReadingDiv is used to show different reading for each question
if ($this->usemoodletheme) {
$canvas = "document.getElementById('$this->themecontainer')"; // moodle
} else {
$canvas = "document.getElementsByTagName('body')[0]"; // original
}
// None: $canvas = "document.getElementById('page-mod-hotpot-attempt')"
$id = $this->embed_object_id;
$onload = $this->embed_object_onload;
$insert = "\n"
."// fix canvas height, if necessary\n"
." if (! window.hotpot_mediafilter_loader){\n"
." StretchCanvasToCoverContent();\n"
." }\n"
."}\n"
."function StretchCanvasToCoverContent(skipTimeout){\n"
." if (! skipTimeout){\n"
." if (navigator.userAgent.indexOf('Firefox/3')>=0){\n"
." var millisecs = 1000;\n"
." } else {\n"
." var millisecs = 500;\n"
." }\n"
." setTimeout('StretchCanvasToCoverContent(true)', millisecs);\n"
." return;\n"
." }\n"
." var canvas = $canvas;\n"
." if (canvas){\n"
." var ids = new Array('Reading','ReadingDiv','MainDiv');\n"
." var i_max = ids.length;\n"
." for (var i=i_max-1; i>=0; i--){\n"
." var obj = document.getElementById(ids[i]);\n"
." if (obj){\n"
." obj.style.height = ''; // reset height\n"
." } else {\n"
." ids.splice(i, 1); // remove this id\n"
." i_max--;\n"
." }\n"
." }\n"
." var b = 0;\n"
." for (var i=0; i<i_max; i++){\n"
." var obj = document.getElementById(ids[i]);\n"
." b = Math.max(b, getOffset(obj,'Bottom'));\n"
." }\n"
." if (window.Segments) {\n" // JMix special
." var obj = document.getElementById('D'+(Segments.length-1));\n"
." if (obj) {\n"
." b = Math.max(b, getOffset(obj,'Bottom'));\n"
." }\n"
." }\n"
." if (b){\n"
." setOffset(canvas, 'Bottom', b + 21);\n"
." for (var i=0; i<i_max; i++){\n"
." var obj = document.getElementById(ids[i]);\n"
." setOffset(obj, 'Bottom', b);\n"
." }\n"
." }\n"
." }\n"
;
if ($this->hotpot->navigation==hotpot::NAVIGATION_EMBED) {
// stretch container object/iframe
$insert .= ''
." if (parent.$onload) {\n"
." parent.$onload(null, parent.document.getElementById('".$this->embed_object_id."'));\n"
." }\n"
;
}
$substr = substr_replace($substr, $insert, $pos, 0);
}
$str = substr_replace($str, $substr, $start, $length);
}
/**
* fix_js_HideFeedback
*
* @uses $CFG
* @param xxx $str (passed by reference)
* @param xxx $start
* @param xxx $length
*/
function fix_js_HideFeedback(&$str, $start, $length) {
global $CFG;
$substr = substr($str, $start, $length);
// unhide <embed> elements on Chrome browser
$search = "/(\s*)ShowElements\(true, 'object'\);/s";
$replace = ''
.'$0$1'
."if (C.chrome) {".'$1'
." ShowElements(true, 'embed');".'$1'
."}"
;
$substr = preg_replace($search, $replace, $substr, 1);
$search = '/('.'\s*if \(Finished == true\){\s*)(?:.*?)(\s*})/s';
if ($this->hotpot->delay3==hotpot::TIME_AFTEROK) {
$replace = '$1'.'HP_send_results(HP.EVENT_SENDVALUES);'.'$2';
} else {
$replace = ''; // i.e. remove this if-block
}
$substr = preg_replace($search, $replace, $substr, 1);
$str = substr_replace($str, $substr, $start, $length);
}
/**