Update RELEASE-NOTES.
[mediawiki.git] / skins / common / ajaxsearch.js
blobb9fb56f39172591fa23880e4a3d9faaa419efeaa
1 // remote scripting library
2 // (c) copyright 2005 modernmethod, inc
4 var started;
5 var typing;
6 var memory=null;
7 var body=null;
8 var oldbody=null;
10 // Remove the typing barrier to allow call() to complete
11 function Search_doneTyping()
13         typing=false;
16 // Wait 500ms to run call()
17 function Searching_Go()
19         setTimeout("Searching_Call()", 500);
22 // If the user is typing wait until they are done.
23 function Search_Typing() {
24         started=true;
25         typing=true;
26         setTimeout("Search_doneTyping()", 500);
28         // I believe these are needed by IE for when the users press return?
29         if (window.event)
30         {
31                 if (event.keyCode == 13)
32                 {
33                         event.cancelBubble = true;
34                         event.returnValue = true;
35                 }
36         }
39 // Set the body div to the results
40 function Searching_SetResult( request )
42         if ( request.status != 200 ) {
43                 alert("Error: " + request.status + " " + request.statusText + ": " + request.responseText);
44                 return;
45         }
47         var result = request.responseText;
49         //body.innerHTML = result;
50         t = document.getElementById("searchTarget");
51         if ( t == null ) {
52                 oldbody=body.innerHTML;
53                 body.innerHTML= '<div id="searchTargetContainer"><div id="searchTarget" ></div></div>' ;
54                 t = document.getElementById("searchTarget");
55         }
56         t.innerHTML = result;
57         t.style.display='block';
60 function Searching_Hide_Results()
62         t = document.getElementById("searchTarget");
63         t.style.display='none';
64         body.innerHTML = oldbody;
68 // This will call the php function that will eventually
69 // return a results table
70 function Searching_Call()
72         var x;
73         Searching_Go();
75         //Don't proceed if user is typing
76         if (typing)
77                 return;
79         x = document.getElementById("searchInput").value;
81         // Don't search again if the query is the same
82         if (x==memory)
83                 return;
85         memory=x;
86         if (started) {
87                 // Don't search for blank or < 3 chars.
88                 if ((x=="") || (x.length < 3))
89                 {
90                         return;
91                 }
93                 sajax_do_call( "wfSajaxSearch", [ x ], Searching_SetResult );
94         }
97 //Initialize
98 function sajax_onload() {
99         x = document.getElementById( 'searchInput' );
100         x.onkeypress= function() { Search_Typing(); };
101         Searching_Go();
102         body = document.getElementById("content");