Merge branch 'release'

Conflicts:
	h5p.classes.php
redesign-copyrights
Frode Petterson 2015-06-04 14:47:34 +02:00
commit b399a68adc
3 changed files with 47 additions and 40 deletions

View File

@ -2398,23 +2398,21 @@ 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 ($this->h5pF->getOption(($bit & H5PCore::DISABLE_DOWNLOAD ? 'export' : $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

View File

@ -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);
}
};
}

View File

@ -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);
});
}
});