X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=html%2F_js%2Feditor.js;fp=html%2F_js%2Feditor.js;h=d4dc06314eda3b7495b45dfa552c706ed4d03a92;hb=ddd6c57aa57e9b5425b529ec4cee89314710d614;hp=84b930ef853028bb99dfa6f45ce714256811695b;hpb=89e8d5757ca111d16ce3dfcc1ce4f2c00a119c85;p=cocanwiki.git diff --git a/html/_js/editor.js b/html/_js/editor.js index 84b930e..d4dc063 100644 --- a/html/_js/editor.js +++ b/html/_js/editor.js @@ -1,9 +1,17 @@ /* Javascript for OCAMLWIKI. * Copyright (C) 2004 Merjis Ltd. - * $Id: editor.js,v 1.4 2004/10/26 17:50:23 rich Exp $ + * $Id: editor.js,v 1.5 2004/11/14 14:23:27 rich Exp $ */ -var delay = 1000; // Delay in milliseconds before updating. +// Delay in milliseconds before updating. +// We will adjust this during editing to take into account the actual +// average round trip time measured during update_preview_now. +var delay = 1000; + +// This is used to measure the average round trip time. +var rtt_sum = 0; +var rtt_n = 0; +var rtt = 0; // Actual average RTT measured (ms). function update_preview (content_id, preview_id) { @@ -25,6 +33,9 @@ function update_preview_now (content_id, preview_id) // Get the Wiki-markup content from the content textarea. var content = document.getElementById (content_id).value; + // Time how long it takes to send the document to the server. + var start_time = (new Date()).getTime(); + // Send the Wiki-markup to the server to be turned into XHTML. var http = document.all ? new ActiveXObject ('Microsoft.XMLHTTP') : new XMLHttpRequest (); @@ -42,6 +53,15 @@ function update_preview_now (content_id, preview_id) // "Unknown runtime error" preview.innerHTML = xhtml; } + + // Finish timer and recompute RTT. + var end_time = (new Date()).getTime(); + rtt_sum += end_time - start_time; + rtt_n++; + rtt = rtt_sum / rtt_n; + + // Recompute the next delay period. + delay = rtt * 2; } // Initialise the edit_buttons for a section.