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

Commit

Permalink
Included item dom element in onCreate and onUpdate event
Browse files Browse the repository at this point in the history
  • Loading branch information
Rainer Simon committed May 2, 2014
1 parent fb9e1f7 commit f59d2bd
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ annotorious.Editor = function(annotator) {
annotator.stopSelection();

if (self._original_annotation)
annotator.fireEvent(annotorious.events.EventType.ANNOTATION_UPDATED, annotation);
annotator.fireEvent(annotorious.events.EventType.ANNOTATION_UPDATED, annotation, annotator.getItem());
else
annotator.fireEvent(annotorious.events.EventType.ANNOTATION_CREATED, annotation);
annotator.fireEvent(annotorious.events.EventType.ANNOTATION_CREATED, annotation, annotator.getItem());
self.close();
});

Expand Down
5 changes: 2 additions & 3 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ annotorious.events.EventBroker.prototype.removeHandler = function(type, handler)
* @param {Object=} opt_event the event object
* @return {boolean} the 'cancel event' flag
*/
annotorious.events.EventBroker.prototype.fireEvent = function(type, opt_event) {
annotorious.events.EventBroker.prototype.fireEvent = function(type, opt_event, opt_extra) {
var cancelEvent = false;

var handlers = this._handlers[type];
if (handlers) {
goog.array.forEach(handlers, function(handler, idx, array) {
var retVal = handler(opt_event);
var retVal = handler(opt_event, opt_extra);
if (goog.isDef(retVal) && !retVal)
cancelEvent = true;
});
Expand Down
4 changes: 2 additions & 2 deletions src/mediatypes/annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ annotorious.mediatypes.Annotator.prototype.addHandler = function(type, handler)
this._eventBroker.addHandler(type, handler);
}

annotorious.mediatypes.Annotator.prototype.fireEvent = function(type, event) {
return this._eventBroker.fireEvent(type, event);
annotorious.mediatypes.Annotator.prototype.fireEvent = function(type, event, opt_extra) {
return this._eventBroker.fireEvent(type, event, opt_extra);
}

annotorious.mediatypes.Annotator.prototype.getActiveSelector = function() {
Expand Down
5 changes: 2 additions & 3 deletions src/mediatypes/image/image.annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,8 @@ annotorious.mediatypes.image.ImageAnnotator.prototype.getAvailableSelectors = fu
* Returns the image that this annotator is responsible for.
* @returns {Object} the image
*/
annotorious.mediatypes.image.ImageAnnotator.prototype.getItem = function() {
// TODO include width and height
return { src: annotorious.mediatypes.image.ImageAnnotator.getItemURL(this._image) };
annotorious.mediatypes.image.ImageAnnotator.prototype.getItem = function() {
return { src: annotorious.mediatypes.image.ImageAnnotator.getItemURL(this._image), element: this._image };
}

/**
Expand Down
4 changes: 4 additions & 0 deletions test/image/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
};

anno.addAnnotation(annotation);

anno.addHandler('onAnnotationCreated', function(annotation, item) {
console.log(item);
});
});
</script>
<style>
Expand Down

0 comments on commit f59d2bd

Please sign in to comment.