Merge branch 'MDL-35971-master' of git://github.com/junpataleta/moodle
[moodle.git] / mod / scorm / view.js
CommitLineData
d5159fb8
DM
1M.mod_scormform = {};
2M.mod_scormform.init = function(Y) {
6573b077 3 var scormform = Y.one('#scormviewform');
d5159fb8
DM
4 var cwidth = scormplayerdata.cwidth;
5 var cheight = scormplayerdata.cheight;
6 var poptions = scormplayerdata.popupoptions;
35cfa9e6
PH
7 var launch = scormplayerdata.launch;
8 var currentorg = scormplayerdata.currentorg;
9 var sco = scormplayerdata.sco;
10 var scorm = scormplayerdata.scorm;
4cb25b36 11 var launch_url = M.cfg.wwwroot + "/mod/scorm/player.php?a=" + scorm + "&currentorg=" + currentorg + "&scoid=" + sco + "&sesskey=" + M.cfg.sesskey + "&display=popup";
b98dcd7d 12 var course_url = scormplayerdata.courseurl;
6573b077 13 var winobj = null;
35cfa9e6 14
18a34b07
DM
15 poptions = poptions + ',resizable=yes'; // Added for IE (MDL-32506).
16
4cb25b36 17 if ((cwidth == 100) && (cheight == 100)) {
18 poptions = poptions + ',width=' + screen.availWidth + ',height=' + screen.availHeight + ',left=0,top=0';
d5159fb8 19 } else {
4cb25b36 20 if (cwidth <= 100) {
d5159fb8
DM
21 cwidth = Math.round(screen.availWidth * cwidth / 100);
22 }
4cb25b36 23 if (cheight <= 100) {
d5159fb8
DM
24 cheight = Math.round(screen.availHeight * cheight / 100);
25 }
4cb25b36 26 poptions = poptions + ',width=' + cwidth + ',height=' + cheight;
d5159fb8 27 }
35cfa9e6 28
6573b077
DM
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');
64e7aa4d 41 scormintro.setHTML('<a href="' + course_url + '">' + M.util.get_string('popuplaunched', 'scorm') + '</a>');
6573b077
DM
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) {
9536334d 49 window.location = course_url;
6573b077
DM
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');
64e7aa4d 62 scormintro.setHTML(M.util.get_string('popupsblocked', 'scorm'));
6573b077
DM
63 }}, 800);
64 }
65
ae72469d
FK
66 // Set mode and newattempt correctly.
67 var setlaunchoptions = function() {
68 var mode = Y.one('#scormviewform input[name=mode]:checked');
69 if (mode) {
70 var modevalue = mode.get('value');
71 launch_url += '&mode=' + (modevalue ? modevalue : 'normal');
72 } else {
73 launch_url += '&mode=normal';
74 }
75
76 var newattempt = Y.one('#scormviewform #a');
77 launch_url += (newattempt && newattempt.get('checked') ? '&newattempt=on' : '');
78 }
79
812bdaeb 80 if (launch == true) {
98939a3c 81 setlaunchoptions();
6573b077 82 winobj = window.open(launch_url,'Popup', poptions);
4cb25b36 83 this.target = 'Popup';
6573b077 84 scormredirect(winobj);
d4f96fa3 85 winobj.opener = null;
6573b077
DM
86 }
87 // Listen for view form submit and generate popup on user interaction.
88 if (scormform) {
89 Y.on('submit', function(e) {
98939a3c 90 setlaunchoptions();
6573b077 91 winobj = window.open(launch_url, 'Popup', poptions);
4cb25b36 92 this.target = 'Popup';
6573b077 93 scormredirect(winobj);
d4f96fa3 94 winobj.opener = null;
6573b077
DM
95 e.preventDefault();
96 }, scormform);
35cfa9e6 97 }
d5159fb8 98}