Last active
August 29, 2015 14:14
-
-
Save IOZ/a0f18d9d41bdfd03e4da to your computer and use it in GitHub Desktop.
css auto reloader
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
/** | |
* Css auto reload | |
* NOTE!!! remove on production | |
*/ | |
(function() { | |
'use strict'; | |
var CssReload = { | |
config: { | |
keyCode: 83 | |
}, | |
init: function() { | |
this.link = $('link[href*="style.css"]'); | |
this.unix = null; | |
this.href = null; | |
this.event(); | |
}, | |
event: function() { | |
$(window).on('keydown', this.reloadStyle.bind(this)); | |
}, | |
reloadStyle: function(e) { | |
if( e.keyCode === this.config.keyCode | |
&& localStorage.getItem('dev') == 1 ){ | |
this._refreshStyle(); | |
} | |
}, | |
_refreshStyle: function() { | |
this.href = this.link.attr('href'); | |
this.unix = new Date().getTime(); | |
this.href = /\?/.test(this.href) ? this.href.split('?')[0] : this.href; | |
this.link.attr('href', this.href + '?' + this.unix); | |
} | |
}; | |
window.CssReload = CssReload; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment