From f59d2bd898ff60f694036c22ef3169a7832ecb5a Mon Sep 17 00:00:00 2001 From: Rainer Simon Date: Fri, 2 May 2014 09:36:09 +0200 Subject: [PATCH] Included item dom element in onCreate and onUpdate event --- src/editor.js | 4 ++-- src/events.js | 5 ++--- src/mediatypes/annotator.js | 4 ++-- src/mediatypes/image/image.annotator.js | 5 ++--- test/image/index.html | 4 ++++ 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/editor.js b/src/editor.js index 1dc8275..59b02e9 100644 --- a/src/editor.js +++ b/src/editor.js @@ -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(); }); diff --git a/src/events.js b/src/events.js index 287efc1..c347b8e 100644 --- a/src/events.js +++ b/src/events.js @@ -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; }); diff --git a/src/mediatypes/annotator.js b/src/mediatypes/annotator.js index a41e7af..0638b96 100644 --- a/src/mediatypes/annotator.js +++ b/src/mediatypes/annotator.js @@ -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() { diff --git a/src/mediatypes/image/image.annotator.js b/src/mediatypes/image/image.annotator.js index 0ab4846..a40136c 100644 --- a/src/mediatypes/image/image.annotator.js +++ b/src/mediatypes/image/image.annotator.js @@ -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 }; } /** diff --git a/test/image/index.html b/test/image/index.html index 5fc051a..09ffef1 100644 --- a/test/image/index.html +++ b/test/image/index.html @@ -20,6 +20,10 @@ }; anno.addAnnotation(annotation); + + anno.addHandler('onAnnotationCreated', function(annotation, item) { + console.log(item); + }); });