* (bug 9430) Update Cantonese translations
[mediawiki.git] / skins / common / ajaxsearch.js
blob1e972236ea236da9a4ef493551c2e29392cd32c3
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         window.status = "Waiting until you're done typing...";
27         setTimeout("Search_doneTyping()", 500);
29         // I believe these are needed by IE for when the users press return?
30         if (window.event)
31         {
32                 if (event.keyCode == 13)
33                 {
34                         event.cancelBubble = true;
35                         event.returnValue = true;
36                 }
37         }
40 // Set the body div to the results
41 function Searching_SetResult( request )
43         if ( request.status != 200 ) {
44                 alert("Error: " + request.status + " " + request.statusText + ": " + request.responseText);
45                 return;
46         }
48         var result = request.responseText;
50         //body.innerHTML = result;
51         t = document.getElementById("searchTarget");
52         if ( t == null ) {
53                 oldbody=body.innerHTML;
54                 body.innerHTML= '<div id="searchTargetContainer"><div id="searchTarget" ></div></div>' ;
55                 t = document.getElementById("searchTarget");
56         }
57         t.innerHTML = result;
58         t.style.display='block';
61 function Searching_Hide_Results()
63         t = document.getElementById("searchTarget");
64         t.style.display='none';
65         body.innerHTML = oldbody;
69 // This will call the php function that will eventually
70 // return a results table
71 function Searching_Call()
73         var x;
74         Searching_Go();
76         //Don't proceed if user is typing
77         if (typing)
78                 return;
80         x = document.getElementById("searchInput").value;
82         // Don't search again if the query is the same
83         if (x==memory)
84                 return;
86         memory=x;
87         if (started) {
88                 // Don't search for blank or < 3 chars.
89                 if ((x=="") || (x.length < 3))
90                 {
91                         return;
92                 }
94                 sajax_do_call( "wfSajaxSearch", [ x ], Searching_SetResult );
95         }
98 //Initialize
99 function sajax_onload() {
100         x = document.getElementById( 'searchInput' );
101         x.onkeypress= function() { Search_Typing(); };
102         Searching_Go();
103         body = document.getElementById("content");