Commit 0a4d5952 authored by icc's avatar icc

Fixed so other modules may attach external scripts to iframe.

Moved embed type detection to own function to increase readabiliy and reuse.
parent 74994192
......@@ -324,6 +324,16 @@ function h5p_get_file_paths($node) {
return $to_return;
}
/**
* Detemine embed type of node.
*
* @return string 'div' or 'iframe'.
*/
function h5p_get_embed_type($node) {
$embed = isset($node->main_library['embedTypes']) && !empty($node->main_library['embedTypes']) ? $node->main_library['embedTypes'] : $node->embed_type;
return strpos(strtolower($embed), 'div') !== FALSE ? 'div' : 'iframe';
}
/**
* Implementation of hook_view().
*/
......@@ -331,11 +341,10 @@ function h5p_view($node, $teaser = FALSE, $page = FALSE) {
$node = node_prepare($node, $teaser);
if (!$teaser) {
if (isset($node->main_library)) {
// if DIV in embed_types, use that, if not, iFrame this.
$content_id = h5p_get_content_id($node);
$main_library = $node->main_library['machineName'];
$embed = isset($node->main_library['embedTypes']) && !empty($node->main_library['embedTypes']) ? $node->main_library['embedTypes'] : $node->embed_type;
if (strpos(strtolower($embed), 'div') !== FALSE) {
if (h5p_get_embed_type($node) === 'div') {
h5p_add_files_and_settings($node, 'div');
$html = '<div class="h5p-content" data-class="' . $main_library . '" data-content-id="' . $content_id . '"></div>';
}
......@@ -463,7 +472,6 @@ function h5p_add_files_and_settings($node, $mode) {
'preprocess' => TRUE,
);
}
$settings['h5p']['cid-' . $content_id]['scripts'] = array(drupal_build_js_cache($scripts, $filename));
}
else {
......
......@@ -62,10 +62,18 @@ H5PIntegration.getFullscreen = function (contentId) {
H5PIntegration.getHeadTags = function (contentId) {
var basePath = window.location.protocol + '//' + window.location.host + Drupal.settings.basePath;
var createUrl = function (path) {
if (path.substring(0,7) !== 'http://') {
// Not external, add base path and cache buster.
path = basePath + path + '?' + Drupal.settings.h5p.cacheBuster;
}
return path;
}
var createStyleTags = function (styles) {
var tags = '';
for (var i = 0; i < styles.length; i++) {
tags += '<link rel="stylesheet" href="' + basePath + styles[i] + '?' + Drupal.settings.h5p.cacheBuster + '">';
tags += '<link rel="stylesheet" href="' + createUrl(styles[i]) + '">';
}
return tags;
};
......@@ -73,7 +81,7 @@ H5PIntegration.getHeadTags = function (contentId) {
var createScriptTags = function (scripts) {
var tags = '';
for (var i = 0; i < scripts.length; i++) {
tags += '<script src="' + basePath + scripts[i] + '?' + Drupal.settings.h5p.cacheBuster + '"></script>';
tags += '<script src="' + createUrl(scripts[i]) + '"></script>';
}
return tags;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment