1 /* Javascript for OCAMLWIKI.
2 * Copyright (C) 2004 Merjis Ltd.
3 * $Id: editor.js,v 1.1 2004/09/07 10:14:09 rich Exp $
6 var delay = 1000 // Delay in milliseconds before updating.
8 function update_preview (content_id, preview_id)
10 // Updating is quite expensive, so only update after a period of apparent
12 var preview = document.getElementById (preview_id);
13 if (preview.timer) clearTimeout (preview.timer);
15 setTimeout ("update_preview_now ('" + content_id + "', '" +
16 preview_id + "')", delay);
19 function update_preview_now (content_id, preview_id)
22 var preview = document.getElementById (preview_id);
23 if (preview.timer) preview.timer = null;
25 // Get the Wiki-markup content from the content textarea.
26 var content = document.getElementById (content_id).value;
28 // Send the Wiki-markup to the server to be turned into XHTML.
29 var http = document.all ?
30 new ActiveXObject ('Microsoft.XMLHTTP') : new XMLHttpRequest ();
33 http.open ('POST', '/_bin/preview.cmo', false);
34 http.setRequestHeader ('Content-Type',
35 'application/x-www-form-urlencoded');
36 http.send ('content=' + encodeURIComponent (content));
38 var xhtml = http.responseText;
40 // Next line fails with my copy of IE if the text contains a
41 // link (ie. <a href...>). It is unclear why. The error is:
42 // "Unknown runtime error"
43 preview.innerHTML = xhtml;