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
91dc8d28
Commit
91dc8d28
authored
Oct 24, 2014
by
Randall Leeds
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1563 from hypothesis/1334-pdfjs-6
[WIP] add support for packaging with PDF.js extension - try 4
parents
06aa76f0
03398c61
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
26 deletions
+73
-26
annotation.coffee
h/static/scripts/directives/annotation.coffee
+9
-2
guest.coffee
h/static/scripts/guest.coffee
+23
-7
annotator.pdf.js
h/static/scripts/vendor/annotator.pdf.js
+41
-15
annotator.permissions.js
h/static/scripts/vendor/annotator.permissions.js
+0
-2
No files found.
h/static/scripts/directives/annotation.coffee
View file @
91dc8d28
...
...
@@ -179,10 +179,17 @@ AnnotationController = [
# Extract the document metadata.
if model.document
domain = extractURIComponent(model.uri, 'hostname')
uri = model.uri
if uri.indexOf("urn") is 0
# This URI is not clickable, see if we have something better
for link in model.document.link when link.href.indexOf("urn")
uri = link.href
break
domain = extractURIComponent(uri, 'hostname')
@document =
uri:
model.
uri
uri: uri
domain: domain
title: model.document.title or domain
...
...
h/static/scripts/guest.coffee
View file @
91dc8d28
...
...
@@ -31,6 +31,9 @@ class Annotator.Guest extends Annotator
super
delete
@
options
.
noScan
if
window
.
PDFJS
delete
@
options
.
Document
@
frame
=
$
(
'<div></div>'
)
.
appendTo
(
@
wrapper
)
.
addClass
(
'annotator-frame annotator-outer annotator-collapsed'
)
...
...
@@ -40,8 +43,7 @@ class Annotator.Guest extends Annotator
this
.
addPlugin
'Bridge'
,
formatter
:
(
annotation
)
=>
formatted
=
{}
if
annotation
.
document
?
formatted
[
'uri'
]
=
@
plugins
.
Document
.
uri
()
formatted
[
'uri'
]
=
@
getHref
()
for
k
,
v
of
annotation
when
k
isnt
'anchors'
formatted
[
k
]
=
v
# Work around issue in jschannel where a repeated object is considered
...
...
@@ -113,6 +115,10 @@ class Annotator.Guest extends Annotator
# Announce the new positions, so that the sidebar knows
this
.
plugins
.
Bridge
.
sync
([
highlight
.
annotation
])
# Utility function to get the decoded form of the document URI
getHref
:
=>
@
plugins
.
PDF
?
.
uri
()
?
@
plugins
.
Document
.
uri
()
?
super
_setupXDM
:
(
options
)
->
# jschannel chokes FF and Chrome extension origins.
if
(
options
.
origin
.
match
/^chrome-extension:\/\//
)
or
...
...
@@ -160,11 +166,21 @@ class Annotator.Guest extends Annotator
return
)
.
bind
(
'getDocumentInfo'
,
=>
return
{
uri
:
@
plugins
.
Document
.
uri
()
metadata
:
@
plugins
.
Document
.
metadata
}
.
bind
(
'getDocumentInfo'
,
(
trans
)
=>
(
@
plugins
.
PDF
?
.
getMetaData
()
?
Promise
.
reject
())
.
then
(
md
)
=>
# console.log "Returning PDF metadata", md
trans
.
complete
uri
:
@
getHref
()
metadata
:
md
.
catch
(
problem
)
=>
# console.log "Returning standard metadata, because"
# console.log problem.stack ? problem
trans
.
complete
uri
:
@
getHref
()
metadata
:
@
plugins
.
Document
?
.
metadata
trans
.
delayReturn
(
true
)
)
.
bind
(
'setTool'
,
(
ctx
,
name
)
=>
...
...
h/static/scripts/vendor/annotator.pdf.js
View file @
91dc8d28
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-
9e0eff3
** Annotator 1.2.6-dev-
fcdf1ea
** https://github.com/okfn/annotator/
**
** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning.
** Dual licensed under the MIT and GPLv3 licenses.
** https://github.com/okfn/annotator/blob/master/LICENSE
**
** Built at: 2014-
09-25 22:41:02
Z
** Built at: 2014-
10-23 22:40:29
Z
*/
...
...
@@ -27,8 +27,7 @@
__extends
(
PDFTextMapper
,
_super
);
PDFTextMapper
.
applicable
=
function
()
{
var
_ref
;
return
(
_ref
=
typeof
PDFView
!==
"undefined"
&&
PDFView
!==
null
?
PDFView
.
initialized
:
void
0
)
!=
null
?
_ref
:
false
;
return
typeof
PDFView
!==
"undefined"
&&
PDFView
!==
null
;
};
PDFTextMapper
.
prototype
.
requiresSmartStringPadding
=
true
;
...
...
@@ -106,20 +105,24 @@
};
PDFTextMapper
.
prototype
.
_waitForInit
=
function
()
{
var
tryIt
;
var
tryIt
,
_this
=
this
;
tryIt
=
function
(
resolve
)
{
var
_this
=
this
;
if
(
PDFView
.
documentFingerprint
)
{
if
(
PDFView
.
documentFingerprint
&&
PDFView
.
documentInfo
)
{
return
resolve
();
}
else
{
return
setTimeout
((
function
()
{
console
.
log
(
"OK, let's try again"
);
return
tryIt
(
resolve
);
}),
100
);
}
};
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
tryIt
(
resolve
);
if
(
typeof
PDFView
!==
"undefined"
&&
PDFView
!==
null
)
{
return
tryIt
(
resolve
);
}
else
{
return
reject
(
"Not a PDF.js document"
);
}
});
};
...
...
@@ -199,6 +202,7 @@
function
PDF
()
{
this
.
beforeAnnotationCreated
=
__bind
(
this
.
beforeAnnotationCreated
,
this
);
this
.
getMetaData
=
__bind
(
this
.
getMetaData
,
this
);
_ref
=
PDF
.
__super__
.
constructor
.
apply
(
this
,
arguments
);
return
_ref
;
}
...
...
@@ -221,9 +225,15 @@
};
PDF
.
prototype
.
_getDocumentURI
=
function
()
{
var
uri
,
_ref1
,
_ref2
;
var
match
,
matches
,
uri
;
uri
=
window
.
location
.
href
;
return
(
_ref1
=
(
_ref2
=
uri
.
match
(
'chrome-extension://[a-z]{32}/(.*)'
))
!=
null
?
_ref2
[
1
]
:
void
0
)
!=
null
?
_ref1
:
uri
;
matches
=
uri
.
match
(
'chrome-extension://[a-z]{32}/(content/web/viewer.html
\\
?file=)?(.*)'
);
match
=
matches
!=
null
?
matches
[
matches
.
length
-
1
]
:
void
0
;
if
(
match
)
{
return
decodeURIComponent
(
match
);
}
else
{
return
uri
;
}
};
PDF
.
prototype
.
_getFingerPrintURI
=
function
()
{
...
...
@@ -249,10 +259,7 @@
}
};
PDF
.
prototype
.
metadata
=
function
()
{
if
(
!
this
.
_isPDF
())
{
return
null
;
}
PDF
.
prototype
.
_metadata
=
function
()
{
return
{
link
:
[
{
...
...
@@ -265,12 +272,30 @@
};
};
PDF
.
prototype
.
getMetaData
=
function
()
{
var
_this
=
this
;
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
init
;
init
=
_this
.
annotator
.
domMapper
.
_waitForInit
;
if
(
init
!=
null
)
{
return
init
().
then
(
function
()
{
return
resolve
(
_this
.
_metadata
());
});
}
else
{
return
reject
(
"Not a PDF dom mapper."
);
}
});
};
PDF
.
prototype
.
events
=
{
'beforeAnnotationCreated'
:
'beforeAnnotationCreated'
};
PDF
.
prototype
.
beforeAnnotationCreated
=
function
(
annotation
)
{
return
annotation
.
document
=
this
.
metadata
();
if
(
!
this
.
_isPDF
())
{
return
;
}
return
annotation
.
document
=
this
.
_metadata
();
};
return
PDF
;
...
...
@@ -278,3 +303,4 @@
})(
Annotator
.
Plugin
);
}).
call
(
this
);
h/static/scripts/vendor/annotator.permissions.js
View file @
91dc8d28
...
...
@@ -231,5 +231,3 @@
}).
call
(
this
);
//
//# sourceMappingURL=annotator.permissions.map
\ No newline at end of file
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