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>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|