Fixed off().

editor-padding
Frode Petterson 2015-08-27 11:36:07 +02:00
parent d8d7fdabdd
commit 7737559dec
1 changed files with 9 additions and 6 deletions

View File

@ -7,7 +7,7 @@ var H5P = H5P || {};
* @param {string} type
* @param {*} data
* @param {Object} [extras]
* @param {boolean} [extras.bubbles]
* @param {boolean} [extras.bubbles]
* @param {boolean} [extras.external]
*/
H5P.Event = function(type, data, extras) {
@ -176,7 +176,7 @@ H5P.EventDispatcher = (function () {
// Find specific listener
for (var i = 0; i < triggers[type].length; i++) {
if (triggers[type][i].listener === listener) {
triggers[type].unshift(i, 1);
triggers[type].splice(i, 1);
self.trigger('removeListener', type, {'listener': listener});
break;
}
@ -199,9 +199,12 @@ H5P.EventDispatcher = (function () {
return;
}
// Clone array (prevents triggers from being modified during the event)
var handlers = triggers[type].slice();
// Call all listeners
for (var i = 0; i < triggers[type].length; i++) {
var trigger = triggers[type][i];
for (var i = 0; i < handlers.length; i++) {
var trigger = handlers[i];
var thisArg = (trigger.thisArg ? trigger.thisArg : this);
trigger.listener.call(thisArg, event);
}
@ -216,14 +219,14 @@ H5P.EventDispatcher = (function () {
* Custom event data(used when event type as string is used as first
* argument).
* @param {Object} [extras]
* @param {boolean} [extras.bubbles]
* @param {boolean} [extras.bubbles]
* @param {boolean} [extras.external]
*/
this.trigger = function (event, eventData, extras) {
if (event === undefined) {
return;
}
if (typeof event === 'string') { // TODO: Check instanceof String as well?
if (event instanceof String || typeof event === 'string') {
event = new H5P.Event(event, eventData, extras);
}
else if (eventData !== undefined) {