r60909 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60908‎ | r60909 | r60910 >
Date:20:23, 10 January 2010
Author:ashley
Status:ok
Tags:
Comment:
cleanup to wikibits.js with the help of JSLint. added missing braces, some spacing, changed double quotes to single in some places, added missing semicolons and fixed some comparisons
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/wikibits.js
@@ -65,8 +65,8 @@
6666 }
6767 loadedScripts[url] = true;
6868 var s = document.createElement('script');
69 - s.setAttribute('src',url);
70 - s.setAttribute('type','text/javascript');
 69+ s.setAttribute('src', url);
 70+ s.setAttribute('type', 'text/javascript');
7171 document.getElementsByTagName('head')[0].appendChild(s);
7272 return s;
7373 }
@@ -75,12 +75,14 @@
7676 return importStylesheetURI(wgScript + '?action=raw&ctype=text/css&title=' + encodeURIComponent(page.replace(/ /g,'_')));
7777 }
7878
79 -function importStylesheetURI(url,media) {
 79+function importStylesheetURI(url, media) {
8080 var l = document.createElement('link');
8181 l.type = 'text/css';
8282 l.rel = 'stylesheet';
8383 l.href = url;
84 - if(media) l.media = media
 84+ if( media ) {
 85+ l.media = media;
 86+ }
8587 document.getElementsByTagName('head')[0].appendChild(l);
8688 return l;
8789 }
@@ -89,8 +91,11 @@
9092 var s = document.createElement('style');
9193 s.type = 'text/css';
9294 s.rel = 'stylesheet';
93 - if (s.styleSheet) s.styleSheet.cssText = text //IE
94 - else s.appendChild(document.createTextNode(text + '')) //Safari sometimes borks on null
 95+ if ( s.styleSheet ) {
 96+ s.styleSheet.cssText = text; //IE
 97+ } else {
 98+ s.appendChild(document.createTextNode(text + '')); //Safari sometimes borks on null
 99+ }
95100 document.getElementsByTagName('head')[0].appendChild(s);
96101 return s;
97102 }
@@ -290,58 +295,73 @@
291296 */
292297 function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) {
293298 var root = document.getElementById(portlet);
294 - if ( !root ) return null;
295 - var node = root.getElementsByTagName( "ul" )[0];
296 - if ( !node ) return null;
 299+ if ( !root ) {
 300+ return null;
 301+ }
 302+ var node = root.getElementsByTagName( 'ul' )[0];
 303+ if ( !node ) {
 304+ return null;
 305+ }
297306
298307 // unhide portlet if it was hidden before
299308 root.className = root.className.replace( /(^| )emptyPortlet( |$)/, "$2" );
300309
301 - var span = document.createElement( "span" );
 310+ var span = document.createElement( 'span' );
302311 span.appendChild( document.createTextNode( text ) );
303312
304 - var link = document.createElement( "a" );
 313+ var link = document.createElement( 'a' );
305314 link.appendChild( span );
306315 link.href = href;
307316
308 - var item = document.createElement( "li" );
 317+ var item = document.createElement( 'li' );
309318 item.appendChild( link );
310 - if ( id ) item.id = id;
 319+ if ( id ) {
 320+ item.id = id;
 321+ }
311322
312323 if ( accesskey ) {
313 - link.setAttribute( "accesskey", accesskey );
314 - tooltip += " ["+accesskey+"]";
 324+ link.setAttribute( 'accesskey', accesskey );
 325+ tooltip += ' [' + accesskey + ']';
315326 }
316327 if ( tooltip ) {
317 - link.setAttribute( "title", tooltip );
 328+ link.setAttribute( 'title', tooltip );
318329 }
319330 if ( accesskey && tooltip ) {
320331 updateTooltipAccessKeys( new Array( link ) );
321332 }
322333
323 - if ( nextnode && nextnode.parentNode == node )
 334+ if ( nextnode && nextnode.parentNode == node ) {
324335 node.insertBefore( item, nextnode );
325 - else
 336+ } else {
326337 node.appendChild( item ); // IE compatibility (?)
 338+ }
327339
328340 return item;
329341 }
330342
331343 function getInnerText(el) {
332 - if (typeof el == "string") return el;
333 - if (typeof el == "undefined") { return el };
334 - if (el.textContent) return el.textContent; // not needed but it is faster
335 - if (el.innerText) return el.innerText; // IE doesn't have textContent
336 - var str = "";
 344+ if ( typeof el == 'string' ) {
 345+ return el;
 346+ }
 347+ if ( typeof el == 'undefined' ) {
 348+ return el;
 349+ }
 350+ if ( el.textContent ) {
 351+ return el.textContent; // not needed but it is faster
 352+ }
 353+ if ( el.innerText ) {
 354+ return el.innerText; // IE doesn't have textContent
 355+ }
 356+ var str = '';
337357
338358 var cs = el.childNodes;
339359 var l = cs.length;
340360 for (var i = 0; i < l; i++) {
341361 switch (cs[i].nodeType) {
342 - case 1: //ELEMENT_NODE
 362+ case 1: // ELEMENT_NODE
343363 str += ts_getInnerText(cs[i]);
344364 break;
345 - case 3: //TEXT_NODE
 365+ case 3: // TEXT_NODE
346366 str += cs[i].nodeValue;
347367 break;
348368 }
@@ -364,16 +384,20 @@
365385 }
366386
367387 function addCheckboxClickHandlers(inputs, start) {
368 - if ( !start) start = 0;
 388+ if ( !start ) {
 389+ start = 0;
 390+ }
369391
370392 var finish = start + 250;
371 - if ( finish > inputs.length )
 393+ if ( finish > inputs.length ) {
372394 finish = inputs.length;
 395+ }
373396
374397 for ( var i = start; i < finish; i++ ) {
375398 var cb = inputs[i];
376 - if ( !cb.type || cb.type.toLowerCase() != 'checkbox' )
 399+ if ( !cb.type || cb.type.toLowerCase() != 'checkbox' ) {
377400 continue;
 401+ }
378402 var end = checkboxes.length;
379403 checkboxes[end] = cb;
380404 cb.index = end;
@@ -406,8 +430,9 @@
407431 }
408432 for (var i = start; i <= finish; ++i ) {
409433 checkboxes[i].checked = endState;
410 - if( i > start && typeof checkboxes[i].onchange == 'function' )
 434+ if( i > start && typeof checkboxes[i].onchange == 'function' ) {
411435 checkboxes[i].onchange(); // fire triggers
 436+ }
412437 }
413438 lastCheckbox = this.index;
414439 return true;
@@ -425,11 +450,13 @@
426451 if ( typeof( oElm.getElementsByClassName ) == "function" ) {
427452 /* Use a native implementation where possible FF3, Saf3.2, Opera 9.5 */
428453 var arrNativeReturn = oElm.getElementsByClassName( oClassNames );
429 - if ( strTagName == "*" )
 454+ if ( strTagName == "*" ) {
430455 return arrNativeReturn;
 456+ }
431457 for ( var h=0; h < arrNativeReturn.length; h++ ) {
432 - if( arrNativeReturn[h].tagName.toLowerCase() == strTagName.toLowerCase() )
 458+ if( arrNativeReturn[h].tagName.toLowerCase() == strTagName.toLowerCase() ) {
433459 arrReturnElements[arrReturnElements.length] = arrNativeReturn[h];
 460+ }
434461 }
435462 return arrReturnElements;
436463 }
@@ -440,8 +467,7 @@
441468 arrRegExpClassNames[arrRegExpClassNames.length] =
442469 new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)");
443470 }
444 - }
445 - else{
 471+ } else {
446472 arrRegExpClassNames[arrRegExpClassNames.length] =
447473 new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)");
448474 }
@@ -460,7 +486,7 @@
461487 arrReturnElements[arrReturnElements.length] = oElement;
462488 }
463489 }
464 - return (arrReturnElements)
 490+ return (arrReturnElements);
