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
b1bedc79
Commit
b1bedc79
authored
May 18, 2015
by
Randall Leeds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PDF anchoring to unrendered pages
parent
67d87893
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
14 deletions
+58
-14
pdf.coffee
h/static/scripts/annotator/anchoring/pdf.coffee
+22
-9
guest.coffee
h/static/scripts/annotator/guest.coffee
+1
-3
highlighter.coffee
h/static/scripts/annotator/highlighter.coffee
+6
-0
pdf.coffee
h/static/scripts/annotator/plugin/pdf.coffee
+25
-2
inject.scss
h/static/styles/annotator/inject.scss
+4
-0
No files found.
h/static/scripts/annotator/anchoring/pdf.coffee
View file @
b1bedc79
...
@@ -20,8 +20,8 @@ getNodeTextLayer = (node) ->
...
@@ -20,8 +20,8 @@ getNodeTextLayer = (node) ->
return
node
.
getElementsByClassName
(
'textLayer'
)[
0
]
return
node
.
getElementsByClassName
(
'textLayer'
)[
0
]
getPage
TextLayer
=
(
pageIndex
)
->
getPage
=
(
pageIndex
)
->
return
PDFViewerApplication
.
pdfViewer
.
pages
[
pageIndex
]
.
textLayer
return
PDFViewerApplication
.
pdfViewer
.
pages
[
pageIndex
]
getPageTextContent
=
(
pageIndex
)
->
getPageTextContent
=
(
pageIndex
)
->
...
@@ -112,14 +112,27 @@ exports.anchor = (selectors) ->
...
@@ -112,14 +112,27 @@ exports.anchor = (selectors) ->
promise
=
promise
.
catch
->
promise
=
promise
.
catch
->
findPage
(
position
.
start
)
findPage
(
position
.
start
)
.
then
(({
index
,
offset
})
->
.
then
(({
index
,
offset
})
->
textLayer
=
getPageTextLayer
(
index
)
page
=
getPage
(
index
)
start
=
position
.
start
-
offset
if
page
.
textLayer
?
.
renderingDone
end
=
position
.
end
-
offset
root
=
page
.
textLayer
.
textLayerDiv
root
=
textLayer
.
textLayerDiv
start
=
position
.
start
-
offset
Promise
.
resolve
(
TextPositionAnchor
.
fromSelector
({
start
,
end
},
{
root
}))
end
=
position
.
end
-
offset
.
then
((
a
)
->
Promise
.
resolve
(
a
.
toRange
({
root
})))
Promise
.
resolve
(
TextPositionAnchor
.
fromSelector
({
start
,
end
},
{
root
}))
.
then
((
a
)
->
Promise
.
resolve
(
a
.
toRange
({
root
})))
.
then
(
assertQuote
)
else
el
=
page
.
el
placeholder
=
el
.
getElementsByClassName
(
'annotator-placeholder'
)[
0
]
unless
placeholder
?
placeholder
=
document
.
createElement
(
'span'
)
placeholder
.
classList
.
add
(
'annotator-placeholder'
)
placeholder
.
textContent
=
'Loading annotations…'
page
.
el
.
appendChild
(
placeholder
)
range
=
document
.
createRange
()
range
.
setStartBefore
(
placeholder
)
range
.
setEndAfter
(
placeholder
)
return
range
)
)
.
then
(
assertQuote
)
return
promise
return
promise
...
...
h/static/scripts/annotator/guest.coffee
View file @
b1bedc79
...
@@ -206,9 +206,7 @@ module.exports = class Guest extends Annotator
...
@@ -206,9 +206,7 @@ module.exports = class Guest extends Annotator
deleteAnnotation
:
(
annotation
)
->
deleteAnnotation
:
(
annotation
)
->
for
info
in
@
anchored
when
info
.
annotation
is
annotation
for
info
in
@
anchored
when
info
.
annotation
is
annotation
for
h
in
info
.
highlights
when
h
.
parentNode
?
highlighter
.
removeHighlights
(
info
.
highlights
)
child
=
h
.
childNodes
[
0
]
$
(
h
).
replaceWith
(
h
.
childNodes
)
@
anchored
=
(
a
for
a
in
@
anchored
when
a
.
annotation
isnt
annotation
)
@
anchored
=
(
a
for
a
in
@
anchored
when
a
.
annotation
isnt
annotation
)
@
unanchored
=
(
a
for
a
in
@
unanchored
when
a
.
annotation
isnt
annotation
)
@
unanchored
=
(
a
for
a
in
@
unanchored
when
a
.
annotation
isnt
annotation
)
...
...
h/static/scripts/annotator/highlighter.coffee
View file @
b1bedc79
...
@@ -22,3 +22,9 @@ exports.highlightRange = (normedRange, cssClass='annotator-hl') ->
...
@@ -22,3 +22,9 @@ exports.highlightRange = (normedRange, cssClass='annotator-hl') ->
nodes
=
$
(
normedRange
.
textNodes
()).
filter
((
i
)
->
not
white
.
test
@
nodeValue
)
nodes
=
$
(
normedRange
.
textNodes
()).
filter
((
i
)
->
not
white
.
test
@
nodeValue
)
r
=
nodes
.
wrap
(
hl
).
parent
().
show
().
toArray
()
r
=
nodes
.
wrap
(
hl
).
parent
().
show
().
toArray
()
exports
.
removeHighlights
=
(
highlights
)
->
for
h
in
highlights
when
h
.
parentNode
?
child
=
h
.
childNodes
[
0
]
$
(
h
).
replaceWith
(
h
.
childNodes
)
h/static/scripts/annotator/plugin/pdf.coffee
View file @
b1bedc79
...
@@ -2,6 +2,8 @@ raf = require('raf')
...
@@ -2,6 +2,8 @@ raf = require('raf')
Promise
=
require
(
'es6-promise'
).
Promise
Promise
=
require
(
'es6-promise'
).
Promise
Annotator
=
require
(
'annotator'
)
Annotator
=
require
(
'annotator'
)
highlighter
=
require
(
'../highlighter'
)
class
PDF
extends
Annotator
.
Plugin
class
PDF
extends
Annotator
.
Plugin
documentPromise
:
null
documentPromise
:
null
...
@@ -46,8 +48,7 @@ class PDF extends Annotator.Plugin
...
@@ -46,8 +48,7 @@ class PDF extends Annotator.Plugin
return
{
title
,
link
}
return
{
title
,
link
}
onpagerendered
:
(
event
)
=>
onpagerendered
:
(
event
)
=>
annotator
=
@
annotator
annotator
=
{
anchored
,
unanchored
}
=
@
annotator
unanchored
=
@
annotator
.
unanchored
page
=
PDFViewerApplication
.
pdfViewer
.
pages
[
event
.
detail
.
pageNumber
-
1
]
page
=
PDFViewerApplication
.
pdfViewer
.
pages
[
event
.
detail
.
pageNumber
-
1
]
waitForTextLayer
=
->
waitForTextLayer
=
->
...
@@ -56,6 +57,28 @@ class PDF extends Annotator.Plugin
...
@@ -56,6 +57,28 @@ class PDF extends Annotator.Plugin
reanchor
=
->
reanchor
=
->
unanchored
=
unanchored
.
splice
(
0
,
unanchored
.
length
)
unanchored
=
unanchored
.
splice
(
0
,
unanchored
.
length
)
placeholder
=
page
.
el
.
getElementsByClassName
(
'annotator-placeholder'
)[
0
]
if
placeholder
?
unchanged
=
[]
for
info
in
anchored
attempt
=
false
for
hl
in
info
.
highlights
if
placeholder
.
contains
(
hl
)
attempt
=
true
break
if
attempt
highlighter
.
removeHighlights
(
info
.
highlights
)
delete
info
.
highlights
unanchored
.
push
(
info
)
else
unchanged
.
push
(
info
)
anchored
.
splice
(
0
,
anchored
.
length
,
unchanged
...)
page
.
el
.
removeChild
(
placeholder
)
for
obj
in
unanchored
for
obj
in
unanchored
annotator
.
setupAnnotation
(
obj
.
annotation
)
annotator
.
setupAnnotation
(
obj
.
annotation
)
...
...
h/static/styles/annotator/inject.scss
View file @
b1bedc79
...
@@ -131,6 +131,10 @@ $base-font-size: 14px;
...
@@ -131,6 +131,10 @@ $base-font-size: 14px;
@include
transition
(
none
!
important
);
@include
transition
(
none
!
important
);
}
}
.annotator-placeholder
{
position
:
absolute
;
}
//CONTROLBAR STUFF////////////////////////////////
//CONTROLBAR STUFF////////////////////////////////
.annotator-frame
.annotator-toolbar
{
.annotator-frame
.annotator-toolbar
{
...
...
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