Created
January 27, 2015 21:23
-
-
Save tadman/db658360cc0feb903d38 to your computer and use it in GitHub Desktop.
Automatic Page Refresher
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
var refresh_element = $('#refresh')[0]; | |
if (refresh_element) { | |
$(refresh_element).data('refresh', 1); | |
setInterval(function() { | |
if ($(refresh_element).data('refresh')) | |
$(refresh_element).load(window.location.href + ' #refresh'); | |
}, 5000); | |
var pauseRefreshments = function() { | |
if ($(refresh_element).data('refresh')) { | |
$('#pause').html('Resume'); | |
$(refresh_element).data('refresh', 0); | |
} | |
else { | |
$(refresh_element).data('refresh', 1); | |
$('#pause').html('Pause'); | |
} | |
}; | |
$('#pause').live('click', function(ev) { | |
ev.preventDefault(); | |
pauseRefreshments(); | |
}); | |
$('body').keyup(function(e) { | |
var p_key = 80; | |
if (e.which === p_key) { | |
pauseRefreshments(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment