Create a single range per post, and detach it when we're done.
This commit is contained in:
parent
a5adff0ab6
commit
27c1a77b86
@ -13,16 +13,17 @@ Linkify =
|
|||||||
node: ->
|
node: ->
|
||||||
return if @isClone or !links = @info.comment.match Linkify.catchAll
|
return if @isClone or !links = @info.comment.match Linkify.catchAll
|
||||||
walker = d.createTreeWalker @nodes.comment, 4
|
walker = d.createTreeWalker @nodes.comment, 4
|
||||||
|
range = d.createRange()
|
||||||
for link in links
|
for link in links
|
||||||
boundaries = Linkify.find link, walker
|
boundaries = Linkify.find link, walker
|
||||||
# continue unless boundaries
|
# continue unless boundaries
|
||||||
anchor = Linkify.createLink link
|
anchor = Linkify.createLink link
|
||||||
if Linkify.surround anchor, link, boundaries
|
if Linkify.surround anchor, link, range, boundaries
|
||||||
Linkify.cleanLink anchor if Conf['Clean Links']
|
Linkify.cleanLink anchor if Conf['Clean Links']
|
||||||
walker.currentNode = anchor.lastChild
|
walker.currentNode = anchor.lastChild
|
||||||
else
|
else
|
||||||
walker.currentNode = boundaries.endNode
|
walker.currentNode = boundaries.endNode
|
||||||
return
|
range.detach()
|
||||||
|
|
||||||
find: (link, walker) ->
|
find: (link, walker) ->
|
||||||
# Walk through the nodes until we find the entire link.
|
# Walk through the nodes until we find the entire link.
|
||||||
@ -54,12 +55,11 @@ Linkify =
|
|||||||
target: '_blank'
|
target: '_blank'
|
||||||
a
|
a
|
||||||
|
|
||||||
surround: (anchor, link, {startOffset, endOffset, startNode, endNode}) ->
|
surround: (anchor, link, range, {startOffset, endOffset, startNode, endNode}) ->
|
||||||
# parent = startNode.parentNode
|
# parent = startNode.parentNode
|
||||||
# if parent?.nodeName is 'S' and parent.textContent.length < link.length
|
# if parent?.nodeName is 'S' and parent.textContent.length < link.length
|
||||||
# parentClone = parent.cloneNode true
|
# parentClone = parent.cloneNode true
|
||||||
# $.replace parent, startNode
|
# $.replace parent, startNode
|
||||||
range = d.createRange()
|
|
||||||
range.setStart startNode, startOffset
|
range.setStart startNode, startOffset
|
||||||
range.setEnd endNode, endOffset
|
range.setEnd endNode, endOffset
|
||||||
try
|
try
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user