Documentation updates
parent
84f8fb1cff
commit
10fbca1549
|
@ -1,6 +1,10 @@
|
|||
/** @namespace H5P */
|
||||
var H5P = H5P || {};
|
||||
|
||||
/**
|
||||
* The Event class for the EventDispatcher
|
||||
* @class
|
||||
*/
|
||||
H5P.Event = function(type, data) {
|
||||
this.type = type;
|
||||
this.data = data;
|
||||
|
@ -27,13 +31,14 @@ H5P.EventDispatcher = (function () {
|
|||
* Add new event listener.
|
||||
*
|
||||
* @public
|
||||
* @throws {TypeError} listener must be a function
|
||||
* @param {String} type Event type
|
||||
* @param {Function} listener Event listener
|
||||
* @throws {TypeError} listener - Must be a function
|
||||
* @param {String} type - Event type
|
||||
* @param {Function} listener - Event listener
|
||||
* @param {Function} thisArg - Optional thisArg to call the listener from
|
||||
*/
|
||||
self.on = function (type, listener, scope) {
|
||||
if (scope === undefined) {
|
||||
scope = self;
|
||||
self.on = function (type, listener, thisArg) {
|
||||
if (thisArg === undefined) {
|
||||
thisArg = self;
|
||||
}
|
||||
if (!(listener instanceof Function)) {
|
||||
throw TypeError('listener must be a function');
|
||||
|
@ -44,11 +49,11 @@ H5P.EventDispatcher = (function () {
|
|||
|
||||
if (!triggers[type]) {
|
||||
// First
|
||||
triggers[type] = [{'listener': listener, 'scope': scope}];
|
||||
triggers[type] = [{'listener': listener, 'thisArg': thisArg}];
|
||||
}
|
||||
else {
|
||||
// Append
|
||||
triggers[type].push({'listener': listener, 'scope': scope});
|
||||
triggers[type].push({'listener': listener, 'thisArg': thisArg});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -60,9 +65,9 @@ H5P.EventDispatcher = (function () {
|
|||
* @param {String} type Event type
|
||||
* @param {Function} listener Event listener
|
||||
*/
|
||||
self.once = function (type, listener, scope) {
|
||||
if (scope === undefined) {
|
||||
scope = self;
|
||||
self.once = function (type, listener, thisArg) {
|
||||
if (thisArg === undefined) {
|
||||
thisArg = self;
|
||||
}
|
||||
if (!(listener instanceof Function)) {
|
||||
throw TypeError('listener must be a function');
|
||||
|
@ -70,10 +75,10 @@ H5P.EventDispatcher = (function () {
|
|||
|
||||
var once = function (event) {
|
||||
self.off(event, once);
|
||||
listener.apply(scope, event);
|
||||
listener.apply(thisArg, event);
|
||||
};
|
||||
|
||||
self.on(type, once, scope);
|
||||
self.on(type, once, thisArg);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -138,7 +143,7 @@ H5P.EventDispatcher = (function () {
|
|||
}
|
||||
// Call all listeners
|
||||
for (var i = 0; i < triggers[event.type].length; i++) {
|
||||
triggers[event.type][i].listener.call(triggers[event.type][i].scope, event);
|
||||
triggers[event.type][i].listener.call(triggers[event.type][i].thisArg, event);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue