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
|
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 =
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue