jQuery Heartbeat Demo
This is a Drupal module wrapper for the jQuery Heartbeat plug-in (created by Jason Levine and customized by A J Richards). This plug-in makes it possible to poll the server and/or trigger callbacks at given intervals.
It's very easy to use this module wrapper and you can use it in your own modules and blocks. And by using callback scripts, you can have several events triggered simultaneously as I do in this demo.
On the is page I've embedded a section into the content and I also have a block on the sidebar that gets updated. The sidebar block is updated both by calling a PHP script as well as by using callbacks to JavaScript functions. The content on this page is only updated via a callback.
This block will change color
For this demo, we've put the jQuery Heartbeat calling function in the block code, but you could also embed it into a module.
The block code looks something like this:
[...]
case 'view':
jquery_heartbeat_set([delay], [div ID], [my PHP script], [my callback functions]);
$output = '<div id="[div ID]">'
. '[Text to be replaced with content from PHP script]'
. '</div>';
$block['subject'] = '[my block title]';
$block['content'] = $output;
return $block;
break;
[...]
In this particular example we use several callbacks separated by ';' (semi-colon). Also note that you only have to supply the [div ID] for jquery_heartbeat_set() if you are using a PHP script to update the content. If you're using Javascript callbacks, then you need to make sure they know what ID tags to manipulate.
- Printer-friendly version
- Login to post comments

