From 9d2276572372f5d249cde8c61d0976e25f0fa4a8 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Mon, 6 Jan 2014 09:43:39 +1300 Subject: [PATCH] MDL-43247 SCORM: improve pop-up handling and redirect to homepage on close. --- mod/scorm/lang/en/scorm.php | 1 + mod/scorm/locallib.php | 2 +- mod/scorm/view.js | 49 ++++++++++++++++++++++++++++++++++--- mod/scorm/view.php | 2 ++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php index d353e78f7cc..fddf49959ae 100644 --- a/mod/scorm/lang/en/scorm.php +++ b/mod/scorm/lang/en/scorm.php @@ -290,6 +290,7 @@ $string['php5'] = 'PHP 5 (DOMXML native library)'; $string['pluginadministration'] = 'SCORM package administration'; $string['pluginname'] = 'SCORM package'; $string['popup'] = 'New window'; +$string['popuplaunched'] = 'This SCORM package has been launched in a popup window, If you have finished viewing this resource, click here to return to the course page'; $string['popupmenu'] = 'In a drop down menu'; $string['popupopen'] = 'Open package in a new window'; $string['popupsblocked'] = 'It appears that popup windows are blocked, stopping this SCORM package from playing. Please check your browser settings before trying again.'; diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index eb77ac3410b..9e7d0b3b606 100644 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -822,7 +822,7 @@ function scorm_view_display ($user, $scorm, $action, $cm) { $organization = optional_param('organization', '', PARAM_INT); if ($scorm->displaycoursestructure == 1) { - echo $OUTPUT->box_start('generalbox boxaligncenter toc'); + echo $OUTPUT->box_start('generalbox boxaligncenter toc', 'toc'); ?>
' + M.str.scorm.popuplaunched + ''); + } + // When pop-up is closed return to course homepage. + winobj.onunload = function () { + // Onunload is called multiple times in the SCORM window - we only want to handle when it is actually closed. + setTimeout(function() { + if (!winobj.opener) { + // Redirect the parent window to the course homepage. + parent.window.location = course_url; + } + }, 200) + } + // 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) { + scormintro.setHTML(M.str.scorm.popupsblocked); + }}, 800); + } + if (launch == true) { launch_url = launch_url+"&display=popup"; - window.open(launch_url,'Popup', poptions); - parent.window.location = course_url; + var winobj = window.open(launch_url,'Popup', poptions); + this.target='Popup'; + scormredirect(winobj); + } + // Listen for view form submit and generate popup on user interaction. + if (scormform) { + scormform.onsubmit = function() { + var winobj = window.open('', 'Popup', poptions); + this.target='Popup'; + scormredirect(winobj); + } } - scormform.onsubmit = function() {window.open('', 'Popup', poptions); this.target='Popup'; parent.window.location = course_url;}; } diff --git a/mod/scorm/view.php b/mod/scorm/view.php index 8f8d5be7669..b898a479eff 100644 --- a/mod/scorm/view.php +++ b/mod/scorm/view.php @@ -100,6 +100,8 @@ if (!empty($scorm->popup)) { 'cwidth' => $scorm->width, 'cheight' => $scorm->height, 'popupoptions' => $scorm->options), true); + $PAGE->requires->string_for_js('popupsblocked', 'scorm'); + $PAGE->requires->string_for_js('popuplaunched', 'scorm'); $PAGE->requires->js('/mod/scorm/view.js', true); } -- 2.43.0