mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
Improve performance of EntryPage#render
This commit is contained in:
parent
b268ba4525
commit
2e915c135a
3 changed files with 4 additions and 3 deletions
|
@ -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 =
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue