Created
July 10, 2010 21:22
-
-
Save keithnorm/471041 to your computer and use it in GitHub Desktop.
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
// Instead of refreshing the page each time and letting Rails regenerate your css files from any changed Sass files, use the Sass watch script: | |
// sass --watch public/stylesheets/sass:public/stylesheets | |
// | |
// Then use javascript to force the new css to load | |
function refreshCSS() { | |
var i,a,s; | |
a=document.getElementsByTagName('link'); | |
for(i=0;i<a.length;i++){ | |
s=a[i]; | |
if(s.rel.toLowerCase().indexOf('stylesheet')>=0&&s.href) { | |
var h=s.href.replace(/(&|%5C?)forceReload=\d+/,''); | |
s.href=h+(h.indexOf('?')>=0?'&':'?')+'forceReload='+(new Date().valueOf()) | |
} | |
} | |
} | |
// You can bind this function to window focus (useful for jumping between editor and browser and seeing changes instantly) | |
$(document).bind('focus', function(e){ | |
refreshCSS(); | |
}); | |
// or bind it to a key command | |
$(document).bind('keydown', function(e){ | |
// mapped to ctrl + R, but feel free to change it if you want | |
if(e.keyCode == 82 && e.ctrlKey) | |
refreshCSS(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment