2014-12-01 05:42:47 -05:00
|
|
|
define [
|
|
|
|
"base"
|
|
|
|
], (App) ->
|
|
|
|
#app = angular.module 'pdfHighlights', []
|
2014-11-25 11:00:21 -05:00
|
|
|
|
2014-12-01 05:42:47 -05:00
|
|
|
App.factory 'pdfHighlights', [ () ->
|
|
|
|
class pdfHighlights
|
2014-11-25 11:00:21 -05:00
|
|
|
|
2014-12-01 05:42:47 -05:00
|
|
|
constructor: (options) ->
|
|
|
|
@highlightsLayerDiv = options.highlights[0]
|
|
|
|
@highlightElements = []
|
2014-11-25 11:00:21 -05:00
|
|
|
|
2014-12-01 05:42:47 -05:00
|
|
|
addHighlight: (viewport, left, top, width, height) ->
|
|
|
|
rect = viewport.convertToViewportRectangle([left, top, left + width, top + height])
|
|
|
|
rect = PDFJS.Util.normalizeRect(rect)
|
|
|
|
element = document.createElement("div")
|
|
|
|
element.style.left = Math.floor(rect[0]) + 'px'
|
|
|
|
element.style.top = Math.floor(rect[1]) + 'px'
|
|
|
|
element.style.width = Math.ceil(rect[2] - rect[0]) + 'px'
|
|
|
|
element.style.height = Math.ceil(rect[3] - rect[1]) + 'px'
|
|
|
|
@highlightElements.push(element)
|
|
|
|
@highlightsLayerDiv.appendChild(element)
|
|
|
|
element
|
2014-11-25 11:00:21 -05:00
|
|
|
|
2014-12-01 05:42:47 -05:00
|
|
|
clearHighlights: () ->
|
|
|
|
for h in @highlightElements
|
2015-02-18 17:29:07 -05:00
|
|
|
h?.remove()
|
2014-12-01 05:42:47 -05:00
|
|
|
@highlightElements = []
|
|
|
|
]
|