mirror of https://github.com/freeCodeCamp/devdocs
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
11 years ago
|
class app.views.BasePage extends app.View
|
||
|
constructor: (@el, @entry) -> super
|
||
|
|
||
9 years ago
|
deactivate: ->
|
||
|
if super
|
||
|
@highlightNodes = []
|
||
|
|
||
9 years ago
|
render: (content, fromCache = false) ->
|
||
9 years ago
|
@highlightNodes = []
|
||
|
@previousTiming = null
|
||
11 years ago
|
@addClass "_#{@entry.doc.type}" unless @constructor.className
|
||
|
@html content
|
||
8 years ago
|
@highlightCode() unless fromCache
|
||
11 years ago
|
@activate()
|
||
|
@delay @afterRender if @afterRender
|
||
9 years ago
|
if @highlightNodes.length > 0
|
||
|
$.requestAnimationFrame => $.requestAnimationFrame(@paintCode)
|
||
11 years ago
|
return
|
||
|
|
||
8 years ago
|
highlightCode: ->
|
||
|
for el in @findAll('pre[data-language]')
|
||
|
language = el.getAttribute('data-language')
|
||
|
el.classList.add("language-#{language}")
|
||
9 years ago
|
@highlightNodes.push(el)
|
||
|
return
|
||
|
|
||
|
paintCode: (timing) =>
|
||
|
if @previousTiming
|
||
|
if Math.round(1000 / (timing - @previousTiming)) > 50 # fps
|
||
|
@nodesPerFrame = Math.round(Math.min(@nodesPerFrame * 1.25, 50))
|
||
|
else
|
||
|
@nodesPerFrame = Math.round(Math.max(@nodesPerFrame * .8, 10))
|
||
|
else
|
||
|
@nodesPerFrame = 10
|
||
8 years ago
|
|
||
|
for el in @highlightNodes.splice(0, @nodesPerFrame)
|
||
|
$.remove(clipEl) if clipEl = el.lastElementChild
|
||
|
Prism.highlightElement(el)
|
||
|
$.append(el, clipEl) if clipEl
|
||
|
|
||
9 years ago
|
$.requestAnimationFrame(@paintCode) if @highlightNodes.length > 0
|
||
|
@previousTiming = timing
|
||
11 years ago
|
return
|