r44265 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44264‎ | r44265 | r44266 >
Date:22:30, 5 December 2008
Author:ialex
Status:deferred
Tags:
Comment:
Fix one more JS issue in IE, but there are many more *sigh*
Modified paths:
  • /trunk/extensions/Configure/Configure.js (modified) (history)
  • /trunk/extensions/Configure/Configure.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Configure/Configure.php
@@ -147,7 +147,7 @@
148148 /**
149149 * Styles versions, you shouldn't change it
150150 */
151 -$wgConfigureStyleVersion = '16';
 151+$wgConfigureStyleVersion = '17';
152152
153153 # Adding new rights...
154154 $wgAvailableRights[] = 'configure';
Index: trunk/extensions/Configure/Configure.js
@@ -3,7 +3,7 @@
44 * create JavaScript buttons to allow to modify the form to have more
55 * flexibility
66 */
7 -
 7+
88 var allSettings = undefined;
99
1010 function setupConfigure(){
@@ -45,7 +45,7 @@
4646 if (i === 0) {
4747 li.className = 'selected';
4848 }
49 -
 49+
5050 var headers = children[i].getElementsByTagName( 'h2' );
5151 var tables = getElementsByClassName( children[i], 'table', 'configure-table' );
5252
@@ -79,7 +79,7 @@
8080 var ul = document.createElement( 'ul' );
8181 ul.style.display = "none";
8282 ul.id = "config-toc-" + i;
83 -
 83+
8484 for( var subsect = 0; subsect < len; subsect++ ){
8585 headers[subsect].id = 'config-head-' + i + '-' + subsect;
8686 tables[subsect].id = 'config-table-' + i + '-' + subsect;
@@ -235,26 +235,26 @@
236236 }
237237 }
238238 }
239 -
 239+
240240 /** Collapsible big lists */
241241 var biglists = getElementsByClassName( configform, '*', 'configure-biglist' );
242 -
 242+
243243 for( var l = 0; l < biglists.length; l++ ) {
244244 var list = biglists[l];
245 -
 245+
246246 list.id = 'configure-biglist-content-'+l;
247247 list.style.display = 'none';
248 -
 248+
249249 var tn = document.createTextNode( wgConfigureBiglistHidden );
250250 var div = document.createElement( 'div' );
251251 var toggleLink = document.createElement( 'a' );
252 -
 252+
253253 toggleLink.appendChild( document.createTextNode( wgConfigureBiglistShow ) );
254254 toggleLink.className = 'configure-biglist-toggle-link';
255255 toggleLink.onclick = createToggleCallback( l );
256256 toggleLink.id = 'configure-biglist-link-'+l;
257257 toggleLink.href = 'javascript:';
258 -
 258+
259259 div.id = 'configure-biglist-placeholder-'+l;
260260 div.className = 'configure-biglist-placeholder';
261261 div.appendChild( tn );
@@ -268,43 +268,43 @@
269269 summariseSetting( list, summary );
270270 list.parentNode.insertBefore( summary, list );
271271 }
272 -
 272+
273273 /** Search box initialise */
274274 buildSearchIndex();
275 -
 275+
