Using constants for the different display options, and avoid special cases [HFP-277]

improved-embed-and-download
Paal Joergensen 2016-12-16 14:22:03 +01:00
parent 7b39a6900c
commit 87ec43d687
3 changed files with 52 additions and 43 deletions

View File

@ -1738,12 +1738,18 @@ class H5PCore {
const DISABLE_COPYRIGHT = 8; const DISABLE_COPYRIGHT = 8;
const DISABLE_ABOUT = 16; const DISABLE_ABOUT = 16;
const DISPLAY_OPTION_FRAME = 'frame';
const DISPLAY_OPTION_DOWNLOAD = 'export';
const DISPLAY_OPTION_EMBED = 'embed';
const DISPLAY_OPTION_COPYRIGHT = 'copyright';
const DISPLAY_OPTION_ABOUT = 'icon';
// Map flags to string // Map flags to string
public static $disable = array( public static $disable = array(
self::DISABLE_FRAME => 'frame', self::DISABLE_FRAME => self::DISPLAY_OPTION_FRAME,
self::DISABLE_DOWNLOAD => 'download', self::DISABLE_DOWNLOAD => self::DISPLAY_OPTION_DOWNLOAD,
self::DISABLE_EMBED => 'embed', self::DISABLE_EMBED => self::DISPLAY_OPTION_EMBED,
self::DISABLE_COPYRIGHT => 'copyright' self::DISABLE_COPYRIGHT => self::DISPLAY_OPTION_COPYRIGHT
); );
/** /**
@ -2473,17 +2479,17 @@ class H5PCore {
*/ */
public function getStorableDisplayOptions(&$sources, $current) { public function getStorableDisplayOptions(&$sources, $current) {
// Download - force setting it if always on or always off // Download - force setting it if always on or always off
$export = $this->h5pF->getOption('export', H5PDisplayOptionBehaviour::ALWAYS_SHOW); $download = $this->h5pF->getOption(self::DISPLAY_OPTION_DOWNLOAD, H5PDisplayOptionBehaviour::ALWAYS_SHOW);
if ($export == H5PDisplayOptionBehaviour::ALWAYS_SHOW || if ($download == H5PDisplayOptionBehaviour::ALWAYS_SHOW ||
$export == H5PDisplayOptionBehaviour::NEVER_SHOW) { $download == H5PDisplayOptionBehaviour::NEVER_SHOW) {
$sources['download'] = ($export == H5PDisplayOptionBehaviour::ALWAYS_SHOW); $sources[self::DISPLAY_OPTION_DOWNLOAD] = ($download == H5PDisplayOptionBehaviour::ALWAYS_SHOW);
} }
// Embed - force setting it if always on or always off // Embed - force setting it if always on or always off
$embed = $this->h5pF->getOption('embed', H5PDisplayOptionBehaviour::ALWAYS_SHOW); $embed = $this->h5pF->getOption(self::DISPLAY_OPTION_EMBED, H5PDisplayOptionBehaviour::ALWAYS_SHOW);
if ($embed == H5PDisplayOptionBehaviour::ALWAYS_SHOW || if ($embed == H5PDisplayOptionBehaviour::ALWAYS_SHOW ||
$embed == H5PDisplayOptionBehaviour::NEVER_SHOW) { $embed == H5PDisplayOptionBehaviour::NEVER_SHOW) {
$sources['embed'] = ($embed == H5PDisplayOptionBehaviour::ALWAYS_SHOW); $sources[self::DISPLAY_OPTION_EMBED] = ($embed == H5PDisplayOptionBehaviour::ALWAYS_SHOW);
} }
foreach (H5PCore::$disable as $bit => $option) { foreach (H5PCore::$disable as $bit => $option) {
@ -2508,34 +2514,37 @@ class H5PCore {
$current_display_options = $disable === NULL ? [] : $this->getDisplayOptionsAsArray($disable); $current_display_options = $disable === NULL ? [] : $this->getDisplayOptionsAsArray($disable);
if ($this->h5pF->getOption('frame', TRUE)) { if ($this->h5pF->getOption(self::DISPLAY_OPTION_FRAME, TRUE)) {
$display_options['frame'] = isset($current_display_options['showFrame']) ? $current_display_options['showFrame'] : TRUE; $display_options[self::DISPLAY_OPTION_FRAME] =
isset($current_display_options[self::DISPLAY_OPTION_FRAME]) ?
$current_display_options[self::DISPLAY_OPTION_FRAME] :
TRUE;
// Download // Download
$export = $this->h5pF->getOption('export', H5PDisplayOptionBehaviour::ALWAYS_SHOW); $export = $this->h5pF->getOption(self::DISPLAY_OPTION_DOWNLOAD, H5PDisplayOptionBehaviour::ALWAYS_SHOW);
if ($export == H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_ON || if ($export == H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_ON ||
$export == H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_OFF) { $export == H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_OFF) {
$display_options['download'] = $display_options[self::DISPLAY_OPTION_DOWNLOAD] =
isset($current_display_options['showDownload']) ? isset($current_display_options[self::DISPLAY_OPTION_DOWNLOAD]) ?
$current_display_options['showDownload'] : $current_display_options[self::DISPLAY_OPTION_DOWNLOAD] :
($export == H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_ON); ($export == H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_ON);
} }
// Embed // Embed
$embed = $this->h5pF->getOption('embed', H5PDisplayOptionBehaviour::ALWAYS_SHOW); $embed = $this->h5pF->getOption(self::DISPLAY_OPTION_EMBED, H5PDisplayOptionBehaviour::ALWAYS_SHOW);
if ($embed == H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_ON || if ($embed == H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_ON ||
$embed == H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_OFF) { $embed == H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_OFF) {
$display_options['embed'] = $display_options[self::DISPLAY_OPTION_EMBED] =
isset($current_display_options['showEmbed']) ? isset($current_display_options[self::DISPLAY_OPTION_EMBED]) ?
$current_display_options['showEmbed'] : $current_display_options[self::DISPLAY_OPTION_EMBED] :
($embed == H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_ON); ($embed == H5PDisplayOptionBehaviour::CONTROLLED_BY_AUTHOR_DEFAULT_ON);
} }
// Copyright // Copyright
if ($this->h5pF->getOption('copyright', TRUE)) { if ($this->h5pF->getOption(self::DISPLAY_OPTION_COPYRIGHT, TRUE)) {
$display_options['copyright'] = $display_options[self::DISPLAY_OPTION_COPYRIGHT] =
isset($current_display_options['showCopyright']) ? isset($current_display_options[self::DISPLAY_OPTION_COPYRIGHT]) ?
$current_display_options['showCopyright'] : $current_display_options[self::DISPLAY_OPTION_COPYRIGHT] :
TRUE; TRUE;
} }
} }
@ -2577,15 +2586,15 @@ class H5PCore {
public function getDisplayOptionsForView($disable, $id) { public function getDisplayOptionsForView($disable, $id) {
$display_options = $this->getDisplayOptionsAsArray($disable); $display_options = $this->getDisplayOptionsAsArray($disable);
if ($this->h5pF->getOption('frame', TRUE) == FALSE) { if ($this->h5pF->getOption(self::DISPLAY_OPTION_FRAME, TRUE) == FALSE) {
$display_options['showFrame'] = false; $display_options[self::DISPLAY_OPTION_FRAME] = false;
} }
else { else {
$this->setDisplayOptionOverrides('export', H5PPermission::DOWNLOAD_H5P, $id, $display_options['showDownload']); $this->setDisplayOptionOverrides(self::DISPLAY_OPTION_DOWNLOAD, H5PPermission::DOWNLOAD_H5P, $id, $display_options[self::DISPLAY_OPTION_DOWNLOAD]);
$this->setDisplayOptionOverrides('embed', H5PPermission::EMBED_H5P, $id, $display_options['showEmbed']); $this->setDisplayOptionOverrides(self::DISPLAY_OPTION_EMBED, H5PPermission::EMBED_H5P, $id, $display_options[self::DISPLAY_OPTION_EMBED]);
if ($this->h5pF->getOption('copyright', TRUE) == FALSE) { if ($this->h5pF->getOption(self::DISPLAY_OPTION_COPYRIGHT, TRUE) == FALSE) {
$display_options['showCopyright'] = false; $display_options[self::DISPLAY_OPTION_COPYRIGHT] = false;
} }
} }
@ -2600,11 +2609,11 @@ class H5PCore {
*/ */
private function getDisplayOptionsAsArray($disable) { private function getDisplayOptionsAsArray($disable) {
return array( return array(
'showFrame' => !($disable & H5PCore::DISABLE_FRAME), self::DISPLAY_OPTION_FRAME => !($disable & H5PCore::DISABLE_FRAME),
'showDownload' => !($disable & H5PCore::DISABLE_DOWNLOAD), self::DISPLAY_OPTION_DOWNLOAD => !($disable & H5PCore::DISABLE_DOWNLOAD),
'showEmbed' => !($disable & H5PCore::DISABLE_EMBED), self::DISPLAY_OPTION_EMBED => !($disable & H5PCore::DISABLE_EMBED),
'showCopyright' => !($disable & H5PCore::DISABLE_COPYRIGHT), self::DISPLAY_OPTION_COPYRIGHT => !($disable & H5PCore::DISABLE_COPYRIGHT),
'showAbout' => $this->h5pF->getOption('icon', TRUE), self::DISPLAY_OPTION_ABOUT => $this->h5pF->getOption(self::DISPLAY_OPTION_ABOUT, TRUE),
); );
} }

View File

@ -44,17 +44,17 @@ H5P.ActionBar = (function ($, EventDispatcher) {
}; };
// Register action bar buttons // Register action bar buttons
if (displayOptions.showDownload) { if (displayOptions.export) {
// Add export button // Add export button
addActionButton('download', 'export'); addActionButton('download', 'export');
} }
if (displayOptions.showCopyright) { if (displayOptions.copyright) {
addActionButton('copyrights'); addActionButton('copyrights');
} }
if (displayOptions.showEmbed) { if (displayOptions.embed) {
addActionButton('embed'); addActionButton('embed');
} }
if (displayOptions.showAbout) { if (displayOptions.icon) {
// Add about H5P button icon // Add about H5P button icon
H5P.jQuery('<li><a class="h5p-link" href="http://h5p.org" target="_blank" title="' + H5P.t('h5pDescription') + '"></a></li>').appendTo($actions); H5P.jQuery('<li><a class="h5p-link" href="http://h5p.org" target="_blank" title="' + H5P.t('h5pDescription') + '"></a></li>').appendTo($actions);
hasActions = true; hasActions = true;

View File

@ -133,12 +133,12 @@ H5P.init = function (target) {
* Create action bar * Create action bar
*/ */
var displayOptions = contentData.displayOptions; var displayOptions = contentData.displayOptions;
if (displayOptions.showFrame) { if (displayOptions.frame) {
// Special handling of copyrights // Special handling of copyrights
if (displayOptions.showCopyright) { if (displayOptions.copyright) {
var copyrights = H5P.getCopyrights(instance, library.params, contentId); var copyrights = H5P.getCopyrights(instance, library.params, contentId);
if (!copyrights) { if (!copyrights) {
displayOptions.showCopyright = false; displayOptions.copyright = false;
} }
} }
@ -163,7 +163,7 @@ H5P.init = function (target) {
$actions.insertAfter($container); $actions.insertAfter($container);
} }
if (displayOptions.showFrame && actionBar.hasActions()) { if (displayOptions.frame && actionBar.hasActions()) {
$element.addClass('h5p-frame'); $element.addClass('h5p-frame');
} }
else { else {