Commit 871ed38b authored by csillag's avatar csillag

Update to latest annotator.

Fixes #378.

However, this introduces many things into Annotator,
might break other stuff.
parent cc2329f2
/*
** Annotator 1.2.6-dev-b660660
** Annotator 1.2.6-dev-383514e
** 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: 2013-04-12 17:10:52Z
** Built at: 2013-04-09 22:06:02Z
*/
(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; };
__hasProp = Object.prototype.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[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 : {
......@@ -54,7 +40,6 @@
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 {
......@@ -63,9 +48,7 @@
ac = 0;
dec = "";
tmp_arr = [];
if (!data) {
return data;
}
if (!data) return data;
data += '';
while (i < data.length) {
h1 = b64.indexOf(data.charAt(i++));
......@@ -89,11 +72,10 @@
};
base64UrlDecode = function(data) {
var i, m, _i, _ref;
var i, m, _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) {
for (i = 0, _ref = 4 - m; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
data += '=';
}
}
......@@ -104,12 +86,12 @@
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 = {
......@@ -130,7 +112,6 @@
Auth.prototype.requestToken = function() {
var _this = this;
this.requestInProgress = true;
return $.ajax({
url: this.options.tokenUrl,
......@@ -142,7 +123,6 @@
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);
......@@ -154,7 +134,6 @@
Auth.prototype.setToken = function(token) {
var _results,
_this = this;
this.token = token;
this._unsafeToken = parseToken(token);
if (this.haveValidToken()) {
......@@ -182,14 +161,12 @@
Auth.prototype.haveValidToken = function() {
var allFields;
allFields = this._unsafeToken && this._unsafeToken.issuedAt && this._unsafeToken.ttl && this._unsafeToken.consumerKey;
return allFields && this.timeToExpiry() > 0;
};
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;
......@@ -203,7 +180,6 @@
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
......@@ -211,16 +187,12 @@
};
Auth.prototype.withToken = function(callback) {
if (callback == null) {
return;
}
if (!(callback != null)) return;
if (this.haveValidToken()) {
return callback(this._unsafeToken);
} else {
this.waitingForToken.push(callback);
if (!this.requestInProgress) {
return this.requestToken();
}
if (!this.requestInProgress) return this.requestToken();
}
};
......
/*
** Annotator 1.2.6-dev-b660660
** Annotator 1.2.6-dev-939cdee
** 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: 2013-04-12 17:10:44Z
** Built at: 2013-04-12 22:18:50Z
*/
(function() {
var $, Annotator, Delegator, LinkParser, Range, fn, functions, g, gettext, util, _Annotator, _gettext, _i, _j, _len, _len1, _ref, _ref1, _t,
__slice = [].slice,
__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; },
var $, Annotator, Delegator, LinkParser, Range, fn, functions, g, gettext, util, _Annotator, _gettext, _i, _j, _len, _len2, _ref, _ref2, _t,
__slice = Array.prototype.slice,
__hasProp = Object.prototype.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); }; };
gettext = null;
......@@ -48,10 +47,8 @@
$.flatten = function(array) {
var flatten;
flatten = function(ary) {
var el, flat, _i, _len;
flat = [];
for (_i = 0, _len = ary.length; _i < _len; _i++) {
el = ary[_i];
......@@ -65,11 +62,9 @@
$.plugin = function(name, object) {
return jQuery.fn[name] = function(options) {
var args;
args = Array.prototype.slice.call(arguments, 1);
return this.each(function() {
var instance;
instance = $.data(this, name);
if (instance) {
return options && instance[options].apply(instance, args);
......@@ -83,10 +78,8 @@
$.fn.textNodes = function() {
var getTextNodes;
getTextNodes = function(node) {
var nodes;
if (node && node.nodeType !== 3) {
nodes = [];
if (node.nodeType !== 8) {
......@@ -108,10 +101,8 @@
$.fn.xpath = function(relativeRoot) {
var jq;
jq = this.map(function() {
var elem, idx, path;
path = '';
elem = this;
while (elem && elem.nodeType === 1 && elem !== relativeRoot) {
......@@ -130,9 +121,7 @@
};
$.fn.escape = function(html) {
if (arguments.length) {
return this.html($.escape(html));
}
if (arguments.length) return this.html($.escape(html));
return this.html();
};
......@@ -141,17 +130,15 @@
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 (console.group == null) {
if (!(console.group != null)) {
console.group = function(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++) {
fn = functions[_i];
if (console[fn] == null) {
if (!(console[fn] != null)) {
console[fn] = function() {
return console.log(_t("Not implemented:") + (" console." + name));
};
......@@ -159,25 +146,24 @@
}
} else {
this.console = {};
for (_j = 0, _len1 = functions.length; _j < _len1; _j++) {
for (_j = 0, _len2 = functions.length; _j < _len2; _j++) {
fn = functions[_j];
this.console[fn] = function() {};
}
this.console['error'] = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return alert("ERROR: " + (args.join(', ')));
};
this.console['warn'] = function() {
var args;
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
return alert("WARNING: " + (args.join(', ')));
};
}
Delegator = (function() {
Delegator.prototype.events = {};
Delegator.prototype.options = {};
......@@ -192,13 +178,12 @@
}
Delegator.prototype.addEvents = function() {
var event, functionName, sel, selector, _k, _ref1, _ref2, _results;
_ref1 = this.events;
var event, functionName, sel, selector, _k, _ref2, _ref3, _results;
_ref2 = this.events;
_results = [];
for (sel in _ref1) {
functionName = _ref1[sel];
_ref2 = sel.split(' '), selector = 2 <= _ref2.length ? __slice.call(_ref2, 0, _k = _ref2.length - 1) : (_k = 0, []), event = _ref2[_k++];
for (sel in _ref2) {
functionName = _ref2[sel];
_ref3 = sel.split(' '), selector = 2 <= _ref3.length ? __slice.call(_ref3, 0, _k = _ref3.length - 1) : (_k = 0, []), event = _ref3[_k++];
_results.push(this.addEvent(selector.join(' '), event, functionName));
}
return _results;
......@@ -207,14 +192,11 @@
Delegator.prototype.addEvent = function(bindTo, event, functionName) {
var closure, isBlankSelector,
_this = this;
closure = function() {
return _this[functionName].apply(_this, arguments);
};
isBlankSelector = typeof bindTo === 'string' && bindTo.replace(/\s+/g, '') === '';
if (isBlankSelector) {
bindTo = this.element;
}
if (isBlankSelector) bindTo = this.element;
if (typeof bindTo === 'string') {
this.element.delegate(bindTo, event, closure);
} else {
......@@ -239,7 +221,6 @@
Delegator.prototype.subscribe = function(event, callback) {
var closure;
closure = function() {
return callback.apply(this, [].slice.call(arguments, 1));
};
......@@ -259,15 +240,13 @@
Delegator.natives = (function() {
var key, specials, val;
specials = (function() {
var _ref1, _results;
_ref1 = jQuery.event.special;
var _ref2, _results;
_ref2 = jQuery.event.special;
_results = [];
for (key in _ref1) {
if (!__hasProp.call(_ref1, key)) continue;
val = _ref1[key];
for (key in _ref2) {
if (!__hasProp.call(_ref2, key)) continue;
val = _ref2[key];
_results.push(key);
}
return _results;
......@@ -299,14 +278,9 @@
Range.nodeFromXPath = function(xpath, root) {
var customResolver, evaluateXPath, namespace, node, segment;
if (root == null) {
root = document;
}
if (root == null) root = document;
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;
};
if (!$.isXMLDoc(document.documentElement)) {
......@@ -316,12 +290,11 @@
node = evaluateXPath(xpath, customResolver);
if (!node) {
xpath = ((function() {
var _k, _len2, _ref1, _results;
_ref1 = xpath.split('/');
var _k, _len3, _ref2, _results;
_ref2 = xpath.split('/');
_results = [];
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
segment = _ref1[_k];
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) {
segment = _ref2[_k];
if (segment && segment.indexOf(':') === -1) {
_results.push(segment.replace(/^([a-z]+)/, 'xhtml:$1'));
} else {
......@@ -345,6 +318,7 @@
};
Range.RangeError = (function(_super) {
__extends(RangeError, _super);
function RangeError(type, message, parent) {
......@@ -359,6 +333,7 @@
})(Error);
Range.BrowserRange = (function() {
function BrowserRange(obj) {
this.commonAncestorContainer = obj.commonAncestorContainer;
this.startContainer = obj.startContainer;
......@@ -368,8 +343,7 @@
}
BrowserRange.prototype.normalize = function(root) {
var isImg, it, node, nr, offset, p, r, _k, _len2, _ref1;
var isImg, it, node, nr, offset, p, r, _k, _len3, _ref2, _ref3;
if (this.tainted) {
console.error(_t("You may only call normalize() once on a BrowserRange!"));
return false;
......@@ -378,23 +352,23 @@
}
r = {};
nr = {};
_ref1 = ['start', 'end'];
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
p = _ref1[_k];
_ref2 = ['start', 'end'];
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) {
p = _ref2[_k];
node = this[p + 'Container'];
offset = this[p + 'Offset'];
if (node.nodeType === 1) {
if (node.nodeType === Node.ELEMENT_NODE) {
it = node.childNodes[offset];
node = it || node.childNodes[offset - 1];
isImg = node.nodeType === 1 && node.tagName.toLowerCase() === "img";
isImg = node.nodeType === Node.ELEMENT_NODE && node.tagName.toLowerCase() === "img";
if (isImg) {
offset = 0;
} else {
if (node.nodeType === 1 && !node.firstChild && !isImg) {
while (node.nodeType === Node.ELEMENT_NODE && !node.firstChild && !isImg) {
it = null;
node = node.previousSibling;
}
while (node.nodeType !== 3) {
while (node.nodeType !== Node.TEXT_NODE) {
node = node.firstChild;
}
offset = it ? 0 : node.nodeValue.length;
......@@ -411,7 +385,7 @@
}
nr.end = nr.start;
} else {
if (r.endOffset < r.end.nodeValue.length && !r.endImg) {
if ((0 < (_ref3 = r.endOffset) && _ref3 < r.end.nodeValue.length) && !r.endImg) {
r.end.splitText(r.endOffset);
}
nr.end = r.end;
......@@ -435,6 +409,7 @@
})();
Range.NormalizedRange = (function() {
function NormalizedRange(obj) {
this.commonAncestor = obj.commonAncestor;
this.start = obj.start;
......@@ -446,20 +421,17 @@
};
NormalizedRange.prototype.limit = function(bounds) {
var nodes, parent, startParents, _k, _len2, _ref1;
var nodes, parent, startParents, _k, _len3, _ref2;
nodes = $.grep(this.textNodes(), function(node) {
return node.parentNode === bounds || $.contains(bounds, node.parentNode);
});
if (!nodes.length) {
return null;
}
if (!nodes.length) return null;
this.start = nodes[0];
this.end = nodes[nodes.length - 1];
startParents = $(this.start).parents();
_ref1 = $(this.end).parents();
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
parent = _ref1[_k];
_ref2 = $(this.end).parents();
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) {
parent = _ref2[_k];
if (startParents.index(parent) !== -1) {
this.commonAncestor = parent;
break;
......@@ -470,10 +442,8 @@
NormalizedRange.prototype.serialize = function(root, ignoreSelector) {
var end, serialization, start;
serialization = function(node, isEnd) {
var isImg, n, nodes, offset, origParent, textNodes, xpath, _k, _len2;
var isImg, n, nodes, offset, origParent, textNodes, xpath, _k, _len3;
if (ignoreSelector) {
origParent = $(node).parents(":not(" + ignoreSelector + ")").eq(0);
} else {
......@@ -483,7 +453,7 @@
textNodes = origParent.textNodes();
nodes = textNodes.slice(0, textNodes.index(node));
offset = 0;
for (_k = 0, _len2 = nodes.length; _k < _len2; _k++) {
for (_k = 0, _len3 = nodes.length; _k < _len3; _k++) {
n = nodes[_k];
offset += n.nodeValue.length;
}
......@@ -506,14 +476,12 @@
NormalizedRange.prototype.text = function() {
var node;
return ((function() {
var _k, _len2, _ref1, _results;
_ref1 = this.textNodes();
var _k, _len3, _ref2, _results;
_ref2 = this.textNodes();
_results = [];
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
node = _ref1[_k];
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) {
node = _ref2[_k];
_results.push(node.nodeValue);
}
return _results;
......@@ -521,16 +489,14 @@
};
NormalizedRange.prototype.textNodes = function() {
var end, start, textNodes, _ref1;
var end, start, textNodes, _ref2;
textNodes = $(this.commonAncestor).textNodes();
_ref1 = [textNodes.index(this.start), textNodes.index(this.end)], start = _ref1[0], end = _ref1[1];
return $.makeArray(textNodes.slice(start, +end + 1 || 9e9));
_ref2 = [textNodes.index(this.start), textNodes.index(this.end)], start = _ref2[0], end = _ref2[1];
return $.makeArray(textNodes.slice(start, end + 1 || 9e9));
};
NormalizedRange.prototype.toRange = function() {
var range;
range = document.createRange();
range.setStartBefore(this.start);
range.setEndAfter(this.end);
......@@ -542,6 +508,7 @@
})();
Range.SerializedRange = (function() {
function SerializedRange(obj) {
this.startContainer = obj.startContainer;
this.startOffset = obj.startOffset;
......@@ -550,26 +517,24 @@
}
SerializedRange.prototype.normalize = function(root) {
var contains, e, length, node, p, range, tn, xpath, _k, _l, _len2, _len3, _ref1, _ref2;
var contains, length, node, p, range, tn, xpath, _k, _l, _len3, _len4, _ref2, _ref3;
range = {};
_ref1 = ['start', 'end'];
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
p = _ref1[_k];
_ref2 = ['start', 'end'];
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) {
p = _ref2[_k];
xpath = this[p + 'Container'];
try {
node = Range.nodeFromXPath(xpath, root);
} catch (_error) {
e = _error;
} catch (e) {
throw new Range.RangeError(p, ("Error while finding " + p + " node: " + xpath + ": ") + e, e);
}
if (!node) {
throw new Range.RangeError(p, "Couldn't find " + p + " node: " + xpath);
}
length = 0;
_ref2 = $(node).textNodes();
for (_l = 0, _len3 = _ref2.length; _l < _len3; _l++) {
tn = _ref2[_l];
_ref3 = $(node).textNodes();
for (_l = 0, _len4 = _ref3.length; _l < _len4; _l++) {
tn = _ref3[_l];
if (length + tn.nodeValue.length >= this[p + 'Offset']) {
range[p + 'Container'] = tn;
range[p + 'Offset'] = this[p + 'Offset'] - length;
......@@ -578,11 +543,11 @@
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]);
}
}
contains = document.compareDocumentPosition == null ? function(a, b) {
contains = !(document.compareDocumentPosition != null) ? function(a, b) {
return a.contains(b);
} : function(a, b) {
return a.compareDocumentPosition(b) & 16;
......@@ -616,7 +581,6 @@
util = {
uuid: (function() {
var counter;
counter = 0;
return function() {
return counter++;
......@@ -629,12 +593,10 @@
},
maxZIndex: function($elements) {
var all, el;
all = (function() {
var _k, _len2, _results;
var _k, _len3, _results;
_results = [];
for (_k = 0, _len2 = $elements.length; _k < _len2; _k++) {
for (_k = 0, _len3 = $elements.length; _k < _len3; _k++) {
el = $elements[_k];
if ($(el).css('position') === 'static') {
_results.push(-1);
......@@ -648,8 +610,7 @@
},
mousePosition: function(e, offsetEl) {
var offset;
offset = $(offsetEl).position();
offset = $(offsetEl).offset();
return {
top: e.pageY - offset.top,
left: e.pageX - offset.left
......@@ -663,6 +624,7 @@
_Annotator = this.Annotator;
Annotator = (function(_super) {
__extends(Annotator, _super);
Annotator.prototype.events = {
......@@ -711,12 +673,8 @@
this.showEditor = __bind(this.showEditor, this);
this.getHref = __bind(this.getHref, this); Annotator.__super__.constructor.apply(this, arguments);
this.plugins = {};
if (!Annotator.supported()) {
return this;
}
if (!this.options.readOnly) {
this._setupDocumentEvents();
}
if (!Annotator.supported()) return this;
if (!this.options.readOnly) this._setupDocumentEvents();
this._setupWrapper()._setupViewer()._setupEditor();
this._setupDynamicStyle();
this.adder = $(this.html.adder).appendTo(this.wrapper).hide();
......@@ -738,7 +696,6 @@
Annotator.prototype._setupViewer = function() {
var _this = this;
this.viewer = new Annotator.Viewer({
readOnly: this.options.readOnly
});
......@@ -784,18 +741,16 @@
Annotator.prototype._setupDynamicStyle = function() {
var max, sel, style, x;
style = $('#annotator-dynamic-style');
if (!style.length) {
style = $('<style id="annotator-dynamic-style"></style>').appendTo(document.head);
}
sel = '*' + ((function() {
var _k, _len2, _ref1, _results;
_ref1 = ['adder', 'outer', 'notice', 'filter'];
var _k, _len3, _ref2, _results;
_ref2 = ['adder', 'outer', 'notice', 'filter'];
_results = [];
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
x = _ref1[_k];
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) {
x = _ref2[_k];
_results.push(":not(.annotator-" + x + ")");
}
return _results;
......@@ -808,11 +763,8 @@
Annotator.prototype.getHref = function() {
var uri;
uri = decodeURIComponent(document.location.href);
if (document.location.hash) {
uri = uri.slice(0, -1 * location.hash.length);
}
if (document.location.hash) uri = uri.slice(0, -1 * location.hash.length);
$('meta[property^="og:url"]').each(function() {
return uri = decodeURIComponent(this.content);
});
......@@ -824,7 +776,6 @@
Annotator.prototype.getRangeSelector = function(range) {
var selector, sr;
sr = range.serialize(this.wrapper[0]);
return selector = {
type: "RangeSelector",
......@@ -836,12 +787,11 @@
};
Annotator.prototype.getTextQuoteSelector = function(range) {
var endOffset, prefix, quote, selector, startOffset, suffix, _ref1;
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);
_ref1 = this.domMapper.getContextForCharRange(startOffset, endOffset), prefix = _ref1[0], suffix = _ref1[1];
_ref2 = this.domMapper.getContextForCharRange(startOffset, endOffset), prefix = _ref2[0], suffix = _ref2[1];
return selector = {
type: "TextQuoteSelector",
exact: quote,
......@@ -852,7 +802,6 @@
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 = {
......@@ -864,7 +813,6 @@
Annotator.prototype.getQuoteForTarget = function(target) {
var selector;
selector = this.findSelector(target.selector, "TextQuoteSelector");
if (selector != null) {
return this.normalizeString(selector.exact);
......@@ -874,25 +822,21 @@
};
Annotator.prototype.getSelectedTargets = function() {
var browserRange, i, normedRange, r, rangesToIgnore, realRange, selection, source, targets, _k, _len2,
var browserRange, i, normedRange, r, rangesToIgnore, realRange, selection, source, targets, _k, _len3,
_this = this;
selection = util.getGlobal().getSelection();
source = this.getHref();
targets = [];
rangesToIgnore = [];
if (!selection.isCollapsed) {
targets = (function() {
var _k, _ref1, _results;
var _ref2, _results;
_results = [];
for (i = _k = 0, _ref1 = selection.rangeCount; 0 <= _ref1 ? _k < _ref1 : _k > _ref1; i = 0 <= _ref1 ? ++_k : --_k) {
for (i = 0, _ref2 = selection.rangeCount; 0 <= _ref2 ? i < _ref2 : i > _ref2; 0 <= _ref2 ? i++ : i--) {
realRange = selection.getRangeAt(i);
browserRange = new Range.BrowserRange(realRange);
normedRange = browserRange.normalize().limit(this.wrapper[0]);
if (normedRange === null) {
rangesToIgnore.push(r);
}
if (normedRange === null) rangesToIgnore.push(r);
_results.push({
selector: [this.getRangeSelector(normedRange), this.getTextQuoteSelector(normedRange), this.getTextPositionSelector(normedRange)],
source: source
......@@ -902,13 +846,12 @@
}).call(this);
selection.removeAllRanges();
}
for (_k = 0, _len2 = rangesToIgnore.length; _k < _len2; _k++) {
for (_k = 0, _len3 = rangesToIgnore.length; _k < _len3; _k++) {
r = rangesToIgnore[_k];
selection.addRange(r);
}
return $.grep(targets, function(target) {
var range, selector;
selector = _this.findSelector(target.selector, "RangeSelector");
if (selector != null) {
range = (Range.sniff(selector)).normalize(_this.wrapper[0]);
......@@ -922,7 +865,6 @@
Annotator.prototype.createAnnotation = function() {
var annotation;
annotation = {};
this.publish('beforeAnnotationCreated', [annotation]);
return annotation;
......@@ -933,24 +875,18 @@
};
Annotator.prototype.findSelector = function(selectors, type) {
var selector, _k, _len2;
for (_k = 0, _len2 = selectors.length; _k < _len2; _k++) {
var selector, _k, _len3;
for (_k = 0, _len3 = selectors.length; _k < _len3; _k++) {
selector = selectors[_k];
if (selector.type === type) {
return selector;
}
if (selector.type === type) return selector;
}
return null;
};
Annotator.prototype.findAnchorFromRangeSelector = function(target) {
var content, currentQuote, endInfo, endOffset, exception, normalizedRange, savedQuote, selector, startInfo, startOffset;
var content, currentQuote, endInfo, endOffset, normalizedRange, savedQuote, selector, startInfo, startOffset;
selector = this.findSelector(target.selector, "RangeSelector");
if (selector == null) {
return null;
}
if (selector == null) return null;
try {
normalizedRange = Range.sniff(selector).normalize(this.wrapper[0]);
savedQuote = this.getQuoteForTarget(target);
......@@ -974,8 +910,7 @@
range: normalizedRange,
quote: savedQuote
};
} catch (_error) {
exception = _error;
} 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;
......@@ -987,11 +922,8 @@
Annotator.prototype.findAnchorFromPositionSelector = function(target) {
var browserRange, content, currentQuote, mappings, normalizedRange, savedQuote, selector;
selector = this.findSelector(target.selector, "TextPositionSelector");
if (selector == null) {
return null;
}
if (selector == null) return null;
savedQuote = this.getQuoteForTarget(target);
if (savedQuote != null) {
content = this.domMapper.getContentForCharRange(selector.start, selector.end);
......@@ -1016,14 +948,11 @@
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;
}
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;
......@@ -1052,18 +981,13 @@
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;
}
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;
}
if (expectedStart == null) expectedStart = len / 2;
options = {
matchDistance: len,
withFuzzyComparison: true
......@@ -1088,34 +1012,28 @@
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.findAnchorFromPositionSelector(target);
if (anchor == null) {
anchor = this.findAnchorWithTwoPhaseFuzzyMatching(target);
}
if (anchor == null) {
anchor = this.findAnchorWithFuzzyMatching(target);
}
if (anchor == null) anchor = this.findAnchorWithFuzzyMatching(target);
return anchor;
};
Annotator.prototype.setupAnnotation = function(annotation) {
var anchor, exception, normed, normedRanges, root, t, _k, _l, _len2, _len3, _ref1;
var anchor, normed, normedRanges, root, t, _k, _l, _len3, _len4, _ref2;
root = this.wrapper[0];
annotation.target || (annotation.target = this.selectedTargets);
if (!(annotation.target instanceof Array)) {
annotation.target = [annotation.target];
}
normedRanges = [];
_ref1 = annotation.target;
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
t = _ref1[_k];
_ref2 = annotation.target;
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) {
t = _ref2[_k];
try {
anchor = this.findAnchor(t);
if ((anchor != null ? anchor.quote : void 0) != null) {
......@@ -1127,17 +1045,14 @@
} else {
console.log("Could not find anchor for annotation target '" + t.id + "' (for annotation '" + annotation.id + "').");
}
} catch (_error) {
exception = _error;
if (exception.stack != null) {
console.log(exception.stack);
}
} catch (exception) {
if (exception.stack != null) console.log(exception.stack);
console.log(exception.message);
console.log(exception);
}
}
annotation.highlights = [];
for (_l = 0, _len3 = normedRanges.length; _l < _len3; _l++) {
for (_l = 0, _len4 = normedRanges.length; _l < _len4; _l++) {
normed = normedRanges[_l];
$.merge(annotation.highlights, this.highlightRange(normed));
}
......@@ -1152,15 +1067,12 @@
};
Annotator.prototype.deleteAnnotation = function(annotation) {
var child, h, _k, _len2, _ref1;
var child, h, _k, _len3, _ref2;
if (annotation.highlights != null) {
_ref1 = annotation.highlights;
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
h = _ref1[_k];
if (!(h.parentNode != null)) {
continue;
}
_ref2 = annotation.highlights;
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) {
h = _ref2[_k];
if (!(h.parentNode != null)) continue;
child = h.childNodes[0];
$(h).replaceWith(h.childNodes);
window.DomTextMapper.changed(child.parentNode, "removed hilite (annotation deleted)");
......@@ -1173,18 +1085,12 @@
Annotator.prototype.loadAnnotations = function(annotations) {
var clone, loader,
_this = this;
if (annotations == null) {
annotations = [];
}
if (annotations == null) annotations = [];
loader = function(annList) {
var n, now, _k, _len2;
if (annList == null) {
annList = [];
}
var n, now, _k, _len3;
if (annList == null) annList = [];
now = annList.splice(0, 10);
for (_k = 0, _len2 = now.length; _k < _len2; _k++) {
for (_k = 0, _len3 = now.length; _k < _len3; _k++) {
n = now[_k];
_this.setupAnnotation(n);
}
......@@ -1197,9 +1103,7 @@
}
};
clone = annotations.slice();
if (annotations.length) {
loader(annotations);
}
if (annotations.length) loader(annotations);
return this;
};
......@@ -1212,20 +1116,15 @@
};
Annotator.prototype.highlightRange = function(normedRange, cssClass) {
var hl, node, r, white, _k, _len2, _ref1, _results;
if (cssClass == null) {
cssClass = 'annotator-hl';
}
var hl, node, r, white, _k, _len3, _ref2, _results;
if (cssClass == null) cssClass = 'annotator-hl';
white = /^\s*$/;
hl = $("<span class='" + cssClass + "'></span>");
_ref1 = normedRange.textNodes();
_ref2 = normedRange.textNodes();
_results = [];
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
node = _ref1[_k];
if (!(!white.test(node.nodeValue))) {
continue;
}
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) {
node = _ref2[_k];
if (!(!white.test(node.nodeValue))) continue;
r = $(node).wrapAll(hl).parent().show()[0];
window.DomTextMapper.changed(node, "created hilite");
_results.push(r);
......@@ -1234,13 +1133,10 @@
};
Annotator.prototype.highlightRanges = function(normedRanges, cssClass) {
var highlights, r, _k, _len2;
if (cssClass == null) {
cssClass = 'annotator-hl';
}
var highlights, r, _k, _len3;
if (cssClass == null) cssClass = 'annotator-hl';
highlights = [];
for (_k = 0, _len2 = normedRanges.length; _k < _len2; _k++) {
for (_k = 0, _len3 = normedRanges.length; _k < _len3; _k++) {
r = normedRanges[_k];
$.merge(highlights, this.highlightRange(r, cssClass));
}
......@@ -1249,7 +1145,6 @@
Annotator.prototype.addPlugin = function(name, options) {
var klass, _base;
if (this.plugins[name]) {
console.error(_t("You cannot have more than one instance of any plugin."));
} else {
......@@ -1308,25 +1203,20 @@
};
Annotator.prototype.checkForEndSelection = function(event) {
var container, range, selector, target, _k, _len2, _ref1;
var container, range, selector, target, _k, _len3, _ref2;
this.mouseIsDown = false;
if (this.ignoreMouseup) {
return;
}
if (this.ignoreMouseup) return;
this.selectedTargets = this.getSelectedTargets();
_ref1 = this.selectedTargets;
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
target = _ref1[_k];
_ref2 = this.selectedTargets;
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) {
target = _ref2[_k];
selector = this.findSelector(target.selector, "RangeSelector");
range = (Range.sniff(selector)).normalize(this.wrapper[0]);
container = range.commonAncestor;
if ($(container).hasClass('annotator-hl')) {
container = $(container).parents('[class^=annotator-hl]')[0];
}
if (this.isAnnotator(container)) {
return;
}
if (this.isAnnotator(container)) return;
}
if (event && this.selectedTargets.length) {
return this.adder.css(util.mousePosition(event, this.wrapper[0])).show();
......@@ -1341,11 +1231,8 @@
Annotator.prototype.onHighlightMouseover = function(event) {
var annotations;
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() {
return $(this).data("annotation");
});
......@@ -1353,19 +1240,14 @@
};
Annotator.prototype.onAdderMousedown = function(event) {
if (event != null) {
event.preventDefault();
}
if (event != null) event.preventDefault();
return this.ignoreMouseup = true;
};
Annotator.prototype.onAdderClick = function(event) {
var annotation, cancel, cleanup, position, save,
_this = this;
if (event != null) {
event.preventDefault();
}
if (event != null) event.preventDefault();
position = this.adder.position();
this.adder.hide();
annotation = this.createAnnotation();
......@@ -1392,7 +1274,6 @@
Annotator.prototype.onEditAnnotation = function(annotation) {
var cleanup, offset, update,
_this = this;
offset = this.viewer.element.position();
update = function() {
cleanup();
......@@ -1418,6 +1299,7 @@
})(Delegator);
Annotator.Plugin = (function(_super) {
__extends(Plugin, _super);
function Plugin(element, options) {
......@@ -1432,15 +1314,15 @@
g = util.getGlobal();
if (((_ref1 = g.document) != null ? _ref1.evaluate : void 0) == null) {
if (!(((_ref2 = g.document) != null ? _ref2.evaluate : void 0) != null)) {
$.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');
}
if (g.JSON == null) {
if (!(g.JSON != null)) {
$.getScript('http://assets.annotateit.org/vendor/json2.min.js');
}
......@@ -1468,6 +1350,7 @@
this.Annotator = Annotator;
Annotator.Widget = (function(_super) {
__extends(Widget, _super);
Widget.prototype.classes = {
......@@ -1485,7 +1368,6 @@
Widget.prototype.checkOrientation = function() {
var current, offset, viewport, widget, window;
this.resetOrientation();
window = $(util.getGlobal());
widget = this.element.children(":first");
......@@ -1498,12 +1380,8 @@
top: offset.top,
right: offset.left + widget.width()
};
if ((current.top - viewport.top) < 0) {
this.invertY();
}
if ((current.right - viewport.right) > 0) {
this.invertX();
}
if ((current.top - viewport.top) < 0) this.invertY();
if ((current.right - viewport.right) > 0) this.invertX();
return this;
};
......@@ -1535,6 +1413,7 @@
})(Delegator);
Annotator.Editor = (function(_super) {
__extends(Editor, _super);
Editor.prototype.events = {
......@@ -1582,25 +1461,23 @@
};
Editor.prototype.load = function(annotation) {
var field, _k, _len2, _ref2;
var field, _k, _len3, _ref3;
this.annotation = annotation;
this.publish('load', [this.annotation]);
_ref2 = this.fields;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
field = _ref2[_k];
_ref3 = this.fields;
for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) {
field = _ref3[_k];
field.load(field.element, this.annotation);
}
return this.show();
};
Editor.prototype.submit = function(event) {
var field, _k, _len2, _ref2;
var field, _k, _len3, _ref3;
util.preventEventDefault(event);
_ref2 = this.fields;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
field = _ref2[_k];
_ref3 = this.fields;
for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) {
field = _ref3[_k];
field.submit(field.element, this.annotation);
}
this.publish('save', [this.annotation]);
......@@ -1609,7 +1486,6 @@
Editor.prototype.addField = function(options) {
var element, field, input;
field = $.extend({
id: 'annotator-field-' + util.uuid(),
type: 'input',
......@@ -1648,7 +1524,6 @@
Editor.prototype.checkOrientation = function() {
var controls, list;
Editor.__super__.checkOrientation.apply(this, arguments);
list = this.element.find('ul');
controls = this.element.find('.annotator-controls');
......@@ -1675,7 +1550,6 @@
Editor.prototype.setupDraggables = function() {
var classes, controls, cornerItem, editor, mousedown, onMousedown, onMousemove, onMouseup, resize, textarea, throttle,
_this = this;
this.element.find('.annotator-resize').remove();
if (this.element.hasClass(this.classes.invert.y)) {
cornerItem = this.element.find('.annotator-item:last');
......@@ -1713,7 +1587,6 @@
};
onMousemove = function(event) {
var diff, directionX, directionY, height, width;
if (mousedown && throttle === false) {
diff = {
top: event.pageY - mousedown.top,
......@@ -1726,12 +1599,8 @@
directionY = editor.hasClass(classes.invert.y) ? 1 : -1;
textarea.height(height + (diff.top * directionY));
textarea.width(width + (diff.left * directionX));
if (textarea.outerHeight() !== height) {
mousedown.top = event.pageY;
}
if (textarea.outerWidth() !== width) {
mousedown.left = event.pageX;
}
if (textarea.outerHeight() !== height) mousedown.top = event.pageY;
if (textarea.outerWidth() !== width) mousedown.left = event.pageX;
} else if (mousedown.element === controls[0]) {
editor.css({
top: parseInt(editor.css('top'), 10) + diff.top,
......@@ -1755,6 +1624,7 @@
})(Annotator.Widget);
Annotator.Viewer = (function(_super) {
__extends(Viewer, _super);
Viewer.prototype.events = {
......@@ -1790,7 +1660,6 @@
Viewer.prototype.show = function(event) {
var controls,
_this = this;
util.preventEventDefault(event);
controls = this.element.find('.annotator-controls').addClass(this.classes.showControls);
setTimeout((function() {
......@@ -1811,13 +1680,12 @@
};
Viewer.prototype.load = function(annotations) {
var annotation, controller, controls, del, edit, element, field, item, link, links, list, _k, _l, _len2, _len3, _ref2, _ref3;
var annotation, controller, controls, del, edit, element, field, item, link, links, list, _k, _l, _len3, _len4, _ref3, _ref4;
this.annotations = annotations || [];
list = this.element.find('ul:first').empty();
_ref2 = this.annotations;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
annotation = _ref2[_k];
_ref3 = this.annotations;
for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) {
annotation = _ref3[_k];
item = $(this.item).clone().appendTo(list).data('annotation', annotation);
controls = item.find('.annotator-controls');
link = controls.find('.annotator-link');
......@@ -1826,7 +1694,7 @@
links = new LinkParser(annotation.links || []).get('alternate', {
'type': 'text/html'
});
if (links.length === 0 || (links[0].href == null)) {
if (links.length === 0 || !(links[0].href != null)) {
link.remove();
} else {
link.attr('href', links[0].href);
......@@ -1850,9 +1718,9 @@
}
};
}
_ref3 = this.fields;
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
field = _ref3[_l];
_ref4 = this.fields;
for (_l = 0, _len4 = _ref4.length; _l < _len4; _l++) {
field = _ref4[_l];
element = $(field.element).clone().appendTo(item)[0];
field.load(element, annotation, controller);
}
......@@ -1863,7 +1731,6 @@
Viewer.prototype.addField = function(options) {
var field;
field = $.extend({
load: function() {}
}, options);
......@@ -1883,7 +1750,6 @@
Viewer.prototype.onButtonClick = function(event, type) {
var item;
item = $(event.target).parents('.annotator-annotation');
return this.publish(type, [item.data('annotation')]);
};
......@@ -1893,22 +1759,19 @@
})(Annotator.Widget);
LinkParser = (function() {
function LinkParser(data) {
this.data = data;
}
LinkParser.prototype.get = function(rel, cond) {
var d, k, keys, match, v, _k, _len2, _ref2, _results;
if (cond == null) {
cond = {};
}
var d, k, keys, match, v, _k, _len3, _ref3, _results;
if (cond == null) cond = {};
cond = $.extend({}, cond, {
rel: rel
});
keys = (function() {
var _results;
_results = [];
for (k in cond) {
if (!__hasProp.call(cond, k)) continue;
......@@ -1917,10 +1780,10 @@
}
return _results;
})();
_ref2 = this.data;
_ref3 = this.data;
_results = [];
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
d = _ref2[_k];
for (_k = 0, _len3 = _ref3.length; _k < _len3; _k++) {
d = _ref3[_k];
match = keys.reduce((function(m, k) {
return m && (d[k] === cond[k]);
}), true);
......@@ -1940,6 +1803,7 @@
Annotator = Annotator || {};
Annotator.Notification = (function(_super) {
__extends(Notification, _super);
Notification.prototype.events = {
......@@ -1962,9 +1826,7 @@
}
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 || "");
setTimeout(this.hide, 5000);
return this;
......@@ -1987,7 +1849,6 @@
$(function() {
var notification;
notification = new Annotator.Notification;
Annotator.showNotification = notification.show;
return Annotator.hideNotification = notification.hide;
......
/*
** Annotator 1.2.6-dev-b660660
** Annotator 1.2.6-dev-383514e
** 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: 2013-04-12 17:10:54Z
** Built at: 2013-04-09 22:05:49Z
*/
(function() {
var __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; };
__hasProp = Object.prototype.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.Permissions = (function(_super) {
__extends(Permissions, _super);
Permissions.prototype.events = {
......@@ -33,17 +33,12 @@
},
userAuthorize: function(action, annotation, user) {
var token, tokens, _i, _len;
if (annotation.permissions) {
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++) {
token = tokens[_i];
if (this.userId(user) === token) {
return true;
}
if (this.userId(user) === token) return true;
}
return false;
} else if (annotation.user) {
......@@ -75,10 +70,7 @@
Permissions.prototype.pluginInit = function() {
var createCallback, self,
_this = this;
if (!Annotator.supported()) {
return;
}
if (!Annotator.supported()) return;
self = this;
createCallback = function(method, type) {
return function(field, annotation) {
......@@ -113,17 +105,12 @@
property: 'user',
isFiltered: function(input, user) {
var keyword, _i, _len, _ref;
user = _this.options.userString(user);
if (!(input && user)) {
return false;
}
if (!(input && user)) return false;
_ref = input.split(/\s*/);
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
keyword = _ref[_i];
if (user.indexOf(keyword) === -1) {
return false;
}
if (user.indexOf(keyword) === -1) return false;
}
return true;
}
......@@ -138,16 +125,12 @@
Permissions.prototype.addFieldsToAnnotation = function(annotation) {
if (annotation) {
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) {
if (user === void 0) {
user = this.user;
}
if (user === void 0) user = this.user;
if (this.options.userAuthorize) {
return this.options.userAuthorize.call(this.options, action, annotation, user);
} else {
......@@ -157,12 +140,9 @@
Permissions.prototype.updatePermissionsField = function(action, field, annotation) {
var input;
field = $(field).show();
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)) {
return input.attr('checked', 'checked');
} else {
......@@ -172,7 +152,6 @@
Permissions.prototype.updateAnnotationPermissions = function(type, field, annotation) {
var dataKey;
if (!annotation.permissions) {
annotation.permissions = this.options.permissions;
}
......@@ -186,7 +165,6 @@
Permissions.prototype.updateViewer = function(field, annotation, controls) {
var user, username;
field = $(field);
username = this.options.userString(annotation.user);
if (annotation.user && username && typeof username === 'string') {
......@@ -196,12 +174,8 @@
field.remove();
}
if (controls) {
if (!this.authorize('update', annotation)) {
controls.hideEdit();
}
if (!this.authorize('delete', annotation)) {
return controls.hideDelete();
}
if (!this.authorize('update', annotation)) controls.hideEdit();
if (!this.authorize('delete', annotation)) return controls.hideDelete();
}
};
......
/*
** Annotator 1.2.6-dev-b660660
** Annotator 1.2.6-dev-939cdee
** 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: 2013-04-12 17:10:55Z
** Built at: 2013-04-12 22:07:29Z
*/
(function() {
var __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; };
__hasProp = Object.prototype.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 = 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; };
Annotator.Plugin.Store = (function(_super) {
__extends(Store, _super);
Store.prototype.events = {
......@@ -48,9 +48,7 @@
}
Store.prototype.pluginInit = function() {
if (!Annotator.supported()) {
return;
}
if (!Annotator.supported()) return;
if (this.annotator.plugins.Auth) {
return this.annotator.plugins.Auth.withToken(this._getAnnotations);
} else {
......@@ -68,11 +66,10 @@
Store.prototype.annotationCreated = function(annotation) {
var _this = this;
if (__indexOf.call(this.annotations, annotation) < 0) {
this.registerAnnotation(annotation);
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);
}
return _this.updateAnnotation(annotation, data);
......@@ -84,7 +81,6 @@
Store.prototype.annotationUpdated = function(annotation) {
var _this = this;
if (__indexOf.call(this.annotations, annotation) >= 0) {
return this._apiRequest('update', annotation, (function(data) {
return _this.updateAnnotation(annotation, data);
......@@ -94,7 +90,6 @@
Store.prototype.annotationDeleted = function(annotation) {
var _this = this;
if (__indexOf.call(this.annotations, annotation) >= 0) {
return this._apiRequest('destroy', annotation, (function() {
return _this.unregisterAnnotation(annotation);
......@@ -124,9 +119,7 @@
};
Store.prototype._onLoadAnnotations = function(data) {
if (data == null) {
data = [];
}
if (data == null) data = [];
this.annotations = this.annotations.concat(data);
return this.annotator.loadAnnotations(data.slice());
};
......@@ -136,15 +129,12 @@
};
Store.prototype._onLoadAnnotationsFromSearch = function(data) {
if (data == null) {
data = {};
}
if (data == null) data = {};
return this._onLoadAnnotations(data.rows || []);
};
Store.prototype.dumpAnnotations = function() {
var ann, _i, _len, _ref, _results;
_ref = this.annotations;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
......@@ -156,7 +146,6 @@
Store.prototype._apiRequest = function(action, obj, onSuccess) {
var id, options, request, url;
id = obj && obj.id;
url = this._urlFor(action, id);
options = this._apiRequestOptions(action, obj, onSuccess);
......@@ -168,7 +157,6 @@
Store.prototype._apiRequestOptions = function(action, obj, onSuccess) {
var data, method, opts;
method = this._methodFor(action);
opts = {
type: method,
......@@ -194,9 +182,7 @@
opts.data = {
json: data
};
if (this.options.emulateHTTP) {
opts.data._method = method;
}
if (this.options.emulateHTTP) opts.data._method = method;
return opts;
}
opts = $.extend(opts, {
......@@ -208,7 +194,6 @@
Store.prototype._urlFor = function(action, id) {
var url;
url = this.options.prefix != null ? this.options.prefix : '';
url += this.options.urls[action];
url = url.replace(/\/:id/, id != null ? '/' + id : '');
......@@ -218,7 +203,6 @@
Store.prototype._methodFor = function(action) {
var table;
table = {
'create': 'POST',
'read': 'GET',
......@@ -231,20 +215,16 @@
Store.prototype._dataFor = function(annotation) {
var data, highlights;
highlights = annotation.highlights;
delete annotation.highlights;
$.extend(annotation, this.options.annotationData);
data = JSON.stringify(annotation);
if (highlights) {
annotation.highlights = highlights;
}
if (highlights) annotation.highlights = highlights;
return data;
};
Store.prototype._onError = function(xhr) {
var action, message;
action = xhr._action;
message = Annotator._t("Sorry we could not ") + action + Annotator._t(" this annotation");
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