465491 }
466492
467493 function redirectToFragment(fragment) {
@@ -476,12 +502,14 @@
477503 if (is_gecko) {
478504 // Mozilla needs to wait until after load, otherwise the window doesn't scroll
479505 addOnloadHook(function () {
480 - if (window.location.hash == "")
 506+ if (window.location.hash == '') {
481507 window.location.hash = fragment;
 508+ }
482509 });
483510 } else {
484 - if (window.location.hash == "")
 511+ if (window.location.hash == '') {
485512 window.location.hash = fragment;
 513+ }
486514 }
487515 }
488516
@@ -496,11 +524,11 @@
497525 * @todo support all accepted date formats (bug 8226)
498526 */
499527
500 -var ts_image_path = stylepath+"/common/images/";
501 -var ts_image_up = "sort_up.gif";
502 -var ts_image_down = "sort_down.gif";
503 -var ts_image_none = "sort_none.gif";
504 -var ts_europeandate = wgContentLanguage != "en"; // The non-American-inclined can change to "true"
 528+var ts_image_path = stylepath + '/common/images/';
 529+var ts_image_up = 'sort_up.gif';
 530+var ts_image_down = 'sort_down.gif';
 531+var ts_image_none = 'sort_none.gif';
 532+var ts_europeandate = wgContentLanguage != 'en'; // The non-American-inclined can change to "true"
