[Instiki] delay in prototype.js ajax calls?
Roman Seidl
rot at granul.at
Fri Oct 28 07:01:40 EDT 2005
Hello instiki users,
I am using i2 as a wiki and i added some live preview to the wiki
editor. The only Problem with live preview is that if i type fast in
the editor it fires lots of http posts.
You can have a look at the editor under:
http://p2.granul.at/wiki/pages/Sandbox
So i thought if there would be a possibility to delay the ajax call.
I know how to delay a javascript call so that only the last call
within a time interval gets called. But it seems awfully complicated
to me to apply this to the prototype library.
Example for a page doing a delay (opens a popup on the last click
within one second):
---------
<html>
<head>
<script language="javascript">
var onceafter_requests=0;
function onceafter(time)
{
onceafter_requests++;
debug(onceafter_requests);
setTimeout("trytodo()",time);
}
function trytodo()
{
onceafter_requests--;
debug("-"+onceafter_requests);
if(onceafter_requests == 0) alert("now!");
}
function debug(str)
{
var dbgObj = document.getElementById("dbg");
dbgObj.innerHTML = (dbgObj.innerHTML + str + "<br>");
}
</script>
</head>
<body>
<form>
<input type="button" value="Push this button to open an alert box for the last click within 1 second" onClick="onceafter(1000);">
</form>
<div id="dbg"></div>
</body>
</html>
-----
Anyone got an idea if this pattern could be applied to the prototype
ajax library and how?
cheers
roman seidl
P.S.: If someone wants to see this editor in i2 i can send a patch or
so. IŽ am actually working on combining i2 and collaboa and so my
pathces to i2 go far beyond the editor.
More information about the Instiki-users
mailing list