276276 // Insert a little search form just before the configuration form
277277 document.getElementById( 'configure-search-form' ).style.display = 'block';
278278 addHandler( document.getElementById( 'configure-search-input' ), 'keyup', function() { doSearch( this.value ); } )
279279 }
280280
281281 function doSearch( query ) {
282 - query = query.toLowerCase();
283 -
 282+ query = document.getElementById( 'configure-search-input' ).value.toLowerCase();
 283+
284284 var results = document.getElementById( 'configure-search-results' );
285 -
 285+
286286 // Empty the existing results
287287 while( results.firstChild ) {
288288 results.removeChild(results.firstChild);
289289 }
290 -
 290+
291291 if ( query == '' ) {
292292 return;
293293 }
294 -
 294+
295295 var isMatch = function(element) { return element.description.indexOf( query ) !== -1; }
296296 for( var i=0; i<allSettings.length; ++i ) {
297297 var data = allSettings[i];
298298 if ( isMatch( data ) ) {
299299 var a = document.createElement( 'a' );
300300 var li = document.createElement( 'li' );
301 -
 301+
302302 a.href = '#config-head-'+data.fid+'-'+data.sid;
303303 addHandler( a, 'click', configToggle );
304304 a.confSec = data.fid;
305305 a.confSub = data.sid;
306306 a.appendChild( document.createTextNode( data.displayDescription ) );
307307 li.appendChild( a );
308 -
 308+
309309 results.appendChild( li );
310310 }
311311 }
@@ -312,7 +312,7 @@
313313
314314 function buildSearchIndex() {
315315 allSettings = [];
316 -
 316+
317317 // For each section...
318318 var rootElement = document.getElementById( 'configure' );
319319 var fieldsets = rootElement.getElementsByTagName( 'fieldset' );
@@ -329,28 +329,32 @@
330330 subsection = subsections[sid];
331331 }
332332 var heading = document.getElementById( subsection.parentNode.id.replace( 'config-table', 'config-head' ) );
333 -
 333+
334334 // For each setting...
335335 for( var i=0; i<subsection.childNodes.length;++i ) {
336 -
337336 var row = subsection.childNodes[i];
338 - if ( row.nodeType != row.ELEMENT_NODE || ( row.tagName != 'tr' && row.tagName != 'TR' ) ) {
 337+ if( typeof row.ELEMENT_NODE == "undefined" ){
 338+ var wantedType = 1; // ELEMENT_NODE
 339+ } else {
 340+ var wantedType = row.ELEMENT_NODE;
 341+ }
 342+ if ( row.nodeType != wantedType || ( row.tagName != 'tr' && row.tagName != 'TR' ) ) {
339343 continue;
340344 }
341 -
 345+
342346 var desc_cell = getElementsByClassName( row, 'td', 'configure-left-column' )[0];
343347 if( typeof desc_cell == "undefined" ){
344348 continue;
345349 }
346350
347351 var description;
348 -
 352+
349353 if ( desc_cell.getElementsByTagName( 'p' ).length ) { // Ward off comments like "This setting has been customised"
350354 description = getInnerText( desc_cell.getElementsByTagName( 'p' )[0] );
351355 } else {
352356 description = getInnerText( desc_cell );
353357 }
354 -
 358+
355359 allSettings.push( { 'description': description.toLowerCase(), 'fid':fid+1, 'sid':sid, 'displayDescription': description } );
356360 }
357361 }
@@ -363,12 +367,12 @@
364368 while(summary.firstChild) {
365369 summary.removeChild(summary.firstChild);
366370 }
367 -
 371+
368372 // Based on class, do something.
369373 var elementType = ' '+div.className+' ';
370 -
 374+
371375 var isType = function(type) { return elementType.indexOf( ' '+type+' ' ) !== -1; }
372 -
 376+
373377 if (isType('assoc') ) {
374378 // If it's too big to display as an associative array, it's too big to display as a summary.
375379 } else if ( isType( 'ns-bool' ) || isType( 'ns-simple' ) || isType( 'group-bool-element' ) || isType( 'group-array-element' ) ) {
@@ -377,39 +381,39 @@
378382 for( var i=0; i<labels.length; ++i ) {
379383 var label = labels[i];
380384 var checkbox = document.getElementById( label.htmlFor );
381 -
 385+
382386 if (checkbox.checked) {
383387 matches.push( label.innerHTML ); // Yuck
384388 }
385389 }
386 -
 390+
387391 summary.innerHTML = matches.join( ', ' ); // Be aware of velociraptors.
388392 } else if ( isType( 'ns-array' ) || isType( 'ns-text' ) || isType( 'configure-rate-limits-action' ) ) {
389393 // Basic strategy: find all labels, and list the values of their corresponding inputs, if those inputs have a value
390394 var header_key = undefined;
391395 var header_value = undefined;
392 -
 396+
393397 var headers = div.getElementsByTagName( 'th' );
394398 header_key = getInnerText( headers[0] );
395399 header_value = getInnerText( headers[1] );
396 -
 400+
397401 var table = document.createElement( 'table' );
398402 table.className = 'assoc';
399403 table.appendChild( document.createElement( 'tbody' ) );
400404 table = table.firstChild;
401 -
 405+
402406 var tr = document.createElement( 'tr' );
403407 var key_th = document.createElement( 'th' );
404408 var value_th = document.createElement( 'th' );
405409 key_th.appendChild( document.createTextNode( header_key ) );
406410 value_th.appendChild( document.createTextNode( header_value ) );
407 -
 411+
408412 tr.appendChild( key_th );
409413 tr.appendChild( value_th );
410414 table.appendChild( tr );
411 -
 415+
412416 var rows = false;
413 -
 417+
414418 if ( isType( 'configure-rate-limits-action' ) ) {
415419 var allRows = div.getElementsByTagName( 'tr' );
416420 for( var i=0; i<allRows.length; ++i ) {
@@ -420,24 +424,24 @@
421425 var typeDesc = getInnerText( row.getElementsByTagName( 'td' )[0] );
422426 var periodField = document.getElementById( row.id+'-period' );
423427 var countField = document.getElementById( row.id+'-count' );
424 -
 428+
425429 if ( periodField && periodField.value>0 ) {
426430 rows = true;
427 -
 431+
428432 tr = document.createElement( 'tr' );
429433 var key_td = document.createElement( 'td' );
430434 var value_td = document.createElement( 'td' );
431 -
 435+
432436 // Create a cute summary.
433437 var summ = wgConfigureThrottleSummary;
434438 summ = summ.replace( '$1', countField.value );
435439 summ = summ.replace( '$2', periodField.value );
436440 key_td.appendChild( document.createTextNode( typeDesc ) );
437441 value_td.appendChild( document.createTextNode( summ ) );
438 -
 442+
439443 tr.appendChild( key_td );
440444 tr.appendChild( value_td );
441 -
 445+
442446 table.appendChild( tr );
443447 }
444448 }
@@ -446,25 +450,25 @@
447451 for( var i=0; i<labels.length; ++i ) {
448452 var label = labels[i];
449453 var arrayfield = document.getElementById( label.htmlFor );
450 -
 454+
451455 if ( arrayfield && arrayfield.value ) {
452456 rows = true;
453 -
 457+
454458 tr = document.createElement( 'tr' );
455459 var key_td = document.createElement( 'td' );
456460 var value_td = document.createElement( 'td' );
457 -
 461+
458462 key_td.appendChild( document.createTextNode( getInnerText( label ) ) );
459463 value_td.appendChild( document.createTextNode( arrayfield.value ) );
460 -
 464+
461465 tr.appendChild( key_td );
462466 tr.appendChild( value_td );
463 -
 467+
464468 table.appendChild( tr );
465469 }
466470 }
467471 }
468 -
 472+
469473 if (!rows) {
470474 tr = document.createElement( 'tr' );
471475 var td = document.createElement( 'td' );
@@ -473,7 +477,7 @@
474478 tr.appendChild( td );
475479 table.appendChild( tr );
476480 }
477 -
 481+
478482 summary.appendChild( table );
479483 } else if ( isType( 'configure-rate-limits-action' ) ) {
480484 } else {
@@ -491,7 +495,7 @@
492496 var act;
493497 var newLinkText;
494498 var newPlaceholderText;
495 -
 499+
496500 if (toggleLink.firstChild.nodeValue == wgConfigureBiglistShow) {
497501 act = 'show';
498502 newLinkText = wgConfigureBiglistHide;
@@ -506,10 +510,10 @@
507511 summariseSetting( content, summary );
508512 newPlaceholderText = wgConfigureBiglistHidden
509513 }
510 -
 514+
511515 toggleLink.removeChild( toggleLink.firstChild );
512516 toggleLink.appendChild( document.createTextNode( newLinkText ) );
513 -
 517+
514518 div.removeChild( div.childNodes[1] );
515519 div.appendChild( document.createTextNode( newPlaceholderText ) );
516520 }

Status & tagging log