Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 48 additions & 5 deletions www/addons/mod/scorm/services/scorm.js
Original file line number Diff line number Diff line change
Expand Up @@ -735,16 +735,40 @@ angular.module('mm.addons.mod_scorm')
* @return {Promise} Promise resolved with the URL.
*/
self.getScoSrc = function(scorm, sco, siteId) {
if (sco.launch.match(/http(s)?:\/\//)) {
// It's an online URL.
return $q.when($sce.trustAsResourceUrl(sco.launch));
siteId = siteId || $mmSite.getId();

// Build the launch URL. Moodle web checks SCORM version, we don't need to, it's always SCORM 1.2.
var launchUrl = sco.launch,
connector = '',
parameters;

if (sco.extradata && sco.extradata.length) {
for (var i = 0; i < sco.extradata.length; i++) {
var entry = sco.extradata[i];
if (entry.element == 'parameters') {
parameters = entry.value;
break;
}
}
}

siteId = siteId || $mmSite.getId();
if (parameters) {
connector = launchUrl.indexOf('?') > -1 ? '&' : '?';
if (parameters.charAt(0) == '?') {
parameters = parameters.substr(1);
}

launchUrl += connector + parameters;
}

if (isExternalLink(launchUrl)) {
// It's an online URL.
return $q.when($sce.trustAsResourceUrl(launchUrl));
}

return $mmFilepool.getPackageDirUrlByUrl(siteId, scorm.moduleurl).then(function(dirPath) {
// This URL is going to be injected in an iframe, we need trustAsResourceUrl to make it work in a browser.
return $sce.trustAsResourceUrl($mmFS.concatenatePaths(dirPath, sco.launch));
return $sce.trustAsResourceUrl($mmFS.concatenatePaths(dirPath, launchUrl));
});
};

Expand Down Expand Up @@ -1071,6 +1095,25 @@ angular.module('mm.addons.mod_scorm')
});
};

/**
* Given a launch URL, check if it's a external link.
* Based on Moodle's scorm_external_link.
*
* @param {String} link Link to check.
* @return {Boolean} Whether it's an external link.
*/
function isExternalLink(link) {
link = link.toLowerCase();

if (link.match(/https?:\/\//)) {
return true;
} else if (link.substr(0, 4) == 'www.') {
return true;
}

return false;
}

/**
* Return whether or not the plugin is enabled in a certain site. Plugin is enabled if the scorm WS are available.
*
Expand Down