Created
May 28, 2014 18:53
-
-
Save greyaperez/1339d27d11da6777abc7 to your computer and use it in GitHub Desktop.
Auto Reload CSS
This file contains hidden or 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
/* | |
* Usage (2 Choices): | |
* Option 1 - Auto Reload on Interval | |
* -- autoCSS.start() | |
* | |
* Option 2 - Reload on Demand | |
* -- autoCSS.init() | |
* -- autoCSS.refresh() | |
*/ | |
var autoCSS = { | |
sheets : [], | |
urls : [], | |
interval : 2000, | |
process : false, | |
init : function(){ | |
if(autoCSS.sheets.length === 0){ | |
autoCSS.sheets = [].slice.call(document.getElementsByTagName('link'), 0).filter(function(el){ return (el.getAttribute('rel') === 'stylesheet'); }); | |
} | |
for(i=0; i < autoCSS.sheets.length; i++){ | |
autoCSS.urls.push( autoCSS.sheets[i].getAttribute('href') ); | |
} | |
}, | |
include : function(inc){ | |
autoCSS.sheets.push(inc); | |
}, | |
start : function(){ | |
autoCSS.init(); | |
autoCSS.process = setInterval(autoCSS.refresh,this.interval); | |
}, | |
stop : function(){ | |
clearInterval(autoCSS.process); | |
}, | |
refresh : function(){ | |
for(i=0; i < autoCSS.sheets.length; i++){ | |
autoCSS.sheets[i].setAttribute('href',autoCSS.urls[i]+'?s='+new Date / 1000); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment