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
6718023a
Commit
6718023a
authored
Jun 29, 2015
by
Randall Leeds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the cache for quote -> position
parent
d5251526
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
3 deletions
+18
-3
pdf.coffee
h/static/scripts/annotator/anchoring/pdf.coffee
+18
-3
No files found.
h/static/scripts/annotator/anchoring/pdf.coffee
View file @
6718023a
...
...
@@ -73,6 +73,10 @@ findPage = (offset) ->
# :rtype: Promise
####
exports
.
anchor
=
(
selectors
,
options
=
{})
->
# Cache of anchoring data
cache
=
options
.
cache
?
{}
cache
.
quotePosition
?=
{}
# Selectors
position
=
null
quote
=
null
...
...
@@ -131,10 +135,18 @@ exports.anchor = (selectors, options = {}) ->
promise
=
promise
.
catch
->
{
pagesCount
}
=
PDFViewerApplication
.
pdfViewer
if
cache
.
quotePosition
[
quote
.
exact
]
?
{
page
,
anchor
}
=
cache
.
quotePosition
[
quote
.
exact
]
return
anchorByPosition
(
page
,
anchor
)
storeAndAnchor
=
(
page
,
anchor
)
->
cache
.
quotePosition
[
quote
.
exact
]
=
{
page
,
anchor
}
return
anchorByPosition
(
page
,
anchor
)
pageSearches
=
for
pageIndex
in
[
0
...
pagesCount
]
page
=
getPage
(
pageIndex
)
content
=
getPageTextContent
(
pageIndex
)
offset
=
getPageOffset
(
pageIndex
,
options
.
cache
)
offset
=
getPageOffset
(
pageIndex
,
cache
)
Promise
.
all
([
content
,
offset
,
page
]).
then
(
results
)
->
[
content
,
offset
,
page
]
=
results
pageOptions
=
{
root
:
{
textContent
:
content
}}
...
...
@@ -146,7 +158,7 @@ exports.anchor = (selectors, options = {}) ->
anchor
=
new
TextQuoteAnchor
.
fromSelector
(
quote
,
pageOptions
)
return
Promise
.
resolve
(
anchor
)
.
then
((
a
)
->
return
a
.
toPositionAnchor
(
pageOptions
))
.
then
((
a
)
->
return
anchorByPosition
(
page
,
a
))
.
then
((
a
)
->
return
storeAndAnchor
(
page
,
a
))
pageSearches
=
(
p
.
catch
(
->
null
)
for
p
in
pageSearches
)
return
Promise
.
all
(
pageSearches
).
then
(
results
)
->
...
...
@@ -158,6 +170,9 @@ exports.anchor = (selectors, options = {}) ->
exports
.
describe
=
(
range
,
options
=
{})
->
# Cache of anchoring data
cache
=
options
.
cache
?
{}
range
=
new
xpathRange
.
BrowserRange
(
range
).
normalize
()
startTextLayer
=
getNodeTextLayer
(
range
.
start
)
...
...
@@ -178,7 +193,7 @@ exports.describe = (range, options = {}) ->
start
=
seek
(
iter
,
range
.
start
)
end
=
seek
(
iter
,
range
.
end
)
+
start
+
range
.
end
.
textContent
.
length
return
getPageOffset
(
startPageIndex
,
options
.
cache
).
then
(
pageOffset
)
->
return
getPageOffset
(
startPageIndex
,
cache
).
then
(
pageOffset
)
->
# XXX: range covers only one page
start
+=
pageOffset
end
+=
pageOffset
...
...
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