Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. /**
  2. * Css auto reload
  3. * NOTE!!! remove on production
  4. */
  5. (function() {
  6. 'use strict';
  7.  
  8. var CssReload = {
  9. config: {
  10. keyCode: 83
  11. },
  12. init: function() {
  13. this.link = $('link[href*="style.css"]');
  14. this.unix = null;
  15. this.href = null;
  16. this.event();
  17. },
  18. event: function() {
  19. jQuery(window).on('keydown', this.reloadStyle.bind(this));
  20. },
  21. reloadStyle: function(e) {
  22. if( e.keyCode === this.config.keyCode
  23. && localStorage.getItem('dev') == 1 ){
  24. this._refreshStyle();
  25. }
  26. },
  27. _refreshStyle: function() {
  28. this.href = this.link.attr('href');
  29. this.unix = new Date().getTime();
  30. this.href = /\?/.test(this.href) ? this.href.split('?')[0] : this.href;
  31. this.link.attr('href', this.href + '?' + this.unix);
  32. }
  33. };
  34.  
  35. window.CssReload = CssReload;
  36.  
  37. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement