Redesign of Special:Userrights.
[lhc/web/wiklou.git] / skins / common / ajaxsearch.js
1 // remote scripting library
2 // (c) copyright 2005 modernmethod, inc
3
4 var started;
5 var typing;
6 var memory=null;
7 var body=null;
8 var oldbody=null;
9
10 // Remove the typing barrier to allow call() to complete
11 function Search_doneTyping()
12 {
13 typing=false;
14 }
15
16 // Wait 500ms to run call()
17 function Searching_Go()
18 {
19 setTimeout("Searching_Call()", 500);
20 }
21
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);
27
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 }
37 }
38
39 // Set the body div to the results
40 function Searching_SetResult( request )
41 {
42 if ( request.status != 200 ) {
43 alert("Error: " + request.status + " " + request.statusText + ": " + request.responseText);
44 return;
45 }
46
47 var result = request.responseText;
48
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';
58 }
59
60 function Searching_Hide_Results()
61 {
62 t = document.getElementById("searchTarget");
63 t.style.display='none';
64 body.innerHTML = oldbody;
65 }
66
67
68 // This will call the php function that will eventually
69 // return a results table
70 function Searching_Call()
71 {
72 var x;
73 Searching_Go();
74
75 //Don't proceed if user is typing
76 if (typing)
77 return;
78
79 x = document.getElementById("searchInput").value;
80
81 // Don't search again if the query is the same
82 if (x==memory)
83 return;
84
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 }
92
93 sajax_do_call( "wfSajaxSearch", [ x ], Searching_SetResult );
94 }
95 }
96
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");
103 }