Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^5: Free Nodelet Hack: AJAX-enabled Chatterbox

by Your Mother (Archbishop)
on Mar 21, 2009 at 07:26 UTC ( #752204=note: print w/replies, xml ) Need Help??

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" ""> <html xmlns="" 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=" +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>

Replies are listed 'Best First'.
Re^6: Free Nodelet Hack: AJAX-enabled Chatterbox
by bellaire (Hermit) on Mar 27, 2009 at 17:05 UTC
    Gotcha, thanks for the suggestion! It looks like binding to the body works just fine, since by default the other bound events will "propagate" up to the body unless explicitly stopped. I think that's the point I was missing on how to implement this before. New version includes these changes, so now to keep your CB alive or to resume, just wave your mouse around on the page.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://752204]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2021-03-01 07:17 GMT
Find Nodes?
    Voting Booth?

    No recent polls found