Fix bubble system

semantics-font
Svein-Tore Griff With 2015-03-22 11:17:58 +01:00
parent 313bb757ba
commit 3da0de4626
1 changed files with 8 additions and 3 deletions

View File

@ -5,10 +5,16 @@ var H5P = H5P || {};
* The Event class for the EventDispatcher * The Event class for the EventDispatcher
* @class * @class
*/ */
H5P.Event = function(type, data) { H5P.Event = function(type, data, extras) {
this.type = type; this.type = type;
this.data = data; this.data = data;
var bubbles = true; var bubbles = true;
if (extras === undefined) {
extras = {};
}
if (extras.bubbles === false) {
bubbles = false;
}
this.preventBubbling = function() { this.preventBubbling = function() {
bubbles = false; bubbles = false;
}; };
@ -139,7 +145,6 @@ H5P.EventDispatcher = (function () {
* argument * argument
*/ */
this.trigger = function (event, eventData) { this.trigger = function (event, eventData) {
console.log(event);
if (event === undefined) { if (event === undefined) {
return; return;
} }
@ -156,7 +161,7 @@ H5P.EventDispatcher = (function () {
for (var i = 0; i < triggers[event.type].length; i++) { for (var i = 0; i < triggers[event.type].length; i++) {
triggers[event.type][i].listener.call(triggers[event.type][i].thisArg, event); triggers[event.type][i].listener.call(triggers[event.type][i].thisArg, event);
} }
if (event.getBubbles() && typeof self.parent === 'function' && typeof self.parent.trigger === 'function') { if (event.getBubbles() && self.parent instanceof H5P.EventDispatcher && typeof self.parent.trigger === 'function') {
self.parent.trigger(event); self.parent.trigger(event);
} }
}; };