Index: trunk/phase3/skins/common/mwsuggest.js |
— | — | @@ -42,32 +42,34 @@ |
43 | 43 | var os_animation_timer = null; |
44 | 44 | |
45 | 45 | /** Timeout timer class that will fetch the results */ |
46 | | -function os_Timer(id,r,query){ |
| 46 | +function os_Timer( id, r, query ) { |
47 | 47 | this.id = id; |
48 | 48 | this.r = r; |
49 | 49 | this.query = query; |
50 | 50 | } |
51 | 51 | |
52 | 52 | /** Timer user to animate expansion/contraction of container width */ |
53 | | -function os_AnimationTimer(r, target){ |
| 53 | +function os_AnimationTimer( r, target ) { |
54 | 54 | this.r = r; |
55 | 55 | var current = document.getElementById(r.container).offsetWidth; |
56 | | - this.inc = Math.round((target-current) / os_animation_steps); |
57 | | - if(this.inc < os_animation_min_step && this.inc >=0) |
| 56 | + this.inc = Math.round( ( target - current ) / os_animation_steps ); |
| 57 | + if( this.inc < os_animation_min_step && this.inc >=0 ) { |
58 | 58 | this.inc = os_animation_min_step; // minimal animation step |
59 | | - if(this.inc > -os_animation_min_step && this.inc <0) |
| 59 | + } |
| 60 | + if( this.inc > -os_animation_min_step && this.inc < 0 ) { |
60 | 61 | this.inc = -os_animation_min_step; |
| 62 | + } |
61 | 63 | this.target = target; |
62 | 64 | } |
63 | 65 | |
64 | 66 | /** Property class for single search box */ |
65 | | -function os_Results(name, formname){ |
| 67 | +function os_Results( name, formname ) { |
66 | 68 | this.searchform = formname; // id of the searchform |
67 | 69 | this.searchbox = name; // id of the searchbox |
68 | | - this.container = name+"Suggest"; // div that holds results |
69 | | - this.resultTable = name+"Result"; // id base for the result table (+num = table row) |
70 | | - this.resultText = name+"ResultText"; // id base for the spans within result tables (+num) |
71 | | - this.toggle = name+"Toggle"; // div that has the toggle (enable/disable) link |
| 70 | + this.container = name + 'Suggest'; // div that holds results |
| 71 | + this.resultTable = name + 'Result'; // id base for the result table (+num = table row) |
| 72 | + this.resultText = name + 'ResultText'; // id base for the spans within result tables (+num) |
| 73 | + this.toggle = name + 'Toggle'; // div that has the toggle (enable/disable) link |
72 | 74 | this.query = null; // last processed query |
73 | 75 | this.results = null; // parsed titles |
74 | 76 | this.resultCount = 0; // number of results |
— | — | @@ -81,359 +83,384 @@ |
82 | 84 | } |
83 | 85 | |
84 | 86 | /** Hide results div */ |
85 | | -function os_hideResults(r){ |
86 | | - var c = document.getElementById(r.container); |
87 | | - if(c != null) |
88 | | - c.style.visibility = "hidden"; |
| 87 | +function os_hideResults( r ) { |
| 88 | + var c = document.getElementById( r.container ); |
| 89 | + if( c !== null ) { |
| 90 | + c.style.visibility = 'hidden'; |
| 91 | + } |
89 | 92 | r.visible = false; |
90 | 93 | r.selected = -1; |
91 | 94 | } |
92 | 95 | |
93 | 96 | /** Show results div */ |
94 | | -function os_showResults(r){ |
95 | | - if(os_is_stopped) |
| 97 | +function os_showResults( r ) { |
| 98 | + if( os_is_stopped ) { |
96 | 99 | return; |
97 | | - if(r.stayHidden) |
98 | | - return |
99 | | - os_fitContainer(r); |
100 | | - var c = document.getElementById(r.container); |
| 100 | + } |
| 101 | + if( r.stayHidden ) { |
| 102 | + return; |
| 103 | + } |
| 104 | + os_fitContainer( r ); |
| 105 | + var c = document.getElementById( r.container ); |
101 | 106 | r.selected = -1; |
102 | | - if(c != null){ |
| 107 | + if( c !== null ) { |
103 | 108 | c.scrollTop = 0; |
104 | | - c.style.visibility = "visible"; |
| 109 | + c.style.visibility = 'visible'; |
105 | 110 | r.visible = true; |
106 | 111 | } |
107 | 112 | } |
108 | 113 | |
109 | | -function os_operaWidthFix(x){ |
| 114 | +function os_operaWidthFix( x ) { |
110 | 115 | // For browsers that don't understand overflow-x, estimate scrollbar width |
111 | | - if(typeof document.body.style.overflowX != "string"){ |
| 116 | + if( typeof document.body.style.overflowX != 'string' ) { |
112 | 117 | return 30; |
113 | 118 | } |
114 | 119 | return 0; |
115 | 120 | } |
116 | 121 | |
117 | | -function os_encodeQuery(value){ |
118 | | - if (encodeURIComponent) { |
119 | | - return encodeURIComponent(value); |
120 | | - } |
121 | | - if(escape) { |
122 | | - return escape(value); |
123 | | - } |
124 | | - return null; |
| 122 | +function os_encodeQuery( value ) { |
| 123 | + if ( encodeURIComponent ) { |
| 124 | + return encodeURIComponent( value ); |
| 125 | + } |
| 126 | + if( escape ) { |
| 127 | + return escape( value ); |
| 128 | + } |
| 129 | + return null; |
125 | 130 | } |
126 | | -function os_decodeValue(value){ |
127 | | - if (decodeURIComponent) { |
128 | | - return decodeURIComponent(value); |
129 | | - } |
130 | | - if(unescape){ |
131 | | - return unescape(value); |
132 | | - } |
133 | | - return null; |
| 131 | + |
| 132 | +function os_decodeValue( value ) { |
| 133 | + if ( decodeURIComponent ) { |
| 134 | + return decodeURIComponent( value ); |
| 135 | + } |
| 136 | + if( unescape ) { |
| 137 | + return unescape( value ); |
| 138 | + } |
| 139 | + return null; |
134 | 140 | } |
135 | 141 | |
136 | 142 | /** Brower-dependent functions to find window inner size, and scroll status */ |
137 | 143 | function f_clientWidth() { |
138 | | - return f_filterResults ( |
| 144 | + return f_filterResults( |
139 | 145 | window.innerWidth ? window.innerWidth : 0, |
140 | 146 | document.documentElement ? document.documentElement.clientWidth : 0, |
141 | 147 | document.body ? document.body.clientWidth : 0 |
142 | 148 | ); |
143 | 149 | } |
| 150 | + |
144 | 151 | function f_clientHeight() { |
145 | | - return f_filterResults ( |
| 152 | + return f_filterResults( |
146 | 153 | window.innerHeight ? window.innerHeight : 0, |
147 | 154 | document.documentElement ? document.documentElement.clientHeight : 0, |
148 | 155 | document.body ? document.body.clientHeight : 0 |
149 | 156 | ); |
150 | 157 | } |
| 158 | + |
151 | 159 | function f_scrollLeft() { |
152 | | - return f_filterResults ( |
| 160 | + return f_filterResults( |
153 | 161 | window.pageXOffset ? window.pageXOffset : 0, |
154 | 162 | document.documentElement ? document.documentElement.scrollLeft : 0, |
155 | 163 | document.body ? document.body.scrollLeft : 0 |
156 | 164 | ); |
157 | 165 | } |
| 166 | + |
158 | 167 | function f_scrollTop() { |
159 | | - return f_filterResults ( |
| 168 | + return f_filterResults( |
160 | 169 | window.pageYOffset ? window.pageYOffset : 0, |
161 | 170 | document.documentElement ? document.documentElement.scrollTop : 0, |
162 | 171 | document.body ? document.body.scrollTop : 0 |
163 | 172 | ); |
164 | 173 | } |
165 | | -function f_filterResults(n_win, n_docel, n_body) { |
| 174 | + |
| 175 | +function f_filterResults( n_win, n_docel, n_body ) { |
166 | 176 | var n_result = n_win ? n_win : 0; |
167 | | - if (n_docel && (!n_result || (n_result > n_docel))) |
| 177 | + if ( n_docel && ( !n_result || ( n_result > n_docel ) ) ) { |
168 | 178 | n_result = n_docel; |
169 | | - return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result; |
| 179 | + } |
| 180 | + return n_body && ( !n_result || ( n_result > n_body ) ) ? n_body : n_result; |
170 | 181 | } |
171 | 182 | |
172 | 183 | /** Get the height available for the results container */ |
173 | | -function os_availableHeight(r){ |
174 | | - var absTop = document.getElementById(r.container).style.top; |
175 | | - var px = absTop.lastIndexOf("px"); |
176 | | - if(px > 0) |
177 | | - absTop = absTop.substring(0,px); |
178 | | - return f_clientHeight() - (absTop - f_scrollTop()); |
| 184 | +function os_availableHeight( r ) { |
| 185 | + var absTop = document.getElementById( r.container ).style.top; |
| 186 | + var px = absTop.lastIndexOf( 'px' ); |
| 187 | + if( px > 0 ) { |
| 188 | + absTop = absTop.substring( 0, px ); |
| 189 | + } |
| 190 | + return f_clientHeight() - ( absTop - f_scrollTop() ); |
179 | 191 | } |
180 | 192 | |
181 | | - |
182 | 193 | /** Get element absolute position {left,top} */ |
183 | | -function os_getElementPosition(elemID){ |
184 | | - var offsetTrail = document.getElementById(elemID); |
| 194 | +function os_getElementPosition( elemID ) { |
| 195 | + var offsetTrail = document.getElementById( elemID ); |
185 | 196 | var offsetLeft = 0; |
186 | 197 | var offsetTop = 0; |
187 | | - while (offsetTrail){ |
| 198 | + while ( offsetTrail ) { |
188 | 199 | offsetLeft += offsetTrail.offsetLeft; |
189 | 200 | offsetTop += offsetTrail.offsetTop; |
190 | 201 | offsetTrail = offsetTrail.offsetParent; |
191 | 202 | } |
192 | | - if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){ |
| 203 | + if ( navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined' ) { |
193 | 204 | offsetLeft += document.body.leftMargin; |
194 | 205 | offsetTop += document.body.topMargin; |
195 | 206 | } |
196 | | - return {left:offsetLeft,top:offsetTop}; |
| 207 | + return { left:offsetLeft, top:offsetTop }; |
197 | 208 | } |
198 | 209 | |
199 | 210 | /** Create the container div that will hold the suggested titles */ |
200 | | -function os_createContainer(r){ |
201 | | - var c = document.createElement("div"); |
202 | | - var s = document.getElementById(r.searchbox); |
203 | | - var pos = os_getElementPosition(r.searchbox); |
| 211 | +function os_createContainer( r ) { |
| 212 | + var c = document.createElement( 'div' ); |
| 213 | + var s = document.getElementById( r.searchbox ); |
| 214 | + var pos = os_getElementPosition( r.searchbox ); |
204 | 215 | var left = pos.left; |
205 | 216 | var top = pos.top + s.offsetHeight; |
206 | | - c.className = "os-suggest"; |
207 | | - c.setAttribute("id", r.container); |
208 | | - document.body.appendChild(c); |
| 217 | + c.className = 'os-suggest'; |
| 218 | + c.setAttribute( 'id', r.container ); |
| 219 | + document.body.appendChild( c ); |
209 | 220 | |
210 | 221 | // dynamically generated style params |
211 | 222 | // IE workaround, cannot explicitely set "style" attribute |
212 | | - c = document.getElementById(r.container); |
213 | | - c.style.top = top+"px"; |
214 | | - c.style.left = left+"px"; |
215 | | - c.style.width = s.offsetWidth+"px"; |
| 223 | + c = document.getElementById( r.container ); |
| 224 | + c.style.top = top + 'px'; |
| 225 | + c.style.left = left + 'px'; |
| 226 | + c.style.width = s.offsetWidth + 'px'; |
216 | 227 | |
217 | 228 | // mouse event handlers |
218 | | - c.onmouseover = function(event) { os_eventMouseover(r.searchbox, event); }; |
219 | | - c.onmousemove = function(event) { os_eventMousemove(r.searchbox, event); }; |
220 | | - c.onmousedown = function(event) { return os_eventMousedown(r.searchbox, event); }; |
221 | | - c.onmouseup = function(event) { os_eventMouseup(r.searchbox, event); }; |
| 229 | + c.onmouseover = function( event ) { os_eventMouseover( r.searchbox, event ); }; |
| 230 | + c.onmousemove = function( event ) { os_eventMousemove( r.searchbox, event ); }; |
| 231 | + c.onmousedown = function( event ) { return os_eventMousedown( r.searchbox, event ); }; |
| 232 | + c.onmouseup = function( event ) { os_eventMouseup( r.searchbox, event ); }; |
222 | 233 | return c; |
223 | 234 | } |
224 | 235 | |
225 | 236 | /** change container height to fit to screen */ |
226 | | -function os_fitContainer(r){ |
227 | | - var c = document.getElementById(r.container); |
228 | | - var h = os_availableHeight(r) - 20; |
| 237 | +function os_fitContainer( r ) { |
| 238 | + var c = document.getElementById( r.container ); |
| 239 | + var h = os_availableHeight( r ) - 20; |
229 | 240 | var inc = r.containerRow; |
230 | | - h = parseInt(h/inc) * inc; |
231 | | - if(h < (2 * inc) && r.resultCount > 1) // min: two results |
| 241 | + h = parseInt( h / inc ) * inc; |
| 242 | + if( h < ( 2 * inc ) && r.resultCount > 1 ) { // min: two results |
232 | 243 | h = 2 * inc; |
233 | | - if((h/inc) > os_max_lines_per_suggest ) |
| 244 | + } |
| 245 | + if( ( h / inc ) > os_max_lines_per_suggest ) { |
234 | 246 | h = inc * os_max_lines_per_suggest; |
235 | | - if(h < r.containerTotal){ |
236 | | - c.style.height = h +"px"; |
237 | | - r.containerCount = parseInt(Math.round(h/inc)); |
238 | | - } else{ |
239 | | - c.style.height = r.containerTotal+"px"; |
| 247 | + } |
| 248 | + if( h < r.containerTotal ) { |
| 249 | + c.style.height = h + 'px'; |
| 250 | + r.containerCount = parseInt( Math.round( h / inc ) ); |
| 251 | + } else { |
| 252 | + c.style.height = r.containerTotal + 'px'; |
240 | 253 | r.containerCount = r.resultCount; |
241 | 254 | } |
242 | 255 | } |
| 256 | + |
243 | 257 | /** If some entries are longer than the box, replace text with "..." */ |
244 | | -function os_trimResultText(r){ |
| 258 | +function os_trimResultText( r ) { |
245 | 259 | // find max width, first see if we could expand the container to fit it |
246 | 260 | var maxW = 0; |
247 | | - for(var i=0;i<r.resultCount;i++){ |
248 | | - var e = document.getElementById(r.resultText+i); |
249 | | - if(e.offsetWidth > maxW) |
| 261 | + for( var i = 0; i < r.resultCount; i++ ) { |
| 262 | + var e = document.getElementById( r.resultText + i ); |
| 263 | + if( e.offsetWidth > maxW ) { |
250 | 264 | maxW = e.offsetWidth; |
| 265 | + } |
251 | 266 | } |
252 | | - var w = document.getElementById(r.container).offsetWidth; |
| 267 | + var w = document.getElementById( r.container ).offsetWidth; |
253 | 268 | var fix = 0; |
254 | | - if(r.containerCount < r.resultCount){ |
| 269 | + if( r.containerCount < r.resultCount ) { |
255 | 270 | fix = 20; // give 20px for scrollbar |
256 | | - } else |
257 | | - fix = os_operaWidthFix(w); |
258 | | - if(fix < 4) |
| 271 | + } else { |
| 272 | + fix = os_operaWidthFix( w ); |
| 273 | + } |
| 274 | + if( fix < 4 ) { |
259 | 275 | fix = 4; // basic padding |
| 276 | + } |
260 | 277 | maxW += fix; |
261 | 278 | |
262 | 279 | // resize container to fit more data if permitted |
263 | | - var normW = document.getElementById(r.searchbox).offsetWidth; |
| 280 | + var normW = document.getElementById( r.searchbox ).offsetWidth; |
264 | 281 | var prop = maxW / normW; |
265 | | - if(prop > os_container_max_width) |
| 282 | + if( prop > os_container_max_width ) { |
266 | 283 | prop = os_container_max_width; |
267 | | - else if(prop < 1) |
| 284 | + } else if( prop < 1 ) { |
268 | 285 | prop = 1; |
| 286 | + } |
269 | 287 | var newW = Math.round( normW * prop ); |
270 | | - if( w != newW ){ |
| 288 | + if( w != newW ) { |
271 | 289 | w = newW; |
272 | | - if( os_animation_timer != null ) |
273 | | - clearInterval(os_animation_timer.id) |
274 | | - os_animation_timer = new os_AnimationTimer(r,w); |
275 | | - os_animation_timer.id = setInterval("os_animateChangeWidth()",os_animation_delay); |
| 290 | + if( os_animation_timer !== null ) { |
| 291 | + clearInterval( os_animation_timer.id ); |
| 292 | + } |
| 293 | + os_animation_timer = new os_AnimationTimer( r, w ); |
| 294 | + os_animation_timer.id = setInterval( "os_animateChangeWidth()", os_animation_delay ); |
276 | 295 | w -= fix; // this much is reserved |
277 | 296 | } |
278 | 297 | |
279 | 298 | // trim results |
280 | | - if(w < 10) |
| 299 | + if( w < 10 ) { |
281 | 300 | return; |
282 | | - for(var i=0;i<r.resultCount;i++){ |
283 | | - var e = document.getElementById(r.resultText+i); |
| 301 | + } |
| 302 | + for( var i = 0; i < r.resultCount; i++ ) { |
| 303 | + var e = document.getElementById( r.resultText + i ); |
284 | 304 | var replace = 1; |
285 | | - var lastW = e.offsetWidth+1; |
| 305 | + var lastW = e.offsetWidth + 1; |
286 | 306 | var iteration = 0; |
287 | 307 | var changedText = false; |
288 | | - while(e.offsetWidth > w && (e.offsetWidth < lastW || iteration<2)){ |
| 308 | + while( e.offsetWidth > w && ( e.offsetWidth < lastW || iteration < 2 ) ) { |
289 | 309 | changedText = true; |
290 | 310 | lastW = e.offsetWidth; |
291 | 311 | var l = e.innerHTML; |
292 | | - e.innerHTML = l.substring(0,l.length-replace)+"..."; |
| 312 | + e.innerHTML = l.substring( 0, l.length - replace ) + '...'; |
293 | 313 | iteration++; |
294 | 314 | replace = 4; // how many chars to replace |
295 | 315 | } |
296 | | - if(changedText){ |
| 316 | + if( changedText ) { |
297 | 317 | // show hint for trimmed titles |
298 | | - document.getElementById(r.resultTable+i).setAttribute("title",r.results[i]); |
| 318 | + document.getElementById( r.resultTable + i ).setAttribute( 'title', r.results[i] ); |
299 | 319 | } |
300 | 320 | } |
301 | 321 | } |
302 | 322 | |
303 | 323 | /** Invoked on timer to animate change in container width */ |
304 | | -function os_animateChangeWidth(){ |
| 324 | +function os_animateChangeWidth() { |
305 | 325 | var r = os_animation_timer.r; |
306 | | - var c = document.getElementById(r.container); |
| 326 | + var c = document.getElementById( r.container ); |
307 | 327 | var w = c.offsetWidth; |
308 | | - var normW = document.getElementById(r.searchbox).offsetWidth; |
309 | | - var normL = os_getElementPosition(r.searchbox).left; |
| 328 | + var normW = document.getElementById( r.searchbox ).offsetWidth; |
| 329 | + var normL = os_getElementPosition( r.searchbox ).left; |
310 | 330 | var inc = os_animation_timer.inc; |
311 | 331 | var target = os_animation_timer.target; |
312 | 332 | var nw = w + inc; |
313 | | - if( (inc > 0 && nw >= target) || (inc <= 0 && nw <= target) ){ |
| 333 | + if( ( inc > 0 && nw >= target ) || ( inc <= 0 && nw <= target ) ) { |
314 | 334 | // finished ! |
315 | | - c.style.width = target+"px"; |
316 | | - clearInterval(os_animation_timer.id) |
| 335 | + c.style.width = target + 'px'; |
| 336 | + clearInterval( os_animation_timer.id ); |
317 | 337 | os_animation_timer = null; |
318 | | - } else{ |
| 338 | + } else { |
319 | 339 | // in-progress |
320 | | - c.style.width = nw+"px"; |
321 | | - if(document.documentElement.dir == "rtl") |
322 | | - c.style.left = (normL + normW + (target - nw) - os_animation_timer.target - 1)+"px"; |
| 340 | + c.style.width = nw + 'px'; |
| 341 | + if( document.documentElement.dir == 'rtl' ) { |
| 342 | + c.style.left = ( normL + normW + ( target - nw ) - os_animation_timer.target - 1 ) + 'px'; |
| 343 | + } |
323 | 344 | } |
324 | 345 | } |
325 | 346 | |
326 | 347 | /** Handles data from XMLHttpRequest, and updates the suggest results */ |
327 | | -function os_updateResults(r, query, text, cacheKey){ |
| 348 | +function os_updateResults( r, query, text, cacheKey ) { |
328 | 349 | os_cache[cacheKey] = text; |
329 | 350 | r.query = query; |
330 | 351 | r.original = query; |
331 | | - if(text == ""){ |
| 352 | + if( text == '' ) { |
332 | 353 | r.results = null; |
333 | 354 | r.resultCount = 0; |
334 | | - os_hideResults(r); |
335 | | - } else{ |
| 355 | + os_hideResults( r ); |
| 356 | + } else { |
336 | 357 | try { |
337 | | - var p = eval('('+text+')'); // simple json parse, could do a safer one |
338 | | - if(p.length<2 || p[1].length == 0){ |
| 358 | + var p = eval( '(' + text + ')' ); // simple json parse, could do a safer one |
| 359 | + if( p.length < 2 || p[1].length === 0 ) { |
339 | 360 | r.results = null; |
340 | 361 | r.resultCount = 0; |
341 | | - os_hideResults(r); |
| 362 | + os_hideResults( r ); |
342 | 363 | return; |
343 | 364 | } |
344 | | - var c = document.getElementById(r.container); |
345 | | - if(c == null) |
346 | | - c = os_createContainer(r); |
347 | | - c.innerHTML = os_createResultTable(r,p[1]); |
| 365 | + var c = document.getElementById( r.container ); |
| 366 | + if( c === null ) { |
| 367 | + c = os_createContainer( r ); |
| 368 | + } |
| 369 | + c.innerHTML = os_createResultTable( r, p[1] ); |
348 | 370 | // init container table sizes |
349 | | - var t = document.getElementById(r.resultTable); |
| 371 | + var t = document.getElementById( r.resultTable ); |
350 | 372 | r.containerTotal = t.offsetHeight; |
351 | 373 | r.containerRow = t.offsetHeight / r.resultCount; |
352 | | - os_fitContainer(r); |
353 | | - os_trimResultText(r); |
354 | | - os_showResults(r); |
355 | | - } catch(e){ |
| 374 | + os_fitContainer( r ); |
| 375 | + os_trimResultText( r ); |
| 376 | + os_showResults( r ); |
| 377 | + } catch( e ) { |
356 | 378 | // bad response from server or such |
357 | | - os_hideResults(r); |
| 379 | + os_hideResults( r ); |
358 | 380 | os_cache[cacheKey] = null; |
359 | 381 | } |
360 | 382 | } |
361 | 383 | } |
362 | 384 | |
363 | 385 | /** Create the result table to be placed in the container div */ |
364 | | -function os_createResultTable(r, results){ |
365 | | - var c = document.getElementById(r.container); |
366 | | - var width = c.offsetWidth - os_operaWidthFix(c.offsetWidth); |
367 | | - var html = "<table class=\"os-suggest-results\" id=\""+r.resultTable+"\" style=\"width: "+width+"px;\">"; |
| 386 | +function os_createResultTable( r, results ) { |
| 387 | + var c = document.getElementById( r.container ); |
| 388 | + var width = c.offsetWidth - os_operaWidthFix( c.offsetWidth ); |
| 389 | + var html = '<table class="os-suggest-results" id="' + r.resultTable + '" style="width: ' + width + 'px;">'; |
368 | 390 | r.results = new Array(); |
369 | 391 | r.resultCount = results.length; |
370 | | - for(i=0;i<results.length;i++){ |
371 | | - var title = os_decodeValue(results[i]); |
| 392 | + for( i = 0; i < results.length; i++ ) { |
| 393 | + var title = os_decodeValue( results[i] ); |
372 | 394 | r.results[i] = title; |
373 | | - html += "<tr><td class=\"os-suggest-result\" id=\""+r.resultTable+i+"\"><span id=\""+r.resultText+i+"\">"+title+"</span></td></tr>"; |
| 395 | + html += '<tr><td class="os-suggest-result" id="' + r.resultTable + i + '"><span id="' + r.resultText + i + '">' + title + '</span></td></tr>'; |
374 | 396 | } |
375 | | - html+="</table>" |
| 397 | + html += '</table>'; |
376 | 398 | return html; |
377 | 399 | } |
378 | 400 | |
379 | 401 | /** Fetch namespaces from checkboxes or hidden fields in the search form, |
380 | 402 | if none defined use wgSearchNamespaces global */ |
381 | | -function os_getNamespaces(r){ |
382 | | - var namespaces = ""; |
| 403 | +function os_getNamespaces( r ) { |
| 404 | + var namespaces = ''; |
383 | 405 | var elements = document.forms[r.searchform].elements; |
384 | | - for(i=0; i < elements.length; i++){ |
| 406 | + for( i = 0; i < elements.length; i++ ) { |
385 | 407 | var name = elements[i].name; |
386 | | - if(typeof name != 'undefined' && name.length > 2 |
387 | | - && name[0]=='n' && name[1]=='s' |
388 | | - && ((elements[i].type=='checkbox' && elements[i].checked) |
389 | | - || (elements[i].type=='hidden' && elements[i].value=="1")) ){ |
390 | | - if(namespaces!="") |
391 | | - namespaces+="|"; |
392 | | - namespaces+=name.substring(2); |
| 408 | + if( typeof name != 'undefined' && name.length > 2 && name[0] == 'n' && |
| 409 | + name[1] == 's' && ( |
| 410 | + ( elements[i].type == 'checkbox' && elements[i].checked ) || |
| 411 | + ( elements[i].type == 'hidden' && elements[i].value == '1' ) |
| 412 | + ) |
| 413 | + ) { |
| 414 | + if( namespaces != '' ) { |
| 415 | + namespaces += '|'; |
| 416 | + } |
| 417 | + namespaces += name.substring( 2 ); |
393 | 418 | } |
394 | 419 | } |
395 | | - if(namespaces == "") |
396 | | - namespaces = wgSearchNamespaces.join("|"); |
| 420 | + if( namespaces == '' ) { |
| 421 | + namespaces = wgSearchNamespaces.join('|'); |
| 422 | + } |
397 | 423 | return namespaces; |
398 | 424 | } |
399 | 425 | |
400 | 426 | /** Update results if user hasn't already typed something else */ |
401 | | -function os_updateIfRelevant(r, query, text, cacheKey){ |
402 | | - var t = document.getElementById(r.searchbox); |
403 | | - if(t != null && t.value == query){ // check if response is still relevant |
404 | | - os_updateResults(r, query, text, cacheKey); |
| 427 | +function os_updateIfRelevant( r, query, text, cacheKey ) { |
| 428 | + var t = document.getElementById( r.searchbox ); |
| 429 | + if( t !== null && t.value == query ) { // check if response is still relevant |
| 430 | + os_updateResults( r, query, text, cacheKey ); |
405 | 431 | } |
406 | 432 | r.query = query; |
407 | 433 | } |
408 | 434 | |
409 | 435 | /** Fetch results after some timeout */ |
410 | | -function os_delayedFetch(){ |
411 | | - if(os_timer == null) |
| 436 | +function os_delayedFetch() { |
| 437 | + if( os_timer === null ) { |
412 | 438 | return; |
| 439 | + } |
413 | 440 | var r = os_timer.r; |
414 | 441 | var query = os_timer.query; |
415 | 442 | os_timer = null; |
416 | | - var path = wgMWSuggestTemplate.replace("{namespaces}",os_getNamespaces(r)) |
417 | | - .replace("{dbname}",wgDBname) |
418 | | - .replace("{searchTerms}",os_encodeQuery(query)); |
| 443 | + var path = wgMWSuggestTemplate.replace( "{namespaces}", os_getNamespaces( r ) ) |
| 444 | + .replace( "{dbname}", wgDBname ) |
| 445 | + .replace( "{searchTerms}", os_encodeQuery( query ) ); |
419 | 446 | |
420 | 447 | // try to get from cache, if not fetch using ajax |
421 | 448 | var cached = os_cache[path]; |
422 | | - if(cached != null){ |
423 | | - os_updateIfRelevant(r, query, cached, path); |
424 | | - } else{ |
| 449 | + if( cached !== null ) { |
| 450 | + os_updateIfRelevant( r, query, cached, path ); |
| 451 | + } else { |
425 | 452 | var xmlhttp = sajax_init_object(); |
426 | | - if(xmlhttp){ |
| 453 | + if( xmlhttp ) { |
427 | 454 | try { |
428 | | - xmlhttp.open("GET", path, true); |
429 | | - xmlhttp.onreadystatechange=function(){ |
430 | | - if (xmlhttp.readyState==4 && typeof os_updateIfRelevant == 'function') { |
431 | | - os_updateIfRelevant(r, query, xmlhttp.responseText, path); |
432 | | - } |
433 | | - }; |
434 | | - xmlhttp.send(null); |
435 | | - } catch (e) { |
436 | | - if (window.location.hostname == "localhost") { |
437 | | - alert("Your browser blocks XMLHttpRequest to 'localhost', try using a real hostname for development/testing."); |
| 455 | + xmlhttp.open( 'GET', path, true ); |
| 456 | + xmlhttp.onreadystatechange = function() { |
| 457 | + if ( xmlhttp.readyState == 4 && typeof os_updateIfRelevant == 'function' ) { |
| 458 | + os_updateIfRelevant( r, query, xmlhttp.responseText, path ); |
| 459 | + } |
| 460 | + }; |
| 461 | + xmlhttp.send( null ); |
| 462 | + } catch ( e ) { |
| 463 | + if ( window.location.hostname == 'localhost' ) { |
| 464 | + alert( "Your browser blocks XMLHttpRequest to 'localhost', try using a real hostname for development/testing." ); |
438 | 465 | } |
439 | 466 | throw e; |
440 | 467 | } |
— | — | @@ -442,420 +469,450 @@ |
443 | 470 | } |
444 | 471 | |
445 | 472 | /** Init timed update via os_delayedUpdate() */ |
446 | | -function os_fetchResults(r, query, timeout){ |
447 | | - if(query == ""){ |
448 | | - r.query = ""; |
449 | | - os_hideResults(r); |
| 473 | +function os_fetchResults( r, query, timeout ) { |
| 474 | + if( query == '' ) { |
| 475 | + r.query = ''; |
| 476 | + os_hideResults( r ); |
450 | 477 | return; |
451 | | - } else if(query == r.query) |
| 478 | + } else if( query == r.query ) { |
452 | 479 | return; // no change |
| 480 | + } |
453 | 481 | |
454 | 482 | os_is_stopped = false; // make sure we're running |
455 | 483 | |
456 | | - /* var cacheKey = wgDBname+":"+query; |
| 484 | + /* var cacheKey = wgDBname + ':' + query; |
457 | 485 | var cached = os_cache[cacheKey]; |
458 | | - if(cached != null){ |
459 | | - os_updateResults(r,wgDBname,query,cached); |
| 486 | + if( cached != null ) { |
| 487 | + os_updateResults( r, wgDBname, query, cached ); |
460 | 488 | return; |
461 | 489 | } */ |
462 | 490 | |
463 | 491 | // cancel any pending fetches |
464 | | - if(os_timer != null && os_timer.id != null) |
465 | | - clearTimeout(os_timer.id); |
| 492 | + if( os_timer !== null && os_timer.id !== null ) { |
| 493 | + clearTimeout( os_timer.id ); |
| 494 | + } |
466 | 495 | // schedule delayed fetching of results |
467 | | - if(timeout != 0){ |
468 | | - os_timer = new os_Timer(setTimeout("os_delayedFetch()",timeout),r,query); |
469 | | - } else{ |
470 | | - os_timer = new os_Timer(null,r,query); |
| 496 | + if( timeout !== 0 ) { |
| 497 | + os_timer = new os_Timer( setTimeout( "os_delayedFetch()", timeout ), r, query ); |
| 498 | + } else { |
| 499 | + os_timer = new os_Timer( null, r, query ); |
471 | 500 | os_delayedFetch(); // do it now! |
472 | 501 | } |
473 | 502 | |
474 | 503 | } |
| 504 | + |
475 | 505 | /** Change the highlighted row (i.e. suggestion), from position cur to next */ |
476 | | -function os_changeHighlight(r, cur, next, updateSearchBox){ |
477 | | - if (next >= r.resultCount) |
478 | | - next = r.resultCount-1; |
479 | | - if (next < -1) |
| 506 | +function os_changeHighlight( r, cur, next, updateSearchBox ) { |
| 507 | + if ( next >= r.resultCount ) { |
| 508 | + next = r.resultCount - 1; |
| 509 | + } |
| 510 | + if ( next < -1 ) { |
480 | 511 | next = -1; |
| 512 | + } |
481 | 513 | r.selected = next; |
482 | | - if (cur == next) |
483 | | - return; // nothing to do. |
| 514 | + if ( cur == next ) { |
| 515 | + return; // nothing to do. |
| 516 | + } |
484 | 517 | |
485 | | - if(cur >= 0){ |
486 | | - var curRow = document.getElementById(r.resultTable + cur); |
487 | | - if(curRow != null) |
488 | | - curRow.className = "os-suggest-result"; |
489 | | - } |
490 | | - var newText; |
491 | | - if(next >= 0){ |
492 | | - var nextRow = document.getElementById(r.resultTable + next); |
493 | | - if(nextRow != null) |
494 | | - nextRow.className = os_HighlightClass(); |
495 | | - newText = r.results[next]; |
496 | | - } else |
497 | | - newText = r.original; |
| 518 | + if( cur >= 0 ) { |
| 519 | + var curRow = document.getElementById( r.resultTable + cur ); |
| 520 | + if( curRow !== null ) { |
| 521 | + curRow.className = 'os-suggest-result'; |
| 522 | + } |
| 523 | + } |
| 524 | + var newText; |
| 525 | + if( next >= 0 ) { |
| 526 | + var nextRow = document.getElementById( r.resultTable + next ); |
| 527 | + if( nextRow !== null ) { |
| 528 | + nextRow.className = os_HighlightClass(); |
| 529 | + } |
| 530 | + newText = r.results[next]; |
| 531 | + } else { |
| 532 | + newText = r.original; |
| 533 | + } |
498 | 534 | |
499 | | - // adjust the scrollbar if any |
500 | | - if(r.containerCount < r.resultCount){ |
501 | | - var c = document.getElementById(r.container); |
502 | | - var vStart = c.scrollTop / r.containerRow; |
503 | | - var vEnd = vStart + r.containerCount; |
504 | | - if(next < vStart) |
505 | | - c.scrollTop = next * r.containerRow; |
506 | | - else if(next >= vEnd) |
507 | | - c.scrollTop = (next - r.containerCount + 1) * r.containerRow; |
508 | | - } |
| 535 | + // adjust the scrollbar if any |
| 536 | + if( r.containerCount < r.resultCount ) { |
| 537 | + var c = document.getElementById( r.container ); |
| 538 | + var vStart = c.scrollTop / r.containerRow; |
| 539 | + var vEnd = vStart + r.containerCount; |
| 540 | + if( next < vStart ) { |
| 541 | + c.scrollTop = next * r.containerRow; |
| 542 | + } else if( next >= vEnd ) { |
| 543 | + c.scrollTop = ( next - r.containerCount + 1 ) * r.containerRow; |
| 544 | + } |
| 545 | + } |
509 | 546 | |
510 | | - // update the contents of the search box |
511 | | - if(updateSearchBox){ |
512 | | - os_updateSearchQuery(r,newText); |
513 | | - } |
| 547 | + // update the contents of the search box |
| 548 | + if( updateSearchBox ) { |
| 549 | + os_updateSearchQuery( r, newText ); |
| 550 | + } |
514 | 551 | } |
515 | 552 | |
516 | 553 | function os_HighlightClass() { |
517 | 554 | var match = navigator.userAgent.match(/AppleWebKit\/(\d+)/); |
518 | | - if (match) { |
519 | | - var webKitVersion = parseInt(match[1]); |
520 | | - if (webKitVersion < 523) { |
| 555 | + if ( match ) { |
| 556 | + var webKitVersion = parseInt( match[1] ); |
| 557 | + if ( webKitVersion < 523 ) { |
521 | 558 | // CSS system highlight colors broken on old Safari |
522 | 559 | // https://bugs.webkit.org/show_bug.cgi?id=6129 |
523 | 560 | // Safari 3.0.4, 3.1 known ok |
524 | | - return "os-suggest-result-hl-webkit"; |
| 561 | + return 'os-suggest-result-hl-webkit'; |
525 | 562 | } |
526 | 563 | } |
527 | | - return "os-suggest-result-hl"; |
| 564 | + return 'os-suggest-result-hl'; |
528 | 565 | } |
529 | 566 | |
530 | | -function os_updateSearchQuery(r,newText){ |
531 | | - document.getElementById(r.searchbox).value = newText; |
532 | | - r.query = newText; |
| 567 | +function os_updateSearchQuery( r, newText ) { |
| 568 | + document.getElementById( r.searchbox ).value = newText; |
| 569 | + r.query = newText; |
533 | 570 | } |
534 | 571 | |
535 | 572 | /** Find event target */ |
536 | | -function os_getTarget(e){ |
537 | | - if (!e) e = window.event; |
538 | | - if (e.target) return e.target; |
539 | | - else if (e.srcElement) return e.srcElement; |
540 | | - else return null; |
| 573 | +function os_getTarget( e ) { |
| 574 | + if ( !e ) { |
| 575 | + e = window.event; |
| 576 | + } |
| 577 | + if ( e.target ) { |
| 578 | + return e.target; |
| 579 | + } else if ( e.srcElement ) { |
| 580 | + return e.srcElement; |
| 581 | + } else { |
| 582 | + return null; |
| 583 | + } |
541 | 584 | } |
542 | 585 | |
543 | 586 | |
544 | | - |
545 | 587 | /******************** |
546 | 588 | * Keyboard events |
547 | 589 | ********************/ |
548 | 590 | |
549 | 591 | /** Event handler that will fetch results on keyup */ |
550 | | -function os_eventKeyup(e){ |
551 | | - var targ = os_getTarget(e); |
| 592 | +function os_eventKeyup( e ) { |
| 593 | + var targ = os_getTarget( e ); |
552 | 594 | var r = os_map[targ.id]; |
553 | | - if(r == null) |
| 595 | + if( r === null ) { |
554 | 596 | return; // not our event |
| 597 | + } |
555 | 598 | |
556 | 599 | // some browsers won't generate keypressed for arrow keys, catch it |
557 | | - if(os_keypressed_count == 0){ |
558 | | - os_processKey(r,os_cur_keypressed,targ); |
| 600 | + if( os_keypressed_count === 0 ) { |
| 601 | + os_processKey( r, os_cur_keypressed, targ ); |
559 | 602 | } |
560 | 603 | var query = targ.value; |
561 | | - os_fetchResults(r,query,os_search_timeout); |
| 604 | + os_fetchResults( r, query, os_search_timeout ); |
562 | 605 | } |
563 | 606 | |
564 | 607 | /** catch arrows up/down and escape to hide the suggestions */ |
565 | | -function os_processKey(r,keypressed,targ){ |
566 | | - if (keypressed == 40){ // Arrow Down |
567 | | - if (r.visible) { |
568 | | - os_changeHighlight(r, r.selected, r.selected+1, true); |
569 | | - } else if(os_timer == null){ |
570 | | - // user wants to get suggestions now |
571 | | - r.query = ""; |
572 | | - os_fetchResults(r,targ.value,0); |
573 | | - } |
574 | | - } else if (keypressed == 38){ // Arrow Up |
575 | | - if (r.visible){ |
576 | | - os_changeHighlight(r, r.selected, r.selected-1, true); |
577 | | - } |
578 | | - } else if(keypressed == 27){ // Escape |
579 | | - document.getElementById(r.searchbox).value = r.original; |
580 | | - r.query = r.original; |
581 | | - os_hideResults(r); |
582 | | - } else if(r.query != document.getElementById(r.searchbox).value){ |
583 | | - // os_hideResults(r); // don't show old suggestions |
584 | | - } |
| 608 | +function os_processKey( r, keypressed, targ ) { |
| 609 | + if ( keypressed == 40 ) { // Arrow Down |
| 610 | + if ( r.visible ) { |
| 611 | + os_changeHighlight( r, r.selected, r.selected + 1, true ); |
| 612 | + } else if( os_timer === null ) { |
| 613 | + // user wants to get suggestions now |
| 614 | + r.query = ''; |
| 615 | + os_fetchResults( r, targ.value, 0 ); |
| 616 | + } |
| 617 | + } else if ( keypressed == 38 ) { // Arrow Up |
| 618 | + if ( r.visible ) { |
| 619 | + os_changeHighlight( r, r.selected, r.selected - 1, true ); |
| 620 | + } |
| 621 | + } else if( keypressed == 27 ) { // Escape |
| 622 | + document.getElementById( r.searchbox ).value = r.original; |
| 623 | + r.query = r.original; |
| 624 | + os_hideResults( r ); |
| 625 | + } else if( r.query != document.getElementById( r.searchbox ).value ) { |
| 626 | + // os_hideResults( r ); // don't show old suggestions |
| 627 | + } |
585 | 628 | } |
586 | 629 | |
587 | 630 | /** When keys is held down use a timer to output regular events */ |
588 | | -function os_eventKeypress(e){ |
589 | | - var targ = os_getTarget(e); |
| 631 | +function os_eventKeypress( e ) { |
| 632 | + var targ = os_getTarget( e ); |
590 | 633 | var r = os_map[targ.id]; |
591 | | - if(r == null) |
| 634 | + if( r === null ) { |
592 | 635 | return; // not our event |
| 636 | + } |
593 | 637 | |
594 | 638 | var keypressed = os_cur_keypressed; |
595 | 639 | |
596 | 640 | os_keypressed_count++; |
597 | | - os_processKey(r,keypressed,targ); |
| 641 | + os_processKey( r, keypressed, targ ); |
598 | 642 | } |
599 | 643 | |
600 | | -/** Catch the key code (Firefox bug) */ |
601 | | -function os_eventKeydown(e){ |
602 | | - if (!e) e = window.event; |
603 | | - var targ = os_getTarget(e); |
| 644 | +/** Catch the key code (Firefox bug) */ |
| 645 | +function os_eventKeydown( e ) { |
| 646 | + if ( !e ) { |
| 647 | + e = window.event; |
| 648 | + } |
| 649 | + var targ = os_getTarget( e ); |
604 | 650 | var r = os_map[targ.id]; |
605 | | - if(r == null) |
| 651 | + if( r === null ) { |
606 | 652 | return; // not our event |
| 653 | + } |
607 | 654 | |
608 | 655 | os_mouse_moved = false; |
609 | 656 | |
610 | | - os_cur_keypressed = (e.keyCode == undefined) ? e.which : e.keyCode; |
| 657 | + os_cur_keypressed = ( e.keyCode === undefined ) ? e.which : e.keyCode; |
611 | 658 | os_keypressed_count = 0; |
612 | 659 | } |
613 | 660 | |
614 | 661 | /** Event: loss of focus of input box */ |
615 | | -function os_eventBlur(e){ |
616 | | - var targ = os_getTarget(e); |
| 662 | +function os_eventBlur( e ) { |
| 663 | + var targ = os_getTarget( e ); |
617 | 664 | var r = os_map[targ.id]; |
618 | | - if(r == null) |
| 665 | + if( r === null ) { |
619 | 666 | return; // not our event |
620 | | - if(!os_mouse_pressed){ |
621 | | - os_hideResults(r); |
| 667 | + } |
| 668 | + if( !os_mouse_pressed ) { |
| 669 | + os_hideResults( r ); |
622 | 670 | // force canvas to stay hidden |
623 | | - r.stayHidden = true |
| 671 | + r.stayHidden = true; |
624 | 672 | // cancel any pending fetches |
625 | | - if(os_timer != null && os_timer.id != null) |
626 | | - clearTimeout(os_timer.id); |
627 | | - os_timer = null |
| 673 | + if( os_timer !== null && os_timer.id !== null ) { |
| 674 | + clearTimeout( os_timer.id ); |
| 675 | + } |
| 676 | + os_timer = null; |
628 | 677 | } |
629 | 678 | } |
630 | 679 | |
631 | 680 | /** Event: focus (catch only when stopped) */ |
632 | | -function os_eventFocus(e){ |
633 | | - var targ = os_getTarget(e); |
| 681 | +function os_eventFocus( e ) { |
| 682 | + var targ = os_getTarget( e ); |
634 | 683 | var r = os_map[targ.id]; |
635 | | - if(r == null) |
| 684 | + if( r === null ) { |
636 | 685 | return; // not our event |
637 | | - r.stayHidden = false |
| 686 | + } |
| 687 | + r.stayHidden = false; |
638 | 688 | } |
639 | 689 | |
640 | 690 | |
641 | | - |
642 | 691 | /******************** |
643 | 692 | * Mouse events |
644 | 693 | ********************/ |
645 | 694 | |
646 | 695 | /** Mouse over the container */ |
647 | | -function os_eventMouseover(srcId, e){ |
648 | | - var targ = os_getTarget(e); |
| 696 | +function os_eventMouseover( srcId, e ) { |
| 697 | + var targ = os_getTarget( e ); |
649 | 698 | var r = os_map[srcId]; |
650 | | - if(r == null || !os_mouse_moved) |
| 699 | + if( r === null || !os_mouse_moved ) { |
651 | 700 | return; // not our event |
652 | | - var num = os_getNumberSuffix(targ.id); |
653 | | - if(num >= 0) |
654 | | - os_changeHighlight(r,r.selected,num,false); |
655 | | - |
| 701 | + } |
| 702 | + var num = os_getNumberSuffix( targ.id ); |
| 703 | + if( num >= 0 ) { |
| 704 | + os_changeHighlight( r, r.selected, num, false ); |
| 705 | + } |
656 | 706 | } |
657 | 707 | |
658 | 708 | /* Get row where the event occured (from its id) */ |
659 | | -function os_getNumberSuffix(id){ |
660 | | - var num = id.substring(id.length-2); |
661 | | - if( ! (num.charAt(0) >= '0' && num.charAt(0) <= '9') ) |
662 | | - num = num.substring(1); |
663 | | - if(os_isNumber(num)) |
664 | | - return parseInt(num); |
665 | | - else |
| 709 | +function os_getNumberSuffix( id ) { |
| 710 | + var num = id.substring( id.length - 2 ); |
| 711 | + if( !( num.charAt( 0 ) >= '0' && num.charAt( 0 ) <= '9' ) ) { |
| 712 | + num = num.substring( 1 ); |
| 713 | + } |
| 714 | + if( os_isNumber( num ) ) { |
| 715 | + return parseInt( num ); |
| 716 | + } else { |
666 | 717 | return -1; |
| 718 | + } |
667 | 719 | } |
668 | 720 | |
669 | 721 | /** Save mouse move as last action */ |
670 | | -function os_eventMousemove(srcId, e){ |
| 722 | +function os_eventMousemove( srcId, e ) { |
671 | 723 | os_mouse_moved = true; |
672 | 724 | } |
673 | 725 | |
674 | | -/** Mouse button held down, register possible click */ |
675 | | -function os_eventMousedown(srcId, e){ |
676 | | - var targ = os_getTarget(e); |
| 726 | +/** Mouse button held down, register possible click */ |
| 727 | +function os_eventMousedown( srcId, e ) { |
| 728 | + var targ = os_getTarget( e ); |
677 | 729 | var r = os_map[srcId]; |
678 | | - if(r == null) |
| 730 | + if( r === null ) { |
679 | 731 | return; // not our event |
680 | | - var num = os_getNumberSuffix(targ.id); |
| 732 | + } |
| 733 | + var num = os_getNumberSuffix( targ.id ); |
681 | 734 | |
682 | 735 | os_mouse_pressed = true; |
683 | | - if(num >= 0){ |
| 736 | + if( num >= 0 ) { |
684 | 737 | os_mouse_num = num; |
685 | | - // os_updateSearchQuery(r,r.results[num]); |
| 738 | + // os_updateSearchQuery( r, r.results[num] ); |
686 | 739 | } |
687 | 740 | // keep the focus on the search field |
688 | | - document.getElementById(r.searchbox).focus(); |
| 741 | + document.getElementById( r.searchbox ).focus(); |
689 | 742 | |
690 | 743 | return false; // prevents selection |
691 | 744 | } |
692 | 745 | |
693 | 746 | /** Mouse button released, check for click on some row */ |
694 | | -function os_eventMouseup(srcId, e){ |
695 | | - var targ = os_getTarget(e); |
| 747 | +function os_eventMouseup( srcId, e ) { |
| 748 | + var targ = os_getTarget( e ); |
696 | 749 | var r = os_map[srcId]; |
697 | | - if(r == null) |
| 750 | + if( r === null ) { |
698 | 751 | return; // not our event |
699 | | - var num = os_getNumberSuffix(targ.id); |
| 752 | + } |
| 753 | + var num = os_getNumberSuffix( targ.id ); |
700 | 754 | |
701 | | - if(num >= 0 && os_mouse_num == num){ |
702 | | - os_updateSearchQuery(r,r.results[num]); |
703 | | - os_hideResults(r); |
704 | | - document.getElementById(r.searchform).submit(); |
| 755 | + if( num >= 0 && os_mouse_num == num ) { |
| 756 | + os_updateSearchQuery( r, r.results[num] ); |
| 757 | + os_hideResults( r ); |
| 758 | + document.getElementById( r.searchform ).submit(); |
705 | 759 | } |
706 | 760 | os_mouse_pressed = false; |
707 | 761 | // keep the focus on the search field |
708 | | - document.getElementById(r.searchbox).focus(); |
| 762 | + document.getElementById( r.searchbox ).focus(); |
709 | 763 | } |
710 | 764 | |
711 | 765 | /** Check if x is a valid integer */ |
712 | | -function os_isNumber(x){ |
713 | | - if(x == "" || isNaN(x)) |
| 766 | +function os_isNumber( x ) { |
| 767 | + if( x == '' || isNaN( x ) ) { |
714 | 768 | return false; |
715 | | - for(var i=0;i<x.length;i++){ |
716 | | - var c = x.charAt(i); |
717 | | - if( ! (c >= '0' && c <= '9') ) |
| 769 | + } |
| 770 | + for( var i = 0; i < x.length; i++ ) { |
| 771 | + var c = x.charAt( i ); |
| 772 | + if( !( c >= '0' && c <= '9' ) ) { |
718 | 773 | return false; |
| 774 | + } |
719 | 775 | } |
720 | 776 | return true; |
721 | 777 | } |
722 | 778 | |
723 | | - |
724 | 779 | /** When the form is submitted hide everything, cancel updates... */ |
725 | | -function os_eventOnsubmit(e){ |
726 | | - var targ = os_getTarget(e); |
| 780 | +function os_eventOnsubmit( e ) { |
| 781 | + var targ = os_getTarget( e ); |
727 | 782 | |
728 | 783 | os_is_stopped = true; |
729 | 784 | // kill timed requests |
730 | | - if(os_timer != null && os_timer.id != null){ |
731 | | - clearTimeout(os_timer.id); |
| 785 | + if( os_timer !== null && os_timer.id !== null ) { |
| 786 | + clearTimeout( os_timer.id ); |
732 | 787 | os_timer = null; |
733 | 788 | } |
734 | 789 | // Hide all suggestions |
735 | | - for(i=0;i<os_autoload_inputs.length;i++){ |
| 790 | + for( i = 0; i < os_autoload_inputs.length; i++ ) { |
736 | 791 | var r = os_map[os_autoload_inputs[i]]; |
737 | | - if(r != null){ |
738 | | - var b = document.getElementById(r.searchform); |
739 | | - if(b != null && b == targ){ |
| 792 | + if( r !== null ) { |
| 793 | + var b = document.getElementById( r.searchform ); |
| 794 | + if( b !== null && b == targ ) { |
740 | 795 | // set query value so the handler won't try to fetch additional results |
741 | | - r.query = document.getElementById(r.searchbox).value; |
| 796 | + r.query = document.getElementById( r.searchbox ).value; |
742 | 797 | } |
743 | | - os_hideResults(r); |
| 798 | + os_hideResults( r ); |
744 | 799 | } |
745 | 800 | } |
746 | 801 | return true; |
747 | 802 | } |
748 | 803 | |
749 | | -function os_hookEvent(element, hookName, hookFunct) { |
750 | | - if (element.addEventListener) { |
751 | | - element.addEventListener(hookName, hookFunct, false); |
752 | | - } else if (window.attachEvent) { |
753 | | - element.attachEvent("on" + hookName, hookFunct); |
| 804 | +function os_hookEvent( element, hookName, hookFunct ) { |
| 805 | + if ( element.addEventListener ) { |
| 806 | + element.addEventListener( hookName, hookFunct, false ); |
| 807 | + } else if ( window.attachEvent ) { |
| 808 | + element.attachEvent( 'on' + hookName, hookFunct ); |
754 | 809 | } |
755 | 810 | } |
756 | 811 | |
757 | 812 | /** Init Result objects and event handlers */ |
758 | | -function os_initHandlers(name, formname, element){ |
759 | | - var r = new os_Results(name, formname); |
| 813 | +function os_initHandlers( name, formname, element ) { |
| 814 | + var r = new os_Results( name, formname ); |
760 | 815 | // event handler |
761 | | - os_hookEvent(element, "keyup", function(event) { os_eventKeyup(event); }); |
762 | | - os_hookEvent(element, "keydown", function(event) { os_eventKeydown(event); }); |
763 | | - os_hookEvent(element, "keypress", function(event) { os_eventKeypress(event); }); |
764 | | - os_hookEvent(element, "blur", function(event) { os_eventBlur(event); }); |
765 | | - os_hookEvent(element, "focus", function(event) { os_eventFocus(event); }); |
766 | | - element.setAttribute("autocomplete","off"); |
| 816 | + os_hookEvent( element, 'keyup', function( event ) { os_eventKeyup( event ); } ); |
| 817 | + os_hookEvent( element, 'keydown', function( event ) { os_eventKeydown( event ); } ); |
| 818 | + os_hookEvent( element, 'keypress', function( event ) { os_eventKeypress( event ); } ); |
| 819 | + os_hookEvent( element, 'blur', function( event ) { os_eventBlur( event ); } ); |
| 820 | + os_hookEvent( element, 'focus', function( event ) { os_eventFocus( event ); } ); |
| 821 | + element.setAttribute( 'autocomplete', 'off' ); |
767 | 822 | // stopping handler |
768 | | - os_hookEvent(document.getElementById(formname), "submit", function(event){ return os_eventOnsubmit(event); }); |
| 823 | + os_hookEvent( document.getElementById( formname ), 'submit', function( event ) { return os_eventOnsubmit( event ); } ); |
769 | 824 | os_map[name] = r; |
770 | 825 | // toggle link |
771 | | - if(document.getElementById(r.toggle) == null){ |
| 826 | + if( document.getElementById( r.toggle ) === null ) { |
772 | 827 | // TODO: disable this while we figure out a way for this to work in all browsers |
773 | | - /* if(name=='searchInput'){ |
| 828 | + /* if( name == 'searchInput' ) { |
774 | 829 | // special case: place above the main search box |
775 | | - var t = os_createToggle(r,"os-suggest-toggle"); |
776 | | - var searchBody = document.getElementById('searchBody'); |
| 830 | + var t = os_createToggle( r, 'os-suggest-toggle' ); |
| 831 | + var searchBody = document.getElementById( 'searchBody' ); |
777 | 832 | var first = searchBody.parentNode.firstChild.nextSibling.appendChild(t); |
778 | | - } else{ |
| 833 | + } else { |
779 | 834 | // default: place below search box to the right |
780 | | - var t = os_createToggle(r,"os-suggest-toggle-def"); |
| 835 | + var t = os_createToggle( r, 'os-suggest-toggle-def' ); |
781 | 836 | var top = element.offsetTop + element.offsetHeight; |
782 | 837 | var left = element.offsetLeft + element.offsetWidth; |
783 | | - t.style.position = "absolute"; |
784 | | - t.style.top = top + "px"; |
785 | | - t.style.left = left + "px"; |
786 | | - element.parentNode.appendChild(t); |
| 838 | + t.style.position = 'absolute'; |
| 839 | + t.style.top = top + 'px'; |
| 840 | + t.style.left = left + 'px'; |
| 841 | + element.parentNode.appendChild( t ); |
787 | 842 | // only now width gets calculated, shift right |
788 | 843 | left -= t.offsetWidth; |
789 | | - t.style.left = left + "px"; |
790 | | - t.style.visibility = "visible"; |
| 844 | + t.style.left = left + 'px'; |
| 845 | + t.style.visibility = 'visible'; |
791 | 846 | } */ |
792 | 847 | } |
793 | 848 | |
794 | 849 | } |
795 | 850 | |
796 | 851 | /** Return the span element that contains the toggle link */ |
797 | | -function os_createToggle(r,className){ |
798 | | - var t = document.createElement("span"); |
| 852 | +function os_createToggle( r, className ) { |
| 853 | + var t = document.createElement( 'span' ); |
799 | 854 | t.className = className; |
800 | | - t.setAttribute("id", r.toggle); |
801 | | - var link = document.createElement("a"); |
802 | | - link.setAttribute("href","javascript:void(0);"); |
803 | | - link.onclick = function(){ os_toggle(r.searchbox,r.searchform) }; |
804 | | - var msg = document.createTextNode(wgMWSuggestMessages[0]); |
805 | | - link.appendChild(msg); |
806 | | - t.appendChild(link); |
| 855 | + t.setAttribute( 'id', r.toggle ); |
| 856 | + var link = document.createElement( 'a' ); |
| 857 | + link.setAttribute( 'href', 'javascript:void(0);' ); |
| 858 | + link.onclick = function() { os_toggle( r.searchbox, r.searchform ); }; |
| 859 | + var msg = document.createTextNode( wgMWSuggestMessages[0] ); |
| 860 | + link.appendChild( msg ); |
| 861 | + t.appendChild( link ); |
807 | 862 | return t; |
808 | 863 | } |
809 | 864 | |
810 | 865 | /** Call when user clicks on some of the toggle links */ |
811 | | -function os_toggle(inputId,formName){ |
| 866 | +function os_toggle( inputId, formName ) { |
812 | 867 | r = os_map[inputId]; |
813 | 868 | var msg = ''; |
814 | | - if(r == null){ |
815 | | - os_enableSuggestionsOn(inputId,formName); |
| 869 | + if( r === null ) { |
| 870 | + os_enableSuggestionsOn( inputId, formName ); |
816 | 871 | r = os_map[inputId]; |
817 | 872 | msg = wgMWSuggestMessages[0]; |
818 | 873 | } else{ |
819 | | - os_disableSuggestionsOn(inputId,formName); |
| 874 | + os_disableSuggestionsOn( inputId, formName ); |
820 | 875 | msg = wgMWSuggestMessages[1]; |
821 | 876 | } |
822 | 877 | // change message |
823 | | - var link = document.getElementById(r.toggle).firstChild; |
824 | | - link.replaceChild(document.createTextNode(msg),link.firstChild); |
| 878 | + var link = document.getElementById( r.toggle ).firstChild; |
| 879 | + link.replaceChild( document.createTextNode( msg ), link.firstChild ); |
825 | 880 | } |
826 | 881 | |
827 | 882 | /** Call this to enable suggestions on input (id=inputId), on a form (name=formName) */ |
828 | | -function os_enableSuggestionsOn(inputId, formName){ |
829 | | - os_initHandlers( inputId, formName, document.getElementById(inputId) ); |
| 883 | +function os_enableSuggestionsOn( inputId, formName ) { |
| 884 | + os_initHandlers( inputId, formName, document.getElementById( inputId ) ); |
830 | 885 | } |
831 | 886 | |
832 | 887 | /** Call this to disable suggestios on input box (id=inputId) */ |
833 | | -function os_disableSuggestionsOn(inputId){ |
| 888 | +function os_disableSuggestionsOn( inputId ) { |
834 | 889 | r = os_map[inputId]; |
835 | | - if(r != null){ |
| 890 | + if( r !== null ) { |
836 | 891 | // cancel/hide results |
837 | 892 | os_timer = null; |
838 | | - os_hideResults(r); |
| 893 | + os_hideResults( r ); |
839 | 894 | // turn autocomplete on ! |
840 | | - document.getElementById(inputId).setAttribute("autocomplete","on"); |
| 895 | + document.getElementById( inputId ).setAttribute( 'autocomplete', 'on' ); |
841 | 896 | // remove descriptor |
842 | 897 | os_map[inputId] = null; |
843 | 898 | } |
844 | | - |
| 899 | + |
845 | 900 | // Remove the element from the os_autoload_* arrays |
846 | | - var index = os_autoload_inputs.indexOf(inputId); |
847 | | - if ( index >= 0 ) |
| 901 | + var index = os_autoload_inputs.indexOf( inputId ); |
| 902 | + if ( index >= 0 ) { |
848 | 903 | os_autoload_inputs[index] = os_autoload_forms[index] = ''; |
| 904 | + } |
849 | 905 | } |
850 | 906 | |
851 | 907 | /** Initialization, call upon page onload */ |
852 | 908 | function os_MWSuggestInit() { |
853 | | - for(i=0;i<os_autoload_inputs.length;i++){ |
| 909 | + for( i = 0; i < os_autoload_inputs.length; i++ ) { |
854 | 910 | var id = os_autoload_inputs[i]; |
855 | 911 | var form = os_autoload_forms[i]; |
856 | 912 | element = document.getElementById( id ); |
857 | | - if(element != null) |
858 | | - os_initHandlers(id,form,element); |
| 913 | + if( element !== null ) { |
| 914 | + os_initHandlers( id, form, element ); |
| 915 | + } |
859 | 916 | } |
860 | 917 | } |
861 | 918 | |
862 | | -hookEvent("load", os_MWSuggestInit); |
| 919 | +hookEvent( 'load', os_MWSuggestInit ); |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -1658,7 +1658,7 @@ |
1659 | 1659 | * to ensure that client-side caches do not keep obsolete copies of global |
1660 | 1660 | * styles. |
1661 | 1661 | */ |
1662 | | -$wgStyleVersion = '263'; |
| 1662 | +$wgStyleVersion = '264'; |
1663 | 1663 | |
1664 | 1664 | |
1665 | 1665 | # Server-side caching: |