How do I make the viewer scroll when dragging text out of the view?

10 views
Skip to first unread message

Justin Jung

unread,
Nov 17, 2017, 2:31:54 PM11/17/17
to pdfnet-w...@googlegroups.com
Q: How do I make the viewer scroll when dragging text or adding annotations out of the view, just like the default browser behavior when selecting text?

A: You can add the following to config.js:

var scrollView = $('#DocumentViewer')[0];
var sidePanel = $('#sidePanel');
var notesPanel = $('#notesPanelWrapper');

var shiftPage = function(e) {
  var leftShift = readerControl.sidePanelVisible() ? sidePanel.width() : 0;
  var rightShift = notesPanel.css('display') === 'none' ? 0 : notesPanel.width();

  if (e.pageX < leftShift + 10) {
    scrollView.scrollLeft -= 10;
  } else if (e.pageX > window.innerWidth - rightShift - 10) {
    scrollView.scrollLeft += 10;
  }
};

var mouseLeftDown = function(originalMouseLeftDown) {
  return function() {
    originalMouseLeftDown.apply(this, arguments);
    this.mouseDown = true;
  }
};

var mouseMove = function(originalMouseMove) {
  return function(e) {
    originalMouseMove.apply(this, arguments);
    if (this.mouseDown) {
      shiftPage(e);
    }
  }
};

var mouseLeftUp = function(originalMouseLeftUp) {
  return function() {
    if (this.annotation) {
      readerControl.docViewer.getAnnotationManager().redrawAnnotation(this.annotation);
    }
    originalMouseLeftUp.apply(this, arguments);
    this.mouseDown = false;
  }
};

var textToolMouseLeftDown = Tools.TextTool.prototype.mouseLeftDown;
Tools.TextTool.prototype.mouseLeftDown = mouseLeftDown(textToolMouseLeftDown);
 
var textToolMouseMove = Tools.TextTool.prototype.mouseMove;
Tools.TextTool.prototype.mouseMove = mouseMove(textToolMouseMove);
 
var textToolMouseLeftUp = Tools.TextTool.prototype.mouseLeftUp;
Tools.TextTool.prototype.mouseLeftUp = mouseLeftUp(textToolMouseLeftUp);

var genericAnnotationMouseLeftDown = Tools.GenericAnnotationCreateTool.prototype.mouseLeftDown;
Tools.GenericAnnotationCreateTool.prototype.mouseLeftDown = mouseLeftDown(genericAnnotationMouseLeftDown);;
 
var genericAnnotationMouseMove = Tools.GenericAnnotationCreateTool.prototype.mouseMove;
Tools.GenericAnnotationCreateTool.prototype.mouseMove = mouseMove(genericAnnotationMouseMove);
 
var genericAnnotationMouseLeftUp = Tools.GenericAnnotationCreateTool.prototype.mouseLeftUp;
Tools.GenericAnnotationCreateTool.prototype.mouseLeftUp = mouseLeftUp(genericAnnotationMouseLeftUp);
Reply all
Reply to author
Forward
0 new messages