* (bug 2866) Revert experimental, non-cross-platform sortable table hack
[lhc/web/wiklou.git] / skins / common / preview.js
1 // Live preview
2
3 function openXMLHttpRequest() {
4 if( window.XMLHttpRequest ) {
5 return new XMLHttpRequest();
6 } else if( window.ActiveXObject && navigator.platform != 'MacPPC' ) {
7 // IE/Mac has an ActiveXObject but it doesn't work.
8 return new ActiveXObject("Microsoft.XMLHTTP");
9 } else {
10 return null;
11 }
12 }
13
14 /**
15 * Returns true if could open the request,
16 * false otherwise (eg no browser support).
17 */
18 function livePreview(target, text, postUrl) {
19 prevTarget = target;
20 if( !target ) {
21 window.alert('crash and burn');
22 }
23 prevReq = openXMLHttpRequest();
24 if( !prevReq ) return false;
25
26 prevReq.onreadystatechange = updatePreviewText;
27 prevReq.open("POST", postUrl, true);
28
29 var postData = 'wpTextbox1=' + encodeURIComponent(text);
30 prevReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
31 prevReq.send(postData);
32 return true;
33 }
34
35 function updatePreviewText() {
36 if( prevReq.readyState != 4 ) {
37 return;
38 }
39 if( prevReq.status != 200 ) {
40 window.alert('Failed to connect: ' + prevReq.status +
41 ' "' + prevReq.statusText + '"');
42 return;
43 }
44 prevTarget.innerHTML = prevReq.responseText;
45 }