Prevent propagation of double click event when clicking on annotation

285 views
Skip to first unread message

Matt Parizeau

unread,
Jan 30, 2014, 12:59:11 PM1/30/14
to pdfnet-w...@googlegroups.com
Q:

Would it be possible to prevent a doubleclick on an annotation to bubble/propagate to the DOM? We want to use the doubleclick on a page to zoom to 200%. So if we click outside an annotation we want the event to zoom, and on an annotation we want it to edit the annotation. Is this possible?

A:

You would want to override the base tool's double click method.  Inside there you'll have to check if an annotation is being clicked on and if so then stop the propagation of the event.  You can do this with code like the following:
var annotManager = docViewer.GetAnnotationManager();

var oldDoubleClick = window.Tools.Tool.prototype.mouseDoubleClick;
window
.Tools.Tool.prototype.mouseDoubleClick = function(e) {
    oldDoubleClick
.call(this, e);

   
var pageCoordinate = this.pageCoordinates[0];
   
var annotations = annotManager.GetAnnotationsList();

   
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) {
                e
.stopImmediatePropagation();
               
break;
           
}
       
}
   
}
};

Note that this is the code necessary for WebViewer 1.6.  With WebViewer 1.7 you'll need to modify the code slightly for it to work with the new annotations and annotation selection.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Matt Parizeau

unread,
Apr 24, 2014, 5:29:49 PM4/24/14
to
For WebViewer 1.7 selection has changed to be more precise so the code to check if there is a hit has changed as well.  You would replace everything in the for loop with: 
var annot = annotations[i];
if (annot.GetPageNumber() - 1 === pageCoordinate.pageIndex) {

    var currentZoom = docViewer.GetPageZoom(docViewer.GetCurrentPage() - 1);
    if (annot.selectionModel.prototype.testSelection(annot, pageCoordinate.x, pageCoordinate.y, currentZoom)) {
        e.stopImmediatePropagation();
        break;
    }
}

Matt Parizeau
Software Developer
PDFTron Systems Inc.
Reply all
Reply to author
Forward
0 new messages