Skip to content

Commit

Permalink
Optimize script execution
Browse files Browse the repository at this point in the history
  • Loading branch information
reed committed Dec 5, 2012
1 parent 1003ccf commit 6f6d82b
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions lib/assets/javascripts/turbolinks.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,12 @@ changePage = (title, body, runScripts) ->

executeScriptTags = ->
for script in document.body.getElementsByTagName 'script' when script.type in ['', 'text/javascript']
if script.src? and script.src isnt '' and not script.getAttribute('data-turbolinks-evaluated')?
copy = document.createElement 'script'
copy.setAttribute attr.name, attr.value for attr in script.attributes
copy.setAttribute 'data-turbolinks-evaluated', ''
parent = script.parentNode
parent.removeChild script
parent.insertBefore copy, parent.childNodes[0]
else
window.eval(script.innerHTML)
copy = document.createElement 'script'
copy.setAttribute attr.name, attr.value for attr in script.attributes
copy.appendChild document.createTextNode script.innerHTML
{ parentNode, nextSibling } = script
parentNode.removeChild script
parentNode.insertBefore copy, nextSibling


reflectNewUrl = (url) ->
Expand Down

0 comments on commit 6f6d82b

Please sign in to comment.