Commit bc535a76 authored by csillag's avatar csillag

Update Annotator to 0d3b9203 (typed-packaging branch)

 - PDF: Support latest PDF.js (v1.0.277)
 - TextRange: Handle an error condition
parent dfd9e2dd
// Generated by CoffeeScript 1.6.3 // Generated by CoffeeScript 1.6.3
/* /*
** Annotator 1.2.6-dev-84bccda ** Annotator 1.2.6-dev-0d3b920
** https://github.com/okfn/annotator/ ** https://github.com/okfn/annotator/
** **
** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning. ** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning.
** Dual licensed under the MIT and GPLv3 licenses. ** Dual licensed under the MIT and GPLv3 licenses.
** https://github.com/okfn/annotator/blob/master/LICENSE ** https://github.com/okfn/annotator/blob/master/LICENSE
** **
** Built at: 2014-07-22 20:43:16Z ** Built at: 2014-08-19 23:59:29Z
*/ */
...@@ -105,24 +105,36 @@ ...@@ -105,24 +105,36 @@
return text.replace(this._extractionPattern, " "); return text.replace(this._extractionPattern, " ");
}; };
PDFTextMapper.prototype._waitForInit = function() {
var tryIt;
tryIt = function(resolve) {
var _this = this;
if (PDFView.documentFingerprint) {
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);
});
};
PDFTextMapper.prototype.scan = function() { PDFTextMapper.prototype.scan = function() {
var _ref, var _this = this;
_this = this; return new Promise(function(resolve, reject) {
if (this.pendingScan == null) { _this._pendingScanResolve = resolve;
this.pendingScan = (_ref = typeof PDFJS.Promise === "function" ? new PDFJS.Promise() : void 0) != null ? _ref : typeof PDFJS.LegacyPromise === "function" ? new PDFJS.LegacyPromise() : void 0; return _this._waitForInit().then(function() {
} return PDFView.getPage(1).then(function() {
if (PDFView.pdfDocument == null) { console.log("Scanning document for text...");
setTimeout((function() { _this.pageInfo = [];
return _this.scan(); return _this._extractPageText(0);
}), 500); });
return this.pendingScan; });
}
PDFView.getPage(1).then(function() {
console.log("Scanning document for text...");
_this.pageInfo = [];
return _this._extractPageText(0);
}); });
return this.pendingScan;
}; };
PDFTextMapper.prototype._extractPageText = function(pageIndex) { PDFTextMapper.prototype._extractPageText = function(pageIndex) {
...@@ -136,13 +148,13 @@ ...@@ -136,13 +148,13 @@
return; return;
} }
return page.getTextContent().then(function(data) { return page.getTextContent().then(function(data) {
var content, rawContent, text; var content, rawContent, text, textData, _ref, _ref1;
textData = (_ref = (_ref1 = data.bidiTexts) != null ? _ref1 : data.items) != null ? _ref : data;
rawContent = ((function() { rawContent = ((function() {
var _i, _len, _ref, _ref1, _results; var _i, _len, _results;
_ref1 = (_ref = data.bidiTexts) != null ? _ref : data;
_results = []; _results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) { for (_i = 0, _len = textData.length; _i < _len; _i++) {
text = _ref1[_i]; text = textData[_i];
_results.push(text.str); _results.push(text.str);
} }
return _results; return _results;
...@@ -162,7 +174,7 @@ ...@@ -162,7 +174,7 @@
PDFTextMapper.prototype._finishScan = function() { PDFTextMapper.prototype._finishScan = function() {
this._onHavePageContents(); this._onHavePageContents();
this.pendingScan.resolve(); this._pendingScanResolve();
return this._onAfterScan(); return this._onAfterScan();
}; };
......
// Generated by CoffeeScript 1.6.3 // Generated by CoffeeScript 1.6.3
/* /*
** Annotator 1.2.6-dev-5c36e53 ** Annotator 1.2.6-dev-0d3b920
** https://github.com/okfn/annotator/ ** https://github.com/okfn/annotator/
** **
** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning. ** Copyright 2012 Aron Carroll, Rufus Pollock, and Nick Stenning.
** Dual licensed under the MIT and GPLv3 licenses. ** Dual licensed under the MIT and GPLv3 licenses.
** https://github.com/okfn/annotator/blob/master/LICENSE ** https://github.com/okfn/annotator/blob/master/LICENSE
** **
** Built at: 2014-06-17 21:13:15Z ** Built at: 2014-08-19 23:59:28Z
*/ */
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
}; };
TextRange.prototype.createFromRangeSelector = function(annotation, target) { TextRange.prototype.createFromRangeSelector = function(annotation, target) {
var currentQuote, endInfo, endOffset, error, normedRange, range, savedQuote, selector, startInfo, startOffset, _base, _ref1, _ref2; var currentQuote, endInfo, endOffset, error, normedRange, range, rawQuote, savedQuote, selector, startInfo, startOffset, _base, _ref1, _ref2;
selector = this.annotator.findSelector(target.selector, "RangeSelector"); selector = this.annotator.findSelector(target.selector, "RangeSelector");
if (selector == null) { if (selector == null) {
return null; return null;
...@@ -98,7 +98,22 @@ ...@@ -98,7 +98,22 @@
error = _error; error = _error;
return null; return null;
} }
currentQuote = this.annotator.normalizeString(this.annotator.domMapper.getInfoForNode != null ? (startInfo = this.annotator.domMapper.getInfoForNode(normedRange.start), startOffset = startInfo.start, endInfo = this.annotator.domMapper.getInfoForNode(normedRange.end), endOffset = endInfo.end, this.annotator.domMapper.getCorpus().slice(startOffset, +(endOffset - 1) + 1 || 9e9).trim()) : normedRange.text().trim()); if (this.annotator.domMapper.getInfoForNode != null) {
startInfo = this.annotator.domMapper.getInfoForNode(normedRange.start);
if (!startInfo) {
return null;
}
startOffset = startInfo.start;
endInfo = this.annotator.domMapper.getInfoForNode(normedRange.end);
if (!endInfo) {
return null;
}
endOffset = endInfo.end;
rawQuote = this.annotator.domMapper.getCorpus().slice(startOffset, +(endOffset - 1) + 1 || 9e9).trim();
} else {
rawQuote = normedRange.text().trim();
}
currentQuote = this.annotator.normalizeString(rawQuote);
savedQuote = typeof (_base = this.annotator).getQuoteForTarget === "function" ? _base.getQuoteForTarget(target) : void 0; savedQuote = typeof (_base = this.annotator).getQuoteForTarget === "function" ? _base.getQuoteForTarget(target) : void 0;
if ((savedQuote != null) && currentQuote !== savedQuote) { if ((savedQuote != null) && currentQuote !== savedQuote) {
return null; return null;
......
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