Commit 2cc65e09 authored by csillag's avatar csillag

Fix URI and metadata handling for PDF documents

 * Don't load the Document plugin for PDF files; Annotator's PDF plugin
   provides the fuctionality (uri+metadata extraction) in these cases.
   Use async metadata extraction for PDF

 * Updated PDF plugin to fcdf1eac (pdf-update branch)
parent 06aa76f0
......@@ -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,6 @@
})(Annotator.Plugin);
}).call(this);
//
//# sourceMappingURL=annotator.pdf.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