function getAnnotationByMouseEvent(pageCoordinate, annotations) {
for (var i = 0; i < annotations.length; i++) {
var annot = annotations[i];
if (annot.GetPageNumber() - 1 === pageCoordinate.pageIndex) {
var rect = {
x1: annot.GetLeft(),
y1: annot.GetTop(),
x2: annot.GetRight(),
y2: annot.GetBottom()
};
if (pageCoordinate.x >= rect.x1 && pageCoordinate.x <= rect.x2 && pageCoordinate.y >= rect.y1 && pageCoordinate.y <= rect.y2) {
return annot;
}
}
}
return null;
}
Tools.AnnotAndTextSelectTool = function(docViewer) {
Tools.TextSelectTool.call(this, docViewer);
this._editTool = new Tools.AnnotationEditTool(docViewer);
this._textSelectTool = new Tools.TextSelectTool(docViewer);
};
Tools.AnnotAndTextSelectTool.prototype = $.extend(new Tools.TextSelectTool(), {
mouseLeftDown: function(e) {
Tools.Tool.prototype.mouseLeftDown.call(this, e);
var am = this.docViewer.GetAnnotationManager();
if (e.originalEvent.touches && e.originalEvent.touches.length > 1) {
return true;
}
this._annot = getAnnotationByMouseEvent(this.pageCoordinates[0], am.GetAnnotationsList());
if (this._annot) {
this._editTool.mouseLeftDown(e);
} else {
am.DeselectAllAnnotations();
this._textSelectTool.mouseLeftDown(e);
}
},
mouseLeftUp: function(e) {
if (this._annot) {
this._editTool.mouseLeftUp(e);
} else {
this._textSelectTool.mouseLeftUp(e);
}
},
mouseMove: function(e) {
if (e.originalEvent.touches && e.originalEvent.touches.length > 1) {
return true;
}
if (this._annot) {
this._editTool.mouseMove(e);
} else {
this._textSelectTool.mouseMove(e);
}
},
keyDown: function(e) {
if (this._annot) {
this._editTool.keyDown(e);
} else {
this._textSelectTool.keyDown(e);
}
}
});