Commit f570532f authored by Randall Leeds's avatar Randall Leeds

Make the choice of anchoring less magical

And hide the cache details from the default implementation that
doesn't use them.
parent bc674252
if (window.PDFViewerApplication)
module.exports = require('./pdf')
else
module.exports = require('./html')
......@@ -3,7 +3,6 @@ Promise = global.Promise ? require('es6-promise').Promise
Annotator = require('annotator')
$ = Annotator.$
anchoring = require('./anchoring/main')
highlighter = require('./highlighter')
......@@ -25,7 +24,11 @@ module.exports = class Guest extends Annotator
TextHighlights: {}
TextSelection: {}
# Anchoring module
anchoring: require('./anchoring/html')
# Internal state
anchors: null
visibleHighlights: false
html: jQuery.extend {}, Annotator::html,
......@@ -36,11 +39,10 @@ module.exports = class Guest extends Annotator
</div>
'''
constructor: (element, options, config = {}) ->
constructor: (element, options) ->
super
this.anchors = []
this.anchoringCache = {}
cfOptions =
on: (event, handler) =>
......@@ -164,7 +166,7 @@ module.exports = class Guest extends Annotator
cache: self.anchoringCache
ignoreSelector: '[class^="annotator-"]'
}
return anchoring.anchor(target.selector, options)
return self.anchoring.anchor(target.selector, options)
.then((range) -> {annotation, target, range})
.catch(-> {annotation, target})
......@@ -226,7 +228,7 @@ module.exports = class Guest extends Annotator
cache: self.anchoringCache
ignoreSelector: '[class^="annotator-"]'
}
return anchoring.describe(range, options)
return self.anchoring.describe(range, options)
setDocumentInfo = ({metadata, uri}) ->
annotation.uri = uri
......
extend = require('extend')
Promise = global.Promise ? require('es6-promise').Promise
Annotator = require('annotator')
......@@ -8,8 +9,21 @@ class PDF extends Annotator.Plugin
pdfViewer: null
pluginInit: ->
@annotator.anchoringCache.pageText = {}
@annotator.anchoringCache.quotePosition = {}
cache = {
pageText: {}
quotePosition: {}
}
anchoring = require('../anchoring/pdf')
@annotator.anchoring = {
anchor: (selectors, options = {}) ->
options = extend({}, options, {cache})
return anchoring.anchor(selectors, options)
describe: (range, options = {}) ->
options = extend({}, options, {cache})
return anchoring.describe(range, options)
}
@pdfViewer = PDFViewerApplication.pdfViewer
@pdfViewer.viewer.classList.add('has-transparent-text-layer')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment