Commit 13dfeac7 authored by Randall Leeds's avatar Randall Leeds

remove webassets cache from gitignore

parent fad2cd29
/* /*
** Annotator 1.2.6-dev-939cdee ** Annotator 1.2.6-dev-d45a366
** 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: 2013-04-10 07:38:34Z ** Built at: 2013-04-12 00:11:35Z
*/ */
(function() { (function() {
var base64Decode, base64UrlDecode, createDateFromISO8601, parseToken, var base64Decode, base64UrlDecode, createDateFromISO8601, parseToken,
__hasProp = Object.prototype.hasOwnProperty, __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; }; __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) { createDateFromISO8601 = function(string) {
var d, date, offset, regexp, time, _ref; 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})))?)?)?)?"; 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)); d = string.match(new RegExp(regexp));
offset = 0; offset = 0;
date = new Date(d[1], 0, 1); date = new Date(d[1], 0, 1);
if (d[3]) date.setMonth(d[3] - 1); if (d[3]) {
if (d[5]) date.setDate(d[5]); date.setMonth(d[3] - 1);
if (d[7]) date.setHours(d[7]); }
if (d[8]) date.setMinutes(d[8]); if (d[5]) {
if (d[10]) date.setSeconds(d[10]); date.setDate(d[5]);
if (d[12]) date.setMilliseconds(Number("0." + d[12]) * 1000); }
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]) { if (d[14]) {
offset = (Number(d[16]) * 60) + Number(d[17]); offset = (Number(d[16]) * 60) + Number(d[17]);
offset *= (_ref = d[15] === '-') != null ? _ref : { offset *= (_ref = d[15] === '-') != null ? _ref : {
...@@ -40,6 +54,7 @@ ...@@ -40,6 +54,7 @@
base64Decode = function(data) { base64Decode = function(data) {
var ac, b64, bits, dec, h1, h2, h3, h4, i, o1, o2, o3, tmp_arr; var ac, b64, bits, dec, h1, h2, h3, h4, i, o1, o2, o3, tmp_arr;
if (typeof atob !== "undefined" && atob !== null) { if (typeof atob !== "undefined" && atob !== null) {
return atob(data); return atob(data);
} else { } else {
...@@ -48,7 +63,9 @@ ...@@ -48,7 +63,9 @@
ac = 0; ac = 0;
dec = ""; dec = "";
tmp_arr = []; tmp_arr = [];
if (!data) return data; if (!data) {
return data;
}
data += ''; data += '';
while (i < data.length) { while (i < data.length) {
h1 = b64.indexOf(data.charAt(i++)); h1 = b64.indexOf(data.charAt(i++));
...@@ -72,10 +89,11 @@ ...@@ -72,10 +89,11 @@
}; };
base64UrlDecode = function(data) { base64UrlDecode = function(data) {
var i, m, _ref; var i, m, _i, _ref;
m = data.length % 4; m = data.length % 4;
if (m !== 0) { if (m !== 0) {
for (i = 0, _ref = 4 - m; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) { for (i = _i = 0, _ref = 4 - m; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
data += '='; data += '=';
} }
} }
...@@ -86,12 +104,12 @@ ...@@ -86,12 +104,12 @@
parseToken = function(token) { parseToken = function(token) {
var head, payload, sig, _ref; var head, payload, sig, _ref;
_ref = token.split('.'), head = _ref[0], payload = _ref[1], sig = _ref[2]; _ref = token.split('.'), head = _ref[0], payload = _ref[1], sig = _ref[2];
return JSON.parse(base64UrlDecode(payload)); return JSON.parse(base64UrlDecode(payload));
}; };
Annotator.Plugin.Auth = (function(_super) { Annotator.Plugin.Auth = (function(_super) {
__extends(Auth, _super); __extends(Auth, _super);
Auth.prototype.options = { Auth.prototype.options = {
...@@ -112,6 +130,7 @@ ...@@ -112,6 +130,7 @@
Auth.prototype.requestToken = function() { Auth.prototype.requestToken = function() {
var _this = this; var _this = this;
this.requestInProgress = true; this.requestInProgress = true;
return $.ajax({ return $.ajax({
url: this.options.tokenUrl, url: this.options.tokenUrl,
...@@ -123,6 +142,7 @@ ...@@ -123,6 +142,7 @@
return _this.setToken(data); return _this.setToken(data);
}).fail(function(xhr, status, err) { }).fail(function(xhr, status, err) {
var msg; var msg;
msg = Annotator._t("Couldn't get auth token:"); msg = Annotator._t("Couldn't get auth token:");
console.error("" + msg + " " + err, xhr); console.error("" + msg + " " + err, xhr);
return Annotator.showNotification("" + msg + " " + xhr.responseText, Annotator.Notification.ERROR); return Annotator.showNotification("" + msg + " " + xhr.responseText, Annotator.Notification.ERROR);
...@@ -134,6 +154,7 @@ ...@@ -134,6 +154,7 @@
Auth.prototype.setToken = function(token) { Auth.prototype.setToken = function(token) {
var _results, var _results,
_this = this; _this = this;
this.token = token; this.token = token;
this._unsafeToken = parseToken(token); this._unsafeToken = parseToken(token);
if (this.haveValidToken()) { if (this.haveValidToken()) {
...@@ -161,12 +182,14 @@ ...@@ -161,12 +182,14 @@
Auth.prototype.haveValidToken = function() { Auth.prototype.haveValidToken = function() {
var allFields; var allFields;
allFields = this._unsafeToken && this._unsafeToken.issuedAt && this._unsafeToken.ttl && this._unsafeToken.consumerKey; allFields = this._unsafeToken && this._unsafeToken.issuedAt && this._unsafeToken.ttl && this._unsafeToken.consumerKey;
return allFields && this.timeToExpiry() > 0; return allFields && this.timeToExpiry() > 0;
}; };
Auth.prototype.timeToExpiry = function() { Auth.prototype.timeToExpiry = function() {
var expiry, issue, now, timeToExpiry; var expiry, issue, now, timeToExpiry;
now = new Date().getTime() / 1000; now = new Date().getTime() / 1000;
issue = createDateFromISO8601(this._unsafeToken.issuedAt).getTime() / 1000; issue = createDateFromISO8601(this._unsafeToken.issuedAt).getTime() / 1000;
expiry = issue + this._unsafeToken.ttl; expiry = issue + this._unsafeToken.ttl;
...@@ -180,6 +203,7 @@ ...@@ -180,6 +203,7 @@
Auth.prototype.updateHeaders = function() { Auth.prototype.updateHeaders = function() {
var current; var current;
current = this.element.data('annotator:headers'); current = this.element.data('annotator:headers');
return this.element.data('annotator:headers', $.extend(current, { return this.element.data('annotator:headers', $.extend(current, {
'x-annotator-auth-token': this.token 'x-annotator-auth-token': this.token
...@@ -187,12 +211,16 @@ ...@@ -187,12 +211,16 @@
}; };
Auth.prototype.withToken = function(callback) { Auth.prototype.withToken = function(callback) {
if (!(callback != null)) return; if (callback == null) {
return;
}
if (this.haveValidToken()) { if (this.haveValidToken()) {
return callback(this._unsafeToken); return callback(this._unsafeToken);
} else { } else {
this.waitingForToken.push(callback); this.waitingForToken.push(callback);
if (!this.requestInProgress) return this.requestToken(); if (!this.requestInProgress) {
return this.requestToken();
}
} }
}; };
......
/* /*
** Annotator 1.2.6-dev-939cdee ** Annotator 1.2.6-dev-d45a366
** 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: 2013-04-10 07:38:29Z ** Built at: 2013-04-12 00:11:28Z
*/ */
(function() { (function() {
var $, Annotator, Delegator, LinkParser, Range, fn, functions, g, gettext, util, _Annotator, _gettext, _i, _j, _len, _len2, _ref, _ref2, _t, var $, Annotator, Delegator, LinkParser, Range, fn, functions, g, gettext, util, _Annotator, _gettext, _i, _j, _len, _len1, _ref, _ref1, _t,
__slice = Array.prototype.slice, __slice = [].slice,
__hasProp = Object.prototype.hasOwnProperty, __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; }, __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); }; }; __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
gettext = null; gettext = null;
...@@ -47,8 +48,10 @@ ...@@ -47,8 +48,10 @@
$.flatten = function(array) { $.flatten = function(array) {
var flatten; var flatten;
flatten = function(ary) { flatten = function(ary) {
var el, flat, _i, _len; var el, flat, _i, _len;
flat = []; flat = [];
for (_i = 0, _len = ary.length; _i < _len; _i++) { for (_i = 0, _len = ary.length; _i < _len; _i++) {
el = ary[_i]; el = ary[_i];
...@@ -62,9 +65,11 @@ ...@@ -62,9 +65,11 @@
$.plugin = function(name, object) { $.plugin = function(name, object) {
return jQuery.fn[name] = function(options) { return jQuery.fn[name] = function(options) {
var args; var args;
args = Array.prototype.slice.call(arguments, 1); args = Array.prototype.slice.call(arguments, 1);
return this.each(function() { return this.each(function() {
var instance; var instance;
instance = $.data(this, name); instance = $.data(this, name);
if (instance) { if (instance) {
return options && instance[options].apply(instance, args); return options && instance[options].apply(instance, args);
...@@ -78,8 +83,10 @@ ...@@ -78,8 +83,10 @@
$.fn.textNodes = function() { $.fn.textNodes = function() {
var getTextNodes; var getTextNodes;
getTextNodes = function(node) { getTextNodes = function(node) {
var nodes; var nodes;
if (node && node.nodeType !== 3) { if (node && node.nodeType !== 3) {
nodes = []; nodes = [];
if (node.nodeType !== 8) { if (node.nodeType !== 8) {
...@@ -101,8 +108,10 @@ ...@@ -101,8 +108,10 @@
$.fn.xpath = function(relativeRoot) { $.fn.xpath = function(relativeRoot) {
var jq; var jq;
jq = this.map(function() { jq = this.map(function() {
var elem, idx, path; var elem, idx, path;
path = ''; path = '';
elem = this; elem = this;
while (elem && elem.nodeType === 1 && elem !== relativeRoot) { while (elem && elem.nodeType === 1 && elem !== relativeRoot) {
...@@ -121,7 +130,9 @@ ...@@ -121,7 +130,9 @@
}; };
$.fn.escape = function(html) { $.fn.escape = function(html) {
if (arguments.length) return this.html($.escape(html)); if (arguments.length) {
return this.html($.escape(html));
}
return this.html(); return this.html();
}; };
...@@ -130,15 +141,17 @@ ...@@ -130,15 +141,17 @@
functions = ["log", "debug", "info", "warn", "exception", "assert", "dir", "dirxml", "trace", "group", "groupEnd", "groupCollapsed", "time", "timeEnd", "profile", "profileEnd", "count", "clear", "table", "error", "notifyFirebug", "firebug", "userObjects"]; functions = ["log", "debug", "info", "warn", "exception", "assert", "dir", "dirxml", "trace", "group", "groupEnd", "groupCollapsed", "time", "timeEnd", "profile", "profileEnd", "count", "clear", "table", "error", "notifyFirebug", "firebug", "userObjects"];
if (typeof console !== "undefined" && console !== null) { if (typeof console !== "undefined" && console !== null) {
if (!(console.group != null)) { if (console.group == null) {
console.group = function(name) { console.group = function(name) {
return console.log("GROUP: ", name); return console.log("GROUP: ", name);
}; };
} }
if (!(console.groupCollapsed != null)) console.groupCollapsed = console.group; if (console.groupCollapsed == null) {
console.groupCollapsed = console.group;
}
for (_i = 0, _len = functions.length; _i < _len; _i++) { for (_i = 0, _len = functions.length; _i < _len; _i++) {
fn = functions[_i]; fn = functions[_i];
if (!(console[fn] != null)) { if (console[fn] == null) {
console[fn] = function() { console[fn] = function() {
return console.log(_t("Not implemented:") + (" console." + name)); return console.log(_t("Not implemented:") + (" console." + name));
}; };
...@@ -146,24 +159,25 @@ ...@@ -146,24 +159,25 @@
} }
} else { } else {
this.console = {}; this.console = {};
for (_j = 0, _len2 = functions.length; _j < _len2; _j++) { for (_j = 0, _len1 = functions.length; _j < _len1; _j++) {
fn = functions[_j]; fn = functions[_j];
this.console[fn] = function() {}; this.console[fn] = function() {};
} }
this.console['error'] = function() { this.console['error'] = function() {
var args; var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return alert("ERROR: " + (args.join(', '))); return alert("ERROR: " + (args.join(', ')));
}; };
this.console['warn'] = function() { this.console['warn'] = function() {
var args; var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return alert("WARNING: " + (args.join(', '))); return alert("WARNING: " + (args.join(', ')));
}; };
} }
Delegator = (function() { Delegator = (function() {
Delegator.prototype.events = {}; Delegator.prototype.events = {};
Delegator.prototype.options = {}; Delegator.prototype.options = {};
...@@ -178,12 +192,13 @@ ...@@ -178,12 +192,13 @@
} }
Delegator.prototype.addEvents = function() { Delegator.prototype.addEvents = function() {
var event, functionName, sel, selector, _k, _ref2, _ref3, _results; var event, functionName, sel, selector, _k, _ref1, _ref2, _results;
_ref2 = this.events;
_ref1 = this.events;
_results = []; _results = [];
for (sel in _ref2) { for (sel in _ref1) {
functionName = _ref2[sel]; functionName = _ref1[sel];
_ref3 = sel.split(' '), selector = 2 <= _ref3.length ? __slice.call(_ref3, 0, _k = _ref3.length - 1) : (_k = 0, []), event = _ref3[_k++]; _ref2 = sel.split(' '), selector = 2 <= _ref2.length ? __slice.call(_ref2, 0, _k = _ref2.length - 1) : (_k = 0, []), event = _ref2[_k++];
_results.push(this.addEvent(selector.join(' '), event, functionName)); _results.push(this.addEvent(selector.join(' '), event, functionName));
} }
return _results; return _results;
...@@ -192,11 +207,14 @@ ...@@ -192,11 +207,14 @@
Delegator.prototype.addEvent = function(bindTo, event, functionName) { Delegator.prototype.addEvent = function(bindTo, event, functionName) {
var closure, isBlankSelector, var closure, isBlankSelector,
_this = this; _this = this;
closure = function() { closure = function() {
return _this[functionName].apply(_this, arguments); return _this[functionName].apply(_this, arguments);
}; };
isBlankSelector = typeof bindTo === 'string' && bindTo.replace(/\s+/g, '') === ''; isBlankSelector = typeof bindTo === 'string' && bindTo.replace(/\s+/g, '') === '';
if (isBlankSelector) bindTo = this.element; if (isBlankSelector) {
bindTo = this.element;
}
if (typeof bindTo === 'string') { if (typeof bindTo === 'string') {
this.element.delegate(bindTo, event, closure); this.element.delegate(bindTo, event, closure);
} else { } else {
...@@ -221,6 +239,7 @@ ...@@ -221,6 +239,7 @@
Delegator.prototype.subscribe = function(event, callback) { Delegator.prototype.subscribe = function(event, callback) {
var closure; var closure;
closure = function() { closure = function() {
return callback.apply(this, [].slice.call(arguments, 1)); return callback.apply(this, [].slice.call(arguments, 1));
}; };
...@@ -240,13 +259,15 @@ ...@@ -240,13 +259,15 @@
Delegator.natives = (function() { Delegator.natives = (function() {
var key, specials, val; var key, specials, val;
specials = (function() { specials = (function() {
var _ref2, _results; var _ref1, _results;
_ref2 = jQuery.event.special;
_ref1 = jQuery.event.special;
_results = []; _results = [];
for (key in _ref2) { for (key in _ref1) {
if (!__hasProp.call(_ref2, key)) continue; if (!__hasProp.call(_ref1, key)) continue;
val = _ref2[key]; val = _ref1[key];
_results.push(key); _results.push(key);
} }
return _results; return _results;
...@@ -260,13 +281,6 @@ ...@@ -260,13 +281,6 @@
if (r.commonAncestorContainer != null) { if (r.commonAncestorContainer != null) {
return new Range.BrowserRange(r); return new Range.BrowserRange(r);
} else if (typeof r.start === "string") { } else if (typeof r.start === "string") {
return new Range.SerializedRange({
startContainer: r.start,
startOffset: r.startOffset,
endContainer: r.end,
endOffset: r.endOffset
});
} else if (typeof r.startContainer === "string") {
return new Range.SerializedRange(r); return new Range.SerializedRange(r);
} else if (r.start && typeof r.start === "object") { } else if (r.start && typeof r.start === "object") {
return new Range.NormalizedRange(r); return new Range.NormalizedRange(r);
...@@ -278,9 +292,14 @@ ...@@ -278,9 +292,14 @@
Range.nodeFromXPath = function(xpath, root) { Range.nodeFromXPath = function(xpath, root) {
var customResolver, evaluateXPath, namespace, node, segment; var customResolver, evaluateXPath, namespace, node, segment;
if (root == null) root = document;
if (root == null) {
root = document;
}
evaluateXPath = function(xp, nsResolver) { evaluateXPath = function(xp, nsResolver) {
if (nsResolver == null) nsResolver = null; if (nsResolver == null) {
nsResolver = null;
}
return document.evaluate('.' + xp, root, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; return document.evaluate('.' + xp, root, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}; };
if (!$.isXMLDoc(document.documentElement)) { if (!$.isXMLDoc(document.documentElement)) {
...@@ -290,11 +309,12 @@ ...@@ -290,11 +309,12 @@
node = evaluateXPath(xpath, customResolver); node = evaluateXPath(xpath, customResolver);
if (!node) { if (!node) {
xpath = ((function() { xpath = ((function() {
var _k, _len3, _ref2, _results; var _k, _len2, _ref1, _results;
_ref2 = xpath.split('/');
_ref1 = xpath.split('/');
_results = []; _results = [];
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
segment = _ref2[_k]; segment = _ref1[_k];
if (segment && segment.indexOf(':') === -1) { if (segment && segment.indexOf(':') === -1) {
_results.push(segment.replace(/^([a-z]+)/, 'xhtml:$1')); _results.push(segment.replace(/^([a-z]+)/, 'xhtml:$1'));
} else { } else {
...@@ -318,7 +338,6 @@ ...@@ -318,7 +338,6 @@
}; };
Range.RangeError = (function(_super) { Range.RangeError = (function(_super) {
__extends(RangeError, _super); __extends(RangeError, _super);
function RangeError(type, message, parent) { function RangeError(type, message, parent) {
...@@ -333,7 +352,6 @@ ...@@ -333,7 +352,6 @@
})(Error); })(Error);
Range.BrowserRange = (function() { Range.BrowserRange = (function() {
function BrowserRange(obj) { function BrowserRange(obj) {
this.commonAncestorContainer = obj.commonAncestorContainer; this.commonAncestorContainer = obj.commonAncestorContainer;
this.startContainer = obj.startContainer; this.startContainer = obj.startContainer;
...@@ -343,7 +361,8 @@ ...@@ -343,7 +361,8 @@
} }
BrowserRange.prototype.normalize = function(root) { BrowserRange.prototype.normalize = function(root) {
var isImg, it, node, nr, offset, p, r, _k, _len3, _ref2; var it, node, nr, offset, p, r, _k, _len2, _ref1;
if (this.tainted) { if (this.tainted) {
console.error(_t("You may only call normalize() once on a BrowserRange!")); console.error(_t("You may only call normalize() once on a BrowserRange!"));
return false; return false;
...@@ -352,40 +371,34 @@ ...@@ -352,40 +371,34 @@
} }
r = {}; r = {};
nr = {}; nr = {};
_ref2 = ['start', 'end']; _ref1 = ['start', 'end'];
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
p = _ref2[_k]; p = _ref1[_k];
node = this[p + 'Container']; node = this[p + 'Container'];
offset = this[p + 'Offset']; offset = this[p + 'Offset'];
if (node.nodeType === 1) { if (node.nodeType === 1) {
it = node.childNodes[offset]; it = node.childNodes[offset];
node = it || node.childNodes[offset - 1]; node = it || node.childNodes[offset - 1];
isImg = node.nodeType === 1 && node.tagName.toLowerCase() === "img"; if (node.nodeType === 1 && !node.firstChild) {
if (isImg) { it = null;
offset = 0; node = node.previousSibling;
} else {
if (node.nodeType === 1 && !node.firstChild && !isImg) {
it = null;
node = node.previousSibling;
}
while (node.nodeType !== 3) {
node = node.firstChild;
}
offset = it ? 0 : node.nodeValue.length;
} }
while (node.nodeType !== 3) {
node = node.firstChild;
}
offset = it ? 0 : node.nodeValue.length;
} }
r[p] = node; r[p] = node;
r[p + 'Offset'] = offset; r[p + 'Offset'] = offset;
r[p + 'Img'] = isImg;
} }
nr.start = r.startOffset > 0 ? r.start.splitText(r.startOffset) : r.start; nr.start = r.startOffset > 0 ? r.start.splitText(r.startOffset) : r.start;
if (r.start === r.end && !r.startImg) { if (r.start === r.end) {
if ((r.endOffset - r.startOffset) < nr.start.nodeValue.length) { if ((r.endOffset - r.startOffset) < nr.start.nodeValue.length) {
nr.start.splitText(r.endOffset - r.startOffset); nr.start.splitText(r.endOffset - r.startOffset);
} }
nr.end = nr.start; nr.end = nr.start;
} else { } else {
if (r.endOffset < r.end.nodeValue.length && !r.endImg) { if (r.endOffset < r.end.nodeValue.length) {
r.end.splitText(r.endOffset); r.end.splitText(r.endOffset);
} }
nr.end = r.end; nr.end = r.end;
...@@ -394,9 +407,6 @@ ...@@ -394,9 +407,6 @@
while (nr.commonAncestor.nodeType !== 1) { while (nr.commonAncestor.nodeType !== 1) {
nr.commonAncestor = nr.commonAncestor.parentNode; nr.commonAncestor = nr.commonAncestor.parentNode;
} }
if (window.DomTextMapper != null) {
window.DomTextMapper.changed(nr.commonAncestor, "range normalization");
}
return new Range.NormalizedRange(nr); return new Range.NormalizedRange(nr);
}; };
...@@ -409,7 +419,6 @@ ...@@ -409,7 +419,6 @@
})(); })();
Range.NormalizedRange = (function() { Range.NormalizedRange = (function() {
function NormalizedRange(obj) { function NormalizedRange(obj) {
this.commonAncestor = obj.commonAncestor; this.commonAncestor = obj.commonAncestor;
this.start = obj.start; this.start = obj.start;
...@@ -421,17 +430,20 @@ ...@@ -421,17 +430,20 @@
}; };
NormalizedRange.prototype.limit = function(bounds) { NormalizedRange.prototype.limit = function(bounds) {
var nodes, parent, startParents, _k, _len3, _ref2; var nodes, parent, startParents, _k, _len2, _ref1;
nodes = $.grep(this.textNodes(), function(node) { nodes = $.grep(this.textNodes(), function(node) {
return node.parentNode === bounds || $.contains(bounds, node.parentNode); return node.parentNode === bounds || $.contains(bounds, node.parentNode);
}); });
if (!nodes.length) return null; if (!nodes.length) {
return null;
}
this.start = nodes[0]; this.start = nodes[0];
this.end = nodes[nodes.length - 1]; this.end = nodes[nodes.length - 1];
startParents = $(this.start).parents(); startParents = $(this.start).parents();
_ref2 = $(this.end).parents(); _ref1 = $(this.end).parents();
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
parent = _ref2[_k]; parent = _ref1[_k];
if (startParents.index(parent) !== -1) { if (startParents.index(parent) !== -1) {
this.commonAncestor = parent; this.commonAncestor = parent;
break; break;
...@@ -442,8 +454,10 @@ ...@@ -442,8 +454,10 @@
NormalizedRange.prototype.serialize = function(root, ignoreSelector) { NormalizedRange.prototype.serialize = function(root, ignoreSelector) {
var end, serialization, start; var end, serialization, start;
serialization = function(node, isEnd) { serialization = function(node, isEnd) {
var isImg, n, nodes, offset, origParent, textNodes, xpath, _k, _len3; var n, nodes, offset, origParent, textNodes, xpath, _k, _len2;
if (ignoreSelector) { if (ignoreSelector) {
origParent = $(node).parents(":not(" + ignoreSelector + ")").eq(0); origParent = $(node).parents(":not(" + ignoreSelector + ")").eq(0);
} else { } else {
...@@ -453,12 +467,11 @@ ...@@ -453,12 +467,11 @@
textNodes = origParent.textNodes(); textNodes = origParent.textNodes();
nodes = textNodes.slice(0, textNodes.index(node)); nodes = textNodes.slice(0, textNodes.index(node));
offset = 0; offset = 0;
for (_k = 0, _len3 = nodes.length; _k < _len3; _k++) { for (_k = 0, _len2 = nodes.length; _k < _len2; _k++) {
n = nodes[_k]; n = nodes[_k];
offset += n.nodeValue.length; offset += n.nodeValue.length;
} }
isImg = node.nodeType === 1 && node.tagName.toLowerCase() === "img"; if (isEnd) {
if (isEnd && !isImg) {
return [xpath, offset + node.nodeValue.length]; return [xpath, offset + node.nodeValue.length];
} else { } else {
return [xpath, offset]; return [xpath, offset];
...@@ -467,8 +480,8 @@ ...@@ -467,8 +480,8 @@
start = serialization(this.start); start = serialization(this.start);
end = serialization(this.end, true); end = serialization(this.end, true);
return new Range.SerializedRange({ return new Range.SerializedRange({
startContainer: start[0], start: start[0],
endContainer: end[0], end: end[0],
startOffset: start[1], startOffset: start[1],
endOffset: end[1] endOffset: end[1]
}); });
...@@ -476,12 +489,14 @@ ...@@ -476,12 +489,14 @@
NormalizedRange.prototype.text = function() { NormalizedRange.prototype.text = function() {
var node; var node;
return ((function() { return ((function() {
var _k, _len3, _ref2, _results; var _k, _len2, _ref1, _results;
_ref2 = this.textNodes();
_ref1 = this.textNodes();
_results = []; _results = [];
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
node = _ref2[_k]; node = _ref1[_k];
_results.push(node.nodeValue); _results.push(node.nodeValue);
} }
return _results; return _results;
...@@ -489,14 +504,16 @@ ...@@ -489,14 +504,16 @@
}; };
NormalizedRange.prototype.textNodes = function() { NormalizedRange.prototype.textNodes = function() {
var end, start, textNodes, _ref2; var end, start, textNodes, _ref1;
textNodes = $(this.commonAncestor).textNodes(); textNodes = $(this.commonAncestor).textNodes();
_ref2 = [textNodes.index(this.start), textNodes.index(this.end)], start = _ref2[0], end = _ref2[1]; _ref1 = [textNodes.index(this.start), textNodes.index(this.end)], start = _ref1[0], end = _ref1[1];
return $.makeArray(textNodes.slice(start, end + 1 || 9e9)); return $.makeArray(textNodes.slice(start, +end + 1 || 9e9));
}; };
NormalizedRange.prototype.toRange = function() { NormalizedRange.prototype.toRange = function() {
var range; var range;
range = document.createRange(); range = document.createRange();
range.setStartBefore(this.start); range.setStartBefore(this.start);
range.setEndAfter(this.end); range.setEndAfter(this.end);
...@@ -508,33 +525,33 @@ ...@@ -508,33 +525,33 @@
})(); })();
Range.SerializedRange = (function() { Range.SerializedRange = (function() {
function SerializedRange(obj) { function SerializedRange(obj) {
this.startContainer = obj.startContainer; this.start = obj.start;
this.startOffset = obj.startOffset; this.startOffset = obj.startOffset;
this.endContainer = obj.endContainer; this.end = obj.end;
this.endOffset = obj.endOffset; this.endOffset = obj.endOffset;
} }
SerializedRange.prototype.normalize = function(root) { SerializedRange.prototype.normalize = function(root) {
var contains, length, node, p, range, tn, xpath, _k, _l, _len3, _len4, _ref2, _ref3; var contains, e, length, node, p, range, tn, _k, _l, _len2, _len3, _ref1, _ref2;
range = {}; range = {};
_ref2 = ['start', 'end']; _ref1 = ['start', 'end'];
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
p = _ref2[_k]; p = _ref1[_k];
xpath = this[p + 'Container'];
try { try {
node = Range.nodeFromXPath(xpath, root); node = Range.nodeFromXPath(this[p], root);
} catch (e) { } catch (_error) {
throw new Range.RangeError(p, ("Error while finding " + p + " node: " + xpath + ": ") + e, e); e = _error;
throw new Range.RangeError(p, ("Error while finding " + p + " node: " + this[p] + ": ") + e, e);
} }
if (!node) { if (!node) {
throw new Range.RangeError(p, "Couldn't find " + p + " node: " + xpath); throw new Range.RangeError(p, "Couldn't find " + p + " node: " + this[p]);
} }
length = 0; length = 0;
_ref3 = $(node).textNodes(); _ref2 = $(node).textNodes();
for (_l = 0, _len4 = _ref3.length; _l < _len4; _l++) { for (_l = 0, _len3 = _ref2.length; _l < _len3; _l++) {
tn = _ref3[_l]; tn = _ref2[_l];
if (length + tn.nodeValue.length >= this[p + 'Offset']) { if (length + tn.nodeValue.length >= this[p + 'Offset']) {
range[p + 'Container'] = tn; range[p + 'Container'] = tn;
range[p + 'Offset'] = this[p + 'Offset'] - length; range[p + 'Offset'] = this[p + 'Offset'] - length;
...@@ -543,11 +560,11 @@ ...@@ -543,11 +560,11 @@
length += tn.nodeValue.length; length += tn.nodeValue.length;
} }
} }
if (!(range[p + 'Offset'] != null)) { if (range[p + 'Offset'] == null) {
throw new Range.RangeError("" + p + "offset", "Couldn't find offset " + this[p + 'Offset'] + " in element " + this[p]); throw new Range.RangeError("" + p + "offset", "Couldn't find offset " + this[p + 'Offset'] + " in element " + this[p]);
} }
} }
contains = !(document.compareDocumentPosition != null) ? function(a, b) { contains = document.compareDocumentPosition == null ? function(a, b) {
return a.contains(b); return a.contains(b);
} : function(a, b) { } : function(a, b) {
return a.compareDocumentPosition(b) & 16; return a.compareDocumentPosition(b) & 16;
...@@ -567,9 +584,9 @@ ...@@ -567,9 +584,9 @@
SerializedRange.prototype.toObject = function() { SerializedRange.prototype.toObject = function() {
return { return {
startContainer: this.startContainer, start: this.start,
startOffset: this.startOffset, startOffset: this.startOffset,
endContainer: this.endContainer, end: this.end,
endOffset: this.endOffset endOffset: this.endOffset
}; };
}; };
...@@ -581,6 +598,7 @@ ...@@ -581,6 +598,7 @@
util = { util = {
uuid: (function() { uuid: (function() {
var counter; var counter;
counter = 0; counter = 0;
return function() { return function() {
return counter++; return counter++;
...@@ -593,10 +611,12 @@ ...@@ -593,10 +611,12 @@
}, },
maxZIndex: function($elements) { maxZIndex: function($elements) {
var all, el; var all, el;
all = (function() { all = (function() {
var _k, _len3, _results; var _k, _len2, _results;
_results = []; _results = [];
for (_k = 0, _len3 = $elements.length; _k < _len3; _k++) { for (_k = 0, _len2 = $elements.length; _k < _len2; _k++) {
el = $elements[_k]; el = $elements[_k];
if ($(el).css('position') === 'static') { if ($(el).css('position') === 'static') {
_results.push(-1); _results.push(-1);
...@@ -610,7 +630,8 @@ ...@@ -610,7 +630,8 @@
}, },
mousePosition: function(e, offsetEl) { mousePosition: function(e, offsetEl) {
var offset; var offset;
offset = $(offsetEl).offset();
offset = $(offsetEl).position();
return { return {
top: e.pageY - offset.top, top: e.pageY - offset.top,
left: e.pageX - offset.left left: e.pageX - offset.left
...@@ -624,7 +645,6 @@ ...@@ -624,7 +645,6 @@
_Annotator = this.Annotator; _Annotator = this.Annotator;
Annotator = (function(_super) { Annotator = (function(_super) {
__extends(Annotator, _super); __extends(Annotator, _super);
Annotator.prototype.events = { Annotator.prototype.events = {
...@@ -649,7 +669,7 @@ ...@@ -649,7 +669,7 @@
Annotator.prototype.viewer = null; Annotator.prototype.viewer = null;
Annotator.prototype.selectedTargets = null; Annotator.prototype.selectedRanges = null;
Annotator.prototype.mouseIsDown = false; Annotator.prototype.mouseIsDown = false;
...@@ -670,22 +690,19 @@ ...@@ -670,22 +690,19 @@
this.showViewer = __bind(this.showViewer, this); this.showViewer = __bind(this.showViewer, this);
this.onEditorSubmit = __bind(this.onEditorSubmit, this); this.onEditorSubmit = __bind(this.onEditorSubmit, this);
this.onEditorHide = __bind(this.onEditorHide, this); this.onEditorHide = __bind(this.onEditorHide, this);
this.showEditor = __bind(this.showEditor, this); this.showEditor = __bind(this.showEditor, this); Annotator.__super__.constructor.apply(this, arguments);
this.getHref = __bind(this.getHref, this); Annotator.__super__.constructor.apply(this, arguments);
this.plugins = {}; this.plugins = {};
if (!Annotator.supported()) return this; if (!Annotator.supported()) {
if (!this.options.readOnly) this._setupDocumentEvents(); return this;
}
if (!this.options.readOnly) {
this._setupDocumentEvents();
}
this._setupWrapper()._setupViewer()._setupEditor(); this._setupWrapper()._setupViewer()._setupEditor();
this._setupDynamicStyle(); this._setupDynamicStyle();
this.adder = $(this.html.adder).appendTo(this.wrapper).hide(); this.adder = $(this.html.adder).appendTo(this.wrapper).hide();
} }
Annotator.prototype._setupMatching = function() {
this.domMapper = new DomTextMapper();
this.domMatcher = new DomTextMatcher(this.domMapper);
return this;
};
Annotator.prototype._setupWrapper = function() { Annotator.prototype._setupWrapper = function() {
this.wrapper = $(this.html.wrapper); this.wrapper = $(this.html.wrapper);
this.element.find('script').remove(); this.element.find('script').remove();
...@@ -696,6 +713,7 @@ ...@@ -696,6 +713,7 @@
Annotator.prototype._setupViewer = function() { Annotator.prototype._setupViewer = function() {
var _this = this; var _this = this;
this.viewer = new Annotator.Viewer({ this.viewer = new Annotator.Viewer({
readOnly: this.options.readOnly readOnly: this.options.readOnly
}); });
...@@ -741,16 +759,18 @@ ...@@ -741,16 +759,18 @@
Annotator.prototype._setupDynamicStyle = function() { Annotator.prototype._setupDynamicStyle = function() {
var max, sel, style, x; var max, sel, style, x;
style = $('#annotator-dynamic-style'); style = $('#annotator-dynamic-style');
if (!style.length) { if (!style.length) {
style = $('<style id="annotator-dynamic-style"></style>').appendTo(document.head); style = $('<style id="annotator-dynamic-style"></style>').appendTo(document.head);
} }
sel = '*' + ((function() { sel = '*' + ((function() {
var _k, _len3, _ref2, _results; var _k, _len2, _ref1, _results;
_ref2 = ['adder', 'outer', 'notice', 'filter'];
_ref1 = ['adder', 'outer', 'notice', 'filter'];
_results = []; _results = [];
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
x = _ref2[_k]; x = _ref1[_k];
_results.push(":not(.annotator-" + x + ")"); _results.push(":not(.annotator-" + x + ")");
} }
return _results; return _results;
...@@ -761,301 +781,80 @@ ...@@ -761,301 +781,80 @@
return this; return this;
}; };
Annotator.prototype.getHref = function() { Annotator.prototype.getSelectedRanges = function() {
var uri; var browserRange, i, normedRange, r, ranges, rangesToIgnore, selection, _k, _len2;
uri = decodeURIComponent(document.location.href);
if (document.location.hash) uri = uri.slice(0, -1 * location.hash.length);
$('meta[property^="og:url"]').each(function() {
return uri = decodeURIComponent(this.content);
});
$('link[rel^="canonical"]').each(function() {
return uri = decodeURIComponent(this.href);
});
return uri;
};
Annotator.prototype.getRangeSelector = function(range) {
var selector, sr;
sr = range.serialize(this.wrapper[0]);
return selector = {
type: "RangeSelector",
startContainer: sr.startContainer,
startOffset: sr.startOffset,
endContainer: sr.endContainer,
endOffset: sr.endOffset
};
};
Annotator.prototype.getTextQuoteSelector = function(range) {
var endOffset, prefix, quote, selector, startOffset, suffix, _ref2;
startOffset = (this.domMapper.getInfoForNode(range.start)).start;
endOffset = (this.domMapper.getInfoForNode(range.end)).end;
quote = this.domMapper.getContentForCharRange(startOffset, endOffset);
_ref2 = this.domMapper.getContextForCharRange(startOffset, endOffset), prefix = _ref2[0], suffix = _ref2[1];
return selector = {
type: "TextQuoteSelector",
exact: quote,
prefix: prefix,
suffix: suffix
};
};
Annotator.prototype.getTextPositionSelector = function(range) {
var endOffset, selector, startOffset;
startOffset = (this.domMapper.getInfoForNode(range.start)).start;
endOffset = (this.domMapper.getInfoForNode(range.end)).end;
return selector = {
type: "TextPositionSelector",
start: startOffset,
end: endOffset
};
};
Annotator.prototype.getQuoteForTarget = function(target) {
var selector;
selector = this.findSelector(target.selector, "TextQuoteSelector");
if (selector != null) {
return this.normalizeString(selector.exact);
} else {
return null;
}
};
Annotator.prototype.getSelectedTargets = function() {
var browserRange, i, normedRange, r, rangesToIgnore, realRange, selection, source, targets, _k, _len3,
_this = this;
selection = util.getGlobal().getSelection(); selection = util.getGlobal().getSelection();
source = this.getHref(); ranges = [];
targets = [];
rangesToIgnore = []; rangesToIgnore = [];
if (!selection.isCollapsed) { if (!selection.isCollapsed) {
targets = (function() { ranges = (function() {
var _ref2, _results; var _k, _ref1, _results;
_results = []; _results = [];
for (i = 0, _ref2 = selection.rangeCount; 0 <= _ref2 ? i < _ref2 : i > _ref2; 0 <= _ref2 ? i++ : i--) { for (i = _k = 0, _ref1 = selection.rangeCount; 0 <= _ref1 ? _k < _ref1 : _k > _ref1; i = 0 <= _ref1 ? ++_k : --_k) {
realRange = selection.getRangeAt(i); r = selection.getRangeAt(i);
browserRange = new Range.BrowserRange(realRange); browserRange = new Range.BrowserRange(r);
normedRange = browserRange.normalize().limit(this.wrapper[0]); normedRange = browserRange.normalize().limit(this.wrapper[0]);
if (normedRange === null) rangesToIgnore.push(r); if (normedRange === null) {
_results.push({ rangesToIgnore.push(r);
selector: [this.getRangeSelector(normedRange), this.getTextQuoteSelector(normedRange), this.getTextPositionSelector(normedRange)], }
source: source _results.push(normedRange);
});
} }
return _results; return _results;
}).call(this); }).call(this);
selection.removeAllRanges(); selection.removeAllRanges();
} }
for (_k = 0, _len3 = rangesToIgnore.length; _k < _len3; _k++) { for (_k = 0, _len2 = rangesToIgnore.length; _k < _len2; _k++) {
r = rangesToIgnore[_k]; r = rangesToIgnore[_k];
selection.addRange(r); selection.addRange(r);
} }
return $.grep(targets, function(target) { return $.grep(ranges, function(range) {
var range, selector; if (range) {
selector = _this.findSelector(target.selector, "RangeSelector"); selection.addRange(range.toRange());
if (selector != null) {
range = (Range.sniff(selector)).normalize(_this.wrapper[0]);
if (range != null) {
selection.addRange(range.toRange());
return true;
}
} }
return range;
}); });
}; };
Annotator.prototype.createAnnotation = function() { Annotator.prototype.createAnnotation = function() {
var annotation; var annotation;
annotation = {}; annotation = {};
this.publish('beforeAnnotationCreated', [annotation]); this.publish('beforeAnnotationCreated', [annotation]);
return annotation; return annotation;
}; };
Annotator.prototype.normalizeString = function(string) {
return string.replace(/\s{2,}/g, " ");
};
Annotator.prototype.findSelector = function(selectors, type) {
var selector, _k, _len3;
for (_k = 0, _len3 = selectors.length; _k < _len3; _k++) {
selector = selectors[_k];
if (selector.type === type) return selector;
}
return null;
};
Annotator.prototype.findAnchorFromRangeSelector = function(target) {
var content, currentQuote, endInfo, endOffset, normalizedRange, savedQuote, selector, startInfo, startOffset;
selector = this.findSelector(target.selector, "RangeSelector");
if (selector == null) return null;
try {
normalizedRange = Range.sniff(selector).normalize(this.wrapper[0]);
savedQuote = this.getQuoteForTarget(target);
if (savedQuote != null) {
startInfo = this.domMapper.getInfoForNode(normalizedRange.start);
startOffset = startInfo.start;
endInfo = this.domMapper.getInfoForNode(normalizedRange.end);
endOffset = endInfo.end;
content = this.domMapper.getContentForCharRange(startOffset, endOffset);
currentQuote = this.normalizeString(content);
if (currentQuote !== savedQuote) {
console.log("Could not apply XPath selector to current document because the quote has changed. (Saved quote is '" + savedQuote + "'. Current quote is '" + currentQuote + "'.)");
return null;
} else {
console.log("Saved quote matches.");
}
} else {
console.log("No saved quote, nothing to compare. Assume that it's OK.");
}
return {
range: normalizedRange,
quote: savedQuote
};
} catch (exception) {
if (exception instanceof Range.RangeError) {
console.log("Could not apply XPath selector to current document. \ The document structure may have changed.");
return null;
} else {
throw exception;
}
}
};
Annotator.prototype.findAnchorFromPositionSelector = function(target) {
var browserRange, content, currentQuote, mappings, normalizedRange, savedQuote, selector;
selector = this.findSelector(target.selector, "TextPositionSelector");
if (selector == null) return null;
savedQuote = this.getQuoteForTarget(target);
if (savedQuote != null) {
content = this.domMapper.getContentForCharRange(selector.start, selector.end);
currentQuote = this.normalizeString(content);
if (currentQuote !== savedQuote) {
console.log("Could not apply position selector to current document because the quote has changed. (Saved quote is '" + savedQuote + "'. Current quote is '" + currentQuote + "'.)");
return null;
} else {
console.log("Saved quote matches.");
}
} else {
console.log("No saved quote, nothing to compare. Assume that it's okay.");
}
mappings = this.domMapper.getMappingsForCharRange(selector.start, selector.end);
browserRange = new Range.BrowserRange(mappings.realRange);
normalizedRange = browserRange.normalize(this.wrapper[0]);
return {
range: normalizedRange,
quote: savedQuote
};
};
Annotator.prototype.findAnchorWithTwoPhaseFuzzyMatching = function(target) {
var anchor, browserRange, expectedEnd, expectedStart, match, normalizedRange, options, posSelector, prefix, quote, quoteSelector, result, suffix;
quoteSelector = this.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.findSelector(target.selector, "TextPositionSelector");
expectedStart = posSelector != null ? posSelector.start : void 0;
expectedEnd = posSelector != null ? posSelector.end : void 0;
options = {
contextMatchDistance: this.domMapper.getDocLength() * 2,
contextMatchThreshold: 0.5,
patternMatchThreshold: 0.5
};
result = this.domMatcher.searchFuzzyWithContext(prefix, suffix, quote, expectedStart, expectedEnd, false, null, options);
if (!result.matches.length) {
console.log("Fuzzy matching did not return any results. Giving up on two-phase strategy.");
return null;
}
match = result.matches[0];
console.log("Fuzzy found match:");
console.log(match);
browserRange = new Range.BrowserRange(match.realRange);
normalizedRange = browserRange.normalize(this.wrapper[0]);
anchor = {
range: normalizedRange,
quote: !match.exact ? match.found : void 0,
diffHTML: !match.exact ? match.comparison.diffHTML : void 0
};
return anchor;
};
Annotator.prototype.findAnchorWithFuzzyMatching = function(target) {
var anchor, browserRange, expectedStart, len, match, normalizedRange, options, posSelector, quote, quoteSelector, result;
quoteSelector = this.findSelector(target.selector, "TextQuoteSelector");
quote = quoteSelector != null ? quoteSelector.exact : void 0;
if (quote == null) return null;
posSelector = this.findSelector(target.selector, "TextPositionSelector");
expectedStart = posSelector != null ? posSelector.start : void 0;
len = this.domMapper.getDocLength();
if (expectedStart == null) expectedStart = len / 2;
options = {
matchDistance: len,
withFuzzyComparison: true
};
result = this.domMatcher.searchFuzzy(quote, expectedStart, false, null, options);
if (!result.matches.length) {
console.log("Fuzzy matching did not return any results. Giving up on one-phase strategy.");
return null;
}
match = result.matches[0];
console.log("Fuzzy found match:");
console.log(match);
browserRange = new Range.BrowserRange(match.realRange);
normalizedRange = browserRange.normalize(this.wrapper[0]);
anchor = {
range: normalizedRange,
quote: !match.exact ? match.found : void 0,
diffHTML: !match.exact ? match.comparison.diffHTML : void 0
};
return anchor;
};
Annotator.prototype.findAnchor = function(target) {
var anchor;
console.log("Trying to find anchor for target: ");
console.log(target);
anchor = this.findAnchorFromRangeSelector(target);
if (anchor == null) anchor = this.findAnchorFromPositionSelector(target);
if (anchor == null) {
anchor = this.findAnchorWithTwoPhaseFuzzyMatching(target);
}
if (anchor == null) anchor = this.findAnchorWithFuzzyMatching(target);
return anchor;
};
Annotator.prototype.setupAnnotation = function(annotation) { Annotator.prototype.setupAnnotation = function(annotation) {
var anchor, normed, normedRanges, root, t, _k, _l, _len3, _len4, _ref2; var e, normed, normedRanges, r, root, _k, _l, _len2, _len3, _ref1;
root = this.wrapper[0]; root = this.wrapper[0];
annotation.target || (annotation.target = this.selectedTargets); annotation.ranges || (annotation.ranges = this.selectedRanges);
if (!(annotation.target instanceof Array)) {
annotation.target = [annotation.target];
}
normedRanges = []; normedRanges = [];
_ref2 = annotation.target; _ref1 = annotation.ranges;
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
t = _ref2[_k]; r = _ref1[_k];
try { try {
anchor = this.findAnchor(t); normedRanges.push(Range.sniff(r).normalize(root));
if ((anchor != null ? anchor.quote : void 0) != null) { } catch (_error) {
t.quote = anchor.quote; e = _error;
t.diffHTML = anchor.diffHTML; if (e instanceof Range.RangeError) {
} this.publish('rangeNormalizeFail', [annotation, r, e]);
if ((anchor != null ? anchor.range : void 0) != null) {
normedRanges.push(anchor.range);
} else { } else {
console.log("Could not find anchor for annotation target '" + t.id + "' (for annotation '" + annotation.id + "')."); throw e;
} }
} catch (exception) {
if (exception.stack != null) console.log(exception.stack);
console.log(exception.message);
console.log(exception);
} }
} }
annotation.quote = [];
annotation.ranges = [];
annotation.highlights = []; annotation.highlights = [];
for (_l = 0, _len4 = normedRanges.length; _l < _len4; _l++) { for (_l = 0, _len3 = normedRanges.length; _l < _len3; _l++) {
normed = normedRanges[_l]; normed = normedRanges[_l];
annotation.quote.push($.trim(normed.text()));
annotation.ranges.push(normed.serialize(this.wrapper[0], '.annotator-hl'));
$.merge(annotation.highlights, this.highlightRange(normed)); $.merge(annotation.highlights, this.highlightRange(normed));
} }
annotation.quote = annotation.quote.join(' / ');
$(annotation.highlights).data('annotation', annotation); $(annotation.highlights).data('annotation', annotation);
return annotation; return annotation;
}; };
...@@ -1067,15 +866,17 @@ ...@@ -1067,15 +866,17 @@
}; };
Annotator.prototype.deleteAnnotation = function(annotation) { Annotator.prototype.deleteAnnotation = function(annotation) {
var child, h, _k, _len3, _ref2; var child, h, _k, _len2, _ref1;
if (annotation.highlights != null) { if (annotation.highlights != null) {
_ref2 = annotation.highlights; _ref1 = annotation.highlights;
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
h = _ref2[_k]; h = _ref1[_k];
if (!(h.parentNode != null)) continue; if (!(h.parentNode != null)) {
continue;
}
child = h.childNodes[0]; child = h.childNodes[0];
$(h).replaceWith(h.childNodes); $(h).replaceWith(h.childNodes);
window.DomTextMapper.changed(child.parentNode, "removed hilite (annotation deleted)");
} }
} }
this.publish('annotationDeleted', [annotation]); this.publish('annotationDeleted', [annotation]);
...@@ -1085,12 +886,18 @@ ...@@ -1085,12 +886,18 @@
Annotator.prototype.loadAnnotations = function(annotations) { Annotator.prototype.loadAnnotations = function(annotations) {
var clone, loader, var clone, loader,
_this = this; _this = this;
if (annotations == null) annotations = [];
if (annotations == null) {
annotations = [];
}
loader = function(annList) { loader = function(annList) {
var n, now, _k, _len3; var n, now, _k, _len2;
if (annList == null) annList = [];
if (annList == null) {
annList = [];
}
now = annList.splice(0, 10); now = annList.splice(0, 10);
for (_k = 0, _len3 = now.length; _k < _len3; _k++) { for (_k = 0, _len2 = now.length; _k < _len2; _k++) {
n = now[_k]; n = now[_k];
_this.setupAnnotation(n); _this.setupAnnotation(n);
} }
...@@ -1103,7 +910,9 @@ ...@@ -1103,7 +910,9 @@
} }
}; };
clone = annotations.slice(); clone = annotations.slice();
if (annotations.length) loader(annotations); if (annotations.length) {
loader(annotations);
}
return this; return this;
}; };
...@@ -1116,27 +925,32 @@ ...@@ -1116,27 +925,32 @@
}; };
Annotator.prototype.highlightRange = function(normedRange, cssClass) { Annotator.prototype.highlightRange = function(normedRange, cssClass) {
var hl, node, r, white, _k, _len3, _ref2, _results; var hl, node, white, _k, _len2, _ref1, _results;
if (cssClass == null) cssClass = 'annotator-hl';
if (cssClass == null) {
cssClass = 'annotator-hl';
}
white = /^\s*$/; white = /^\s*$/;
hl = $("<span class='" + cssClass + "'></span>"); hl = $("<span class='" + cssClass + "'></span>");
_ref2 = normedRange.textNodes(); _ref1 = normedRange.textNodes();
_results = []; _results = [];
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
node = _ref2[_k]; node = _ref1[_k];
if (!(!white.test(node.nodeValue))) continue; if (!white.test(node.nodeValue)) {
r = $(node).wrapAll(hl).parent().show()[0]; _results.push($(node).wrapAll(hl).parent().show()[0]);
window.DomTextMapper.changed(node, "created hilite"); }
_results.push(r);
} }
return _results; return _results;
}; };
Annotator.prototype.highlightRanges = function(normedRanges, cssClass) { Annotator.prototype.highlightRanges = function(normedRanges, cssClass) {
var highlights, r, _k, _len3; var highlights, r, _k, _len2;
if (cssClass == null) cssClass = 'annotator-hl';
if (cssClass == null) {
cssClass = 'annotator-hl';
}
highlights = []; highlights = [];
for (_k = 0, _len3 = normedRanges.length; _k < _len3; _k++) { for (_k = 0, _len2 = normedRanges.length; _k < _len2; _k++) {
r = normedRanges[_k]; r = normedRanges[_k];
$.merge(highlights, this.highlightRange(r, cssClass)); $.merge(highlights, this.highlightRange(r, cssClass));
} }
...@@ -1145,6 +959,7 @@ ...@@ -1145,6 +959,7 @@
Annotator.prototype.addPlugin = function(name, options) { Annotator.prototype.addPlugin = function(name, options) {
var klass, _base; var klass, _base;
if (this.plugins[name]) { if (this.plugins[name]) {
console.error(_t("You cannot have more than one instance of any plugin.")); console.error(_t("You cannot have more than one instance of any plugin."));
} else { } else {
...@@ -1203,22 +1018,25 @@ ...@@ -1203,22 +1018,25 @@
}; };
Annotator.prototype.checkForEndSelection = function(event) { Annotator.prototype.checkForEndSelection = function(event) {
var container, range, selector, target, _k, _len3, _ref2; var container, range, _k, _len2, _ref1;
this.mouseIsDown = false; this.mouseIsDown = false;
if (this.ignoreMouseup) return; if (this.ignoreMouseup) {
this.selectedTargets = this.getSelectedTargets(); return;
_ref2 = this.selectedTargets; }
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) { this.selectedRanges = this.getSelectedRanges();
target = _ref2[_k]; _ref1 = this.selectedRanges;
selector = this.findSelector(target.selector, "RangeSelector"); for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
range = (Range.sniff(selector)).normalize(this.wrapper[0]); range = _ref1[_k];
container = range.commonAncestor; container = range.commonAncestor;
if ($(container).hasClass('annotator-hl')) { if ($(container).hasClass('annotator-hl')) {
container = $(container).parents('[class^=annotator-hl]')[0]; container = $(container).parents('[class^=annotator-hl]')[0];
} }
if (this.isAnnotator(container)) return; if (this.isAnnotator(container)) {
return;
}
} }
if (event && this.selectedTargets.length) { if (event && this.selectedRanges.length) {
return this.adder.css(util.mousePosition(event, this.wrapper[0])).show(); return this.adder.css(util.mousePosition(event, this.wrapper[0])).show();
} else { } else {
return this.adder.hide(); return this.adder.hide();
...@@ -1231,8 +1049,11 @@ ...@@ -1231,8 +1049,11 @@
Annotator.prototype.onHighlightMouseover = function(event) { Annotator.prototype.onHighlightMouseover = function(event) {
var annotations; var annotations;
this.clearViewerHideTimer(); this.clearViewerHideTimer();
if (this.mouseIsDown || this.viewer.isShown()) return false; if (this.mouseIsDown || this.viewer.isShown()) {
return false;
}
annotations = $(event.target).parents('.annotator-hl').andSelf().map(function() { annotations = $(event.target).parents('.annotator-hl').andSelf().map(function() {
return $(this).data("annotation"); return $(this).data("annotation");
}); });
...@@ -1240,18 +1061,22 @@ ...@@ -1240,18 +1061,22 @@
}; };
Annotator.prototype.onAdderMousedown = function(event) { Annotator.prototype.onAdderMousedown = function(event) {
if (event != null) event.preventDefault(); if (event != null) {
event.preventDefault();
}
return this.ignoreMouseup = true; return this.ignoreMouseup = true;
}; };
Annotator.prototype.onAdderClick = function(event) { Annotator.prototype.onAdderClick = function(event) {
var annotation, cancel, cleanup, position, save, var annotation, cancel, cleanup, position, save,
_this = this; _this = this;
if (event != null) event.preventDefault();
if (event != null) {
event.preventDefault();
}
position = this.adder.position(); position = this.adder.position();
this.adder.hide(); this.adder.hide();
annotation = this.createAnnotation(); annotation = this.setupAnnotation(this.createAnnotation());
annotation = this.setupAnnotation(annotation);
$(annotation.highlights).addClass('annotator-hl-temporary'); $(annotation.highlights).addClass('annotator-hl-temporary');
save = function() { save = function() {
cleanup(); cleanup();
...@@ -1274,6 +1099,7 @@ ...@@ -1274,6 +1099,7 @@
Annotator.prototype.onEditAnnotation = function(annotation) { Annotator.prototype.onEditAnnotation = function(annotation) {
var cleanup, offset, update, var cleanup, offset, update,
_this = this; _this = this;
offset = this.viewer.element.position(); offset = this.viewer.element.position();
update = function() { update = function() {
cleanup(); cleanup();
...@@ -1299,7 +1125,6 @@ ...@@ -1299,7 +1125,6 @@
})(Delegator); })(Delegator);
Annotator.Plugin = (function(_super) { Annotator.Plugin = (function(_super) {
__extends(Plugin, _super); __extends(Plugin, _super);
function Plugin(element, options) { function Plugin(element, options) {
...@@ -1314,15 +1139,15 @@ ...@@ -1314,15 +1139,15 @@
g = util.getGlobal(); g = util.getGlobal();
if (!(((_ref2 = g.document) != null ? _ref2.evaluate : void 0) != null)) { if (((_ref1 = g.document) != null ? _ref1.evaluate : void 0) == null) {
$.getScript('http://assets.annotateit.org/vendor/xpath.min.js'); $.getScript('http://assets.annotateit.org/vendor/xpath.min.js');
} }
if (!(g.getSelection != null)) { if (g.getSelection == null) {
$.getScript('http://assets.annotateit.org/vendor/ierange.min.js'); $.getScript('http://assets.annotateit.org/vendor/ierange.min.js');
} }
if (!(g.JSON != null)) { if (g.JSON == null) {
$.getScript('http://assets.annotateit.org/vendor/json2.min.js'); $.getScript('http://assets.annotateit.org/vendor/json2.min.js');
} }
...@@ -1350,7 +1175,6 @@ ...@@ -1350,7 +1175,6 @@
this.Annotator = Annotator; this.Annotator = Annotator;
Annotator.Widget = (function(_super) { Annotator.Widget = (function(_super) {
__extends(Widget, _super); __extends(Widget, _super);
Widget.prototype.classes = { Widget.prototype.classes = {
...@@ -1368,6 +1192,7 @@ ...@@ -1368,6 +1192,7 @@
Widget.prototype.checkOrientation = function() { Widget.prototype.checkOrientation = function() {
var current, offset, viewport, widget, window; var current, offset, viewport, widget, window;
this.resetOrientation(); this.resetOrientation();
window = $(util.getGlobal()); window = $(util.getGlobal());
widget = this.element.children(":first"); widget = this.element.children(":first");
...@@ -1380,8 +1205,12 @@ ...@@ -1380,8 +1205,12 @@
top: offset.top, top: offset.top,
right: offset.left + widget.width() right: offset.left + widget.width()
}; };
if ((current.top - viewport.top) < 0) this.invertY(); if ((current.top - viewport.top) < 0) {
if ((current.right - viewport.right) > 0) this.invertX(); this.invertY();
}
if ((current.right - viewport.right) > 0) {
this.invertX();
}
return this; return this;
}; };
...@@ -1413,7 +1242,6 @@ ...@@ -1413,7 +1242,6 @@
})(Delegator); })(Delegator);
Annotator.Editor = (function(_super) { Annotator.Editor = (function(_super) {
__extends(Editor, _super); __extends(Editor, _super);
Editor.prototype.events = { Editor.prototype.events = {
...@@ -1461,23 +1289,25 @@ ...@@ -1461,23 +1289,25 @@
}; };
Editor.prototype.load = function(annotation) { Editor.prototype.load = function(annotation) {
var field, _k, _len3, _ref3; var field, _k, _len2, _ref2;
this.annotation = annotation; this.annotation = annotation;
this.publish('load', [this.annotation]); this.publish('load', [this.annotation]);
_ref3 = this.fields; _ref2 = this.fields;
for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
field = _ref3[_k]; field = _ref2[_k];
field.load(field.element, this.annotation); field.load(field.element, this.annotation);
} }
return this.show(); return this.show();
}; };
Editor.prototype.submit = function(event) { Editor.prototype.submit = function(event) {
var field, _k, _len3, _ref3; var field, _k, _len2, _ref2;
util.preventEventDefault(event); util.preventEventDefault(event);
_ref3 = this.fields; _ref2 = this.fields;
for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
field = _ref3[_k]; field = _ref2[_k];
field.submit(field.element, this.annotation); field.submit(field.element, this.annotation);
} }
this.publish('save', [this.annotation]); this.publish('save', [this.annotation]);
...@@ -1486,6 +1316,7 @@ ...@@ -1486,6 +1316,7 @@
Editor.prototype.addField = function(options) { Editor.prototype.addField = function(options) {
var element, field, input; var element, field, input;
field = $.extend({ field = $.extend({
id: 'annotator-field-' + util.uuid(), id: 'annotator-field-' + util.uuid(),
type: 'input', type: 'input',
...@@ -1524,6 +1355,7 @@ ...@@ -1524,6 +1355,7 @@
Editor.prototype.checkOrientation = function() { Editor.prototype.checkOrientation = function() {
var controls, list; var controls, list;
Editor.__super__.checkOrientation.apply(this, arguments); Editor.__super__.checkOrientation.apply(this, arguments);
list = this.element.find('ul'); list = this.element.find('ul');
controls = this.element.find('.annotator-controls'); controls = this.element.find('.annotator-controls');
...@@ -1550,6 +1382,7 @@ ...@@ -1550,6 +1382,7 @@
Editor.prototype.setupDraggables = function() { Editor.prototype.setupDraggables = function() {
var classes, controls, cornerItem, editor, mousedown, onMousedown, onMousemove, onMouseup, resize, textarea, throttle, var classes, controls, cornerItem, editor, mousedown, onMousedown, onMousemove, onMouseup, resize, textarea, throttle,
_this = this; _this = this;
this.element.find('.annotator-resize').remove(); this.element.find('.annotator-resize').remove();
if (this.element.hasClass(this.classes.invert.y)) { if (this.element.hasClass(this.classes.invert.y)) {
cornerItem = this.element.find('.annotator-item:last'); cornerItem = this.element.find('.annotator-item:last');
...@@ -1587,6 +1420,7 @@ ...@@ -1587,6 +1420,7 @@
}; };
onMousemove = function(event) { onMousemove = function(event) {
var diff, directionX, directionY, height, width; var diff, directionX, directionY, height, width;
if (mousedown && throttle === false) { if (mousedown && throttle === false) {
diff = { diff = {
top: event.pageY - mousedown.top, top: event.pageY - mousedown.top,
...@@ -1599,8 +1433,12 @@ ...@@ -1599,8 +1433,12 @@
directionY = editor.hasClass(classes.invert.y) ? 1 : -1; directionY = editor.hasClass(classes.invert.y) ? 1 : -1;
textarea.height(height + (diff.top * directionY)); textarea.height(height + (diff.top * directionY));
textarea.width(width + (diff.left * directionX)); textarea.width(width + (diff.left * directionX));
if (textarea.outerHeight() !== height) mousedown.top = event.pageY; if (textarea.outerHeight() !== height) {
if (textarea.outerWidth() !== width) mousedown.left = event.pageX; mousedown.top = event.pageY;
}
if (textarea.outerWidth() !== width) {
mousedown.left = event.pageX;
}
} else if (mousedown.element === controls[0]) { } else if (mousedown.element === controls[0]) {
editor.css({ editor.css({
top: parseInt(editor.css('top'), 10) + diff.top, top: parseInt(editor.css('top'), 10) + diff.top,
...@@ -1624,7 +1462,6 @@ ...@@ -1624,7 +1462,6 @@
})(Annotator.Widget); })(Annotator.Widget);
Annotator.Viewer = (function(_super) { Annotator.Viewer = (function(_super) {
__extends(Viewer, _super); __extends(Viewer, _super);
Viewer.prototype.events = { Viewer.prototype.events = {
...@@ -1660,6 +1497,7 @@ ...@@ -1660,6 +1497,7 @@
Viewer.prototype.show = function(event) { Viewer.prototype.show = function(event) {
var controls, var controls,
_this = this; _this = this;
util.preventEventDefault(event); util.preventEventDefault(event);
controls = this.element.find('.annotator-controls').addClass(this.classes.showControls); controls = this.element.find('.annotator-controls').addClass(this.classes.showControls);
setTimeout((function() { setTimeout((function() {
...@@ -1680,12 +1518,13 @@ ...@@ -1680,12 +1518,13 @@
}; };
Viewer.prototype.load = function(annotations) { Viewer.prototype.load = function(annotations) {
var annotation, controller, controls, del, edit, element, field, item, link, links, list, _k, _l, _len3, _len4, _ref3, _ref4; var annotation, controller, controls, del, edit, element, field, item, link, links, list, _k, _l, _len2, _len3, _ref2, _ref3;
this.annotations = annotations || []; this.annotations = annotations || [];
list = this.element.find('ul:first').empty(); list = this.element.find('ul:first').empty();
_ref3 = this.annotations; _ref2 = this.annotations;
for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
annotation = _ref3[_k]; annotation = _ref2[_k];
item = $(this.item).clone().appendTo(list).data('annotation', annotation); item = $(this.item).clone().appendTo(list).data('annotation', annotation);
controls = item.find('.annotator-controls'); controls = item.find('.annotator-controls');
link = controls.find('.annotator-link'); link = controls.find('.annotator-link');
...@@ -1694,7 +1533,7 @@ ...@@ -1694,7 +1533,7 @@
links = new LinkParser(annotation.links || []).get('alternate', { links = new LinkParser(annotation.links || []).get('alternate', {
'type': 'text/html' 'type': 'text/html'
}); });
if (links.length === 0 || !(links[0].href != null)) { if (links.length === 0 || (links[0].href == null)) {
link.remove(); link.remove();
} else { } else {
link.attr('href', links[0].href); link.attr('href', links[0].href);
...@@ -1718,9 +1557,9 @@ ...@@ -1718,9 +1557,9 @@
} }
}; };
} }
_ref4 = this.fields; _ref3 = this.fields;
for (_l = 0, _len4 = _ref4.length; _l < _len4; _l++) { for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
field = _ref4[_l]; field = _ref3[_l];
element = $(field.element).clone().appendTo(item)[0]; element = $(field.element).clone().appendTo(item)[0];
field.load(element, annotation, controller); field.load(element, annotation, controller);
} }
...@@ -1731,6 +1570,7 @@ ...@@ -1731,6 +1570,7 @@
Viewer.prototype.addField = function(options) { Viewer.prototype.addField = function(options) {
var field; var field;
field = $.extend({ field = $.extend({
load: function() {} load: function() {}
}, options); }, options);
...@@ -1750,6 +1590,7 @@ ...@@ -1750,6 +1590,7 @@
Viewer.prototype.onButtonClick = function(event, type) { Viewer.prototype.onButtonClick = function(event, type) {
var item; var item;
item = $(event.target).parents('.annotator-annotation'); item = $(event.target).parents('.annotator-annotation');
return this.publish(type, [item.data('annotation')]); return this.publish(type, [item.data('annotation')]);
}; };
...@@ -1759,19 +1600,22 @@ ...@@ -1759,19 +1600,22 @@
})(Annotator.Widget); })(Annotator.Widget);
LinkParser = (function() { LinkParser = (function() {
function LinkParser(data) { function LinkParser(data) {
this.data = data; this.data = data;
} }
LinkParser.prototype.get = function(rel, cond) { LinkParser.prototype.get = function(rel, cond) {
var d, k, keys, match, v, _k, _len3, _ref3, _results; var d, k, keys, match, v, _k, _len2, _ref2, _results;
if (cond == null) cond = {};
if (cond == null) {
cond = {};
}
cond = $.extend({}, cond, { cond = $.extend({}, cond, {
rel: rel rel: rel
}); });
keys = (function() { keys = (function() {
var _results; var _results;
_results = []; _results = [];
for (k in cond) { for (k in cond) {
if (!__hasProp.call(cond, k)) continue; if (!__hasProp.call(cond, k)) continue;
...@@ -1780,10 +1624,10 @@ ...@@ -1780,10 +1624,10 @@
} }
return _results; return _results;
})(); })();
_ref3 = this.data; _ref2 = this.data;
_results = []; _results = [];
for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) { for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
d = _ref3[_k]; d = _ref2[_k];
match = keys.reduce((function(m, k) { match = keys.reduce((function(m, k) {
return m && (d[k] === cond[k]); return m && (d[k] === cond[k]);
}), true); }), true);
...@@ -1803,7 +1647,6 @@ ...@@ -1803,7 +1647,6 @@
Annotator = Annotator || {}; Annotator = Annotator || {};
Annotator.Notification = (function(_super) { Annotator.Notification = (function(_super) {
__extends(Notification, _super); __extends(Notification, _super);
Notification.prototype.events = { Notification.prototype.events = {
...@@ -1826,7 +1669,9 @@ ...@@ -1826,7 +1669,9 @@
} }
Notification.prototype.show = function(message, status) { Notification.prototype.show = function(message, status) {
if (status == null) status = Annotator.Notification.INFO; if (status == null) {
status = Annotator.Notification.INFO;
}
$(this.element).addClass(this.options.classes.show).addClass(this.options.classes[status]).escape(message || ""); $(this.element).addClass(this.options.classes.show).addClass(this.options.classes[status]).escape(message || "");
setTimeout(this.hide, 5000); setTimeout(this.hide, 5000);
return this; return this;
...@@ -1849,6 +1694,7 @@ ...@@ -1849,6 +1694,7 @@
$(function() { $(function() {
var notification; var notification;
notification = new Annotator.Notification; notification = new Annotator.Notification;
Annotator.showNotification = notification.show; Annotator.showNotification = notification.show;
return Annotator.hideNotification = notification.hide; return Annotator.hideNotification = notification.hide;
......
/* /*
** Annotator 1.2.6-dev-939cdee ** Annotator 1.2.6-dev-d45a366
** 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: 2013-04-10 07:38:36Z ** Built at: 2013-04-12 00:11:37Z
*/ */
(function() { (function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = Object.prototype.hasOwnProperty, __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; }; __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.Permissions = (function(_super) { Annotator.Plugin.Permissions = (function(_super) {
__extends(Permissions, _super); __extends(Permissions, _super);
Permissions.prototype.events = { Permissions.prototype.events = {
...@@ -33,12 +33,17 @@ ...@@ -33,12 +33,17 @@
}, },
userAuthorize: function(action, annotation, user) { userAuthorize: function(action, annotation, user) {
var token, tokens, _i, _len; var token, tokens, _i, _len;
if (annotation.permissions) { if (annotation.permissions) {
tokens = annotation.permissions[action] || []; tokens = annotation.permissions[action] || [];
if (tokens.length === 0) return true; if (tokens.length === 0) {
return true;
}
for (_i = 0, _len = tokens.length; _i < _len; _i++) { for (_i = 0, _len = tokens.length; _i < _len; _i++) {
token = tokens[_i]; token = tokens[_i];
if (this.userId(user) === token) return true; if (this.userId(user) === token) {
return true;
}
} }
return false; return false;
} else if (annotation.user) { } else if (annotation.user) {
...@@ -70,7 +75,10 @@ ...@@ -70,7 +75,10 @@
Permissions.prototype.pluginInit = function() { Permissions.prototype.pluginInit = function() {
var createCallback, self, var createCallback, self,
_this = this; _this = this;
if (!Annotator.supported()) return;
if (!Annotator.supported()) {
return;
}
self = this; self = this;
createCallback = function(method, type) { createCallback = function(method, type) {
return function(field, annotation) { return function(field, annotation) {
...@@ -105,12 +113,17 @@ ...@@ -105,12 +113,17 @@
property: 'user', property: 'user',
isFiltered: function(input, user) { isFiltered: function(input, user) {
var keyword, _i, _len, _ref; var keyword, _i, _len, _ref;
user = _this.options.userString(user); user = _this.options.userString(user);
if (!(input && user)) return false; if (!(input && user)) {
return false;
}
_ref = input.split(/\s*/); _ref = input.split(/\s*/);
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
keyword = _ref[_i]; keyword = _ref[_i];
if (user.indexOf(keyword) === -1) return false; if (user.indexOf(keyword) === -1) {
return false;
}
} }
return true; return true;
} }
...@@ -125,12 +138,16 @@ ...@@ -125,12 +138,16 @@
Permissions.prototype.addFieldsToAnnotation = function(annotation) { Permissions.prototype.addFieldsToAnnotation = function(annotation) {
if (annotation) { if (annotation) {
annotation.permissions = this.options.permissions; annotation.permissions = this.options.permissions;
if (this.user) return annotation.user = this.user; if (this.user) {
return annotation.user = this.user;
}
} }
}; };
Permissions.prototype.authorize = function(action, annotation, user) { Permissions.prototype.authorize = function(action, annotation, user) {
if (user === void 0) user = this.user; if (user === void 0) {
user = this.user;
}
if (this.options.userAuthorize) { if (this.options.userAuthorize) {
return this.options.userAuthorize.call(this.options, action, annotation, user); return this.options.userAuthorize.call(this.options, action, annotation, user);
} else { } else {
...@@ -140,9 +157,12 @@ ...@@ -140,9 +157,12 @@
Permissions.prototype.updatePermissionsField = function(action, field, annotation) { Permissions.prototype.updatePermissionsField = function(action, field, annotation) {
var input; var input;
field = $(field).show(); field = $(field).show();
input = field.find('input').removeAttr('disabled'); input = field.find('input').removeAttr('disabled');
if (!this.authorize('admin', annotation)) field.hide(); if (!this.authorize('admin', annotation)) {
field.hide();
}
if (this.authorize(action, annotation || {}, null)) { if (this.authorize(action, annotation || {}, null)) {
return input.attr('checked', 'checked'); return input.attr('checked', 'checked');
} else { } else {
...@@ -152,6 +172,7 @@ ...@@ -152,6 +172,7 @@
Permissions.prototype.updateAnnotationPermissions = function(type, field, annotation) { Permissions.prototype.updateAnnotationPermissions = function(type, field, annotation) {
var dataKey; var dataKey;
if (!annotation.permissions) { if (!annotation.permissions) {
annotation.permissions = this.options.permissions; annotation.permissions = this.options.permissions;
} }
...@@ -165,6 +186,7 @@ ...@@ -165,6 +186,7 @@
Permissions.prototype.updateViewer = function(field, annotation, controls) { Permissions.prototype.updateViewer = function(field, annotation, controls) {
var user, username; var user, username;
field = $(field); field = $(field);
username = this.options.userString(annotation.user); username = this.options.userString(annotation.user);
if (annotation.user && username && typeof username === 'string') { if (annotation.user && username && typeof username === 'string') {
...@@ -174,8 +196,12 @@ ...@@ -174,8 +196,12 @@
field.remove(); field.remove();
} }
if (controls) { if (controls) {
if (!this.authorize('update', annotation)) controls.hideEdit(); if (!this.authorize('update', annotation)) {
if (!this.authorize('delete', annotation)) return controls.hideDelete(); controls.hideEdit();
}
if (!this.authorize('delete', annotation)) {
return controls.hideDelete();
}
} }
}; };
......
/* /*
** Annotator 1.2.6-dev-939cdee ** Annotator 1.2.6-dev-d45a366
** 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: 2013-04-10 07:38:36Z ** Built at: 2013-04-12 00:11:38Z
*/ */
(function() { (function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = Object.prototype.hasOwnProperty, __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; }, __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 = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; __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.Store = (function(_super) { Annotator.Plugin.Store = (function(_super) {
__extends(Store, _super); __extends(Store, _super);
Store.prototype.events = { Store.prototype.events = {
...@@ -48,7 +48,9 @@ ...@@ -48,7 +48,9 @@
} }
Store.prototype.pluginInit = function() { Store.prototype.pluginInit = function() {
if (!Annotator.supported()) return; if (!Annotator.supported()) {
return;
}
if (this.annotator.plugins.Auth) { if (this.annotator.plugins.Auth) {
return this.annotator.plugins.Auth.withToken(this._getAnnotations); return this.annotator.plugins.Auth.withToken(this._getAnnotations);
} else { } else {
...@@ -66,10 +68,11 @@ ...@@ -66,10 +68,11 @@
Store.prototype.annotationCreated = function(annotation) { Store.prototype.annotationCreated = function(annotation) {
var _this = this; var _this = this;
if (__indexOf.call(this.annotations, annotation) < 0) { if (__indexOf.call(this.annotations, annotation) < 0) {
this.registerAnnotation(annotation); this.registerAnnotation(annotation);
return this._apiRequest('create', annotation, function(data) { return this._apiRequest('create', annotation, function(data) {
if (!(data.id != null)) { if (data.id == null) {
console.warn(Annotator._t("Warning: No ID returned from server for annotation "), annotation); console.warn(Annotator._t("Warning: No ID returned from server for annotation "), annotation);
} }
return _this.updateAnnotation(annotation, data); return _this.updateAnnotation(annotation, data);
...@@ -81,6 +84,7 @@ ...@@ -81,6 +84,7 @@
Store.prototype.annotationUpdated = function(annotation) { Store.prototype.annotationUpdated = function(annotation) {
var _this = this; var _this = this;
if (__indexOf.call(this.annotations, annotation) >= 0) { if (__indexOf.call(this.annotations, annotation) >= 0) {
return this._apiRequest('update', annotation, (function(data) { return this._apiRequest('update', annotation, (function(data) {
return _this.updateAnnotation(annotation, data); return _this.updateAnnotation(annotation, data);
...@@ -90,6 +94,7 @@ ...@@ -90,6 +94,7 @@
Store.prototype.annotationDeleted = function(annotation) { Store.prototype.annotationDeleted = function(annotation) {
var _this = this; var _this = this;
if (__indexOf.call(this.annotations, annotation) >= 0) { if (__indexOf.call(this.annotations, annotation) >= 0) {
return this._apiRequest('destroy', annotation, (function() { return this._apiRequest('destroy', annotation, (function() {
return _this.unregisterAnnotation(annotation); return _this.unregisterAnnotation(annotation);
...@@ -119,7 +124,9 @@ ...@@ -119,7 +124,9 @@
}; };
Store.prototype._onLoadAnnotations = function(data) { Store.prototype._onLoadAnnotations = function(data) {
if (data == null) data = []; if (data == null) {
data = [];
}
this.annotations = this.annotations.concat(data); this.annotations = this.annotations.concat(data);
return this.annotator.loadAnnotations(data.slice()); return this.annotator.loadAnnotations(data.slice());
}; };
...@@ -129,12 +136,15 @@ ...@@ -129,12 +136,15 @@
}; };
Store.prototype._onLoadAnnotationsFromSearch = function(data) { Store.prototype._onLoadAnnotationsFromSearch = function(data) {
if (data == null) data = {}; if (data == null) {
data = {};
}
return this._onLoadAnnotations(data.rows || []); return this._onLoadAnnotations(data.rows || []);
}; };
Store.prototype.dumpAnnotations = function() { Store.prototype.dumpAnnotations = function() {
var ann, _i, _len, _ref, _results; var ann, _i, _len, _ref, _results;
_ref = this.annotations; _ref = this.annotations;
_results = []; _results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) { for (_i = 0, _len = _ref.length; _i < _len; _i++) {
...@@ -146,6 +156,7 @@ ...@@ -146,6 +156,7 @@
Store.prototype._apiRequest = function(action, obj, onSuccess) { Store.prototype._apiRequest = function(action, obj, onSuccess) {
var id, options, request, url; var id, options, request, url;
id = obj && obj.id; id = obj && obj.id;
url = this._urlFor(action, id); url = this._urlFor(action, id);
options = this._apiRequestOptions(action, obj, onSuccess); options = this._apiRequestOptions(action, obj, onSuccess);
...@@ -157,6 +168,7 @@ ...@@ -157,6 +168,7 @@
Store.prototype._apiRequestOptions = function(action, obj, onSuccess) { Store.prototype._apiRequestOptions = function(action, obj, onSuccess) {
var data, method, opts; var data, method, opts;
method = this._methodFor(action); method = this._methodFor(action);
opts = { opts = {
type: method, type: method,
...@@ -182,7 +194,9 @@ ...@@ -182,7 +194,9 @@
opts.data = { opts.data = {
json: data json: data
}; };
if (this.options.emulateHTTP) opts.data._method = method; if (this.options.emulateHTTP) {
opts.data._method = method;
}
return opts; return opts;
} }
opts = $.extend(opts, { opts = $.extend(opts, {
...@@ -194,6 +208,7 @@ ...@@ -194,6 +208,7 @@
Store.prototype._urlFor = function(action, id) { Store.prototype._urlFor = function(action, id) {
var url; var url;
url = this.options.prefix != null ? this.options.prefix : ''; url = this.options.prefix != null ? this.options.prefix : '';
url += this.options.urls[action]; url += this.options.urls[action];
url = url.replace(/\/:id/, id != null ? '/' + id : ''); url = url.replace(/\/:id/, id != null ? '/' + id : '');
...@@ -203,6 +218,7 @@ ...@@ -203,6 +218,7 @@
Store.prototype._methodFor = function(action) { Store.prototype._methodFor = function(action) {
var table; var table;
table = { table = {
'create': 'POST', 'create': 'POST',
'read': 'GET', 'read': 'GET',
...@@ -215,16 +231,20 @@ ...@@ -215,16 +231,20 @@
Store.prototype._dataFor = function(annotation) { Store.prototype._dataFor = function(annotation) {
var data, highlights; var data, highlights;
highlights = annotation.highlights; highlights = annotation.highlights;
delete annotation.highlights; delete annotation.highlights;
$.extend(annotation, this.options.annotationData); $.extend(annotation, this.options.annotationData);
data = JSON.stringify(annotation); data = JSON.stringify(annotation);
if (highlights) annotation.highlights = highlights; if (highlights) {
annotation.highlights = highlights;
}
return data; return data;
}; };
Store.prototype._onError = function(xhr) { Store.prototype._onError = function(xhr) {
var action, message; var action, message;
action = xhr._action; action = xhr._action;
message = Annotator._t("Sorry we could not ") + action + Annotator._t(" this annotation"); message = Annotator._t("Sorry we could not ") + action + Annotator._t(" this annotation");
if (xhr._action === 'search') { if (xhr._action === 'search') {
......
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