forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.js
96 lines (87 loc) · 3.61 KB
/
view.js
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
M.mod_scormform = {};
M.mod_scormform.init = function(Y) {
var scormform = Y.one('#scormviewform');
var cwidth = scormplayerdata.cwidth;
var cheight = scormplayerdata.cheight;
var poptions = scormplayerdata.popupoptions;
var launch = scormplayerdata.launch;
var currentorg = scormplayerdata.currentorg;
var sco = scormplayerdata.sco;
var scorm = scormplayerdata.scorm;
var launch_url = M.cfg.wwwroot + "/mod/scorm/player.php?a=" + scorm + "¤torg=" + currentorg + "&scoid=" + sco + "&sesskey=" + M.cfg.sesskey + "&display=popup";
var course_url = scormplayerdata.courseurl;
var winobj = null;
poptions = poptions + ',resizable=yes'; // Added for IE (MDL-32506).
if ((cwidth == 100) && (cheight == 100)) {
poptions = poptions + ',width=' + screen.availWidth + ',height=' + screen.availHeight + ',left=0,top=0';
} else {
if (cwidth <= 100) {
cwidth = Math.round(screen.availWidth * cwidth / 100);
}
if (cheight <= 100) {
cheight = Math.round(screen.availHeight * cheight / 100);
}
poptions = poptions + ',width=' + cwidth + ',height=' + cheight;
}
// Hide the form and toc if it exists - we don't want to allow multiple submissions when a window is open.
var scormload = function () {
if (scormform) {
scormform.hide();
}
var scormtoc = Y.one('#toc');
if (scormtoc) {
scormtoc.hide();
}
// Hide the intro and display a message to the user if the window is closed.
var scormintro = Y.one('#intro');
scormintro.setHTML('<a href="' + course_url + '">' + M.util.get_string('popuplaunched', 'scorm') + '</a>');
}
// When pop-up is closed return to course homepage.
var scormunload = function () {
// Onunload is called multiple times in the SCORM window - we only want to handle when it is actually closed.
setTimeout(function() {
if (winobj.closed) {
window.location = course_url;
}
}, 800)
}
var scormredirect = function (winobj) {
Y.on('load', scormload, winobj);
Y.on('unload', scormunload, winobj);
// Check to make sure pop-up has been launched - if not display a warning,
// this shouldn't happen as the pop-up here is launched on user action but good to make sure.
setTimeout(function() {
if (!winobj) {
var scormintro = Y.one('#intro');
scormintro.setHTML(M.util.get_string('popupsblocked', 'scorm'));
}}, 800);
}
// Set mode and newattempt correctly.
var setlaunchoptions = function(mode) {
if (mode) {
launch_url += '&mode=' + (mode ? mode : 'normal');
} else {
launch_url += '&mode=normal';
}
var newattempt = Y.one('#scormviewform #a');
launch_url += (newattempt && newattempt.get('checked') ? '&newattempt=on' : '');
}
if (launch == true) {
setlaunchoptions();
winobj = window.open(launch_url,'Popup', poptions);
this.target = 'Popup';
scormredirect(winobj);
winobj.opener = null;
}
// Listen for view form submit and generate popup on user interaction.
if (scormform) {
scormform.delegate('click', function(e) {
setlaunchoptions(e.currentTarget.getAttribute('value'));
winobj = window.open(launch_url, 'Popup', poptions);
this.target = 'Popup';
scormredirect(winobj);
winobj.opener = null;
e.preventDefault();
}, 'button[name=mode]');
}
}