Make code highlighting more robust against race conditions. #357
This commit is contained in:
parent
cd2e24d5e8
commit
41d6c922a4
@ -3,10 +3,20 @@ Fourchan =
|
|||||||
return unless g.VIEW in ['index', 'thread']
|
return unless g.VIEW in ['index', 'thread']
|
||||||
|
|
||||||
if g.BOARD.ID is 'g'
|
if g.BOARD.ID is 'g'
|
||||||
|
$.on window, 'prettyprint:cb', (e) ->
|
||||||
|
return unless post = g.posts[e.detail.ID]
|
||||||
|
return unless pre = $$('.prettyprint', post.nodes.comment)[e.detail.i]
|
||||||
|
unless $.hasClass pre, 'prettyprinted'
|
||||||
|
pre.innerHTML = e.detail.html
|
||||||
|
$.addClass pre, 'prettyprinted'
|
||||||
$.globalEval '''
|
$.globalEval '''
|
||||||
window.addEventListener('prettyprint', function(e) {
|
window.addEventListener('prettyprint', function(e) {
|
||||||
window.dispatchEvent(new CustomEvent('prettyprint:cb', {
|
window.dispatchEvent(new CustomEvent('prettyprint:cb', {
|
||||||
detail: prettyPrintOne(e.detail)
|
detail: {
|
||||||
|
ID: e.detail.ID,
|
||||||
|
i: e.detail.i,
|
||||||
|
html: prettyPrintOne(e.detail.html)
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
}, false);
|
}, false);
|
||||||
'''
|
'''
|
||||||
@ -50,13 +60,8 @@ Fourchan =
|
|||||||
|
|
||||||
code: ->
|
code: ->
|
||||||
return if @isClone
|
return if @isClone
|
||||||
apply = (e) ->
|
for pre, i in $$('.prettyprint', @nodes.comment) when not $.hasClass(pre, 'prettyprinted')
|
||||||
pre.innerHTML = e.detail
|
$.event 'prettyprint', {ID: @fullID, i: i, html: pre.innerHTML}, window
|
||||||
$.addClass pre, 'prettyprinted'
|
|
||||||
$.on window, 'prettyprint:cb', apply
|
|
||||||
for pre in $$ '.prettyprint:not(.prettyprinted)', @nodes.comment
|
|
||||||
$.event 'prettyprint', pre.innerHTML, window
|
|
||||||
$.off window, 'prettyprint:cb', apply
|
|
||||||
return
|
return
|
||||||
|
|
||||||
math: ->
|
math: ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user