Commit f9421db9 authored by Randall Leeds's avatar Randall Leeds

upgrade annotator to 1.2.6-dev-d2ea449

parent 0c3a527d
...@@ -4,6 +4,7 @@ class Hypothesis extends Annotator ...@@ -4,6 +4,7 @@ class Hypothesis extends Annotator
# Plugin configuration # Plugin configuration
options: options:
noMatching: true
Discovery: {} Discovery: {}
Heatmap: {} Heatmap: {}
Permissions: Permissions:
......
/* /*
** Annotator 1.2.6-dev-8daf38c ** Annotator 1.2.6-dev-d2ea449
** 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-05-17 21:32:30Z ** Built at: 2013-05-24 21:48:00Z
*/ */
......
/* /*
** Annotator 1.2.6-dev-6014b60 ** Annotator 1.2.6-dev-d2ea449
** 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-05-17 21:40:10Z ** Built at: 2013-05-24 21:47:58Z
*/ */
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
path = ''; path = '';
elem = this; elem = this;
while (elem && elem.nodeType === 1 && elem !== relativeRoot) { while ((elem != null ? elem.nodeType : void 0) === Node.ELEMENT_NODE && elem !== relativeRoot) {
tagName = elem.tagName.replace(":", "\\:"); tagName = elem.tagName.replace(":", "\\:");
idx = $(elem.parentNode).children(tagName).index(elem) + 1; idx = $(elem.parentNode).children(tagName).index(elem) + 1;
idx = "[" + idx + "]"; idx = "[" + idx + "]";
...@@ -193,9 +193,9 @@ ...@@ -193,9 +193,9 @@
getTextNodes = function(node) { getTextNodes = function(node) {
var nodes; var nodes;
if (node && node.nodeType !== 3) { if (node && node.nodeType !== Node.TEXT_NODE) {
nodes = []; nodes = [];
if (node.nodeType !== 8) { if (node.nodeType !== Node.COMMENT_NODE) {
node = node.lastChild; node = node.lastChild;
while (node) { while (node) {
nodes.push(getTextNodes(node)); nodes.push(getTextNodes(node));
...@@ -470,9 +470,10 @@ ...@@ -470,9 +470,10 @@
Range.RangeError = (function(_super) { Range.RangeError = (function(_super) {
__extends(RangeError, _super); __extends(RangeError, _super);
function RangeError(type, message, parent) { function RangeError(message, range, type, parent) {
this.type = type;
this.message = message; this.message = message;
this.range = range;
this.type = type;
this.parent = parent != null ? parent : null; this.parent = parent != null ? parent : null;
RangeError.__super__.constructor.call(this, this.message); RangeError.__super__.constructor.call(this, this.message);
} }
...@@ -556,7 +557,7 @@ ...@@ -556,7 +557,7 @@
nr.end = r.end; nr.end = r.end;
} }
nr.commonAncestor = this.commonAncestorContainer; nr.commonAncestor = this.commonAncestorContainer;
while (nr.commonAncestor.nodeType !== 1) { while (nr.commonAncestor.nodeType !== Node.ELEMENT_NODE) {
nr.commonAncestor = nr.commonAncestor.parentNode; nr.commonAncestor = nr.commonAncestor.parentNode;
} }
if ((window.DomTextMapper != null) && changed) { if ((window.DomTextMapper != null) && changed) {
...@@ -700,10 +701,10 @@ ...@@ -700,10 +701,10 @@
node = Range.nodeFromXPath(xpath, root); node = Range.nodeFromXPath(xpath, root);
} catch (_error) { } catch (_error) {
e = _error; e = _error;
throw new Range.RangeError(p, ("Error while finding " + p + " node: " + xpath + ": ") + e, e); throw new Range.RangeError("Error while finding " + p + " node: " + xpath + ": " + e, range, p, e);
} }
if (!node) { if (!node) {
throw new Range.RangeError(p, "Couldn't find " + p + " node: " + xpath); throw new Range.RangeError("Couldn't find " + p + " node: " + xpath, range, p);
} }
length = 0; length = 0;
targetOffset = this[p + 'Offset'] + (p === "start" ? 1 : 0); targetOffset = this[p + 'Offset'] + (p === "start" ? 1 : 0);
...@@ -827,7 +828,7 @@ ...@@ -827,7 +828,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;
...@@ -857,17 +858,29 @@ ...@@ -857,17 +858,29 @@
if (!this.options.readOnly) { if (!this.options.readOnly) {
this._setupDocumentEvents(); this._setupDocumentEvents();
} }
this._setupWrapper()._setupViewer()._setupEditor(); this._setupWrapper();
if (!this.options.noMatching) {
this._setupMatching();
}
this._setupViewer()._setupEditor();
this._setupDynamicStyle(); this._setupDynamicStyle();
if (!(this.options.noScan || this.options.noMatching)) {
this._scan();
}
this.adder = $(this.html.adder).appendTo(this.wrapper).hide(); this.adder = $(this.html.adder).appendTo(this.wrapper).hide();
} }
Annotator.prototype._setupMatching = function() { Annotator.prototype._setupMatching = function() {
this.domMapper = new DomTextMapper(); this.domMapper = new DomTextMapper();
this.domMatcher = new DomTextMatcher(this.domMapper); this.domMatcher = new DomTextMatcher(this.domMapper);
this.domMapper.setRootNode(this.wrapper[0]);
return this; return this;
}; };
Annotator.prototype._scan = function() {
return this.domMatcher.scan();
};
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();
...@@ -976,10 +989,21 @@ ...@@ -976,10 +989,21 @@
}; };
Annotator.prototype.getTextQuoteSelector = function(range) { Annotator.prototype.getTextQuoteSelector = function(range) {
var endOffset, prefix, quote, selector, startOffset, suffix, _ref1; var endOffset, prefix, quote, rangeEnd, rangeStart, selector, startOffset, suffix, _ref1;
startOffset = (this.domMapper.getInfoForNode(range.start)).start; if (range == null) {
endOffset = (this.domMapper.getInfoForNode(range.end)).end; throw new Error("Called getTextQuoteSelector(range) with null range!");
}
rangeStart = range.start;
if (rangeStart == null) {
throw new Error("Called getTextQuoteSelector(range) on a range with no valid start.");
}
startOffset = (this.domMapper.getInfoForNode(rangeStart)).start;
rangeEnd = range.end;
if (rangeEnd == null) {
throw new Error("Called getTextQuoteSelector(range) on a range with no valid end.");
}
endOffset = (this.domMapper.getInfoForNode(rangeEnd)).end;
quote = this.domMapper.getContentForCharRange(startOffset, endOffset); quote = this.domMapper.getContentForCharRange(startOffset, endOffset);
_ref1 = this.domMapper.getContextForCharRange(startOffset, endOffset), prefix = _ref1[0], suffix = _ref1[1]; _ref1 = this.domMapper.getContextForCharRange(startOffset, endOffset), prefix = _ref1[0], suffix = _ref1[1];
return selector = { return selector = {
...@@ -1013,13 +1037,35 @@ ...@@ -1013,13 +1037,35 @@
} }
}; };
Annotator.prototype.getSelectedRanges = function() {
var range, target, _k, _len2, _ref1, _results;
_ref1 = this.getSelectedTargets();
_results = [];
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
target = _ref1[_k];
range = this.findSelector(target.selector, "RangeSelector");
if (range == null) {
continue;
}
_results.push(Range.sniff(range).normalize(this.wrapper[0]));
}
return _results;
};
Annotator.prototype.getSelectedTargets = function() { Annotator.prototype.getSelectedTargets = function() {
var browserRange, i, normedRange, r, rangesToIgnore, realRange, selection, source, targets, _k, _len2, var browserRange, i, normedRange, r, ranges, rangesToIgnore, realRange, selection, source, targets, _k, _len2;
_this = this;
if (this.domMapper == null) {
throw new Error("Can not execute getSelectedTargets() before _setupMatching()!");
}
if (!this.wrapper) {
throw new Error("Can not execute getSelectedTargets() before @wrapper is configured!");
}
selection = util.getGlobal().getSelection(); selection = util.getGlobal().getSelection();
source = this.getHref(); source = this.getHref();
targets = []; targets = [];
ranges = [];
rangesToIgnore = []; rangesToIgnore = [];
if (!selection.isCollapsed) { if (!selection.isCollapsed) {
targets = (function() { targets = (function() {
...@@ -1030,13 +1076,16 @@ ...@@ -1030,13 +1076,16 @@
realRange = selection.getRangeAt(i); realRange = selection.getRangeAt(i);
browserRange = new Range.BrowserRange(realRange); browserRange = new Range.BrowserRange(realRange);
normedRange = browserRange.normalize().limit(this.wrapper[0]); normedRange = browserRange.normalize().limit(this.wrapper[0]);
if (normedRange === null) { if (normedRange != null) {
rangesToIgnore.push(r); ranges.push(normedRange);
}
_results.push({ _results.push({
selector: [this.getRangeSelector(normedRange), this.getTextQuoteSelector(normedRange), this.getTextPositionSelector(normedRange)], selector: [this.getRangeSelector(normedRange), this.getTextQuoteSelector(normedRange), this.getTextPositionSelector(normedRange)],
source: source source: source
}); });
} else {
rangesToIgnore.push(realRange);
continue;
}
} }
return _results; return _results;
}).call(this); }).call(this);
...@@ -1046,18 +1095,13 @@ ...@@ -1046,18 +1095,13 @@
r = rangesToIgnore[_k]; r = rangesToIgnore[_k];
selection.addRange(r); selection.addRange(r);
} }
return $.grep(targets, function(target) { $.grep(ranges, function(range) {
var range, selector; if (range) {
selector = _this.findSelector(target.selector, "RangeSelector");
if (selector != null) {
range = (Range.sniff(selector)).normalize(_this.wrapper[0]);
if (range != null) {
selection.addRange(range.toRange()); selection.addRange(range.toRange());
return true;
}
} }
return range;
}); });
return targets;
}; };
Annotator.prototype.createAnnotation = function() { Annotator.prototype.createAnnotation = function() {
...@@ -1085,13 +1129,12 @@ ...@@ -1085,13 +1129,12 @@
}; };
Annotator.prototype.findAnchorFromRangeSelector = function(target) { 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"); selector = this.findSelector(target.selector, "RangeSelector");
if (selector == null) { if (selector == null) {
return null; return null;
} }
try {
normalizedRange = Range.sniff(selector).normalize(this.wrapper[0]); normalizedRange = Range.sniff(selector).normalize(this.wrapper[0]);
savedQuote = this.getQuoteForTarget(target); savedQuote = this.getQuoteForTarget(target);
if (savedQuote != null) { if (savedQuote != null) {
...@@ -1114,15 +1157,6 @@ ...@@ -1114,15 +1157,6 @@
range: normalizedRange, range: normalizedRange,
quote: savedQuote quote: savedQuote
}; };
} catch (_error) {
exception = _error;
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) { Annotator.prototype.findAnchorFromPositionSelector = function(target) {
...@@ -1227,43 +1261,77 @@ ...@@ -1227,43 +1261,77 @@
}; };
Annotator.prototype.findAnchor = function(target) { Annotator.prototype.findAnchor = function(target) {
var anchor; var anchor, error, strategies, _k, _len2;
if (target == null) {
throw new Error("Trying to find anchor for null target!");
}
console.log("Trying to find anchor for target: "); console.log("Trying to find anchor for target: ");
console.log(target); console.log(target);
anchor = this.findAnchorFromRangeSelector(target); strategies = [this.findAnchorFromRangeSelector, this.findAnchorFromPositionSelector, this.findAnchorWithTwoPhaseFuzzyMatching, this.findAnchorWithFuzzyMatching];
error = null;
anchor = null;
for (_k = 0, _len2 = strategies.length; _k < _len2; _k++) {
fn = strategies[_k];
try {
if (anchor == null) { if (anchor == null) {
anchor = this.findAnchorFromPositionSelector(target); anchor = fn.call(this, target);
} }
if (anchor == null) { } catch (_error) {
anchor = this.findAnchorWithTwoPhaseFuzzyMatching(target); error = _error;
if (!(error instanceof Range.RangeError)) {
throw error;
} }
if (anchor == null) {
anchor = this.findAnchorWithFuzzyMatching(target);
} }
return anchor; }
return {
error: error,
anchor: anchor
};
}; };
Annotator.prototype.setupAnnotation = function(annotation) { Annotator.prototype.setupAnnotation = function(annotation) {
var anchor, exception, normed, normedRanges, root, t, _k, _l, _len2, _len3, _ref1; var anchor, error, exception, normed, normedRanges, r, ranges, root, t, _k, _l, _len2, _len3, _ref1, _ref2;
root = this.wrapper[0]; root = this.wrapper[0];
annotation.target || (annotation.target = this.selectedTargets); ranges = annotation.ranges || this.selectedRanges || [];
if (!(ranges instanceof Array)) {
ranges = [ranges];
}
annotation.target || (annotation.target = {
selector: (function() {
var _k, _len2, _results;
_results = [];
for (_k = 0, _len2 = ranges.length; _k < _len2; _k++) {
r = ranges[_k];
_results.push(this.getRangeSelector(Range.sniff(r)));
}
return _results;
}).call(this),
source: this.getHref()
});
if (annotation.target == null) {
throw new Error("Can not run setupAnnotation(). No target or selection available.");
}
if (!(annotation.target instanceof Array)) { if (!(annotation.target instanceof Array)) {
annotation.target = [annotation.target]; annotation.target = [annotation.target];
} }
normedRanges = []; normedRanges = [];
annotation.quote = [];
_ref1 = annotation.target; _ref1 = annotation.target;
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) { for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
t = _ref1[_k]; t = _ref1[_k];
try { try {
anchor = this.findAnchor(t); _ref2 = this.findAnchor(t), anchor = _ref2.anchor, error = _ref2.error;
if ((anchor != null ? anchor.quote : void 0) != null) { if (error instanceof Range.RangeError) {
t.quote = anchor.quote; this.publish('rangeNormalizeFail', [annotation, error.range, error]);
t.diffHTML = anchor.diffHTML;
} }
if ((anchor != null ? anchor.range : void 0) != null) { if (anchor != null) {
t.quote = anchor.quote || $.trim(anchor.range.text());
t.diffHTML = anchor.diffHTML;
normedRanges.push(anchor.range); normedRanges.push(anchor.range);
annotation.quote.push(t.quote);
} else { } else {
console.log("Could not find anchor target for annotation '" + annotation.id + "'."); console.log("Could not find anchor target for annotation '" + annotation.id + "'.");
} }
...@@ -1276,11 +1344,14 @@ ...@@ -1276,11 +1344,14 @@
console.log(exception); console.log(exception);
} }
} }
annotation.ranges = [];
annotation.highlights = []; annotation.highlights = [];
for (_l = 0, _len3 = normedRanges.length; _l < _len3; _l++) { for (_l = 0, _len3 = normedRanges.length; _l < _len3; _l++) {
normed = normedRanges[_l]; normed = normedRanges[_l];
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;
}; };
...@@ -1449,26 +1520,16 @@ ...@@ -1449,26 +1520,16 @@
}; };
Annotator.prototype.checkForEndSelection = function(event) { Annotator.prototype.checkForEndSelection = function(event) {
var container, exception, range, selector, target, _k, _len2, _ref1; var container, range, _k, _len2, _ref1;
this.mouseIsDown = false; this.mouseIsDown = false;
if (this.ignoreMouseup) { if (this.ignoreMouseup) {
return; return;
} }
try { this.selectedRanges = this.getSelectedRanges();
this.selectedTargets = this.getSelectedTargets(); _ref1 = this.selectedRanges;
} catch (_error) {
exception = _error;
console.log("Error while checking selection:");
console.log(exception.stack);
alert("There is something very strange about the current selection. Sorry, but I can not annotate this.");
return;
}
_ref1 = this.selectedTargets;
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) { for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
target = _ref1[_k]; range = _ref1[_k];
selector = this.findSelector(target.selector, "RangeSelector");
range = (Range.sniff(selector)).normalize(this.wrapper[0]);
container = range.commonAncestor; container = range.commonAncestor;
if ($(container).hasClass('annotator-hl')) { if ($(container).hasClass('annotator-hl')) {
container = $(container).parents(':not([class^=annotator-hl])')[0]; container = $(container).parents(':not([class^=annotator-hl])')[0];
...@@ -1477,7 +1538,7 @@ ...@@ -1477,7 +1538,7 @@
return; 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();
...@@ -1593,6 +1654,23 @@ ...@@ -1593,6 +1654,23 @@
$.getScript('http://assets.annotateit.org/vendor/json2.min.js'); $.getScript('http://assets.annotateit.org/vendor/json2.min.js');
} }
if (g.Node == null) {
g.Node = {
ELEMENT_NODE: 1,
ATTRIBUTE_NODE: 2,
TEXT_NODE: 3,
CDATA_SECTION_NODE: 4,
ENTITY_REFERENCE_NODE: 5,
ENTITY_NODE: 6,
PROCESSING_INSTRUCTION_NODE: 7,
COMMENT_NODE: 8,
DOCUMENT_NODE: 9,
DOCUMENT_TYPE_NODE: 10,
DOCUMENT_FRAGMENT_NODE: 11,
NOTATION_NODE: 12
};
}
Annotator.$ = $; Annotator.$ = $;
Annotator.Delegator = Delegator; Annotator.Delegator = Delegator;
......
/* /*
** Annotator 1.2.6-dev-8daf38c ** Annotator 1.2.6-dev-d2ea449
** 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-05-17 21:32:32Z ** Built at: 2013-05-24 21:48:00Z
*/ */
......
/* /*
** Annotator 1.2.6-dev-8daf38c ** Annotator 1.2.6-dev-d2ea449
** 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-05-17 21:32:33Z ** Built at: 2013-05-24 21:48:01Z
*/ */
...@@ -124,11 +124,29 @@ ...@@ -124,11 +124,29 @@
}; };
Store.prototype._onLoadAnnotations = function(data) { Store.prototype._onLoadAnnotations = function(data) {
var a, annotation, annotationMap, newData, _i, _j, _len, _len1, _ref;
if (data == null) { if (data == null) {
data = []; data = [];
} }
this.annotations = this.annotations.concat(data); annotationMap = {};
return this.annotator.loadAnnotations(data.slice()); _ref = this.annotations;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
a = _ref[_i];
annotationMap[a.id] = a;
}
newData = [];
for (_j = 0, _len1 = data.length; _j < _len1; _j++) {
a = data[_j];
if (annotationMap[a.id]) {
annotation = annotationMap[a.id];
this.updateAnnotation(annotation, a);
} else {
newData.push(a);
}
}
this.annotations = this.annotations.concat(newData);
return this.annotator.loadAnnotations(newData.slice());
}; };
Store.prototype.loadAnnotationsFromSearch = function(searchOptions) { Store.prototype.loadAnnotationsFromSearch = function(searchOptions) {
......
...@@ -11,7 +11,7 @@ class window.DomTextMapper ...@@ -11,7 +11,7 @@ class window.DomTextMapper
if @instances.length is 0 then return if @instances.length is 0 then return
# dm = @instances[0] # dm = @instances[0]
# console.log "Node @ " + (dm.getPathTo node) + " has changed: " + reason # console.log "Node @ " + (dm.getPathTo node) + " has changed: " + reason
for instance in @instances for instance in @instances when instance.rootNode.contains(node)
instance.performUpdateOnNode node instance.performUpdateOnNode node
null null
...@@ -42,7 +42,7 @@ class window.DomTextMapper ...@@ -42,7 +42,7 @@ class window.DomTextMapper
throw new Error "Can't find iframe with specified ID!" throw new Error "Can't find iframe with specified ID!"
@rootWin = iframe.contentWindow @rootWin = iframe.contentWindow
unless @rootWin? unless @rootWin?
throw new Error "Can't access contents of the spefified iframe!" throw new Error "Can't access contents of the specified iframe!"
@rootNode = @rootWin.document @rootNode = @rootWin.document
@pathStartNode = @getBody() @pathStartNode = @getBody()
...@@ -87,6 +87,10 @@ class window.DomTextMapper ...@@ -87,6 +87,10 @@ class window.DomTextMapper
# console.log "We have a valid DOM structure cache." # console.log "We have a valid DOM structure cache."
return @path return @path
unless @pathStartNode.ownerDocument.body.contains @pathStartNode
# We cannot map nodes that are not attached.
return @path
# console.log "No valid cache, will have to do a scan." # console.log "No valid cache, will have to do a scan."
startTime = @timestamp() startTime = @timestamp()
@saveSelection() @saveSelection()
...@@ -195,7 +199,10 @@ class window.DomTextMapper ...@@ -195,7 +199,10 @@ class window.DomTextMapper
result result
# Return info for a given node in the DOM # Return info for a given node in the DOM
getInfoForNode: (node) -> @getInfoForPath @getPathTo node getInfoForNode: (node) ->
unless node?
throw new Error "Called getInfoForNode(node) with null node!"
@getInfoForPath @getPathTo node
# Get the matching DOM elements for a given set of charRanges # Get the matching DOM elements for a given set of charRanges
# (Calles getMappingsForCharRange for each element in the givenl ist) # (Calles getMappingsForCharRange for each element in the givenl ist)
...@@ -384,6 +391,8 @@ class window.DomTextMapper ...@@ -384,6 +391,8 @@ class window.DomTextMapper
getPathTo: (node) -> getPathTo: (node) ->
xpath = ''; xpath = '';
while node != @rootNode while node != @rootNode
unless node?
throw new Error "Called getPathTo on a node which was not a descendant of @rootNode. " + @rootNode
xpath = (@getPathSegment node) + '/' + xpath xpath = (@getPathSegment node) + '/' + xpath
node = node.parentNode node = node.parentNode
xpath = (if @rootNode.ownerDocument? then './' else '/') + xpath xpath = (if @rootNode.ownerDocument? then './' else '/') + xpath
...@@ -612,8 +621,7 @@ class window.DomTextMapper ...@@ -612,8 +621,7 @@ class window.DomTextMapper
# Returns: # Returns:
# the first character offset position in the content of this node's # the first character offset position in the content of this node's
# parent node that is not accounted for by this node # parent node that is not accounted for by this node
collectPositions: (node, path, parentContent = null, collectPositions: (node, path, parentContent = null, parentIndex = 0, index = 0) ->
parentIndex = 0, index = 0) ->
# console.log "Scanning path " + path # console.log "Scanning path " + path
# content = @getNodeContent node, false # content = @getNodeContent node, false
......
...@@ -110,8 +110,7 @@ class window.DomTextMatcher ...@@ -110,8 +110,7 @@ class window.DomTextMatcher
# #
# For the details about the returned data structure, # For the details about the returned data structure,
# see the documentation of the search() method. # see the documentation of the search() method.
searchFuzzy: (pattern, pos, searchFuzzy: (pattern, pos, caseSensitive = false, path = null, options = {}) ->
caseSensitive = false, path = null, options = {}) ->
@ensureDMP() @ensureDMP()
@dmp.setMatchDistance options.matchDistance ? 1000 @dmp.setMatchDistance options.matchDistance ? 1000
@dmp.setMatchThreshold options.matchThreshold ? 0.5 @dmp.setMatchThreshold options.matchThreshold ? 0.5
...@@ -122,9 +121,7 @@ class window.DomTextMatcher ...@@ -122,9 +121,7 @@ class window.DomTextMatcher
# Used to even out some browser differences. # Used to even out some browser differences.
normalizeString: (string) -> string.replace /\s{2,}/g, " " normalizeString: (string) -> string.replace /\s{2,}/g, " "
searchFuzzyWithContext: (prefix, suffix, pattern, searchFuzzyWithContext: (prefix, suffix, pattern, expectedStart = null, expectedEnd = null, caseSensitive = false, path = null, options = {}) ->
expectedStart = null, expectedEnd = null, caseSensitive = false,
path = null, options = {}) ->
@ensureDMP() @ensureDMP()
# No context, to joy # No context, to joy
......
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