Commit 643a22e4 authored by Nick Stenning's avatar Nick Stenning

Use imported Annotator plugins

Rather than using prebuilt JavaScript in the vendor directory, build the
relevant Annotator plugins from CoffeeScript imported in the previous
commit.
parent 89c8183e
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-9e0eff3
** 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:40:54Z
*/
/*
//
*/
// Generated by CoffeeScript 1.6.3
(function() {
var base64Decode, base64UrlDecode, createDateFromISO8601, parseToken,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
createDateFromISO8601 = function(string) {
var d, date, offset, regexp, time, _ref;
regexp = "([0-9]{4})(-([0-9]{2})(-([0-9]{2})" + "(T([0-9]{2}):([0-9]{2})(:([0-9]{2})(\.([0-9]+))?)?" + "(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?";
d = string.match(new RegExp(regexp));
offset = 0;
date = new Date(d[1], 0, 1);
if (d[3]) {
date.setMonth(d[3] - 1);
}
if (d[5]) {
date.setDate(d[5]);
}
if (d[7]) {
date.setHours(d[7]);
}
if (d[8]) {
date.setMinutes(d[8]);
}
if (d[10]) {
date.setSeconds(d[10]);
}
if (d[12]) {
date.setMilliseconds(Number("0." + d[12]) * 1000);
}
if (d[14]) {
offset = (Number(d[16]) * 60) + Number(d[17]);
offset *= (_ref = d[15] === '-') != null ? _ref : {
1: -1
};
}
offset -= date.getTimezoneOffset();
time = Number(date) + (offset * 60 * 1000);
date.setTime(Number(time));
return date;
};
base64Decode = function(data) {
var ac, b64, bits, dec, h1, h2, h3, h4, i, o1, o2, o3, tmp_arr;
if (typeof atob !== "undefined" && atob !== null) {
return atob(data);
} else {
b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
i = 0;
ac = 0;
dec = "";
tmp_arr = [];
if (!data) {
return data;
}
data += '';
while (i < data.length) {
h1 = b64.indexOf(data.charAt(i++));
h2 = b64.indexOf(data.charAt(i++));
h3 = b64.indexOf(data.charAt(i++));
h4 = b64.indexOf(data.charAt(i++));
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
o1 = bits >> 16 & 0xff;
o2 = bits >> 8 & 0xff;
o3 = bits & 0xff;
if (h3 === 64) {
tmp_arr[ac++] = String.fromCharCode(o1);
} else if (h4 === 64) {
tmp_arr[ac++] = String.fromCharCode(o1, o2);
} else {
tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
}
}
return tmp_arr.join('');
}
};
base64UrlDecode = function(data) {
var i, m, _i, _ref;
m = data.length % 4;
if (m !== 0) {
for (i = _i = 0, _ref = 4 - m; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
data += '=';
}
}
data = data.replace(/-/g, '+');
data = data.replace(/_/g, '/');
return base64Decode(data);
};
parseToken = function(token) {
var head, payload, sig, _ref;
_ref = token.split('.'), head = _ref[0], payload = _ref[1], sig = _ref[2];
return JSON.parse(base64UrlDecode(payload));
};
Annotator.Plugin.Auth = (function(_super) {
__extends(Auth, _super);
Auth.prototype.options = {
token: null,
tokenUrl: '/auth/token',
autoFetch: true
};
function Auth(element, options) {
Auth.__super__.constructor.apply(this, arguments);
this.waitingForToken = [];
if (this.options.token) {
this.setToken(this.options.token);
} else {
this.requestToken();
}
}
Auth.prototype.requestToken = function() {
var _this = this;
this.requestInProgress = true;
return $.ajax({
url: this.options.tokenUrl,
dataType: 'text',
xhrFields: {
withCredentials: true
}
}).done(function(data, status, xhr) {
return _this.setToken(data);
}).fail(function(xhr, status, err) {
var msg;
msg = Annotator._t("Couldn't get auth token:");
console.error("" + msg + " " + err, xhr);
return Annotator.showNotification("" + msg + " " + xhr.responseText, Annotator.Notification.ERROR);
}).always(function() {
return _this.requestInProgress = false;
});
};
Auth.prototype.setToken = function(token) {
var _results,
_this = this;
this.token = token;
this._unsafeToken = parseToken(token);
if (this.haveValidToken()) {
if (this.options.autoFetch) {
this.refreshTimeout = setTimeout((function() {
return _this.requestToken();
}), (this.timeToExpiry() - 2) * 1000);
}
this.updateHeaders();
_results = [];
while (this.waitingForToken.length > 0) {
_results.push(this.waitingForToken.pop()(this._unsafeToken));
}
return _results;
} else {
console.warn(Annotator._t("Didn't get a valid token."));
if (this.options.autoFetch) {
console.warn(Annotator._t("Getting a new token in 10s."));
return setTimeout((function() {
return _this.requestToken();
}), 10 * 1000);
}
}
};
Auth.prototype.haveValidToken = function() {
var allFields;
allFields = this._unsafeToken && this._unsafeToken.issuedAt && this._unsafeToken.ttl && this._unsafeToken.consumerKey;
if (allFields && this.timeToExpiry() > 0) {
return true;
} else {
return false;
}
};
Auth.prototype.timeToExpiry = function() {
var expiry, issue, now, timeToExpiry;
now = new Date().getTime() / 1000;
issue = createDateFromISO8601(this._unsafeToken.issuedAt).getTime() / 1000;
expiry = issue + this._unsafeToken.ttl;
timeToExpiry = expiry - now;
if (timeToExpiry > 0) {
return timeToExpiry;
} else {
return 0;
}
};
Auth.prototype.updateHeaders = function() {
var current;
current = this.element.data('annotator:headers');
return this.element.data('annotator:headers', $.extend(current, {
'x-annotator-auth-token': this.token
}));
};
Auth.prototype.withToken = function(callback) {
if (callback == null) {
return;
}
if (this.haveValidToken()) {
return callback(this._unsafeToken);
} else {
this.waitingForToken.push(callback);
if (!this.requestInProgress) {
return this.requestToken();
}
}
};
return Auth;
})(Annotator.Plugin);
}).call(this);
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-b8c7514
** 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-12-15 12:18:02Z
*/
/*
//
*/
// Generated by CoffeeScript 1.6.3
(function() {
var _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
Annotator.Plugin.Document = (function(_super) {
var $;
__extends(Document, _super);
function Document() {
this._getDocOwners = __bind(this._getDocOwners, this);
this._getFavicon = __bind(this._getFavicon, this);
this._getLinks = __bind(this._getLinks, this);
this._getTitle = __bind(this._getTitle, this);
this._getMetaTags = __bind(this._getMetaTags, this);
this._getEprints = __bind(this._getEprints, this);
this._getPrism = __bind(this._getPrism, this);
this._getDublinCore = __bind(this._getDublinCore, this);
this._getTwitter = __bind(this._getTwitter, this);
this._getFacebook = __bind(this._getFacebook, this);
this._getHighwire = __bind(this._getHighwire, this);
this.getDocumentMetadata = __bind(this.getDocumentMetadata, this);
this.beforeAnnotationCreated = __bind(this.beforeAnnotationCreated, this);
this.uris = __bind(this.uris, this);
this.uri = __bind(this.uri, this);
_ref = Document.__super__.constructor.apply(this, arguments);
return _ref;
}
$ = Annotator.$;
Document.prototype.events = {
'beforeAnnotationCreated': 'beforeAnnotationCreated'
};
Document.prototype.pluginInit = function() {
return this.getDocumentMetadata();
};
Document.prototype.uri = function() {
var link, uri, _i, _len, _ref1;
uri = decodeURIComponent(document.location.href);
_ref1 = this.metadata.link;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
link = _ref1[_i];
if (link.rel === "canonical") {
uri = link.href;
}
}
return uri;
};
Document.prototype.uris = function() {
var href, link, uniqueUrls, _i, _len, _ref1;
uniqueUrls = {};
_ref1 = this.metadata.link;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
link = _ref1[_i];
if (link.href) {
uniqueUrls[link.href] = true;
}
}
return (function() {
var _results;
_results = [];
for (href in uniqueUrls) {
_results.push(href);
}
return _results;
})();
};
Document.prototype.beforeAnnotationCreated = function(annotation) {
return annotation.document = this.metadata;
};
Document.prototype.getDocumentMetadata = function() {
this.metadata = {};
this._getHighwire();
this._getDublinCore();
this._getFacebook();
this._getEprints();
this._getPrism();
this._getTwitter();
this._getFavicon();
this._getDocOwners();
this._getTitle();
this._getLinks();
return this.metadata;
};
Document.prototype._getHighwire = function() {
return this.metadata.highwire = this._getMetaTags("citation", "name", "_");
};
Document.prototype._getFacebook = function() {
return this.metadata.facebook = this._getMetaTags("og", "property", ":");
};
Document.prototype._getTwitter = function() {
return this.metadata.twitter = this._getMetaTags("twitter", "name", ":");
};
Document.prototype._getDublinCore = function() {
return this.metadata.dc = this._getMetaTags("dc", "name", ".");
};
Document.prototype._getPrism = function() {
return this.metadata.prism = this._getMetaTags("prism", "name", ".");
};
Document.prototype._getEprints = function() {
return this.metadata.eprints = this._getMetaTags("eprints", "name", ".");
};
Document.prototype._getMetaTags = function(prefix, attribute, delimiter) {
var content, match, meta, n, name, tags, _i, _len, _ref1;
tags = {};
_ref1 = $("meta");
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
meta = _ref1[_i];
name = $(meta).attr(attribute);
content = $(meta).prop("content");
if (name) {
match = name.match(RegExp("^" + prefix + delimiter + "(.+)$", "i"));
if (match) {
n = match[1];
if (tags[n]) {
tags[n].push(content);
} else {
tags[n] = [content];
}
}
}
}
return tags;
};
Document.prototype._getTitle = function() {
if (this.metadata.highwire.title) {
return this.metadata.title = this.metadata.highwire.title[0];
} else if (this.metadata.eprints.title) {
return this.metadata.title = this.metadata.eprints.title;
} else if (this.metadata.prism.title) {
return this.metadata.title = this.metadata.prism.title;
} else if (this.metadata.facebook.title) {
return this.metadata.title = this.metadata.facebook.title;
} else if (this.metadata.twitter.title) {
return this.metadata.title = this.metadata.twitter.title;
} else if (this.metadata.dc.title) {
return this.metadata.title = this.metadata.dc.title;
} else {
return this.metadata.title = $("head title").text();
}
};
Document.prototype._getLinks = function() {
var doi, dropTypes, href, id, l, link, name, rel, relTypes, type, url, values, _i, _j, _k, _len, _len1, _len2, _ref1, _ref2, _ref3, _results;
this.metadata.link = [
{
href: document.location.href
}
];
_ref1 = $("link");
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
link = _ref1[_i];
l = $(link);
href = this._absoluteUrl(l.prop('href'));
rel = l.prop('rel');
type = l.prop('type');
relTypes = ["alternate", "canonical", "bookmark", "shortlink"];
dropTypes = ["application/rss+xml", "application/atom+xml"];
if (__indexOf.call(relTypes, rel) >= 0 && __indexOf.call(dropTypes, type) < 0) {
this.metadata.link.push({
href: href,
rel: rel,
type: type
});
}
}
_ref2 = this.metadata.highwire;
for (name in _ref2) {
values = _ref2[name];
if (name === "pdf_url") {
for (_j = 0, _len1 = values.length; _j < _len1; _j++) {
url = values[_j];
this.metadata.link.push({
href: this._absoluteUrl(url),
type: "application/pdf"
});
}
}
if (name === "doi") {
for (_k = 0, _len2 = values.length; _k < _len2; _k++) {
doi = values[_k];
if (doi.slice(0, 4) !== "doi:") {
doi = "doi:" + doi;
}
this.metadata.link.push({
href: doi
});
}
}
}
_ref3 = this.metadata.dc;
_results = [];
for (name in _ref3) {
values = _ref3[name];
if (name === "identifier") {
_results.push((function() {
var _l, _len3, _results1;
_results1 = [];
for (_l = 0, _len3 = values.length; _l < _len3; _l++) {
id = values[_l];
if (id.slice(0, 4) === "doi:") {
_results1.push(this.metadata.link.push({
href: id
}));
} else {
_results1.push(void 0);
}
}
return _results1;
}).call(this));
} else {
_results.push(void 0);
}
}
return _results;
};
Document.prototype._getFavicon = function() {
var link, _i, _len, _ref1, _ref2, _results;
_ref1 = $("link");
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
link = _ref1[_i];
if ((_ref2 = $(link).prop("rel")) === "shortcut icon" || _ref2 === "icon") {
_results.push(this.metadata["favicon"] = this._absoluteUrl(link.href));
} else {
_results.push(void 0);
}
}
return _results;
};
Document.prototype._getDocOwners = function() {
var a, _i, _len, _ref1, _results;
this.metadata.reply_to = [];
_ref1 = $("a");
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
a = _ref1[_i];
if (a.rel === 'reply-to') {
if (a.href.toLowerCase().slice(0, 7) === "mailto:") {
_results.push(this.metadata.reply_to.push(a.href.slice(7)));
} else {
_results.push(this.metadata.reply_to.push(a.href));
}
} else {
_results.push(void 0);
}
}
return _results;
};
Document.prototype._absoluteUrl = function(url) {
var d;
d = document.createElement('a');
d.href = url;
return d.href;
};
return Document;
})(Annotator.Plugin);
}).call(this);
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-9e0eff3
** 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:40:58Z
*/
/*
//
*/
// Generated by CoffeeScript 1.6.3
(function() {
var _ref,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Annotator.Plugin.DomTextMapper = (function(_super) {
__extends(DomTextMapper, _super);
function DomTextMapper() {
_ref = DomTextMapper.__super__.constructor.apply(this, arguments);
return _ref;
}
DomTextMapper.prototype.pluginInit = function() {
var _this = this;
if (this.options.skip) {
console.log("Not registering DOM-Text-Mapper.");
return;
}
return this.annotator.documentAccessStrategies.unshift({
name: "DOM-Text-Mapper",
mapper: window.DomTextMapper,
init: function() {
return _this.annotator.domMapper.setRootNode(_this.annotator.wrapper[0]);
}
});
};
return DomTextMapper;
})(Annotator.Plugin);
}).call(this);
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-9e0eff3
** 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
*/
/*
//
*/
// Generated by CoffeeScript 1.6.3
(function() {
var _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Annotator.Plugin.FuzzyTextAnchors = (function(_super) {
__extends(FuzzyTextAnchors, _super);
function FuzzyTextAnchors() {
this.fuzzyMatching = __bind(this.fuzzyMatching, this);
this.twoPhaseFuzzyMatching = __bind(this.twoPhaseFuzzyMatching, this);
_ref = FuzzyTextAnchors.__super__.constructor.apply(this, arguments);
return _ref;
}
FuzzyTextAnchors.prototype.pluginInit = function() {
var _this = this;
if (!this.annotator.plugins.TextAnchors) {
console.warn("The FuzzyTextAnchors Annotator plugin requires the TextAnchors plugin. Skipping.");
return;
}
this.Annotator = Annotator;
this.textFinder = new DomTextMatcher(function() {
return _this.annotator.domMapper.getCorpus();
});
this.annotator.anchoringStrategies.push({
name: "two-phase fuzzy",
code: this.twoPhaseFuzzyMatching
});
return this.annotator.anchoringStrategies.push({
name: "one-phase fuzzy",
code: this.fuzzyMatching
});
};
FuzzyTextAnchors.prototype.twoPhaseFuzzyMatching = function(annotation, target) {
var expectedEnd, expectedStart, match, options, posSelector, prefix, quote, quoteSelector, result, suffix;
if (this.annotator.domMapper.getInfoForNode == null) {
return;
}
quoteSelector = this.annotator.findSelector(target.selector, "TextQuoteSelector");
prefix = quoteSelector != null ? quoteSelector.prefix : void 0;
suffix = quoteSelector != null ? quoteSelector.suffix : void 0;
quote = quoteSelector != null ? quoteSelector.exact : void 0;
if (!((prefix != null) && (suffix != null))) {
return null;
}
posSelector = this.annotator.findSelector(target.selector, "TextPositionSelector");
expectedStart = posSelector != null ? posSelector.start : void 0;
expectedEnd = posSelector != null ? posSelector.end : void 0;
options = {
contextMatchDistance: this.annotator.domMapper.getCorpus().length * 2,
contextMatchThreshold: 0.5,
patternMatchThreshold: 0.5,
flexContext: true
};
result = this.textFinder.searchFuzzyWithContext(prefix, suffix, quote, expectedStart, expectedEnd, false, options);
if (!result.matches.length) {
return null;
}
match = result.matches[0];
return new this.Annotator.TextPositionAnchor(this.annotator, annotation, target, match.start, match.end, this.annotator.domMapper.getPageIndexForPos(match.start), this.annotator.domMapper.getPageIndexForPos(match.end), match.found, !match.exact ? match.comparison.diffHTML : void 0, !match.exact ? match.exactExceptCase : void 0);
};
FuzzyTextAnchors.prototype.fuzzyMatching = function(annotation, target) {
var expectedStart, len, match, options, posSelector, quote, quoteSelector, result;
if (this.annotator.domMapper.getInfoForNode == null) {
return;
}
quoteSelector = this.annotator.findSelector(target.selector, "TextQuoteSelector");
quote = quoteSelector != null ? quoteSelector.exact : void 0;
if (quote == null) {
return null;
}
if (!(quote.length >= 32)) {
return;
}
posSelector = this.annotator.findSelector(target.selector, "TextPositionSelector");
expectedStart = posSelector != null ? posSelector.start : void 0;
len = this.annotator.domMapper.getCorpus().length;
if (expectedStart == null) {
expectedStart = Math.floor(len / 2);
}
options = {
matchDistance: len * 2,
withFuzzyComparison: true
};
result = this.textFinder.searchFuzzy(quote, expectedStart, false, options);
if (!result.matches.length) {
return null;
}
match = result.matches[0];
return new this.Annotator.TextPositionAnchor(this.annotator, annotation, target, match.start, match.end, this.annotator.domMapper.getPageIndexForPos(match.start), this.annotator.domMapper.getPageIndexForPos(match.end), match.found, !match.exact ? match.comparison.diffHTML : void 0, !match.exact ? match.exactExceptCase : void 0);
};
return FuzzyTextAnchors;
})(Annotator.Plugin);
}).call(this);
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-4627466
** 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-12-18 11:08:27Z
*/
/*
//
*/
// Generated by CoffeeScript 1.6.3
(function() {
var compareVersions, detectedPDFjsVersion, _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
detectedPDFjsVersion = typeof PDFJS !== "undefined" && PDFJS !== null ? PDFJS.version.split(".").map(parseFloat) : void 0;
compareVersions = function(v1, v2) {
var i, _i, _ref;
if (!(Array.isArray(v1) && Array.isArray(v2))) {
throw new Error("Expecting arrays, in the form of [1, 0, 123]");
}
if (v1.length !== v2.length) {
throw new Error("Can't compare versions in different formats.");
}
for (i = _i = 0, _ref = v1.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
if (v1[i] < v2[i]) {
return -1;
} else if (v1[i] > v2[i]) {
return 1;
}
}
return 0;
};
window.PDFTextMapper = (function(_super) {
__extends(PDFTextMapper, _super);
PDFTextMapper.isPDFDocument = function() {
return (typeof PDFView !== "undefined" && PDFView !== null) || (typeof PDFViewerApplication !== "undefined" && PDFViewerApplication !== null);
};
PDFTextMapper.applicable = function() {
return this.isPDFDocument();
};
PDFTextMapper.prototype.requiresSmartStringPadding = true;
PDFTextMapper.prototype.getPageCount = function() {
return this._viewer.pages.length;
};
PDFTextMapper.prototype.getPageIndex = function() {
return this._app.page - 1;
};
PDFTextMapper.prototype.setPageIndex = function(index) {
return this._app.page = index + 1;
};
PDFTextMapper.prototype._isPageRendered = function(index) {
var _ref, _ref1;
return (_ref = this._viewer.pages[index]) != null ? (_ref1 = _ref.textLayer) != null ? _ref1.renderingDone : void 0 : void 0;
};
PDFTextMapper.prototype.getRootNodeForPage = function(index) {
return this._viewer.pages[index].textLayer.textLayerDiv;
};
function PDFTextMapper() {
this._finishScan = __bind(this._finishScan, this);
this._parseExtractedText = __bind(this._parseExtractedText, this);
var _ref,
_this = this;
if (typeof PDFViewerApplication !== "undefined" && PDFViewerApplication !== null) {
this._app = PDFViewerApplication;
this._viewer = this._app.pdfViewer;
this._tryExtractPage = function(index) {
return _this._viewer.getPageTextContent(index);
};
} else {
this._app = this._viewer = PDFView;
this._finder = (_ref = this._app.findController) != null ? _ref : PDFFindController;
this._tryExtractPage = function(index) {
return new Promise(function(resolve, reject) {
var tryIt;
tryIt = function() {
var page;
page = _this._finder.pdfPageSource.pages[index];
if ((page != null ? page.pdfPage : void 0) != null) {
return page.getTextContent().then(resolve);
} else {
return setTimeout(tryIt, 100);
}
};
return tryIt();
});
};
}
this.setEvents();
if (compareVersions(detectedPDFjsVersion, [1, 0, 822]) >= 0) {
this._viewer.container.className += " has-transparent-text-layer";
}
}
PDFTextMapper.prototype.setEvents = function() {
var viewer,
_this = this;
addEventListener("pagerender", function(evt) {
var index;
if (_this.pageInfo == null) {
return;
}
index = evt.detail.pageNumber - 1;
return _this._onPageRendered(index);
});
addEventListener("DOMNodeRemoved", function(evt) {
var index, node;
node = evt.target;
if (node.nodeType === Node.ELEMENT_NODE && node.nodeName.toLowerCase() === "div" && node.className === "textLayer") {
index = parseInt(node.parentNode.id.substr(13) - 1);
return _this._unmapPage(_this.pageInfo[index]);
}
});
viewer = document.getElementById("viewer");
viewer.addEventListener("domChange", function(event) {
var data, endPage, node, startPage, _ref;
node = (_ref = event.srcElement) != null ? _ref : event.target;
data = event.data;
if ("viewer" === (typeof node.getAttribute === "function" ? node.getAttribute("id") : void 0)) {
console.log("Detected cross-page change event.");
if ((data.start != null) && (data.end != null)) {
startPage = _this.getPageForNode(data.start);
_this._updateMap(_this.pageInfo[startPage.index]);
endPage = _this.getPageForNode(data.end);
return _this._updateMap(_this.pageInfo[endPage.index]);
}
}
});
return this._viewer.container.addEventListener("scroll", this._onScroll);
};
PDFTextMapper.prototype._extractionPattern = /[ ]+/g;
PDFTextMapper.prototype._parseExtractedText = function(text) {
return text.replace(this._extractionPattern, " ");
};
PDFTextMapper.prototype.waitForInit = function() {
var tryIt,
_this = this;
tryIt = function(resolve) {
if (_this._app.documentFingerprint && _this._app.documentInfo) {
return resolve();
} else {
return setTimeout((function() {
return tryIt(resolve);
}), 100);
}
};
return new Promise(function(resolve, reject) {
if (PDFTextMapper.applicable()) {
return tryIt(resolve);
} else {
return reject("Not a PDF.js document");
}
});
};
PDFTextMapper.prototype.scan = function() {
var _this = this;
return new Promise(function(resolve, reject) {
_this._pendingScanResolve = resolve;
return _this.waitForInit().then(function() {
return _this._app.pdfDocument.getPage(1).then(function() {
_this.pageInfo = [];
return _this._extractPageText(0);
});
});
});
};
PDFTextMapper.prototype._extractPageText = function(pageIndex) {
var _this = this;
return this._tryExtractPage(pageIndex).then(function(data) {
var content, rawContent, text, textData, _ref, _ref1;
textData = (_ref = (_ref1 = data.bidiTexts) != null ? _ref1 : data.items) != null ? _ref : data;
rawContent = ((function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = textData.length; _i < _len; _i++) {
text = textData[_i];
_results.push(text.str);
}
return _results;
})()).join(" ");
content = _this._parseExtractedText(rawContent);
_this.pageInfo[pageIndex] = {
index: pageIndex,
content: content
};
if (pageIndex === _this.getPageCount() - 1) {
return _this._finishScan();
} else {
return _this._extractPageText(pageIndex + 1);
}
});
};
PDFTextMapper.prototype._finishScan = function() {
this._onHavePageContents();
this._pendingScanResolve();
return this._onAfterScan();
};
PDFTextMapper.prototype.getPageForNode = function(node) {
var div, index;
div = node;
while ((div.nodeType !== Node.ELEMENT_NODE) || (div.getAttribute("class") == null) || (div.getAttribute("class") !== "textLayer")) {
div = div.parentNode;
}
index = parseInt(div.parentNode.id.substr(13) - 1);
return this.pageInfo[index];
};
PDFTextMapper.prototype.getDocumentFingerprint = function() {
return this._app.documentFingerprint;
};
PDFTextMapper.prototype.getDocumentInfo = function() {
return this._app.documentInfo;
};
return PDFTextMapper;
})(PageTextMapperCore);
Annotator.Plugin.PDF = (function(_super) {
var $;
__extends(PDF, _super);
function PDF() {
this.beforeAnnotationCreated = __bind(this.beforeAnnotationCreated, this);
this.getMetaData = __bind(this.getMetaData, this);
_ref = PDF.__super__.constructor.apply(this, arguments);
return _ref;
}
$ = Annotator.$;
PDF.prototype.pluginInit = function() {
if (!this.annotator.plugins.DomTextMapper) {
console.warn("The PDF Annotator plugin requires the DomTextMapper plugin. Skipping.");
return;
}
return this.annotator.documentAccessStrategies.unshift({
name: "PDF.js",
mapper: PDFTextMapper
});
};
PDF.prototype._isPDF = function() {
return PDFTextMapper.applicable();
};
PDF.prototype._getDocumentURI = function() {
var match, matches, uri;
uri = window.location.href;
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() {
var fingerprint;
fingerprint = this.annotator.domMapper.getDocumentFingerprint();
return "urn:x-pdf:" + fingerprint;
};
PDF.prototype.uri = function() {
if (!this._isPDF()) {
return null;
}
return this._getFingerPrintURI();
};
PDF.prototype._getTitle = function() {
var title, _ref1;
title = (_ref1 = this.annotator.domMapper.getDocumentInfo().Title) != null ? _ref1.trim() : void 0;
if ((title != null) && title !== "") {
return title;
} else {
return $("head title").text().trim();
}
};
PDF.prototype._metadata = function() {
var documentURI, metadata;
metadata = {
link: [
{
href: this._getFingerPrintURI()
}
],
title: this._getTitle()
};
documentURI = this._getDocumentURI();
if (documentURI.toLowerCase().indexOf('file://') === 0) {
metadata.filename = new URL(documentURI).pathname.split('/').pop();
} else {
metadata.link.push({
href: documentURI
});
}
return metadata;
};
PDF.prototype.getMetaData = function() {
var _this = this;
return new Promise(function(resolve, reject) {
if (_this.annotator.domMapper.waitForInit != null) {
return _this.annotator.domMapper.waitForInit().then(function() {
var error;
try {
return resolve(_this._metadata());
} catch (_error) {
error = _error;
return reject("Internal error");
}
});
} else {
return reject("Not a PDF dom mapper.");
}
});
};
PDF.prototype.events = {
'beforeAnnotationCreated': 'beforeAnnotationCreated'
};
PDF.prototype.beforeAnnotationCreated = function(annotation) {
if (!this._isPDF()) {
return;
}
return annotation.document = this._metadata();
};
return PDF;
})(Annotator.Plugin);
}).call(this);
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-9e0eff3
** 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:40:59Z
*/
/*
//
*/
// Generated by CoffeeScript 1.6.3
(function() {
var _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Annotator.Plugin.TextAnchors = (function(_super) {
__extends(TextAnchors, _super);
function TextAnchors() {
this.checkForEndSelection = __bind(this.checkForEndSelection, this);
_ref = TextAnchors.__super__.constructor.apply(this, arguments);
return _ref;
}
TextAnchors.prototype.pluginInit = function() {
var _this = this;
if (!this.annotator.plugins.TextHighlights) {
throw new Error("The TextAnchors Annotator plugin requires the TextHighlights plugin.");
}
this.Annotator = Annotator;
this.$ = Annotator.$;
$(document).bind({
"mouseup": this.checkForEndSelection
});
this.annotator.subscribe("enableAnnotating", function(value) {
if (value) {
return setTimeout(_this.checkForEndSelection, 500);
}
});
return null;
};
TextAnchors.prototype._getSelectedRanges = function() {
var browserRange, i, normedRange, r, ranges, rangesToIgnore, selection, _i, _len;
selection = this.Annotator.util.getGlobal().getSelection();
ranges = [];
rangesToIgnore = [];
if (!selection.isCollapsed) {
ranges = (function() {
var _i, _ref1, _results;
_results = [];
for (i = _i = 0, _ref1 = selection.rangeCount; 0 <= _ref1 ? _i < _ref1 : _i > _ref1; i = 0 <= _ref1 ? ++_i : --_i) {
r = selection.getRangeAt(i);
browserRange = new this.Annotator.Range.BrowserRange(r);
normedRange = browserRange.normalize().limit(this.annotator.wrapper[0]);
if (normedRange === null) {
rangesToIgnore.push(r);
}
_results.push(normedRange);
}
return _results;
}).call(this);
selection.removeAllRanges();
}
for (_i = 0, _len = rangesToIgnore.length; _i < _len; _i++) {
r = rangesToIgnore[_i];
selection.addRange(r);
}
return this.$.grep(ranges, function(range) {
if (range) {
selection.addRange(range.toRange());
}
return range;
});
};
TextAnchors.prototype.checkForEndSelection = function(event) {
var container, pos, r, range, selectedRanges, _i, _j, _len, _len1;
if (event == null) {
event = {};
}
this.annotator.mouseIsDown = false;
if (this.annotator.inAdderClick) {
return;
}
selectedRanges = this._getSelectedRanges();
for (_i = 0, _len = selectedRanges.length; _i < _len; _i++) {
range = selectedRanges[_i];
container = range.commonAncestor;
if (this.Annotator.TextHighlight.isInstance(container)) {
container = this.Annotator.TextHighlight.getIndependentParent(container);
}
if (this.annotator.isAnnotator(container)) {
return;
}
}
if (selectedRanges.length) {
event.segments = [];
for (_j = 0, _len1 = selectedRanges.length; _j < _len1; _j++) {
r = selectedRanges[_j];
event.segments.push({
type: "text range",
range: r
});
}
if (!event.pageX) {
pos = selectedRanges[0].getEndCoords();
event.pageX = pos.x;
event.pageY = pos.y;
}
return this.annotator.onSuccessfulSelection(event);
} else {
return this.annotator.onFailedSelection(event);
}
};
return TextAnchors;
})(Annotator.Plugin);
}).call(this);
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-b8c7514
** 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-12-15 12:18:04Z
*/
/*
//
*/
// Generated by CoffeeScript 1.6.3
(function() {
var TextHighlight, _ref,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
TextHighlight = (function(_super) {
__extends(TextHighlight, _super);
TextHighlight.highlightClass = 'annotator-hl';
TextHighlight.Annotator = Annotator;
TextHighlight.$ = Annotator.$;
TextHighlight.highlightType = 'TextHighlight';
TextHighlight.isInstance = function(element) {
return this.$(element).hasClass('annotator-hl');
};
TextHighlight.getIndependentParent = function(element) {
return this.$(element).parents(':not([class^=annotator-hl])')[0];
};
TextHighlight._inited = [];
TextHighlight.getAnnotations = function(event) {
return TextHighlight.$(event.target).parents('.annotator-hl').andSelf().map(function() {
return TextHighlight.$(this).data("annotation");
}).toArray();
};
TextHighlight._init = function(annotator) {
var _this = this;
if (__indexOf.call(this._inited, annotator) >= 0) {
return;
}
annotator.element.delegate(".annotator-hl", "mouseover", this, function(event) {
return annotator.onAnchorMouseover(event);
});
annotator.element.delegate(".annotator-hl", "mouseout", this, function(event) {
return annotator.onAnchorMouseout(event);
});
annotator.element.delegate(".annotator-hl", "mousedown", this, function(event) {
return annotator.onAnchorMousedown(event);
});
annotator.element.delegate(".annotator-hl", "click", this, function(event) {
return annotator.onAnchorClick(event);
});
return this._inited.push(annotator);
};
TextHighlight.prototype._highlightRange = function(normedRange, cssClass) {
var event, hl, node, nodes, r, white, _i, _len;
if (cssClass == null) {
cssClass = 'annotator-hl';
}
white = /^\s*$/;
hl = this.$("<span class='" + cssClass + "'></span>");
nodes = this.$(normedRange.textNodes()).filter(function(i) {
return !white.test(this.nodeValue);
});
r = nodes.wrap(hl).parent().show().toArray();
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
node = nodes[_i];
event = document.createEvent("UIEvents");
event.initUIEvent("domChange", true, false, window, 0);
event.reason = "created hilite";
node.dispatchEvent(event);
}
return r;
};
function TextHighlight(anchor, pageIndex, normedRange) {
TextHighlight.__super__.constructor.call(this, anchor, pageIndex);
TextHighlight._init(this.annotator);
this.$ = TextHighlight.$;
this.Annotator = TextHighlight.Annotator;
this._highlights = this._highlightRange(normedRange);
this.$(this._highlights).data("annotation", this.annotation);
}
TextHighlight.prototype.isTemporary = function() {
return this._temporary;
};
TextHighlight.prototype.setTemporary = function(value) {
this._temporary = value;
if (value) {
return this.$(this._highlights).addClass('annotator-hl-temporary');
} else {
return this.$(this._highlights).removeClass('annotator-hl-temporary');
}
};
TextHighlight.prototype.setFocused = function(value) {
if (value) {
return this.$(this._highlights).addClass('annotator-hl-focused');
} else {
return this.$(this._highlights).removeClass('annotator-hl-focused');
}
};
TextHighlight.prototype.removeFromDocument = function() {
var child, event, hl, _i, _len, _ref, _results;
_ref = this._highlights;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
hl = _ref[_i];
if ((hl.parentNode != null) && this.annotator.domMapper.isPageMapped(this.pageIndex)) {
child = hl.childNodes[0];
this.$(hl).replaceWith(hl.childNodes);
event = document.createEvent("UIEvents");
event.initUIEvent("domChange", true, false, window, 0);
event.reason = "removed hilite (annotation deleted)";
_results.push(child.parentNode.dispatchEvent(event));
} else {
_results.push(void 0);
}
}
return _results;
};
TextHighlight.prototype._getDOMElements = function() {
return this._highlights;
};
return TextHighlight;
})(Annotator.Highlight);
Annotator.Plugin.TextHighlights = (function(_super) {
__extends(TextHighlights, _super);
function TextHighlights() {
_ref = TextHighlights.__super__.constructor.apply(this, arguments);
return _ref;
}
TextHighlights.prototype.pluginInit = function() {
return Annotator.TextHighlight = TextHighlight;
};
return TextHighlights;
})(Annotator.Plugin);
}).call(this);
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-62d3d3f
** 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-11-06 15:35:12Z
*/
/*
//
*/
// Generated by CoffeeScript 1.6.3
(function() {
var TextPositionAnchor, _ref,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
TextPositionAnchor = (function(_super) {
__extends(TextPositionAnchor, _super);
TextPositionAnchor.Annotator = Annotator;
function TextPositionAnchor(annotator, annotation, target, start, end, startPage, endPage, quote, diffHTML, diffCaseOnly) {
this.start = start;
this.end = end;
TextPositionAnchor.__super__.constructor.call(this, annotator, annotation, target, startPage, endPage, quote, diffHTML, diffCaseOnly);
if (this.start == null) {
throw new Error("start is required!");
}
if (this.end == null) {
throw new Error("end is required!");
}
this.Annotator = TextPositionAnchor.Annotator;
}
TextPositionAnchor.prototype._createHighlight = function(page) {
var browserRange, mappings, normedRange, realRange;
mappings = this.annotator.domMapper.getMappingsForCharRange(this.start, this.end, [page]);
realRange = mappings.sections[page].realRange;
browserRange = new this.Annotator.Range.BrowserRange(realRange);
normedRange = browserRange.normalize(this.annotator.wrapper[0]);
return new this.Annotator.TextHighlight(this, page, normedRange);
};
return TextPositionAnchor;
})(Annotator.Anchor);
Annotator.Plugin.TextPosition = (function(_super) {
__extends(TextPosition, _super);
function TextPosition() {
this.createFromPositionSelector = __bind(this.createFromPositionSelector, this);
this._getTextPositionSelector = __bind(this._getTextPositionSelector, this);
_ref = TextPosition.__super__.constructor.apply(this, arguments);
return _ref;
}
TextPosition.prototype.pluginInit = function() {
this.Annotator = Annotator;
this.annotator.selectorCreators.push({
name: "TextPositionSelector",
describe: this._getTextPositionSelector
});
this.annotator.anchoringStrategies.push({
name: "position",
code: this.createFromPositionSelector
});
return this.Annotator.TextPositionAnchor = TextPositionAnchor;
};
TextPosition.prototype._getTextPositionSelector = function(selection) {
var endOffset, startOffset;
if (selection.type !== "text range") {
return [];
}
if (this.annotator.domMapper.getStartPosForNode == null) {
return [];
}
startOffset = this.annotator.domMapper.getStartPosForNode(selection.range.start);
endOffset = this.annotator.domMapper.getEndPosForNode(selection.range.end);
if ((startOffset != null) && (endOffset != null)) {
return [
{
type: "TextPositionSelector",
start: startOffset,
end: endOffset
}
];
} else {
if (startOffset == null) {
console.log("Warning: can't generate TextPosition selector, because", selection.range.start, "does not have a valid start position.");
}
if (endOffset == null) {
console.log("Warning: can't generate TextPosition selector, because", selection.range.end, "does not have a valid end position.");
}
return [];
}
};
TextPosition.prototype.createFromPositionSelector = function(annotation, target) {
var content, corpus, currentQuote, savedQuote, selector, _base, _base1;
selector = this.annotator.findSelector(target.selector, "TextPositionSelector");
if (selector == null) {
return;
}
if (selector.start == null) {
console.log("Warning: 'start' field is missing from TextPositionSelector. Skipping.");
return null;
}
if (selector.end == null) {
console.log("Warning: 'end' field is missing from TextPositionSelector. Skipping.");
return null;
}
corpus = typeof (_base = this.annotator.domMapper).getCorpus === "function" ? _base.getCorpus() : void 0;
if (!corpus) {
return null;
}
content = corpus.slice(selector.start, selector.end).trim();
currentQuote = this.annotator.normalizeString(content);
savedQuote = typeof (_base1 = this.annotator).getQuoteForTarget === "function" ? _base1.getQuoteForTarget(target) : void 0;
if ((savedQuote != null) && currentQuote !== savedQuote) {
return null;
}
return new TextPositionAnchor(this.annotator, annotation, target, selector.start, selector.end, this.annotator.domMapper.getPageIndexForPos(selector.start), this.annotator.domMapper.getPageIndexForPos(selector.end), currentQuote);
};
return TextPosition;
})(Annotator.Plugin);
}).call(this);
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-9e0eff3
** 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:01Z
*/
/*
//
*/
// Generated by CoffeeScript 1.6.3
(function() {
var _ref,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Annotator.Plugin.TextQuote = (function(_super) {
__extends(TextQuote, _super);
function TextQuote() {
this._getTextQuoteSelector = __bind(this._getTextQuoteSelector, this);
_ref = TextQuote.__super__.constructor.apply(this, arguments);
return _ref;
}
TextQuote.Annotator = Annotator;
TextQuote.$ = Annotator.$;
TextQuote.prototype.pluginInit = function() {
var _this = this;
this.annotator.selectorCreators.push({
name: "TextQuoteSelector",
describe: this._getTextQuoteSelector
});
return this.annotator.getQuoteForTarget = function(target) {
var selector;
selector = _this.annotator.findSelector(target.selector, "TextQuoteSelector");
if (selector != null) {
return _this.annotator.normalizeString(selector.exact);
} else {
return null;
}
};
};
TextQuote.prototype._getTextQuoteSelector = function(selection) {
var endOffset, prefix, quote, rangeEnd, rangeStart, startOffset, suffix, _ref1;
if (selection.type !== "text range") {
return [];
}
if (selection.range == null) {
throw new Error("Called getTextQuoteSelector() with null range!");
}
rangeStart = selection.range.start;
if (rangeStart == null) {
throw new Error("Called getTextQuoteSelector() on a range with no valid start.");
}
rangeEnd = selection.range.end;
if (rangeEnd == null) {
throw new Error("Called getTextQuoteSelector() on a range with no valid end.");
}
if (this.annotator.domMapper.getStartPosForNode != null) {
startOffset = this.annotator.domMapper.getStartPosForNode(rangeStart);
endOffset = this.annotator.domMapper.getEndPosForNode(rangeEnd);
if ((startOffset != null) && (endOffset != null)) {
quote = this.annotator.domMapper.getCorpus().slice(startOffset, +(endOffset - 1) + 1 || 9e9).trim();
_ref1 = this.annotator.domMapper.getContextForCharRange(startOffset, endOffset), prefix = _ref1[0], suffix = _ref1[1];
return [
{
type: "TextQuoteSelector",
exact: quote,
prefix: prefix,
suffix: suffix
}
];
} else {
console.log("Warning: can't generate TextQuote selector.", startOffset, endOffset);
return [];
}
} else {
return [
{
type: "TextQuoteSelector",
exact: selection.range.text().trim()
}
];
}
};
return TextQuote;
})(Annotator.Plugin);
}).call(this);
// Generated by CoffeeScript 1.6.3
/*
** Annotator 1.2.6-dev-9e0eff3
** 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:00Z
*/
/*
//
*/
// Generated by CoffeeScript 1.6.3
(function() {
var TextRangeAnchor, _ref,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
TextRangeAnchor = (function(_super) {
__extends(TextRangeAnchor, _super);
TextRangeAnchor.Annotator = Annotator;
function TextRangeAnchor(annotator, annotation, target, range, quote) {
this.range = range;
TextRangeAnchor.__super__.constructor.call(this, annotator, annotation, target, 0, 0, quote);
if (this.range == null) {
throw new Error("range is required!");
}
this.Annotator = TextRangeAnchor.Annotator;
}
TextRangeAnchor.prototype._createHighlight = function() {
return new this.Annotator.TextHighlight(this, 0, this.range);
};
return TextRangeAnchor;
})(Annotator.Anchor);
Annotator.Plugin.TextRange = (function(_super) {
__extends(TextRange, _super);
function TextRange() {
this.createFromRangeSelector = __bind(this.createFromRangeSelector, this);
this._getRangeSelector = __bind(this._getRangeSelector, this);
_ref = TextRange.__super__.constructor.apply(this, arguments);
return _ref;
}
TextRange.prototype.pluginInit = function() {
this.Annotator = Annotator;
this.annotator.selectorCreators.push({
name: "RangeSelector",
describe: this._getRangeSelector
});
this.annotator.anchoringStrategies.push({
name: "range",
code: this.createFromRangeSelector
});
return this.annotator.TextRangeAnchor = TextRangeAnchor;
};
TextRange.prototype._getRangeSelector = function(selection) {
var sr;
if (selection.type !== "text range") {
return [];
}
sr = selection.range.serialize(this.annotator.wrapper[0], '.' + this.Annotator.TextHighlight.highlightClass);
return [
{
type: "RangeSelector",
startContainer: sr.startContainer,
startOffset: sr.startOffset,
endContainer: sr.endContainer,
endOffset: sr.endOffset
}
];
};
TextRange.prototype.createFromRangeSelector = function(annotation, target) {
var currentQuote, endInfo, endOffset, error, normedRange, range, rawQuote, savedQuote, selector, startInfo, startOffset, _base, _ref1, _ref2;
selector = this.annotator.findSelector(target.selector, "RangeSelector");
if (selector == null) {
return null;
}
try {
range = this.Annotator.Range.sniff(selector);
normedRange = range.normalize(this.annotator.wrapper[0]);
} catch (_error) {
error = _error;
return null;
}
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;
if ((savedQuote != null) && currentQuote !== savedQuote) {
return null;
}
if (((startInfo != null ? startInfo.start : void 0) != null) && ((endInfo != null ? endInfo.end : void 0) != null)) {
return new this.Annotator.TextPositionAnchor(this.annotator, annotation, target, startInfo.start, endInfo.end, (_ref1 = startInfo.pageIndex) != null ? _ref1 : 0, (_ref2 = endInfo.pageIndex) != null ? _ref2 : 0, currentQuote);
} else {
return new TextRangeAnchor(this.annotator, annotation, target, normedRange, currentQuote);
}
};
return TextRange;
})(Annotator.Plugin);
}).call(this);
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