Created
August 11, 2011 02:16
-
-
Save peterwmwong/1138772 to your computer and use it in GitHub Desktop.
livejs 4 patch to track dynamically added JS & CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -34,12 +34,12 @@ | |
var Live = { | |
// performs a cycle per interval | |
heartbeat: function () { | |
if (document.body) { | |
- // make sure all resources are loaded on first activation | |
- if (!loaded) Live.loadresources(); | |
+ // Look for resources to track | |
+ Live.loadresources(); | |
Live.checkForChanges(); | |
} | |
setTimeout(Live.heartbeat, interval); | |
}, | |
@@ -59,11 +59,11 @@ | |
uris = []; | |
// track local js urls | |
for (var i = 0; i < scripts.length; i++) { | |
var script = scripts[i], src = script.getAttribute("src"); | |
- if (src && isLocal(src)) | |
+ if (src && isLocal(src) && resources[src] == null) | |
uris.push(src); | |
if (src && src.match(/\blive.js#/)) { | |
for (var type in active) | |
active[type] = src.match("[#,|]" + type) != null | |
if (src.match("notify")) | |
@@ -74,11 +74,11 @@ | |
if (active.html) uris.push(document.location.href); | |
// track local css urls | |
for (var i = 0; i < links.length && active.css; i++) { | |
var link = links[i], rel = link.getAttribute("rel"), href = link.getAttribute("href", 2); | |
- if (href && rel && rel.match(new RegExp("stylesheet", "i")) && isLocal(href)) { | |
+ if (href && rel && rel.match(new RegExp("stylesheet", "i")) && isLocal(href) && resources[src] == null) { | |
uris.push(href); | |
currentLinkElements[href] = link; | |
} | |
} | |
@@ -89,17 +89,19 @@ | |
resources[url] = info; | |
}); | |
} | |
// add rule for morphing between old and new css files | |
- var head = document.getElementsByTagName("head")[0], | |
- style = document.createElement("style"), | |
- rule = "transition: all .3s ease-out;" | |
- css = [".livejs-loading * { ", rule, " -webkit-", rule, "-moz-", rule, "-o-", rule, "}"].join(''); | |
- style.setAttribute("type", "text/css"); | |
- head.appendChild(style); | |
- style.styleSheet ? style.styleSheet.cssText = css : style.appendChild(document.createTextNode(css)); | |
+ if(!loaded){ | |
+ var head = document.getElementsByTagName("head")[0], | |
+ style = document.createElement("style"), | |
+ rule = "transition: all .3s ease-out;" | |
+ css = [".livejs-loading * { ", rule, " -webkit-", rule, "-moz-", rule, "-o-", rule, "}"].join(''); | |
+ style.setAttribute("type", "text/css"); | |
+ head.appendChild(style); | |
+ style.styleSheet ? style.styleSheet.cssText = css : style.appendChild(document.createTextNode(css)); | |
+ } | |
// yep | |
loaded = true; | |
}, | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment