Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
dcab98ab
Commit
dcab98ab
authored
Mar 03, 2013
by
csillag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added position-based anchoir rettachment strategy. Now we can handle DOM structure changes.
parent
2766e46d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
34 deletions
+63
-34
annotator.js
h/lib/annotator.js
+63
-34
No files found.
h/lib/annotator.js
View file @
dcab98ab
/*
** Annotator 1.2.5-dev-
4109850
** Annotator 1.2.5-dev-
f066e48
** 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-03-03 22:
22:50
Z
** Built at: 2013-03-03 22:
52:56
Z
*/
(
function
()
{
...
...
@@ -872,43 +872,66 @@
};
Annotator
.
prototype
.
findAnchorFromXPathRangeSelector
=
function
(
target
)
{
var
currentQuote
,
endOffset
,
nRange
,
quoteSelector
,
savedQuote
,
selector
,
startOffset
;
var
currentQuote
,
endOffset
,
nRange
,
savedQuote
,
selector
,
startOffset
;
selector
=
this
.
findSelector
(
target
.
selector
,
"xpath range"
);
if
(
selector
!=
null
)
{
try
{
nRange
=
this
.
getNormalizedRangeFromXPathRangeSelector
(
selector
);
quoteSelector
=
this
.
findSelector
(
target
.
selector
,
"context+quote"
);
savedQuote
=
quoteSelector
!=
null
?
quoteSelector
.
exact
:
void
0
;
if
(
savedQuote
!=
null
)
{
startOffset
=
(
this
.
domMapper
.
getInfoForNode
(
nRange
.
start
)).
start
;
endOffset
=
(
this
.
domMapper
.
getInfoForNode
(
nRange
.
end
)).
end
;
currentQuote
=
this
.
domMapper
.
getContentForRange
(
startOffset
,
endOffset
);
if
(
currentQuote
!==
savedQuote
)
{
console
.
log
(
"Could not apply XPath selector to current document, because the quote has changed."
);
console
.
log
(
"Saved quote is '"
+
savedQuote
+
"'."
);
console
.
log
(
"Current quote is '"
+
currentQuote
+
"'."
);
return
null
;
}
}
else
{
}
return
nRange
;
}
catch
(
exception
)
{
if
(
exception
instanceof
Range
.
RangeError
)
{
console
.
log
(
"Could not apply XPath selector to current document. Structure must have changed."
);
if
(
selector
==
null
)
return
null
;
try
{
nRange
=
this
.
getNormalizedRangeFromXPathRangeSelector
(
selector
);
savedQuote
=
this
.
getQuoteForTarget
(
target
);
if
(
savedQuote
!=
null
)
{
startOffset
=
(
this
.
domMapper
.
getInfoForNode
(
nRange
.
start
)).
start
;
endOffset
=
(
this
.
domMapper
.
getInfoForNode
(
nRange
.
end
)).
end
;
currentQuote
=
this
.
domMapper
.
getContentForRange
(
startOffset
,
endOffset
);
if
(
currentQuote
!==
savedQuote
)
{
console
.
log
(
"Could not apply XPath selector to current document, because the quote has changed."
);
console
.
log
(
"Saved quote is '"
+
savedQuote
+
"'."
);
console
.
log
(
"Current quote is '"
+
currentQuote
+
"'."
);
return
null
;
}
else
{
console
.
log
(
exception
.
stack
);
throw
exception
;
}
}
else
{
}
return
nRange
;
}
catch
(
exception
)
{
if
(
exception
instanceof
Range
.
RangeError
)
{
console
.
log
(
"Could not apply XPath selector to current document. Structure must have changed."
);
return
null
;
}
else
{
throw
exception
;
}
}
return
null
;
};
Annotator
.
prototype
.
findAnchorFromPositionSelector
=
function
(
target
)
{
var
browserRange
,
currentQuote
,
mappings
,
savedQuote
,
selector
;
selector
=
this
.
findSelector
(
target
.
selector
,
"position"
);
if
(
selector
==
null
)
return
null
;
savedQuote
=
this
.
getQuoteForTarget
(
target
);
if
(
savedQuote
!=
null
)
{
savedQuote
=
this
.
getQuoteForTarget
(
target
);
currentQuote
=
this
.
domMapper
.
getContentForRange
(
selector
.
start
,
selector
.
end
);
if
(
currentQuote
!==
savedQuote
)
{
console
.
log
(
"Could not apply position selector to current document, because the quote has changed."
);
console
.
log
(
"Saved quote is '"
+
savedQuote
+
"'."
);
console
.
log
(
"Current quote is '"
+
currentQuote
+
"'."
);
return
null
;
}
else
{
}
}
else
{
}
mappings
=
this
.
domMapper
.
getMappingsForRange
(
selector
.
start
,
selector
.
end
);
browserRange
=
new
Range
.
BrowserRange
(
mappings
.
range
);
return
browserRange
.
normalize
();
};
Annotator
.
prototype
.
findAnchor
=
function
(
target
)
{
var
anchor
;
anchor
=
this
.
findAnchorFromXPathRangeSelector
(
target
);
anchor
||
(
anchor
=
this
.
findAnchorFromPositionSelector
(
target
));
return
anchor
;
};
...
...
@@ -923,12 +946,18 @@
_ref2
=
annotation
.
target
;
for
(
_k
=
0
,
_len3
=
_ref2
.
length
;
_k
<
_len3
;
_k
++
)
{
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
]);
try
{
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
]);
}
}
catch
(
exception
)
{
if
(
exception
.
stack
!=
null
)
console
.
log
(
exception
.
stack
);
console
.
log
(
exception
.
message
);
console
.
log
(
exception
);
}
}
annotation
.
currentQuote
=
[];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment