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
f9421db9
Commit
f9421db9
authored
May 28, 2013
by
Randall Leeds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
upgrade annotator to 1.2.6-dev-d2ea449
parent
0c3a527d
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
215 additions
and
113 deletions
+215
-113
services.coffee
h/js/services.coffee
+1
-0
annotator.auth.js
h/lib/annotator.auth.js
+2
-2
annotator.js
h/lib/annotator.js
+173
-95
annotator.permissions.js
h/lib/annotator.permissions.js
+2
-2
annotator.store.js
h/lib/annotator.store.js
+22
-4
dom_text_mapper.coffee
h/lib/dom_text_mapper.coffee
+13
-5
dom_text_matcher.coffee
h/lib/dom_text_matcher.coffee
+2
-5
No files found.
h/js/services.coffee
View file @
f9421db9
...
...
@@ -4,6 +4,7 @@ class Hypothesis extends Annotator
# Plugin configuration
options
:
noMatching
:
true
Discovery
:
{}
Heatmap
:
{}
Permissions
:
...
...
h/lib/annotator.auth.js
View file @
f9421db9
/*
** Annotator 1.2.6-dev-
8daf38c
** Annotator 1.2.6-dev-
d2ea449
** 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-05-
17 21:32:3
0Z
** Built at: 2013-05-
24 21:48:0
0Z
*/
...
...
h/lib/annotator.js
View file @
f9421db9
/*
** Annotator 1.2.6-dev-
6014b60
** Annotator 1.2.6-dev-
d2ea449
** 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-05-
17 21:40:10
Z
** Built at: 2013-05-
24 21:47:58
Z
*/
...
...
@@ -25,7 +25,7 @@
path
=
''
;
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
(
":"
,
"
\\
:"
);
idx
=
$
(
elem
.
parentNode
).
children
(
tagName
).
index
(
elem
)
+
1
;
idx
=
"["
+
idx
+
"]"
;
...
...
@@ -193,9 +193,9 @@
getTextNodes
=
function
(
node
)
{
var
nodes
;
if
(
node
&&
node
.
nodeType
!==
3
)
{
if
(
node
&&
node
.
nodeType
!==
Node
.
TEXT_NODE
)
{
nodes
=
[];
if
(
node
.
nodeType
!==
8
)
{
if
(
node
.
nodeType
!==
Node
.
COMMENT_NODE
)
{
node
=
node
.
lastChild
;
while
(
node
)
{
nodes
.
push
(
getTextNodes
(
node
));
...
...
@@ -470,9 +470,10 @@
Range
.
RangeError
=
(
function
(
_super
)
{
__extends
(
RangeError
,
_super
);
function
RangeError
(
type
,
message
,
parent
)
{
this
.
type
=
type
;
function
RangeError
(
message
,
range
,
type
,
parent
)
{
this
.
message
=
message
;
this
.
range
=
range
;
this
.
type
=
type
;
this
.
parent
=
parent
!=
null
?
parent
:
null
;
RangeError
.
__super__
.
constructor
.
call
(
this
,
this
.
message
);
}
...
...
@@ -556,7 +557,7 @@
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
)
&&
changed
)
{
...
...
@@ -700,10 +701,10 @@
node
=
Range
.
nodeFromXPath
(
xpath
,
root
);
}
catch
(
_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
)
{
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
;
targetOffset
=
this
[
p
+
'Offset'
]
+
(
p
===
"start"
?
1
:
0
);
...
...
@@ -827,7 +828,7 @@
Annotator
.
prototype
.
viewer
=
null
;
Annotator
.
prototype
.
selected
Target
s
=
null
;
Annotator
.
prototype
.
selected
Range
s
=
null
;
Annotator
.
prototype
.
mouseIsDown
=
false
;
...
...
@@ -857,17 +858,29 @@
if
(
!
this
.
options
.
readOnly
)
{
this
.
_setupDocumentEvents
();
}
this
.
_setupWrapper
().
_setupViewer
().
_setupEditor
();
this
.
_setupWrapper
();
if
(
!
this
.
options
.
noMatching
)
{
this
.
_setupMatching
();
}
this
.
_setupViewer
().
_setupEditor
();
this
.
_setupDynamicStyle
();
if
(
!
(
this
.
options
.
noScan
||
this
.
options
.
noMatching
))
{
this
.
_scan
();
}
this
.
adder
=
$
(
this
.
html
.
adder
).
appendTo
(
this
.
wrapper
).
hide
();
}
Annotator
.
prototype
.
_setupMatching
=
function
()
{
this
.
domMapper
=
new
DomTextMapper
();
this
.
domMatcher
=
new
DomTextMatcher
(
this
.
domMapper
);
this
.
domMapper
.
setRootNode
(
this
.
wrapper
[
0
]);
return
this
;
};
Annotator
.
prototype
.
_scan
=
function
()
{
return
this
.
domMatcher
.
scan
();
};
Annotator
.
prototype
.
_setupWrapper
=
function
()
{
this
.
wrapper
=
$
(
this
.
html
.
wrapper
);
this
.
element
.
find
(
'script'
).
remove
();
...
...
@@ -976,10 +989,21 @@
};
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
;
endOffset
=
(
this
.
domMapper
.
getInfoForNode
(
range
.
end
)).
end
;
if
(
range
==
null
)
{
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
);
_ref1
=
this
.
domMapper
.
getContextForCharRange
(
startOffset
,
endOffset
),
prefix
=
_ref1
[
0
],
suffix
=
_ref1
[
1
];
return
selector
=
{
...
...
@@ -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
()
{
var
browserRange
,
i
,
normedRange
,
r
,
rangesToIgnore
,
realRange
,
selection
,
source
,
targets
,
_k
,
_len2
,
_this
=
this
;
var
browserRange
,
i
,
normedRange
,
r
,
ranges
,
rangesToIgnore
,
realRange
,
selection
,
source
,
targets
,
_k
,
_len2
;
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
();
source
=
this
.
getHref
();
targets
=
[];
ranges
=
[];
rangesToIgnore
=
[];
if
(
!
selection
.
isCollapsed
)
{
targets
=
(
function
()
{
...
...
@@ -1030,13 +1076,16 @@
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
)
{
ranges
.
push
(
normedRange
);
_results
.
push
({
selector
:
[
this
.
getRangeSelector
(
normedRange
),
this
.
getTextQuoteSelector
(
normedRange
),
this
.
getTextPositionSelector
(
normedRange
)],
source
:
source
});
}
else
{
rangesToIgnore
.
push
(
realRange
);
continue
;
}
}
return
_results
;
}).
call
(
this
);
...
...
@@ -1046,18 +1095,13 @@
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
]);
if
(
range
!=
null
)
{
$
.
grep
(
ranges
,
function
(
range
)
{
if
(
range
)
{
selection
.
addRange
(
range
.
toRange
());
return
true
;
}
}
return
range
;
});
return
targets
;
};
Annotator
.
prototype
.
createAnnotation
=
function
()
{
...
...
@@ -1085,13 +1129,12 @@
};
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
;
}
try
{
normalizedRange
=
Range
.
sniff
(
selector
).
normalize
(
this
.
wrapper
[
0
]);
savedQuote
=
this
.
getQuoteForTarget
(
target
);
if
(
savedQuote
!=
null
)
{
...
...
@@ -1114,15 +1157,6 @@
range
:
normalizedRange
,
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
)
{
...
...
@@ -1227,43 +1261,77 @@
};
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
(
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
)
{
anchor
=
this
.
findAnchorFromPositionSelector
(
target
);
anchor
=
fn
.
call
(
this
,
target
);
}
if
(
anchor
==
null
)
{
anchor
=
this
.
findAnchorWithTwoPhaseFuzzyMatching
(
target
);
}
catch
(
_error
)
{
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
)
{
var
anchor
,
e
xception
,
normed
,
normedRanges
,
root
,
t
,
_k
,
_l
,
_len2
,
_len3
,
_ref1
;
var
anchor
,
e
rror
,
exception
,
normed
,
normedRanges
,
r
,
ranges
,
root
,
t
,
_k
,
_l
,
_len2
,
_len3
,
_ref1
,
_ref2
;
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
))
{
annotation
.
target
=
[
annotation
.
target
];
}
normedRanges
=
[];
annotation
.
quote
=
[];
_ref1
=
annotation
.
target
;
for
(
_k
=
0
,
_len2
=
_ref1
.
length
;
_k
<
_len2
;
_k
++
)
{
t
=
_ref1
[
_k
];
try
{
anchor
=
this
.
findAnchor
(
t
);
if
((
anchor
!=
null
?
anchor
.
quote
:
void
0
)
!=
null
)
{
t
.
quote
=
anchor
.
quote
;
t
.
diffHTML
=
anchor
.
diffHTML
;
_ref2
=
this
.
findAnchor
(
t
),
anchor
=
_ref2
.
anchor
,
error
=
_ref2
.
error
;
if
(
error
instanceof
Range
.
RangeError
)
{
this
.
publish
(
'rangeNormalizeFail'
,
[
annotation
,
error
.
range
,
error
]);
}
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
);
annotation
.
quote
.
push
(
t
.
quote
);
}
else
{
console
.
log
(
"Could not find anchor target for annotation '"
+
annotation
.
id
+
"'."
);
}
...
...
@@ -1276,11 +1344,14 @@
console
.
log
(
exception
);
}
}
annotation
.
ranges
=
[];
annotation
.
highlights
=
[];
for
(
_l
=
0
,
_len3
=
normedRanges
.
length
;
_l
<
_len3
;
_l
++
)
{
normed
=
normedRanges
[
_l
];
annotation
.
ranges
.
push
(
normed
.
serialize
(
this
.
wrapper
[
0
],
'.annotator-hl'
));
$
.
merge
(
annotation
.
highlights
,
this
.
highlightRange
(
normed
));
}
annotation
.
quote
=
annotation
.
quote
.
join
(
' / '
);
$
(
annotation
.
highlights
).
data
(
'annotation'
,
annotation
);
return
annotation
;
};
...
...
@@ -1449,26 +1520,16 @@
};
Annotator
.
prototype
.
checkForEndSelection
=
function
(
event
)
{
var
container
,
exception
,
range
,
selector
,
target
,
_k
,
_len2
,
_ref1
;
var
container
,
range
,
_k
,
_len2
,
_ref1
;
this
.
mouseIsDown
=
false
;
if
(
this
.
ignoreMouseup
)
{
return
;
}
try
{
this
.
selectedTargets
=
this
.
getSelectedTargets
();
}
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
;
this
.
selectedRanges
=
this
.
getSelectedRanges
();
_ref1
=
this
.
selectedRanges
;
for
(
_k
=
0
,
_len2
=
_ref1
.
length
;
_k
<
_len2
;
_k
++
)
{
target
=
_ref1
[
_k
];
selector
=
this
.
findSelector
(
target
.
selector
,
"RangeSelector"
);
range
=
(
Range
.
sniff
(
selector
)).
normalize
(
this
.
wrapper
[
0
]);
range
=
_ref1
[
_k
];
container
=
range
.
commonAncestor
;
if
(
$
(
container
).
hasClass
(
'annotator-hl'
))
{
container
=
$
(
container
).
parents
(
':not([class^=annotator-hl])'
)[
0
];
...
...
@@ -1477,7 +1538,7 @@
return
;
}
}
if
(
event
&&
this
.
selected
Target
s
.
length
)
{
if
(
event
&&
this
.
selected
Range
s
.
length
)
{
return
this
.
adder
.
css
(
util
.
mousePosition
(
event
,
this
.
wrapper
[
0
])).
show
();
}
else
{
return
this
.
adder
.
hide
();
...
...
@@ -1593,6 +1654,23 @@
$
.
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
.
Delegator
=
Delegator
;
...
...
h/lib/annotator.permissions.js
View file @
f9421db9
/*
** Annotator 1.2.6-dev-
8daf38c
** Annotator 1.2.6-dev-
d2ea449
** 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-05-
17 21:32:32
Z
** Built at: 2013-05-
24 21:48:00
Z
*/
...
...
h/lib/annotator.store.js
View file @
f9421db9
/*
** Annotator 1.2.6-dev-
8daf38c
** Annotator 1.2.6-dev-
d2ea449
** 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-05-
17 21:32:33
Z
** Built at: 2013-05-
24 21:48:01
Z
*/
...
...
@@ -124,11 +124,29 @@
};
Store
.
prototype
.
_onLoadAnnotations
=
function
(
data
)
{
var
a
,
annotation
,
annotationMap
,
newData
,
_i
,
_j
,
_len
,
_len1
,
_ref
;
if
(
data
==
null
)
{
data
=
[];
}
this
.
annotations
=
this
.
annotations
.
concat
(
data
);
return
this
.
annotator
.
loadAnnotations
(
data
.
slice
());
annotationMap
=
{};
_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
)
{
...
...
h/lib/dom_text_mapper.coffee
View file @
f9421db9
...
...
@@ -11,7 +11,7 @@ class window.DomTextMapper
if
@
instances
.
length
is
0
then
return
# dm = @instances[0]
# 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
null
...
...
@@ -42,7 +42,7 @@ class window.DomTextMapper
throw
new
Error
"Can't find iframe with specified ID!"
@
rootWin
=
iframe
.
contentWindow
unless
@
rootWin
?
throw
new
Error
"Can't access contents of the spe
f
ified iframe!"
throw
new
Error
"Can't access contents of the spe
c
ified iframe!"
@
rootNode
=
@
rootWin
.
document
@
pathStartNode
=
@
getBody
()
...
...
@@ -87,6 +87,10 @@ class window.DomTextMapper
# console.log "We have a valid DOM structure cache."
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."
startTime
=
@
timestamp
()
@
saveSelection
()
...
...
@@ -195,7 +199,10 @@ class window.DomTextMapper
result
# 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
# (Calles getMappingsForCharRange for each element in the givenl ist)
...
...
@@ -384,6 +391,8 @@ class window.DomTextMapper
getPathTo
:
(
node
)
->
xpath
=
''
;
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
node
=
node
.
parentNode
xpath
=
(
if
@
rootNode
.
ownerDocument
?
then
'./'
else
'/'
)
+
xpath
...
...
@@ -612,8 +621,7 @@ class window.DomTextMapper
# Returns:
# the first character offset position in the content of this node's
# parent node that is not accounted for by this node
collectPositions
:
(
node
,
path
,
parentContent
=
null
,
parentIndex
=
0
,
index
=
0
)
->
collectPositions
:
(
node
,
path
,
parentContent
=
null
,
parentIndex
=
0
,
index
=
0
)
->
# console.log "Scanning path " + path
# content = @getNodeContent node, false
...
...
h/lib/dom_text_matcher.coffee
View file @
f9421db9
...
...
@@ -110,8 +110,7 @@ class window.DomTextMatcher
#
# For the details about the returned data structure,
# see the documentation of the search() method.
searchFuzzy
:
(
pattern
,
pos
,
caseSensitive
=
false
,
path
=
null
,
options
=
{})
->
searchFuzzy
:
(
pattern
,
pos
,
caseSensitive
=
false
,
path
=
null
,
options
=
{})
->
@
ensureDMP
()
@
dmp
.
setMatchDistance
options
.
matchDistance
?
1000
@
dmp
.
setMatchThreshold
options
.
matchThreshold
?
0.5
...
...
@@ -122,9 +121,7 @@ class window.DomTextMatcher
# Used to even out some browser differences.
normalizeString
:
(
string
)
->
string
.
replace
/\s{2,}/g
,
" "
searchFuzzyWithContext
:
(
prefix
,
suffix
,
pattern
,
expectedStart
=
null
,
expectedEnd
=
null
,
caseSensitive
=
false
,
path
=
null
,
options
=
{})
->
searchFuzzyWithContext
:
(
prefix
,
suffix
,
pattern
,
expectedStart
=
null
,
expectedEnd
=
null
,
caseSensitive
=
false
,
path
=
null
,
options
=
{})
->
@
ensureDMP
()
# No context, to joy
...
...
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