http://qs321.pair.com?node_id=752204


in reply to Re^4: Free Nodelet Hack: AJAX-enabled Chatterbox
in thread Free Nodelet Hack: AJAX-enabled Chatterbox

This is a first stab, not rigorously tested so it might have pitfalls but it seems to work and cover the correct bases. The layout could be used to restart the CB refresh (on a 10 second timer in the dummy code) as long as the user is interacting with the page; no clicky, no mousy, no chatty. If they go away for 2 hours, or 2 weeks for that matter, and come back it would start working again as soon as they triggered one of the bound events. Working sample to play with-

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>Body listener + timeOut test</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery. +js" type="text/javascript"></script> <script type="text/javascript">//<![CDATA[ // This would be the function that refreshes CB. function ohHaiCB () { $("body").prepend("<h1>It'll be just like starting over</h1>"); // Clear our place holder so any page even will restart // timeOut to call this function again. $(".myperfectlyuniqueid").remove(); } jQuery(function($) { // Bind to some interaction-y events. $("body").bind("focus resize scroll click mouseover keypress", function(evt){ $("body").prepend("<span> Got a " + evt.type + " </span>"); // We keep a placeholder element/node to know // if we're already in a setTimeOut. if ( $(".myperfectlyuniqueid").size() ) return true; // It wasn't there so refresh the CB. setTimeout(ohHaiCB, 10000); // Create our place holder element. // Why class instead of id? It's less likely to be // buggy x-browser which can do weird/different things // with DOM node removal. var placeHolder = $("<div class='myperfectlyuniqueid'/>"); // Hide it even though it's empty. placeHolder.hide(); // Tack it into the body. $("body").append(placeHolder); }); }); //]]> </script> </head> <body> <p>Something here to start.</p> </body></html>

To do the selectors for PM something like-

<script type="text/javascript">//<![CDATA[ jQuery(function($) { $("td.main_content, td.nodelets").bind("focus resize scroll click mo +useover keypress", function(){ // et cetera }); }); //]]> </script>