HighlightsLayerBuilder.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. (function (name, context, definition) {
  2. if (typeof module != 'undefined' && module.exports) module.exports = definition()
  3. else if (typeof define == 'function' && define.amd) define(definition)
  4. else context[name] = definition()
  5. })('HighlightsLayerBuilder', this, function (name, context) {
  6. function HighlightsLayerBuilder(pageView, highlightsLayerDiv) {
  7. this.highlightsLayerDiv = highlightsLayerDiv;
  8. this.pageView = pageView;
  9. this.highlightElements = [];
  10. };
  11. HighlightsLayerBuilder.EXTERNAL_LINK_TARGET = "_blank";
  12. HighlightsLayerBuilder.prototype = {
  13. addHighlight: function(left, top, width, height) {
  14. rect = this.pageView.viewport.convertToViewportRectangle([left, top, left + width, top + height]);
  15. rect = PDFJS.Util.normalizeRect(rect);
  16. var element = document.createElement("div");
  17. element.style.left = Math.floor(rect[0]) + 'px';
  18. element.style.top = Math.floor(rect[1]) + 'px';
  19. element.style.width = Math.ceil(rect[2] - rect[0]) + 'px';
  20. element.style.height = Math.ceil(rect[3] - rect[1]) + 'px';
  21. this.highlightElements.push(element);
  22. this.highlightsLayerDiv.appendChild(element);
  23. return element;
  24. },
  25. clearHighlights: function() {
  26. for (var i = 0; i < this.highlightElements.length; i++) {
  27. this.highlightElements[i].remove();
  28. }
  29. this.highlightElements = [];
  30. }
  31. }
  32. return HighlightsLayerBuilder;
  33. });