MDL-45943: Replacement for publisher icons
[moodle.git] / mod / scorm / view.js
blob51c19d170656a22d83963e94d94e2af5da2bf92f
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+"&currentorg="+currentorg+"&scoid="+sco+"&sesskey="+M.cfg.sesskey+"&display=popup";
12     var course_url = scormplayerdata.courseurl;
13     var winobj = null;
15     poptions = poptions + ',resizable=yes'; // Added for IE (MDL-32506).
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     }
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         }
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.str.scorm.popuplaunched + '</a>');
42     }
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                 // Redirect the parent window to the course homepage.
50                 parent.window.location = course_url;
51             }
52         }, 800)
53     }
55     var scormredirect = function (winobj) {
56         Y.on('load', scormload, winobj);
57         Y.on('unload', scormunload, winobj);
58         // Check to make sure pop-up has been launched - if not display a warning,
59         // this shouldn't happen as the pop-up here is launched on user action but good to make sure.
60         setTimeout(function() {
61             if (!winobj) {
62                 var scormintro = Y.one('#intro');
63                 scormintro.setHTML(M.str.scorm.popupsblocked);
64             }}, 800);
65     }
67     if (launch == true) {
68         winobj = window.open(launch_url,'Popup', poptions);
69         this.target='Popup';
70         scormredirect(winobj);
71     }
72     // Listen for view form submit and generate popup on user interaction.
73     if (scormform) {
74         Y.on('submit', function(e) {
75             winobj = window.open(launch_url, 'Popup', poptions);
76             this.target='Popup';
77             scormredirect(winobj);
78             e.preventDefault();
79         }, scormform);
80     }