1 |
efrain |
1 |
M.mod_scormform = {};
|
|
|
2 |
M.mod_scormform.init = function(Y) {
|
|
|
3 |
var scormform = Y.one('#scormviewform');
|
|
|
4 |
var cwidth = scormplayerdata.cwidth;
|
|
|
5 |
var cheight = scormplayerdata.cheight;
|
|
|
6 |
var poptions = scormplayerdata.popupoptions;
|
|
|
7 |
var launch = scormplayerdata.launch;
|
|
|
8 |
var currentorg = scormplayerdata.currentorg;
|
|
|
9 |
var sco = scormplayerdata.sco;
|
|
|
10 |
var scorm = scormplayerdata.scorm;
|
|
|
11 |
var launch_url = M.cfg.wwwroot + "/mod/scorm/player.php?a=" + scorm + "¤torg=" + currentorg + "&scoid=" + sco + "&sesskey=" + M.cfg.sesskey + "&display=popup";
|
|
|
12 |
var course_url = scormplayerdata.courseurl;
|
|
|
13 |
var winobj = null;
|
|
|
14 |
|
|
|
15 |
poptions = poptions + ',resizable=yes'; // Added for IE (MDL-32506).
|
|
|
16 |
|
|
|
17 |
if ((cwidth == 100) && (cheight == 100)) {
|
|
|
18 |
poptions = poptions + ',width=' + screen.availWidth + ',height=' + screen.availHeight + ',left=0,top=0';
|
|
|
19 |
} else {
|
|
|
20 |
if (cwidth <= 100) {
|
|
|
21 |
cwidth = Math.round(screen.availWidth * cwidth / 100);
|
|
|
22 |
}
|
|
|
23 |
if (cheight <= 100) {
|
|
|
24 |
cheight = Math.round(screen.availHeight * cheight / 100);
|
|
|
25 |
}
|
|
|
26 |
poptions = poptions + ',width=' + cwidth + ',height=' + cheight;
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
// Hide the form and toc if it exists - we don't want to allow multiple submissions when a window is open.
|
|
|
30 |
var scormload = function () {
|
|
|
31 |
if (scormform) {
|
|
|
32 |
scormform.hide();
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
var scormtoc = Y.one('#toc');
|
|
|
36 |
if (scormtoc) {
|
|
|
37 |
scormtoc.hide();
|
|
|
38 |
}
|
|
|
39 |
// Hide the intro and display a message to the user if the window is closed.
|
|
|
40 |
var scormintro = Y.one('#intro');
|
|
|
41 |
scormintro.setHTML('<a href="' + course_url + '">' + M.util.get_string('popuplaunched', 'scorm') + '</a>');
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
// When pop-up is closed return to course homepage.
|
|
|
45 |
var scormunload = function () {
|
|
|
46 |
// Onunload is called multiple times in the SCORM window - we only want to handle when it is actually closed.
|
|
|
47 |
setTimeout(function() {
|
|
|
48 |
if (winobj.closed) {
|
|
|
49 |
window.location = course_url;
|
|
|
50 |
}
|
|
|
51 |
}, 800)
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
var scormredirect = function (winobj) {
|
|
|
55 |
Y.on('load', scormload, winobj);
|
|
|
56 |
Y.on('unload', scormunload, winobj);
|
|
|
57 |
// Check to make sure pop-up has been launched - if not display a warning,
|
|
|
58 |
// this shouldn't happen as the pop-up here is launched on user action but good to make sure.
|
|
|
59 |
setTimeout(function() {
|
|
|
60 |
if (!winobj) {
|
|
|
61 |
var scormintro = Y.one('#intro');
|
|
|
62 |
scormintro.setHTML(M.util.get_string('popupsblocked', 'scorm'));
|
|
|
63 |
}}, 800);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
// Set mode and newattempt correctly.
|
|
|
67 |
var setlaunchoptions = function(mode) {
|
|
|
68 |
if (mode) {
|
|
|
69 |
launch_url += '&mode=' + (mode ? mode : 'normal');
|
|
|
70 |
} else {
|
|
|
71 |
launch_url += '&mode=normal';
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
var newattempt = Y.one('#scormviewform #a');
|
|
|
75 |
launch_url += (newattempt && newattempt.get('checked') ? '&newattempt=on' : '');
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
if (launch == true) {
|
|
|
79 |
setlaunchoptions();
|
|
|
80 |
winobj = window.open(launch_url,'Popup', poptions);
|
|
|
81 |
this.target = 'Popup';
|
|
|
82 |
scormredirect(winobj);
|
|
|
83 |
winobj.opener = null;
|
|
|
84 |
}
|
|
|
85 |
// Listen for view form submit and generate popup on user interaction.
|
|
|
86 |
if (scormform) {
|
|
|
87 |
scormform.delegate('click', function(e) {
|
|
|
88 |
setlaunchoptions(e.currentTarget.getAttribute('value'));
|
|
|
89 |
winobj = window.open(launch_url, 'Popup', poptions);
|
|
|
90 |
this.target = 'Popup';
|
|
|
91 |
scormredirect(winobj);
|
|
|
92 |
winobj.opener = null;
|
|
|
93 |
e.preventDefault();
|
|
|
94 |
}, 'button[name=mode]');
|
|
|
95 |
}
|
|
|
96 |
}
|