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
972dfa47
Commit
972dfa47
authored
Apr 25, 2013
by
csillag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update annotator: fixes #377, and also bring in 3x speedup in anchoring!
parent
ca5d5a29
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
9 deletions
+26
-9
annotator.js
h/lib/annotator.js
+26
-9
No files found.
h/lib/annotator.js
View file @
972dfa47
/*
** Annotator 1.2.6-dev-
e666b05
** Annotator 1.2.6-dev-
68379aa
** 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-2
4 10:16:24
Z
** Built at: 2013-04-2
5 14:33:49
Z
*/
(
function
()
{
...
...
@@ -344,7 +344,7 @@
}
BrowserRange
.
prototype
.
normalize
=
function
(
root
)
{
var
isImg
,
it
,
node
,
nr
,
offset
,
p
,
r
,
_k
,
_len3
,
_ref2
;
var
changed
,
isImg
,
it
,
node
,
nr
,
offset
,
p
,
r
,
_k
,
_len3
,
_ref2
;
if
(
this
.
tainted
)
{
console
.
error
(
_t
(
"You may only call normalize() once on a BrowserRange!"
));
return
false
;
...
...
@@ -379,23 +379,39 @@
r
[
p
+
'Offset'
]
=
offset
;
r
[
p
+
'Img'
]
=
isImg
;
}
nr
.
start
=
r
.
startOffset
>
0
?
r
.
start
.
splitText
(
r
.
startOffset
)
:
r
.
start
;
changed
=
false
;
if
(
r
.
startOffset
>
0
)
{
if
(
r
.
start
.
data
.
length
>
r
.
startOffset
)
{
nr
.
start
=
r
.
start
.
splitText
(
r
.
startOffset
);
changed
=
true
;
}
else
{
nr
.
start
=
r
.
start
.
nextSibling
;
}
}
else
{
nr
.
start
=
r
.
start
;
}
if
(
r
.
start
===
r
.
end
&&
!
r
.
startImg
)
{
if
((
r
.
endOffset
-
r
.
startOffset
)
<
nr
.
start
.
nodeValue
.
length
)
{
nr
.
start
.
splitText
(
r
.
endOffset
-
r
.
startOffset
);
changed
=
true
;
}
else
{
}
nr
.
end
=
nr
.
start
;
}
else
{
if
(
r
.
endOffset
<
r
.
end
.
nodeValue
.
length
&&
!
r
.
endImg
)
{
r
.
end
.
splitText
(
r
.
endOffset
);
changed
=
true
;
}
else
{
}
nr
.
end
=
r
.
end
;
}
nr
.
commonAncestor
=
this
.
commonAncestorContainer
;
while
(
nr
.
commonAncestor
.
nodeType
!==
1
)
{
while
(
nr
.
commonAncestor
.
nodeType
!==
Node
.
ELEMENT_NODE
)
{
nr
.
commonAncestor
=
nr
.
commonAncestor
.
parentNode
;
}
if
(
window
.
DomTextMapper
!=
null
)
{
if
(
(
window
.
DomTextMapper
!=
null
)
&&
changed
)
{
window
.
DomTextMapper
.
changed
(
nr
.
commonAncestor
,
"range normalization"
);
}
return
new
Range
.
NormalizedRange
(
nr
);
...
...
@@ -458,7 +474,7 @@
n
=
nodes
[
_k
];
offset
+=
n
.
nodeValue
.
length
;
}
isImg
=
node
.
nodeType
===
1
&&
node
.
tagName
.
toLowerCase
()
===
"img"
;
isImg
=
node
.
nodeType
===
Node
.
ELEMENT_NODE
&&
node
.
tagName
.
toLowerCase
()
===
"img"
;
if
(
isEnd
&&
!
isImg
)
{
return
[
xpath
,
offset
+
node
.
nodeValue
.
length
];
}
else
{
...
...
@@ -518,7 +534,7 @@
}
SerializedRange
.
prototype
.
normalize
=
function
(
root
)
{
var
contains
,
length
,
node
,
p
,
range
,
tn
,
xpath
,
_k
,
_l
,
_len3
,
_len4
,
_ref2
,
_ref3
;
var
contains
,
length
,
node
,
p
,
range
,
t
argetOffset
,
t
n
,
xpath
,
_k
,
_l
,
_len3
,
_len4
,
_ref2
,
_ref3
;
range
=
{};
_ref2
=
[
'start'
,
'end'
];
for
(
_k
=
0
,
_len3
=
_ref2
.
length
;
_k
<
_len3
;
_k
++
)
{
...
...
@@ -533,10 +549,11 @@
throw
new
Range
.
RangeError
(
p
,
"Couldn't find "
+
p
+
" node: "
+
xpath
);
}
length
=
0
;
targetOffset
=
this
[
p
+
'Offset'
]
+
(
p
===
"start"
?
1
:
0
);
_ref3
=
$
(
node
).
textNodes
();
for
(
_l
=
0
,
_len4
=
_ref3
.
length
;
_l
<
_len4
;
_l
++
)
{
tn
=
_ref3
[
_l
];
if
(
length
+
tn
.
nodeValue
.
length
>=
t
his
[
p
+
'Offset'
]
)
{
if
(
length
+
tn
.
nodeValue
.
length
>=
t
argetOffset
)
{
range
[
p
+
'Container'
]
=
tn
;
range
[
p
+
'Offset'
]
=
this
[
p
+
'Offset'
]
-
length
;
break
;
...
...
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