Improve performance of EntryPage#render

This commit is contained in:
Thibaut Courouble 2016-06-05 12:31:23 -04:00
parent b268ba4525
commit 2e915c135a
3 changed files with 4 additions and 3 deletions

View file

@ -41,10 +41,10 @@ class app.views.EntryPage extends app.View
return
CLIPBOARD_LINK = '<a class="_pre-clip" title="Copy to clipboard" tabindex="-1"></a>'
PRE_TAGS = /<pre[^>]*>/g
addClipboardLinks: ->
for el in @findAllByTag('pre')
el.insertAdjacentHTML('afterbegin', CLIPBOARD_LINK)
@el.innerHTML = @el.innerHTML.replace(PRE_TAGS, "$&#{CLIPBOARD_LINK}")
return
LINKS =

View file

@ -10,6 +10,7 @@ class app.views.BasePage extends app.View
return
highlightCode: (el, language) ->
return unless language
if $.isCollection(el)
@highlightCode e, language for e in el
else if el

View file

@ -2,7 +2,7 @@
class app.views.SimplePage extends app.views.BasePage
prepare: ->
for el in @findAllByTag('pre') when el.hasAttribute('data-language')
for el in @findAll('pre[data-language]')
@highlightCode el, el.getAttribute('data-language')
return