From 99522f59bfafbe50c99b1eebde841d38b14b9357 Mon Sep 17 00:00:00 2001 From: Thomas Marstrander Date: Thu, 21 May 2015 13:02:52 +0200 Subject: [PATCH 1/6] Skip groups that are null. This is done because groups with only one entry are concatenated with their entry. --- h5p.classes.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index 0bd122a..ca0fb8e 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2811,6 +2811,10 @@ class H5PContentValidator { } } if (!(isset($semantics->optional) && $semantics->optional)) { + if ($group === NULL) { + // Error no value. Errors aren't printed... + return; + } foreach ($semantics->fields as $field) { if (!(isset($field->optional) && $field->optional)) { // Check if field is in group. From 101d5aab3165acfd6344c0234d33c4f1d513294d Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 22 May 2015 13:20:44 +0200 Subject: [PATCH 2/6] There is no disable all option. Disabling frame does the same. --- h5p.classes.php | 1 - 1 file changed, 1 deletion(-) diff --git a/h5p.classes.php b/h5p.classes.php index 0bd122a..8480fd9 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1642,7 +1642,6 @@ class H5PCore { const DISABLE_EMBED = 4; const DISABLE_COPYRIGHT = 8; const DISABLE_ABOUT = 16; - const DISABLE_ALL = 31; // Map flags to string public static $disable = array( From 6ecb15a1d03f38fe825ca615092cc2522d1c8fea Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 22 May 2015 13:18:13 +0200 Subject: [PATCH 3/6] There is no disable about for content, it's only a global setting. --- h5p.classes.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 8480fd9..17cc04c 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2367,9 +2367,6 @@ class H5PCore { if (!isset($sources['embed']) || !$sources['embed']) { $disable |= H5PCore::DISABLE_EMBED; } - if (!isset($sources['about']) || !$sources['about']) { - $disable |= H5PCore::DISABLE_ABOUT; - } return $disable; } From d85815b3be7ed0c2b573c4ab686d6b4874b6eebf Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 22 May 2015 15:31:28 +0200 Subject: [PATCH 4/6] Keep the content's disable settings when re-saving after global options have changed. (More consistent and reliable) --- h5p.classes.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 34f637e..4c34549 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2351,23 +2351,24 @@ class H5PCore { * Determine disable state from sources. * * @param array $sources + * @param int $current * @return int */ - public static function getDisable(&$sources) { - $disable = H5PCore::DISABLE_NONE; - if (!isset($sources['frame']) || !$sources['frame']) { - $disable |= H5PCore::DISABLE_FRAME; + public function getDisable(&$sources, $current) { + foreach (H5PCore::$disable as $bit => $option) { + if ($option === 'download') { + $option = 'export'; + } + if ($this->h5pF->getOption($option, TRUE) ) { + if (!isset($sources[$option]) || !$sources[$option]) { + $current |= $bit; // Disable + } + else { + $current &= ~$bit; // Enable + } + } } - if (!isset($sources['download']) || !$sources['download']) { - $disable |= H5PCore::DISABLE_DOWNLOAD; - } - if (!isset($sources['copyright']) || !$sources['copyright']) { - $disable |= H5PCore::DISABLE_COPYRIGHT; - } - if (!isset($sources['embed']) || !$sources['embed']) { - $disable |= H5PCore::DISABLE_EMBED; - } - return $disable; + return $current; } // Cache for getting library ids From 3460e400a00bb955d69a5f8aaf69628f2d392f11 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 22 May 2015 15:50:00 +0200 Subject: [PATCH 5/6] Fixed special case for export/download. --- h5p.classes.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 4c34549..c247a71 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2356,10 +2356,7 @@ class H5PCore { */ public function getDisable(&$sources, $current) { foreach (H5PCore::$disable as $bit => $option) { - if ($option === 'download') { - $option = 'export'; - } - if ($this->h5pF->getOption($option, TRUE) ) { + if ($this->h5pF->getOption(($bit & H5PCore::DISABLE_DOWNLOAD ? 'export' : $option), TRUE)) { if (!isset($sources[$option]) || !$sources[$option]) { $current |= $bit; // Disable } From c40d27370464201afc25a16349bfb5e7de7cde29 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Thu, 4 Jun 2015 14:39:02 +0200 Subject: [PATCH 6/6] Fixed this arg for external dispatcher. --- js/h5p-event-dispatcher.js | 57 +++++++++++++++++++++----------------- js/h5p.js | 4 ++- 2 files changed, 35 insertions(+), 26 deletions(-) diff --git a/js/h5p-event-dispatcher.js b/js/h5p-event-dispatcher.js index b6f59a6..0fb9acb 100644 --- a/js/h5p-event-dispatcher.js +++ b/js/h5p-event-dispatcher.js @@ -99,13 +99,10 @@ H5P.EventDispatcher = (function () { * Event type * @param {H5P.EventCallback} listener * Event listener - * @param {function} thisArg + * @param {Object} thisArg * Optionally specify the this value when calling listener. */ this.on = function (type, listener, thisArg) { - if (thisArg === undefined) { - thisArg = self; - } if (typeof listener !== 'function') { throw TypeError('listener must be a function'); } @@ -113,13 +110,14 @@ H5P.EventDispatcher = (function () { // Trigger event before adding to avoid recursion self.trigger('newListener', {'type': type, 'listener': listener}); + var trigger = {'listener': listener, 'thisArg': thisArg}; if (!triggers[type]) { // First - triggers[type] = [{'listener': listener, 'thisArg': thisArg}]; + triggers[type] = [trigger]; } else { // Append - triggers[type].push({'listener': listener, 'thisArg': thisArg}); + triggers[type].push(trigger); } }; @@ -132,20 +130,17 @@ H5P.EventDispatcher = (function () { * Event type * @param {H5P.EventCallback} listener * Event listener - * @param {function} thisArg + * @param {Object} thisArg * Optionally specify the this value when calling listener. */ this.once = function (type, listener, thisArg) { - if (thisArg === undefined) { - thisArg = self; - } if (!(listener instanceof Function)) { throw TypeError('listener must be a function'); } var once = function (event) { self.off(event, once); - listener.apply(thisArg, event); + listener.apply(this, event); }; self.on(type, once, thisArg); @@ -193,6 +188,25 @@ H5P.EventDispatcher = (function () { } }; + /** + * Try to call all event listeners for the given event type. + * + * @private + * @param {string} Event type + */ + var call = function (type, event) { + if (triggers[type] === undefined) { + return; + } + + // Call all listeners + for (var i = 0; i < triggers[type].length; i++) { + var trigger = triggers[type][i]; + var thisArg = (trigger.thisArg ? trigger.thisArg : this); + trigger.listener.call(thisArg, event); + } + }; + /** * Dispatch event. * @@ -219,27 +233,20 @@ H5P.EventDispatcher = (function () { // Check to see if this event should go externally after all triggering and bubbling is done var scheduledForExternal = event.scheduleForExternal(); - if (triggers[event.type] !== undefined) { - // Call all listeners - for (var i = 0; i < triggers[event.type].length; i++) { - triggers[event.type][i].listener.call(triggers[event.type][i].thisArg, event); - } - } + // Call all listeners + call.call(this, event.type, event); - if (triggers['*'] !== undefined) { - // Call all * listeners - for (var j = 0; j < triggers['*'].length; j++) { - triggers['*'][j].listener.call(triggers['*'][j].thisArg, event); - } - } + // Call all * listeners + call.call(this, '*', event); // Bubble - if (event.getBubbles() && self.parent instanceof H5P.EventDispatcher && typeof self.parent.trigger === 'function') { // TODO: Check instanceof Function as well? + if (event.getBubbles() && self.parent instanceof H5P.EventDispatcher && + (self.parent.trigger instanceof Function || typeof self.parent.trigger === 'function')) { self.parent.trigger(event); } if (scheduledForExternal) { - H5P.externalDispatcher.trigger(event); + H5P.externalDispatcher.trigger.call(this, event); } }; } diff --git a/js/h5p.js b/js/h5p.js index faab8e6..2137da4 100644 --- a/js/h5p.js +++ b/js/h5p.js @@ -1914,7 +1914,9 @@ H5P.createTitle = function (rawTitle, maxLength) { // Relay events to top window. if (H5P.isFramed && H5P.externalEmbed === false) { - H5P.externalDispatcher.on('*', window.top.H5P.externalDispatcher.trigger); + H5P.externalDispatcher.on('*', function (event) { + window.top.H5P.externalDispatcher.trigger.call(this, event); + }); } });