Skip to content

Commit 87be49d

Browse files
klasskeKlaske van Vuurden
authored andcommitted
Only refresh images when the window has focus
1 parent 4efd5fa commit 87be49d

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

image-autorefresh.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44

55
jQuery(document).ready(function(){
66

7+
8+
//todo find a better way to determine width
79
jQuery('img.image_autorefresh').width(jQuery('#content').width());
810

11+
jQuery(document).focus(function(){
12+
jQuery('img.image_autorefresh').each(function(){
13+
d = new Date();
14+
this.attr("src", this.data("src") + "?" + d.getTime());
15+
});
16+
17+
});
918

1019
});

image-autorefresh.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ function image_autorefresh_shortcode($atts){
3030
<script>
3131
setInterval(function()
3232
{
33-
d = new Date();
34-
image = jQuery('img#image_autorefresh_<?php echo $randomString ?>');
35-
image.attr("src", image.data("src") + "?" + d.getTime());
33+
if(document.hasFocus()){
34+
d = new Date();
35+
image = jQuery('img#image_autorefresh_<?php echo $randomString ?>');
36+
image.attr("src", image.data("src") + "?" + d.getTime());
37+
}
3638
}, <?php echo $a['refresh_time']; ?>000);
39+
3740
</script>
3841

3942
<div class="<?php echo '' != $a['caption'] ? 'wp-caption ': ''; ?>align<?php echo $a['align']; ?>">

0 commit comments

Comments
 (0)