1 // remote scripting library
2 // (c) copyright 2005 modernmethod, inc
3 var sajax_debug_mode = false;
4 var sajax_request_type = "GET";
12 function sajax_debug(text) {
18 function sajax_init_object() {
19 sajax_debug("sajax_init_object() called..")
22 A=new ActiveXObject("Msxml2.XMLHTTP");
25 A=new ActiveXObject("Microsoft.XMLHTTP");
30 if(!A && typeof XMLHttpRequest != "undefined")
31 A = new XMLHttpRequest();
33 sajax_debug("Could not create connection object.");
38 function sajax_do_call(func_name, args) {
42 uri = wgServer + "/" + wgScriptPath + "/index.php?action=ajax";
43 if (sajax_request_type == "GET") {
44 if (uri.indexOf("?") == -1)
45 uri = uri + "?rs=" + escape(func_name);
47 uri = uri + "&rs=" + escape(func_name);
48 for (i = 0; i < args.length-1; i++)
49 uri = uri + "&rsargs[]=" + escape(args[i]);
50 //uri = uri + "&rsrnd=" + new Date().getTime();
53 post_data = "rs=" + escape(func_name);
54 for (i = 0; i < args.length-1; i++)
55 post_data = post_data + "&rsargs[]=" + escape(args[i]);
57 x = sajax_init_object();
58 x.open(sajax_request_type, uri, true);
59 if (sajax_request_type == "POST") {
60 x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
61 x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
63 x.setRequestHeader("Pragma", "cache=yes");
64 x.setRequestHeader("Cache-Control", "no-transform");
65 x.onreadystatechange = function() {
66 if (x.readyState != 4)
68 sajax_debug("received " + x.responseText);
71 status = x.responseText.charAt(0);
72 data = x.responseText.substring(2);
74 alert("Error: " + data);
76 args[args.length-1](data);
79 sajax_debug(func_name + " uri = " + uri + "/post = " + post_data);
80 sajax_debug(func_name + " waiting..");
84 // Remove the typing barrier to allow call() to complete
85 function Search_doneTyping()
90 // Wait 500ms to run call()
91 function Searching_Go()
93 setTimeout("Searching_Call()", 500);
96 // If the user is typing wait until they are done.
97 function Search_Typing() {
100 window.status = "Waiting until you're done typing...";
101 setTimeout("Search_doneTyping()", 500);
103 // I believe these are needed by IE for when the users press return?
106 if (event.keyCode == 13)
108 event.cancelBubble = true;
109 event.returnValue = false;
114 // Set the body div to the results
115 function Searching_SetResult(result)
117 //body.innerHTML = result;
118 t = document.getElementById("searchTarget");
120 oldbody=body.innerHTML;
121 body.innerHTML= '<div id="searchTargetContainer"><div id="searchTarget" ></div></div>' ;
122 t = document.getElementById("searchTarget");
124 t.innerHTML = result;
125 t.style.display='block';
128 function Searching_Hide_Results()
130 t = document.getElementById("searchTarget");
131 t.style.display='none';
132 body.innerHTML = oldbody;
136 // This will call the php function that will eventually
137 // return a results table
138 function Searching_Call()
143 //Don't proceed if user is typing
147 x = document.getElementById("searchInput").value;
149 // Don't search again if the query is the same
155 // Don't search for blank or < 3 chars.
156 if ((x=="") || (x.length < 3))
160 x_wfSajaxSearch(x, Searching_SetResult);
164 function x_wfSajaxSearch() {
165 sajax_do_call( "wfSajaxSearch", x_wfSajaxSearch.arguments );
170 function sajax_onload() {
171 x = document.getElementById( 'searchInput' );
172 x.onkeypress= function() { Search_Typing(); };
174 body = document.getElementById("content");
177 hookEvent("load", sajax_onload);