Commit cbadb7cc authored by csillag's avatar csillag

- Updated to newest Annotator version (with support for the new, selector-based format)

- Moved from ranges to targets
- Moved to different method for determining the quote. (It's now inside a selector)
parent 51ce3007
......@@ -118,7 +118,7 @@ class Annotator.Host extends Annotator
getHref: =>
uri = decodeURIComponent document.location.href
if document.location.hash
uri = uri.slice 0, (-1 * location.hash.length)
uri = uri.slice 0, (-1 * location.hash.length)
$('meta[property^="og:url"]').each -> uri = decodeURIComponent this.content
$('link[rel^="canonical"]').each -> uri = decodeURIComponent this.href
return uri
......@@ -235,6 +235,7 @@ class Annotator.Host extends Annotator
setupAnnotation: (annotation) ->
annotation = super
annotation.quote = this.getQuoteForTarget annotation.target[0]
# Highlights are jQuery collections which have a circular references to the
# annotation via data stored with `.data()`. Therefore, reconfigure the
......
......@@ -130,7 +130,7 @@ class Hypothesis extends Annotator
id: annotation.id
loadAnnotations [
id: data.id
ranges: data.ranges
target: data.target
quote: data.quote
]
......@@ -298,14 +298,17 @@ class Hypothesis extends Annotator
# Returns the initialised annotation.
setupAnnotation: (annotation) ->
# Delagate to Annotator implementation after we give it a valid array of
# ranges. This is needed until Annotator stops assuming ranges need to be
# targets. This is needed until Annotator stops assuming targets need to be
# added.
if annotation.thread
annotation.ranges = []
annotation.target = []
else
unless annotation.target instanceof Array
annotation.target = [annotation.target]
@provider.setupAnnotation
id: annotation.id
ranges: annotation.ranges
target: annotation.target
annotation.quote = this.getQuoteForTarget annotation.target[0]
showViewer: (annotations=[]) =>
@element.injector().invoke [
......
/*
** Annotator 1.2.6-dev-c4fcdfe
** Annotator 1.2.5-dev-5a5e03a
** 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-01-29 11:20:24Z
** Built at: 2013-02-25 17:23:26Z
*/
(function() {
......
/*
** Annotator 1.2.6-dev-6743e3f
** Annotator 1.2.5-dev-95dc8ee
** 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-01-29 18:25:34Z
** Built at: 2013-02-28 16:15:11Z
*/
(function() {
......@@ -629,7 +629,7 @@
Annotator.prototype.viewer = null;
Annotator.prototype.selectedRanges = null;
Annotator.prototype.selectedTargets = null;
Annotator.prototype.mouseIsDown = false;
......@@ -650,7 +650,8 @@
this.showViewer = __bind(this.showViewer, this);
this.onEditorSubmit = __bind(this.onEditorSubmit, this);
this.onEditorHide = __bind(this.onEditorHide, this);
this.showEditor = __bind(this.showEditor, this); Annotator.__super__.constructor.apply(this, arguments);
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();
......@@ -734,13 +735,86 @@
return this;
};
Annotator.prototype.getSelectedRanges = function() {
var browserRange, i, normedRange, r, ranges, rangesToIgnore, selection, _k, _len3;
Annotator.prototype.getHref = function() {
var uri;
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.getSerializedRangeFromXPathRangeSelector = function(selector) {
var r;
r = {
start: selector.startXpath,
startOffset: selector.startOffset,
end: selector.endXpath,
endOffset: selector.endOffset
};
return new Range.SerializedRange(r);
};
Annotator.prototype.getNormalizedRangeFromXPathRangeSelector = function(selector) {
var sr;
sr = this.getSerializedRangeFromXPathRangeSelector(selector);
return sr.normalize(this.wrapper[0]);
};
Annotator.prototype.getXPathRangeSelectorFromRange = function(range) {
var selector, sr;
sr = range.serialize(this.wrapper[0]);
return selector = {
source: this.getHref(),
type: "xpath range",
startXpath: sr.start,
startOffset: sr.startOffset,
endXpath: sr.end,
endOffset: sr.endOffset
};
};
Annotator.prototype.getContextQuoteSelectorFromRange = function(range) {
var quote, r, selector;
r = range.normalize(this.wrapper[0]);
quote = $.trim(r.text());
return selector = {
source: this.getHref(),
type: "context+quote",
exact: quote,
prefix: "TODO prefix",
suffix: "TODO suffix"
};
};
Annotator.prototype.getPositionSelectorFromRange = function(range) {
var selector;
return selector = {
source: this.getHref(),
type: "position",
start: "100",
end: "200"
};
};
Annotator.prototype.getQuoteForTarget = function(target) {
var mySelector;
mySelector = this.findSelector(target.selector, "context+quote");
return mySelector != null ? mySelector.exact : void 0;
};
Annotator.prototype.getSelectedTargets = function() {
var browserRange, i, normedRange, r, rangesToIgnore, selection, t, targets, _k, _len3,
_this = this;
selection = util.getGlobal().getSelection();
ranges = [];
targets = [];
rangesToIgnore = [];
if (!selection.isCollapsed) {
ranges = (function() {
targets = (function() {
var _ref2, _results;
_results = [];
for (i = 0, _ref2 = selection.rangeCount; 0 <= _ref2 ? i < _ref2 : i > _ref2; 0 <= _ref2 ? i++ : i--) {
......@@ -748,7 +822,10 @@
browserRange = new Range.BrowserRange(r);
normedRange = browserRange.normalize().limit(this.wrapper[0]);
if (normedRange === null) rangesToIgnore.push(r);
_results.push(normedRange);
_results.push(t = {
id: "",
selector: [this.getXPathRangeSelectorFromRange(normedRange), this.getContextQuoteSelectorFromRange(normedRange), this.getPositionSelectorFromRange(normedRange)]
});
}
return _results;
}).call(this);
......@@ -758,7 +835,12 @@
r = rangesToIgnore[_k];
selection.addRange(r);
}
return $.grep(ranges, function(range) {
return $.grep(targets, function(target) {
var mySelector, range;
mySelector = _this.findSelector(target.selector, "xpath range");
if (mySelector != null) {
range = _this.getNormalizedRangeFromXPathRangeSelector(mySelector);
}
if (range) selection.addRange(range.toRange());
return range;
});
......@@ -771,34 +853,70 @@
return annotation;
};
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.findAnchorFromXPathRangeSelector = function(target) {
var mySelector, nRange, root;
mySelector = this.findSelector(target.selector, "xpath range");
if (mySelector != null) {
try {
root = this.wrapper[0];
nRange = this.getNormalizedRangeFromXPathRangeSelector(mySelector);
return nRange;
} catch (exception) {
if (exception instanceof Range.RangeError) {
console.log("Could not apply XPath selector to current document. Must have changed.");
return null;
} else {
throw exception;
}
}
}
return null;
};
Annotator.prototype.findAnchor = function(target) {
var anchor;
anchor = this.findAnchorFromXPathRangeSelector(target);
return anchor;
};
Annotator.prototype.setupAnnotation = function(annotation) {
var normed, normedRanges, r, root, _k, _l, _len3, _len4, _ref2;
var normed, normedRanges, r, root, t, _k, _l, _len3, _len4, _ref2;
root = this.wrapper[0];
annotation.ranges || (annotation.ranges = this.selectedRanges);
annotation.target || (annotation.target = this.selectedTargets);
if (!(annotation.target instanceof Array)) {
annotation.target = [annotation.target];
}
normedRanges = [];
_ref2 = annotation.ranges;
_ref2 = annotation.target;
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) {
r = _ref2[_k];
try {
normedRanges.push(Range.sniff(r).normalize(root));
} catch (e) {
if (e instanceof Range.RangeError) {
this.publish('rangeNormalizeFail', [annotation, r, e]);
} else {
throw e;
}
t = _ref2[_k];
r = this.findAnchor(t);
if (r != null) {
normedRanges.push(r);
} else {
console.log("Could not find anchor for annotation target '" + t.id + "' (for annotation '" + annotation.id + "').");
this.publish('findAnchorFail', [annotation, t]);
}
}
annotation.quote = [];
annotation.ranges = [];
annotation.currentQuote = [];
annotation.currentRanges = [];
annotation.highlights = [];
for (_l = 0, _len4 = normedRanges.length; _l < _len4; _l++) {
normed = normedRanges[_l];
annotation.quote.push($.trim(normed.text()));
annotation.ranges.push(normed.serialize(this.wrapper[0], '.annotator-hl'));
annotation.currentQuote.push($.trim(normed.text()));
annotation.currentRanges.push(normed.serialize(this.wrapper[0], '.annotator-hl'));
$.merge(annotation.highlights, this.highlightRange(normed));
}
annotation.quote = annotation.quote.join(' / ');
annotation.currentQuote = annotation.currentQuote.join(' / ');
$(annotation.highlights).data('annotation', annotation);
return annotation;
};
......@@ -940,20 +1058,22 @@
};
Annotator.prototype.checkForEndSelection = function(event) {
var container, range, _k, _len3, _ref2;
var container, mySelector, range, target, _k, _len3, _ref2;
this.mouseIsDown = false;
if (this.ignoreMouseup) return;
this.selectedRanges = this.getSelectedRanges();
_ref2 = this.selectedRanges;
this.selectedTargets = this.getSelectedTargets();
_ref2 = this.selectedTargets;
for (_k = 0, _len3 = _ref2.length; _k < _len3; _k++) {
range = _ref2[_k];
target = _ref2[_k];
mySelector = this.findSelector(target.selector, "xpath range");
range = this.getNormalizedRangeFromXPathRangeSelector(mySelector);
container = range.commonAncestor;
if ($(container).hasClass('annotator-hl')) {
container = $(container).parents('[class^=annotator-hl]')[0];
}
if (this.isAnnotator(container)) return;
}
if (event && this.selectedRanges.length) {
if (event && this.selectedTargets.length) {
return this.adder.css(util.mousePosition(event, this.wrapper[0])).show();
} else {
return this.adder.hide();
......
/*
** Annotator 1.2.6-dev-c4fcdfe
** Annotator 1.2.5-dev-5a5e03a
** 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-01-29 11:20:26Z
** Built at: 2013-02-25 17:23:22Z
*/
(function() {
......
/*
** Annotator 1.2.6-dev-c4fcdfe
** Annotator 1.2.5-dev-5a5e03a
** 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-01-29 11:20:27Z
** Built at: 2013-02-25 17:23:23Z
*/
(function() {
......@@ -180,7 +180,7 @@
Store.prototype._urlFor = function(action, id) {
var replaceWith, url;
replaceWith = id != null ? '/' + id : '';
url = this.options.prefix != null ? this.options.prefix : '';
url = this.options.prefix || '/';
url += this.options.urls[action];
url = url.replace(/\/:id/, replaceWith);
return url;
......
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