505533 var ts_alternate_row_colors = false;
506534 var ts_number_transform_table = null;
507535 var ts_number_regex = null;
@@ -527,7 +555,9 @@
528556 firstRow = table.rows[0];
529557 }
530558 }
531 - if (!firstRow) return;
 559+ if ( !firstRow ) {
 560+ return;
 561+ }
532562
533563 // We have a first row: assume it's the header, and make its contents clickable links
534564 for (var i = 0; i < firstRow.cells.length; i++) {
@@ -560,14 +590,19 @@
561591 var column = td.cellIndex;
562592
563593 var table = tr.parentNode;
564 - while (table && !(table.tagName && table.tagName.toLowerCase() == 'table'))
 594+ while (table && !(table.tagName && table.tagName.toLowerCase() == 'table')) {
565595 table = table.parentNode;
566 - if (!table) return;
 596+ }
 597+ if ( !table ) {
 598+ return;
 599+ }
567600
568 - if (table.rows.length <= 1) return;
 601+ if ( table.rows.length <= 1 ) {
 602+ return;
 603+ }
569604
570605 // Generate the number transform table if it's not done already
571 - if (ts_number_transform_table == null) {
 606+ if (ts_number_transform_table === null) {
572607 ts_initTransformTable();
573608 }
574609
@@ -575,12 +610,14 @@
576611 // Skip the first row if that's where the headings are
577612 var rowStart = (table.tHead && table.tHead.rows.length > 0 ? 0 : 1);
578613
579 - var itm = "";
 614+ var itm = '';
580615 for (var i = rowStart; i < table.rows.length; i++) {
581616 if (table.rows[i].cells.length > column) {
582617 itm = ts_getInnerText(table.rows[i].cells[column]);
583618 itm = itm.replace(/^[\s\xa0]+/, "").replace(/[\s\xa0]+$/, "");
584 - if (itm != "") break;
 619+ if ( itm != '' ) {
 620+ break;
 621+ }
585622 }
586623 }
587624
@@ -608,14 +645,16 @@
609646 var row = table.rows[j];
610647 if((" "+row.className+" ").indexOf(" unsortable ") < 0) {
611648 var keyText = ts_getInnerText(row.cells[column]);
612 - if(keyText == undefined) {
613 - keyText = "";
 649+ if(keyText === undefined) {
 650+ keyText = '';
614651 }
615652 var oldIndex = (reverse ? -j : j);
616653 var preprocessed = preprocessor( keyText.replace(/^[\s\xa0]+/, "").replace(/[\s\xa0]+$/, "") );
617654
618655 newRows[newRows.length] = new Array(row, preprocessed, oldIndex);
619 - } else staticRows[staticRows.length] = new Array(row, false, j-rowStart);
 656+ } else {
 657+ staticRows[staticRows.length] = new Array(row, false, j-rowStart);
 658+ }
620659 }
621660
622661 newRows.sort(sortfn);
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1664,7 +1664,7 @@
16651665 * to ensure that client-side caches do not keep obsolete copies of global
16661666 * styles.
16671667 */
1668 -$wgStyleVersion = '259';
 1668+$wgStyleVersion = '260';
16691669
16701670
16711671 # Server-side caching:

Status & tagging log