diff --git a/h5p.classes.php b/h5p.classes.php index 13c196d..b5cf5ff 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -15,7 +15,6 @@ interface H5PFrameworkInterface { */ public function getPlatformInfo(); - /** * Fetches a file from a remote server using HTTP GET * @@ -1602,6 +1601,22 @@ class H5PCore { private $exportEnabled; + // Disable flags + const DISABLE_NONE = 0; + const DISABLE_FRAME = 1; + const DISABLE_DOWNLOAD = 2; + const DISABLE_EMBED = 4; + const DISABLE_COPYRIGHT = 8; + const DISABLE_ABOUT = 16; + + // Map flags to string + public static $disable = array( + self::DISABLE_FRAME => 'frame', + self::DISABLE_DOWNLOAD => 'download', + self::DISABLE_EMBED => 'embed', + self::DISABLE_COPYRIGHT => 'copyright' + ); + /** * Constructor for the H5PCore * @@ -2271,11 +2286,59 @@ class H5PCore { } } if($platformInfo['uuid'] === '' && isset($json->uuid)) { - $this->h5pF->setOption('h5p_site_uuid', $json->uuid); + $this->h5pF->setOption('site_uuid', $json->uuid); } } } + public function getGlobalDisable() { + $disable = self::DISABLE_NONE; + + // Allow global settings to override and disable options + if (!$this->h5pF->getOption('frame', TRUE)) { + $disable |= self::DISABLE_FRAME; + } + else { + if (!$this->h5pF->getOption('export', TRUE)) { + $disable |= self::DISABLE_DOWNLOAD; + } + if (!$this->h5pF->getOption('embed', TRUE)) { + $disable |= self::DISABLE_EMBED; + } + if (!$this->h5pF->getOption('copyright', TRUE)) { + $disable |= self::DISABLE_COPYRIGHT; + } + if (!$this->h5pF->getOption('icon', TRUE)) { + $disable |= self::DISABLE_ABOUT; + } + } + + return $disable; + } + + /** + * Determine disable state from sources. + * + * @param array $sources + * @return int + */ + public static function getDisable(&$sources) { + $disable = H5PCore::DISABLE_NONE; + if (!$sources['frame']) { + $disable |= H5PCore::DISABLE_FRAME; + } + if (!$sources['download']) { + $disable |= H5PCore::DISABLE_DOWNLOAD; + } + if (!$sources['copyright']) { + $disable |= H5PCore::DISABLE_COPYRIGHT; + } + if (!$sources['embed']) { + $disable |= H5PCore::DISABLE_EMBED; + } + return $disable; + } + // Cache for getting library ids private $libraryIdMap = array(); diff --git a/js/disable.js b/js/disable.js new file mode 100644 index 0000000..83d740c --- /dev/null +++ b/js/disable.js @@ -0,0 +1,19 @@ +(function ($) { + $(document).ready(function () { + var $inputs = $('.h5p-action-bar-settings input'); + var $frame = $inputs.filter('input[name="frame"], input[name="h5p_frame"]'); + var $others = $inputs.filter(':not(input[name="frame"], input[name="h5p_frame"])'); + + var toggle = function () { + if ($frame.is(':checked')) { + $others.attr('disabled', false); + } + else { + $others.attr('disabled', true); + } + }; + + $frame.change(toggle); + toggle(); + }); +})(jQuery); diff --git a/js/h5p.js b/js/h5p.js index a9c2617..09a6c4b 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -30,7 +30,29 @@ else if (document.documentElement.msRequestFullscreen) { H5P.fullScreenBrowserPrefix = 'ms'; } -// Keep track of when the H5Ps where started +/** @const {Number} */ +H5P.DISABLE_NONE = 0; + +/** @const {Number} */ +H5P.DISABLE_FRAME = 1; + +/** @const {Number} */ +H5P.DISABLE_DOWNLOAD = 2; + +/** @const {Number} */ +H5P.DISABLE_EMBED = 4; + +/** @const {Number} */ +H5P.DISABLE_COPYRIGHT = 8; + +/** @const {Number} */ +H5P.DISABLE_ABOUT = 16; + +/** + * Keep track of when the H5Ps where started. + * + * @type {Array} + */ H5P.opened = {}; /** @@ -72,21 +94,23 @@ H5P.init = function (target) { }); } + // Create action bar var $actions = H5P.jQuery(''); - if (contentData.exportUrl !== '') { - // Display export button + + if (!(contentData.disable & H5P.DISABLE_DOWNLOAD)) { + // Add export button H5P.jQuery('
  • ' + H5P.t('download') + '
  • ').appendTo($actions).click(function () { window.location.href = contentData.exportUrl; }); } - - // Display copyrights button - H5P.jQuery('
  • ' + H5P.t('copyrights') + '
  • ').appendTo($actions).click(function () { - H5P.openCopyrightsDialog($actions, instance, library.params, contentId); - }); - - if (contentData.embedCode !== undefined) { - // Display embed button + if (!(contentData.disable & H5P.DISABLE_COPYRIGHT) && instance.getCopyrights !== undefined) { + // Add copyrights button + H5P.jQuery('
  • ' + H5P.t('copyrights') + '
  • ').appendTo($actions).click(function () { + H5P.openCopyrightsDialog($actions, instance, library.params, contentId); + }); + } + if (!(contentData.disable & H5P.DISABLE_EMBED)) { + // Add embed button H5P.jQuery('
  • ' + H5P.t('embed') + '
  • ').appendTo($actions).click(function () { H5P.openEmbedDialog($actions, contentData.embedCode, contentData.resizeCode, { width: $container.width(), @@ -94,10 +118,18 @@ H5P.init = function (target) { }); }); } - if (contentData.showH5PIconInActionBar) { + if (!(contentData.disable & H5P.DISABLE_ABOUT)) { + // Add about H5P button icon H5P.jQuery('
  • ').appendTo($actions); } - $actions.insertAfter($container); + + // Insert action bar if it has any content + if ($actions.children().length) { + $actions.insertAfter($container); + } + else { + $element.addClass('h5p-no-frame'); + } // Keep track of when we started H5P.opened[contentId] = new Date(); diff --git a/styles/h5p.css b/styles/h5p.css index e6bd6fd..c949a14 100644 --- a/styles/h5p.css +++ b/styles/h5p.css @@ -36,7 +36,9 @@ html.h5p-iframe .h5p-content { width: 100%; height: 100%; } -.h5p-fullscreen .h5p-content, .h5p-semi-fullscreen .h5p-content { +.h5p-content.h5p-no-frame, +.h5p-fullscreen .h5p-content, +.h5p-semi-fullscreen .h5p-content { border: 0; } .h5p-container {