Skip to content
This repository has been archived by the owner on Apr 2, 2023. It is now read-only.

Commit

Permalink
removeHandler method changes only
Browse files Browse the repository at this point in the history
  • Loading branch information
harshalitalele committed Apr 12, 2018
1 parent 49c51c7 commit 1867743
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/annotorious.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ annotorious.Annotorious.prototype.addHandler = function(type, handler) {
});
}

/**
* Removes an event handler to Annotorious.
* @param {annotorious.events.EventType} type the event type
* @param {Function} handler the handler function
*/
annotorious.Annotorious.prototype.removeHandler = function(type, handler) {
goog.array.forEach(this._modules, function(module) {
module.removeHandler(type, handler);
});
}

/**
* Adds a plugin to Annotorious.
* @param {string} plugin_name the plugin name
Expand Down
4 changes: 4 additions & 0 deletions src/mediatypes/annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ annotorious.mediatypes.Annotator.prototype.addHandler = function(type, handler)
this._eventBroker.addHandler(type, handler);
}

-annotorious.mediatypes.Annotator.prototype.removeHandler = function(type) {
- this._eventBroker.removeHandler(type);
-}

annotorious.mediatypes.Annotator.prototype.fireEvent = function(type, event, opt_extra) {
return this._eventBroker.fireEvent(type, event, opt_extra);
}
Expand Down
18 changes: 18 additions & 0 deletions src/mediatypes/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,24 @@ annotorious.mediatypes.Module.prototype.addHandler = function(type, handler) {
this._eventHandlers.push({ type: type, handler: handler });
}

/**
- * Removes a/all lifecycle event handler/s to this module.
- * @param {annotorious.events.EventType} type the event type
- * @param {Function} handler the handler function (optional)
- */
-annotorious.mediatypes.Module.prototype.removeHandler = function(type, handler) {
- goog.array.forEach(this._annotators.getValues(), function(annotator, idx, array) {
- annotator.removeHandler(type, handler);
- });
- goog.array.forEach(this._eventHandlers, function(elem, index, array) {
- if(elem.type === type) {
- if(!handler || elem.handler === handler) {
- goog.array.removeAt(array, index);
- }
- }
- });
-}

/**
* Adds a plugin to this module.
* @param {Plugin} plugin the plugin
Expand Down

0 comments on commit 1867743

Please sign in to comment.