Commit 91dc8d28 authored by Randall Leeds's avatar Randall Leeds

Merge pull request #1563 from hypothesis/1334-pdfjs-6

[WIP] add support for packaging with PDF.js extension - try 4
parents 06aa76f0 03398c61
......@@ -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
......
......@@ -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) =>
......
// 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:02Z
** Built at: 2014-10-23 22:40:29Z
*/
......@@ -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) {
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);
......@@ -231,5 +231,3 @@
}).call(this);
//
//# sourceMappingURL=annotator.permissions.map
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment