Permalink
Browse files

Tweaks to polling heartbeat: use setTimeout rather than setInterval t…

…o prevent backing up. Allow setting html{-pie-poll-interval:N} to customize the interval on a page.
  • Loading branch information...
1 parent 8d73e90 commit 6744f0440f4656cfe19f86d57e4e221c2eb2a51c @lojjic committed Feb 8, 2012
Showing with 8 additions and 3 deletions.
  1. +8 −3 sources/Heartbeat.js
View
@@ -2,15 +2,20 @@
* Simple heartbeat timer - this is a brute-force workaround for syncing issues caused by IE not
* always firing the onmove and onresize events when elements are moved or resized. We check a few
* times every second to make sure the elements have the correct position and size. See Element.js
- * which adds heartbeat listeners based on the custom -pie-poll flag, which defaults to true in IE8
+ * which adds heartbeat listeners based on the custom -pie-poll flag, which defaults to true in IE8-9
* and false elsewhere.
*/
PIE.Heartbeat = new PIE.Observable();
PIE.Heartbeat.run = function() {
- var me = this;
+ var me = this,
+ interval;
if( !me.running ) {
- setInterval( function() { me.fire() }, 250 );
+ interval = doc.documentElement.currentStyle.getAttribute( PIE.CSS_PREFIX + 'poll-interval' ) || 250;
+ (function beat() {
+ me.fire();
+ setTimeout(beat, interval);
+ })();
me.running = 1;
}
};

0 comments on commit 6744f04

Please sign in to comment.