Commit cd4057a5 authored by Randall Leeds's avatar Randall Leeds

Standardize the use of Annotator requires

parent b4dc5ac9
Annotator = require('annotator')
# Annotator plugin for fuzzy text matching
class Annotator.Plugin.FuzzyTextAnchors extends Annotator.Plugin
......@@ -7,8 +10,6 @@ class Annotator.Plugin.FuzzyTextAnchors extends Annotator.Plugin
console.warn "The FuzzyTextAnchors Annotator plugin requires the TextPosition plugin. Skipping."
return
@Annotator = Annotator
@anchoring = @annotator.anchoring
# Initialize the text matcher library
......@@ -70,7 +71,7 @@ class Annotator.Plugin.FuzzyTextAnchors extends Annotator.Plugin
# OK, we have everything
# Create a TextPositionAnchor from this data
new @Annotator.TextPositionAnchor @anchoring, annotation, target,
new Annotator.TextPositionAnchor @anchoring, annotation, target,
match.start, match.end,
(document.getPageIndexForPos match.start),
(document.getPageIndexForPos match.end),
......@@ -124,7 +125,7 @@ class Annotator.Plugin.FuzzyTextAnchors extends Annotator.Plugin
# OK, we have everything
# Create a TextPosutionAnchor from this data
new @Annotator.TextPositionAnchor @anchoring, annotation, target,
new Annotator.TextPositionAnchor @anchoring, annotation, target,
match.start, match.end,
(document.getPageIndexForPos match.start),
(document.getPageIndexForPos match.end),
......
Annotator = require('annotator')
$ = Annotator.$
require('jquery-scrollintoview')
......
Annotator = require('annotator')
# This anchor type stores information about a piece of text,
# described using start and end character offsets
class TextPositionAnchor extends Annotator.Anchor
@Annotator = Annotator
constructor: (anchoring, annotation, target,
@start, @end, startPage, endPage,
quote, diffHTML, diffCaseOnly) ->
......@@ -17,8 +17,6 @@ class TextPositionAnchor extends Annotator.Anchor
unless @start? then throw new Error "start is required!"
unless @end? then throw new Error "end is required!"
@Annotator = TextPositionAnchor.Annotator
# This is how we create a highlight out of this kind of anchor
_getSegment: (page) ->
......@@ -29,7 +27,7 @@ class TextPositionAnchor extends Annotator.Anchor
realRange = mappings.sections[page].realRange
# Get a BrowserRange
browserRange = new @Annotator.Range.BrowserRange realRange
browserRange = new Annotator.Range.BrowserRange realRange
# Get a NormalizedRange
normedRange = browserRange.normalize @anchoring.annotator.wrapper[0]
......@@ -41,9 +39,6 @@ class TextPositionAnchor extends Annotator.Anchor
class Annotator.Plugin.TextPosition extends Annotator.Plugin
pluginInit: ->
@Annotator = Annotator
@anchoring = @annotator.anchoring
# Register the creator for text quote selectors
......@@ -59,7 +54,7 @@ class Annotator.Plugin.TextPosition extends Annotator.Plugin
code: @createFromPositionSelector
# Export the anchor type
@Annotator.TextPositionAnchor = TextPositionAnchor
Annotator.TextPositionAnchor = TextPositionAnchor
# Create a TextPositionSelector around a range
_getTextPositionSelector: (selection) =>
......
Annotator = require('annotator')
# This plugin defines the TextQuote selector
class Annotator.Plugin.TextQuote extends Annotator.Plugin
@Annotator = Annotator
@$ = Annotator.$
# Plugin initialization
pluginInit: ->
......
Annotator = require('annotator')
# This anhor type stores information about a piece of text,
# described using the actual reference to the range in the DOM.
#
......@@ -18,17 +21,12 @@
# If the TextPosition plugin is loaded, it will create a TextPosition
# anchor; otherwise it will record a TextRangeAnchor.
class TextRangeAnchor extends Annotator.Anchor
@Annotator = Annotator
constructor: (annotator, annotation, target, @range, quote) ->
super annotator, annotation, target, 0, 0, quote
unless @range? then throw new Error "range is required!"
@Annotator = TextRangeAnchor.Annotator
# This is how we create a highlight out of this kind of anchor
_getSegment: ->
type: "magic range"
......@@ -39,9 +37,6 @@ class TextRangeAnchor extends Annotator.Anchor
class Annotator.Plugin.TextRange extends Annotator.Plugin
pluginInit: ->
@Annotator = Annotator
@anchoring = @annotator.anchoring
# Register the creator for range selectors
......@@ -89,7 +84,7 @@ class Annotator.Plugin.TextRange extends Annotator.Plugin
# Try to apply the saved XPath
try
range = @Annotator.Range.sniff serializedRange
range = Annotator.Range.sniff serializedRange
normedRange = range.normalize @annotator.wrapper[0]
catch error
return null
......@@ -123,7 +118,7 @@ class Annotator.Plugin.TextRange extends Annotator.Plugin
# Create a TextPositionAnchor from the start and end offsets
# of this range
# (to be used with dom-text-mapper)
new @Annotator.TextPositionAnchor @anchoring, annotation, target,
new Annotator.TextPositionAnchor @anchoring, annotation, target,
startInfo.start, endInfo.end,
(startInfo.pageIndex ? 0), (endInfo.pageIndex ? 0),
currentQuote
......
Annotator = require('annotator')
$ = Annotator.$
# This plugin implements the UI code for creating text annotations
class Annotator.Plugin.TextSelection extends Annotator.Plugin
pluginInit: ->
@Annotator = Annotator
@$ = Annotator.$
# Register the event handlers required for creating a selection
$(document).bind({
"touchend": @checkForEndSelection
......@@ -37,14 +38,14 @@ class Annotator.Plugin.TextSelection extends Annotator.Plugin
#
# Returns Array of NormalizedRange instances.
_getSelectedRanges: ->
selection = @Annotator.Util.getGlobal().getSelection()
selection = Annotator.Util.getGlobal().getSelection()
ranges = []
rangesToIgnore = []
unless selection.isCollapsed
ranges = for i in [0...selection.rangeCount]
r = selection.getRangeAt(i)
browserRange = new @Annotator.Range.BrowserRange(r)
browserRange = new Annotator.Range.BrowserRange(r)
normedRange = browserRange.normalize().limit @annotator.wrapper[0]
# If the new range falls fully outside the wrapper, we
......@@ -63,7 +64,7 @@ class Annotator.Plugin.TextSelection extends Annotator.Plugin
selection.addRange(r)
# Remove any ranges that fell outside of @wrapper.
@$.grep ranges, (range) ->
$.grep ranges, (range) ->
# Add the normed range back to the selection if it exists.
selection.addRange(range.toRange()) if range
range
......
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