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

Commit f59d2bd

Browse files
author
Rainer Simon
committed
Included item dom element in onCreate and onUpdate event
1 parent fb9e1f7 commit f59d2bd

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

src/editor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ annotorious.Editor = function(annotator) {
5858
annotator.stopSelection();
5959

6060
if (self._original_annotation)
61-
annotator.fireEvent(annotorious.events.EventType.ANNOTATION_UPDATED, annotation);
61+
annotator.fireEvent(annotorious.events.EventType.ANNOTATION_UPDATED, annotation, annotator.getItem());
6262
else
63-
annotator.fireEvent(annotorious.events.EventType.ANNOTATION_CREATED, annotation);
63+
annotator.fireEvent(annotorious.events.EventType.ANNOTATION_CREATED, annotation, annotator.getItem());
6464
self.close();
6565
});
6666

src/events.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ annotorious.events.EventBroker.prototype.removeHandler = function(type, handler)
4545
* @param {Object=} opt_event the event object
4646
* @return {boolean} the 'cancel event' flag
4747
*/
48-
annotorious.events.EventBroker.prototype.fireEvent = function(type, opt_event) {
48+
annotorious.events.EventBroker.prototype.fireEvent = function(type, opt_event, opt_extra) {
4949
var cancelEvent = false;
50-
5150
var handlers = this._handlers[type];
5251
if (handlers) {
5352
goog.array.forEach(handlers, function(handler, idx, array) {
54-
var retVal = handler(opt_event);
53+
var retVal = handler(opt_event, opt_extra);
5554
if (goog.isDef(retVal) && !retVal)
5655
cancelEvent = true;
5756
});

src/mediatypes/annotator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ annotorious.mediatypes.Annotator.prototype.addHandler = function(type, handler)
1414
this._eventBroker.addHandler(type, handler);
1515
}
1616

17-
annotorious.mediatypes.Annotator.prototype.fireEvent = function(type, event) {
18-
return this._eventBroker.fireEvent(type, event);
17+
annotorious.mediatypes.Annotator.prototype.fireEvent = function(type, event, opt_extra) {
18+
return this._eventBroker.fireEvent(type, event, opt_extra);
1919
}
2020

2121
annotorious.mediatypes.Annotator.prototype.getActiveSelector = function() {

src/mediatypes/image/image.annotator.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,8 @@ annotorious.mediatypes.image.ImageAnnotator.prototype.getAvailableSelectors = fu
288288
* Returns the image that this annotator is responsible for.
289289
* @returns {Object} the image
290290
*/
291-
annotorious.mediatypes.image.ImageAnnotator.prototype.getItem = function() {
292-
// TODO include width and height
293-
return { src: annotorious.mediatypes.image.ImageAnnotator.getItemURL(this._image) };
291+
annotorious.mediatypes.image.ImageAnnotator.prototype.getItem = function() {
292+
return { src: annotorious.mediatypes.image.ImageAnnotator.getItemURL(this._image), element: this._image };
294293
}
295294

296295
/**

test/image/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
};
2121

2222
anno.addAnnotation(annotation);
23+
24+
anno.addHandler('onAnnotationCreated', function(annotation, item) {
25+
console.log(item);
26+
});
2327
});
2428
</script>
2529
<style>

0 commit comments

Comments
 (0)