Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
cd4057a5
Commit
cd4057a5
authored
Apr 16, 2015
by
Randall Leeds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Standardize the use of Annotator requires
parent
b4dc5ac9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
33 deletions
+26
-33
fuzzytextanchors.coffee
h/static/scripts/annotator/plugin/fuzzytextanchors.coffee
+5
-4
texthighlights.coffee
h/static/scripts/annotator/plugin/texthighlights.coffee
+1
-0
textposition.coffee
h/static/scripts/annotator/plugin/textposition.coffee
+5
-10
textquote.coffee
h/static/scripts/annotator/plugin/textquote.coffee
+3
-3
textrange.coffee
h/static/scripts/annotator/plugin/textrange.coffee
+5
-10
textselection.coffee
h/static/scripts/annotator/plugin/textselection.coffee
+7
-6
No files found.
h/static/scripts/annotator/plugin/fuzzytextanchors.coffee
View file @
cd4057a5
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
),
...
...
h/static/scripts/annotator/plugin/texthighlights.coffee
View file @
cd4057a5
Annotator
=
require
(
'annotator'
)
$
=
Annotator
.
$
require
(
'jquery-scrollintoview'
)
...
...
h/static/scripts/annotator/plugin/textposition.coffee
View file @
cd4057a5
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
)
=>
...
...
h/static/scripts/annotator/plugin/textquote.coffee
View file @
cd4057a5
Annotator
=
require
(
'annotator'
)
# This plugin defines the TextQuote selector
class
Annotator
.
Plugin
.
TextQuote
extends
Annotator
.
Plugin
@
Annotator
=
Annotator
@
$
=
Annotator
.
$
# Plugin initialization
pluginInit
:
->
...
...
h/static/scripts/annotator/plugin/textrange.coffee
View file @
cd4057a5
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
...
...
h/static/scripts/annotator/plugin/textselection.coffee
View file @
cd4057a5
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment