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 return
CLIPBOARD_LINK = '<a class="_pre-clip" title="Copy to clipboard" tabindex="-1"></a>' CLIPBOARD_LINK = '<a class="_pre-clip" title="Copy to clipboard" tabindex="-1"></a>'
PRE_TAGS = /<pre[^>]*>/g
addClipboardLinks: -> addClipboardLinks: ->
for el in @findAllByTag('pre') @el.innerHTML = @el.innerHTML.replace(PRE_TAGS, "$&#{CLIPBOARD_LINK}")
el.insertAdjacentHTML('afterbegin', CLIPBOARD_LINK)
return return
LINKS = LINKS =

View file

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

View file

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