MDL-43247 SCORM: improve pop-up handling and redirect to homepage on close.

This commit is contained in:
Dan Marsden
2014-03-08 21:03:38 +13:00
parent ef0ee34df0
commit 34d0ed1cbf
5 changed files with 67 additions and 11 deletions
+1
View File
@@ -284,6 +284,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.';
+1 -1
View File
@@ -830,7 +830,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');
?>
<div class="structurehead"><?php print_string('contents', 'scorm') ?></div>
<?php
+1 -1
View File
@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die();
$module->version = 2013110502; // The current module version (Date: YYYYMMDDXX)
$module->version = 2013110503; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2013110500; // Requires this Moodle version
$module->component = 'mod_scorm'; // Full name of the plugin (used for diagnostics)
$module->cron = 300;
+53 -6
View File
@@ -1,6 +1,6 @@
M.mod_scormform = {};
M.mod_scormform.init = function(Y) {
var scormform = document.getElementById('scormviewform');
var scormform = Y.one('#scormviewform');
var cwidth = scormplayerdata.cwidth;
var cheight = scormplayerdata.cheight;
var poptions = scormplayerdata.popupoptions;
@@ -8,8 +8,9 @@ M.mod_scormform.init = function(Y) {
var currentorg = scormplayerdata.currentorg;
var sco = scormplayerdata.sco;
var scorm = scormplayerdata.scorm;
var launch_url = M.cfg.wwwroot+"/mod/scorm/player.php?a="+scorm+"&currentorg="+currentorg+"&scoid="+sco+"&sesskey="+M.cfg.sesskey;
var launch_url = M.cfg.wwwroot+"/mod/scorm/player.php?a="+scorm+"&currentorg="+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).
@@ -25,10 +26,56 @@ M.mod_scormform.init = function(Y) {
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.str.scorm.popuplaunched + '</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) {
// Redirect the parent window to the course homepage.
parent.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.str.scorm.popupsblocked);
}}, 800);
}
if (launch == true) {
launch_url = launch_url+"&display=popup";
window.open(launch_url,'Popup', poptions);
parent.window.location = course_url;
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) {
Y.on('submit', function(e) {
winobj = window.open(launch_url, 'Popup', poptions);
this.target='Popup';
scormredirect(winobj);
e.preventDefault();
}, scormform);
}
scormform.onsubmit = function() {window.open('', 'Popup', poptions); this.target='Popup'; parent.window.location = course_url;};
}
+11 -3
View File
@@ -22,6 +22,7 @@ $id = optional_param('id', '', PARAM_INT); // Course Module ID, or
$a = optional_param('a', '', PARAM_INT); // scorm ID
$organization = optional_param('organization', '', PARAM_INT); // organization ID
$action = optional_param('action', '', PARAM_ALPHA);
$preventskip = optional_param('preventskip', '', PARAM_INT); // Prevent Skip view, set by javascript redirects.
if (!empty($id)) {
if (! $cm = get_coursemodule_from_id('scorm', $id, 0, true)) {
@@ -66,7 +67,7 @@ $launch = false; // Does this automatically trigger a launch based on skipview.
if (!empty($scorm->popup)) {
$orgidentifier = '';
$scoid = 0;
if ($scorm->skipview >= SCORM_SKIPVIEW_FIRST &&
if (empty($preventskip) && $scorm->skipview >= SCORM_SKIPVIEW_FIRST &&
has_capability('mod/scorm:skipview', $contextmodule) &&
!has_capability('mod/scorm:viewreport', $contextmodule)) { // Don't skip users with the capability to view reports.
@@ -91,15 +92,22 @@ if (!empty($scorm->popup)) {
if (isset($courseformat->coursedisplay) && $courseformat->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
$sectionid = $cm->sectionnum;
}
if ($courseformat->format == 'singleactivity') {
$courseurl = $url->out(false, array('preventskip' => '1'));
} else {
$courseurl = course_get_url($course, $sectionid)->out(false);
}
$PAGE->requires->data_for_js('scormplayerdata', Array('launch' => $launch,
'currentorg' => $orgidentifier,
'sco' => $scoid,
'scorm' => $scorm->id,
'courseurl' => course_get_url($course, $sectionid)->out(false),
'courseurl' => $courseurl,
'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);
}
@@ -115,7 +123,7 @@ $pagetitle = strip_tags($shortname.': '.format_string($scorm->name));
add_to_log($course->id, 'scorm', 'pre-view', 'view.php?id='.$cm->id, "$scorm->id", $cm->id);
if (empty($launch) && (has_capability('mod/scorm:skipview', $contextmodule))) {
if (empty($preventskip) && empty($launch) && (has_capability('mod/scorm:skipview', $contextmodule))) {
scorm_simple_play($scorm, $USER, $contextmodule, $cm->id);
}