1 // hopefully fool ie IE proof way of getting DOM element
2 function safeGetElement(doc
, el
) {
3 return doc
.ids ? doc
.ids
[el
] : doc
.getElementById ? doc
.getElementById(el
) : doc
.all
[el
];
6 // Add in a JS controlled link for toggling the Debug logging
7 var logButton
= document
.createElement('a');
8 logButton
.id
= 'mod-scorm-log-toggle';
9 logButton
.name
= 'logToggle';
10 logButton
.href
= 'javascript:toggleLog();';
11 if (getLoggingActive() == "A") {
12 logButton
.innerHTML
= '<?php print_string('scormloggingon
','scorm
') ?>';
14 logButton
.innerHTML
= '<?php print_string('scormloggingoff
','scorm
') ?>';
16 var content
= safeGetElement(document
, 'content');
17 content
.appendChild(logButton
);
19 // retrieve cookie data
20 function getCookie (cookie_name
){
21 var results
= document
.cookie
.match ( '(^|;) ?' + cookie_name +
'=([^;]*)(;|$)' );
23 return (unescape(results
[2]));
29 // retrieve the logging flag from a Cookie
30 function getLoggingActive () {
31 var loggingActive
= getCookie('SCORMLoggingActive');
38 // set the logging flag in a cookie
39 function setLoggingActive (flag
) {
40 new cookie("SCORMLoggingActive", flag
, 365, "/").set();
44 function toggleLog () {
45 if (getLoggingActive() == "A") {
46 AppendToLog("Moodle Logging Deactivated", 0);
47 setLoggingActive('N');
48 logButton
.innerHTML
= '<?php print_string('scormloggingoff
','scorm
') ?>';
50 setLoggingActive('A');
51 AppendToLog("Moodle Logging Activated", 0);
52 logButton
.innerHTML
= '<?php print_string('scormloggingon
','scorm
') ?>';
53 logPopUpWindow
.focus();
57 // globals for the log accumulation
60 var logPopUpWindow
= "N";
62 // add each entry to the log, or setup the log pane first time round
63 function UpdateLog(s
) {
64 var s1
= '<html><head><style>\n'
65 +
'body {font-family: Arial, Helvetica, Sans-Serif;font-size: xx-small;'
66 +
'margin: 0px 0px 0px 0px; padding: 0px 0px 0px 0px; '
67 +
'background-color: ffffff;}\n'
68 +
'.even {background-color: ffffff; width: 100%;}\n'
69 +
'.odd {background-color: e8f2fe; width: 100%;}\n'
70 +
'.error {background-color: ffffff; color: red; width: 100%;}\n'
71 +
'<\/style><\/head><body STYLE="background-color: ffffff; color: black"'
72 +
'marginwidth="0" leftmargin="0" hspace="0">'
73 +
'<input type="hidden" id="mod-scorm-logstate" name="mod-scorm-logstate" value="A" \/>'
74 +
'<h3 id="mod-scorm-marker">SCORM API Activity Log<\/h3>';
77 if (getLoggingActive() != "A") {
83 if (logPopUpWindow
!= 'N' && !logPopUpWindow
.closed
) {
84 popupdoc
= logPopUpWindow
.document
;
85 popupdoc
.body
.innerHTML +
= s
;
87 logPopUpWindow
= open( '', 'logpopupwindow', '' );
88 popupdoc
= logPopUpWindow
.document
;
90 var marker
= safeGetElement(popupdoc
, 'mod-scorm-marker');
92 popupdoc
.body
.innerHTML +
= s
;
96 popupdoc
.write(logString
);
97 popupdoc
.write('<\/body><\/html>')
99 popupdoc
.title
= 'SCORM API Activity Log';
100 logPopUpWindow
.focus();
103 if (popupdoc
.body
.childNodes
.length
> 0) {
104 popupdoc
.body
.lastChild
.scrollIntoView();
108 //add an individual log entry
109 function AppendToLog(s
, rc
) {
112 sStyle
= 'class="error';
113 } else if (logRow %
2 != 0) {
114 sStyle
= 'class="even';
116 sStyle
= 'class="odd';
119 var now
= new Date();
120 now
.setTime( now
.getTime() );
121 s
= '<div ' + sStyle +
'>' + now
.toGMTString() +
': ' + s +
'<\/div>';
123 // switch colours for a new section of work
124 if (s
.match(/Commit|Loaded|Initialize|Terminate|Finish|Moodle SCORM|Moodle Logging
/)) {
129 // format a log entry
130 function LogAPICall(func
, nam
, val
, rc
) {
131 // drop call to GetLastError for the time being - it produces too much chatter
132 if (func
.match(/GetLastError
/)) {
135 var s
= func +
'("' + nam +
'"';
136 if (val
!= null && ! (func
.match(/GetValue|GetLastError
/))) {
137 s +
= ', "' + val +
'"';
140 if (func
.match(/GetValue
/)) {
143 s +
= ' => ' +
String(rc
);