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
3ec977f3
Commit
3ec977f3
authored
Jan 17, 2015
by
Nick Stenning
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use util.coffee from upstream
parent
ce3f0905
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
49 deletions
+71
-49
annotator.coffee
h/static/scripts/annotator/annotator.coffee
+5
-40
editor.coffee
h/static/scripts/annotator/editor.coffee
+4
-4
textselection.coffee
h/static/scripts/annotator/plugin/textselection.coffee
+1
-1
util.coffee
h/static/scripts/annotator/util.coffee
+57
-0
viewer.coffee
h/static/scripts/annotator/viewer.coffee
+2
-2
widget.coffee
h/static/scripts/annotator/widget.coffee
+1
-1
guest.coffee
h/static/scripts/guest.coffee
+1
-1
No files found.
h/static/scripts/annotator/annotator.coffee
View file @
3ec977f3
...
...
@@ -4,40 +4,6 @@
# I've removed any support for IE TextRange (see commit d7085bf2 for code)
# for the moment, having no means of testing it.
util
=
uuid
:
(
->
counter
=
0
;
->
counter
++
)()
getGlobal
:
->
(
->
this
)()
# Return the maximum z-index of any element in $elements (a jQuery collection).
maxZIndex
:
(
$elements
)
->
all
=
for
el
in
$elements
if
$
(
el
).
css
(
'position'
)
==
'static'
-
1
else
# Use parseFloat since we may get scientific notation for large
# values.
parseFloat
(
$
(
el
).
css
(
'z-index'
))
or
-
1
Math
.
max
.
apply
(
Math
,
all
)
mousePosition
:
(
e
,
offsetEl
)
->
# If the offset element is not a positioning root use its offset parent
unless
$
(
offsetEl
).
css
(
'position'
)
in
[
'absolute'
,
'fixed'
,
'relative'
]
offsetEl
=
$
(
offsetEl
).
offsetParent
()[
0
]
offset
=
$
(
offsetEl
).
offset
()
{
top
:
e
.
pageY
-
offset
.
top
,
left
:
e
.
pageX
-
offset
.
left
}
# Checks to see if an event parameter is provided and contains the prevent
# default method. If it does it calls it.
#
# This is useful for methods that can be optionally used as callbacks
# where the existance of the parameter must be checked before calling.
preventEventDefault
:
(
event
)
->
event
?
.
preventDefault
?
()
# Store a reference to the current Annotator object.
_Annotator
=
this
.
Annotator
...
...
@@ -190,7 +156,7 @@ class Annotator extends Delegator
sel
=
'*'
+
(
":not(.annotator-
#{
x
}
)"
for
x
in
[
'adder'
,
'outer'
,
'notice'
,
'filter'
]).
join
(
''
)
# use the maximum z-index in the page
max
=
u
til
.
maxZIndex
(
$
(
document
.
body
).
find
(
sel
))
max
=
U
til
.
maxZIndex
(
$
(
document
.
body
).
find
(
sel
))
# but don't go smaller than 1010, because this isn't bulletproof --
# dynamic elements in the page (notifications, dialogs, etc.) may well
...
...
@@ -543,7 +509,7 @@ class Annotator extends Delegator
else
# Show the adder button
@
adder
.
css
(
u
til
.
mousePosition
(
event
,
@
wrapper
[
0
]))
.
css
(
U
til
.
mousePosition
(
event
,
@
wrapper
[
0
]))
.
show
()
true
...
...
@@ -686,7 +652,7 @@ class Annotator extends Delegator
return
false
if
@
mouseIsDown
or
@
viewer
.
isShown
()
this
.
showViewer
event
.
data
.
getAnnotations
(
event
),
u
til
.
mousePosition
(
event
,
@
wrapper
[
0
])
U
til
.
mousePosition
(
event
,
@
wrapper
[
0
])
onAnchorMouseout
:
(
event
)
->
this
.
startViewerHideTimer
()
...
...
@@ -706,7 +672,7 @@ class Annotator.Plugin extends Delegator
this
.
removeEvents
()
# Sniff the browser environment and attempt to add missing functionality.
g
=
u
til
.
getGlobal
()
g
=
U
til
.
getGlobal
()
# Checks for the presence of wicked-good-xpath
# It is always safe to install it, it'll not overwrite existing functions
...
...
@@ -740,7 +706,6 @@ Annotator.$ = $
# Export other modules for use in plugins.
Annotator
.
Delegator
=
Delegator
Annotator
.
Range
=
Range
Annotator
.
util
=
util
Annotator
.
Util
=
Util
# Expose a global instance registry
...
...
@@ -757,7 +722,7 @@ Annotator.supported = -> (-> !!this.getSelection)()
# Restores the Annotator property on the global object to it's
# previous value and returns the Annotator.
Annotator
.
noConflict
=
->
u
til
.
getGlobal
().
Annotator
=
_Annotator
U
til
.
getGlobal
().
Annotator
=
_Annotator
this
# Create global access for Annotator
...
...
h/static/scripts/annotator/editor.coffee
View file @
3ec977f3
...
...
@@ -72,7 +72,7 @@ class Annotator.Editor extends Annotator.Widget
#
# Returns itself.
show
:
(
event
)
=>
u
til
.
preventEventDefault
event
Annotator
.
U
til
.
preventEventDefault
event
@
element
.
removeClass
(
@
classes
.
hide
)
@
element
.
find
(
'.annotator-save'
).
addClass
(
@
classes
.
focus
)
...
...
@@ -104,7 +104,7 @@ class Annotator.Editor extends Annotator.Widget
#
# Returns itself.
hide
:
(
event
)
=>
u
til
.
preventEventDefault
event
Annotator
.
U
til
.
preventEventDefault
event
@
element
.
addClass
(
@
classes
.
hide
)
this
.
publish
(
'hide'
)
...
...
@@ -161,7 +161,7 @@ class Annotator.Editor extends Annotator.Widget
#
# Returns itself.
submit
:
(
event
)
=>
u
til
.
preventEventDefault
event
Annotator
.
U
til
.
preventEventDefault
event
for
field
in
@
fields
field
.
submit
(
field
.
element
,
@
annotation
)
...
...
@@ -227,7 +227,7 @@ class Annotator.Editor extends Annotator.Widget
# Returns the created <li> Element.
addField
:
(
options
)
->
field
=
$
.
extend
({
id
:
'annotator-field-'
+
u
til
.
uuid
()
id
:
'annotator-field-'
+
Annotator
.
U
til
.
uuid
()
type
:
'input'
label
:
''
load
:
->
...
...
h/static/scripts/annotator/plugin/textselection.coffee
View file @
3ec977f3
...
...
@@ -34,7 +34,7 @@ class Annotator.Plugin.TextSelection extends Annotator.Plugin
#
# Returns Array of NormalizedRange instances.
_getSelectedRanges
:
->
selection
=
@
Annotator
.
u
til
.
getGlobal
().
getSelection
()
selection
=
@
Annotator
.
U
til
.
getGlobal
().
getSelection
()
ranges
=
[]
rangesToIgnore
=
[]
...
...
h/static/scripts/annotator/util.coffee
View file @
3ec977f3
...
...
@@ -33,6 +33,19 @@ Util.flatten = (array) ->
flatten
(
array
)
# Public: decides whether node A is an ancestor of node B.
#
# This function purposefully ignores the native browser function for this,
# because it acts weird in PhantomJS.
# Issue: https://github.com/ariya/phantomjs/issues/11479
Util
.
contains
=
(
parent
,
child
)
->
node
=
child
while
node
?
if
node
is
parent
then
return
true
node
=
node
.
parentNode
return
false
# Public: Finds all text nodes within the elements in the current collection.
#
# Returns a new jQuery collection of text nodes.
...
...
@@ -97,6 +110,17 @@ Util.getFirstTextNodeNotBefore = (n) ->
else
null
# Public: read out the text value of a range using the selection API
#
# This method selects the specified range, and asks for the string
# value of the selection. What this returns is very close to what the user
# actually sees.
Util
.
readRangeViaSelection
=
(
range
)
->
sel
=
Util
.
getGlobal
().
getSelection
()
# Get the browser selection object
sel
.
removeAllRanges
()
# clear the selection
sel
.
addRange
range
.
toRange
()
# Select the range
sel
.
toString
()
# Read out the selection
Util
.
xpathFromNode
=
(
el
,
relativeRoot
)
->
try
result
=
simpleXPathJQuery
.
call
el
,
relativeRoot
...
...
@@ -121,3 +145,36 @@ Util.escape = (html) ->
.
replace
(
/</g
,
'<'
)
.
replace
(
/>/g
,
'>'
)
.
replace
(
/"/g
,
'"'
)
Util
.
uuid
=
(
->
counter
=
0
;
->
counter
++
)()
Util
.
getGlobal
=
->
(
->
this
)()
# Return the maximum z-index of any element in $elements (a jQuery collection).
Util
.
maxZIndex
=
(
$elements
)
->
all
=
for
el
in
$elements
if
$
(
el
).
css
(
'position'
)
==
'static'
-
1
else
# Use parseFloat since we may get scientific notation for large
# values.
parseFloat
(
$
(
el
).
css
(
'z-index'
))
or
-
1
Math
.
max
.
apply
(
Math
,
all
)
Util
.
mousePosition
=
(
e
,
offsetEl
)
->
# If the offset element is not a positioning root use its offset parent
unless
$
(
offsetEl
).
css
(
'position'
)
in
[
'absolute'
,
'fixed'
,
'relative'
]
offsetEl
=
$
(
offsetEl
).
offsetParent
()[
0
]
offset
=
$
(
offsetEl
).
offset
()
{
top
:
e
.
pageY
-
offset
.
top
,
left
:
e
.
pageX
-
offset
.
left
}
# Checks to see if an event parameter is provided and contains the prevent
# default method. If it does it calls it.
#
# This is useful for methods that can be optionally used as callbacks
# where the existance of the parameter must be checked before calling.
Util
.
preventEventDefault
=
(
event
)
->
event
?
.
preventDefault
?
()
h/static/scripts/annotator/viewer.coffee
View file @
3ec977f3
...
...
@@ -70,7 +70,7 @@ class Annotator.Viewer extends Annotator.Widget
#
# Returns itself.
show
:
(
event
)
=>
u
til
.
preventEventDefault
event
Annotator
.
U
til
.
preventEventDefault
event
controls
=
@
element
.
find
(
'.annotator-controls'
)
...
...
@@ -110,7 +110,7 @@ class Annotator.Viewer extends Annotator.Widget
#
# Returns itself.
hide
:
(
event
)
=>
u
til
.
preventEventDefault
event
Annotator
.
U
til
.
preventEventDefault
event
@
element
.
addClass
(
@
classes
.
hide
)
this
.
publish
(
'hide'
)
...
...
h/static/scripts/annotator/widget.coffee
View file @
3ec977f3
...
...
@@ -33,7 +33,7 @@ class Annotator.Widget extends Delegator
checkOrientation
:
->
this
.
resetOrientation
()
window
=
$
(
u
til
.
getGlobal
())
window
=
$
(
Annotator
.
U
til
.
getGlobal
())
widget
=
@
element
.
children
(
":first"
)
offset
=
widget
.
offset
()
viewport
=
{
...
...
h/static/scripts/guest.coffee
View file @
3ec977f3
...
...
@@ -353,7 +353,7 @@ class Annotator.Guest extends Annotator
event
.
stopPropagation
()
@
adder
.
hide
()
annotation
=
this
.
setupAnnotation
(
this
.
createAnnotation
())
Annotator
.
u
til
.
getGlobal
().
getSelection
().
removeAllRanges
()
Annotator
.
U
til
.
getGlobal
().
getSelection
().
removeAllRanges
()
this
.
showEditor
(
annotation
)
onSetTool
:
(
name
)
->
...
...
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