From f63b279b212c18c747af41f62e9fadd2d6e41232 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Wed, 27 Oct 2010 20:42:33 +0000 Subject: [PATCH] whitespace cleanup in mediawiki.util.js --- resources/mediawiki.util/mediawiki.util.js | 147 +++++++++--------- .../mediawiki.util/mediawiki.util.test.js | 12 +- 2 files changed, 80 insertions(+), 79 deletions(-) diff --git a/resources/mediawiki.util/mediawiki.util.js b/resources/mediawiki.util/mediawiki.util.js index 26ec9eefcd..93f7320b7a 100644 --- a/resources/mediawiki.util/mediawiki.util.js +++ b/resources/mediawiki.util/mediawiki.util.js @@ -9,33 +9,34 @@ /* Initialisation */ 'initialised' : false, 'init' : function () { - if (this.initialised === false) { + if ( this.initialised === false ) { this.initialised = true; // Set tooltipAccessKeyPrefix - if (is_opera) { + if ( is_opera ) { this.tooltipAccessKeyPrefix = 'shift-esc-'; - } else if (is_chrome) { + } else if ( is_chrome ) { this.tooltipAccessKeyPrefix = is_chrome_mac ? 'ctrl-option-' : 'alt-'; - } else if (!is_safari_win && is_safari && webkit_version > 526) { + } else if ( !is_safari_win && is_safari && webkit_version > 526 ) { this.tooltipAccessKeyPrefix = 'ctrl-alt-'; - } else if (!is_safari_win && - (is_safari || clientPC.indexOf('mac') !== -1 || clientPC.indexOf('konqueror') !== -1)) { + } else if ( !is_safari_win && ( is_safari + || clientPC.indexOf('mac') !== -1 + || clientPC.indexOf('konqueror') !== -1 ) ) { this.tooltipAccessKeyPrefix = 'ctrl-'; - } else if (is_ff2) { + } else if ( is_ff2 ) { this.tooltipAccessKeyPrefix = 'alt-shift-'; } // Any initialisation after the DOM is ready $(function () { - + // Enable CheckboxShiftClick $('input[type=checkbox]:not(.noshiftselect)').checkboxShiftClick(); - + // Fill bodyContant var - if ($('#bodyContent').length) { + if ( $('#bodyContent').length ) { mw.util.$content = $('#bodyContent'); - } else if ($('#article').length) { + } else if ( $('#article').length ) { mw.util.$content = $('#article'); } else { mw.util.$content = $('#content'); @@ -57,8 +58,8 @@ */ 'rawurlencode' : function( str ) { str = (str + '').toString(); - return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28') - .replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/~/g, '%7E'); + return encodeURIComponent( str ).replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' ) + .replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /~/g, '%7E' ); }, /** @@ -69,7 +70,7 @@ * @param String str string to be encoded */ 'wfUrlencode' : function( str ) { - return this.rawurlencode(str).replace(/%20/g, '_').replace(/%3A/g, ':').replace(/%2F/g, '/'); + return this.rawurlencode( str ).replace( /%20/g, '_' ).replace( /%3A/g, ':' ).replace( /%2F/g, '/' ); }, /** @@ -78,25 +79,25 @@ * @param String str pagename to link to */ 'wfGetlink' : function( str ) { - return wgServer + wgArticlePath.replace('$1', this.wfUrlencode(str)); + return wgServer + wgArticlePath.replace( '$1', this.wfUrlencode( str ) ); }, /** * Check is a variable is empty. Support for strings, booleans, arrays and objects. - * String "0" is considered empty. String containing only whitespace (ie. " ") is considered not empty. + * String "0" is considered empty. String containing only whitespace (ie. " ") is considered not empty. * * @param Mixed v the variable to check for empty ness */ 'isEmpty' : function( v ) { var key; - if (v === "" || v === 0 || v === "0" || v === null || v === false || typeof v === 'undefined') { + if ( v === "" || v === 0 || v === "0" || v === null || v === false || typeof v === 'undefined' ) { return true; } - if (v.length === 0) { + if ( v.length === 0 ) { return true; } - if (typeof v === 'object') { - for (key in v) { + if ( typeof v === 'object' ) { + for ( key in v ) { return false; } return true; @@ -114,10 +115,10 @@ */ 'getParamValue' : function( param, url ) { url = url ? url : document.location.href; - var re = new RegExp('[^#]*[&?]' + param.escapeRE() + '=([^&#]*)'); // Get last match, stop at hash - var m = re.exec(url); - if (m && m.length > 1) { - return decodeURIComponent(m[1]); + var re = new RegExp( '[^#]*[&?]' + param.escapeRE() + '=([^&#]*)' ); // Get last match, stop at hash + var m = re.exec( url ); + if ( m && m.length > 1 ) { + return decodeURIComponent( m[1] ); } return null; }, @@ -129,12 +130,12 @@ * @param Bool quotes if true escapes single and double quotes aswell (by default false) */ 'htmlEscape' : function( str, quotes ) { - str = $('
').text(str).html(); - if (typeof quotes === 'undefined') { + str = $('
').text( str ).html(); + if ( typeof quotes === 'undefined' ) { quotes = false; } - if (quotes === true) { - str = str.replace(/'/g, ''').replace(/"/g, '"'); + if ( quotes === true ) { + str = str.replace( /'/g, ''' ).replace( /"/g, '"' ); } return str; }, @@ -145,7 +146,7 @@ * @param String str text to unescape */ 'htmlUnescape' : function( str ) { - return $('
').html(str).text(); + return $('
').html( str ).text(); }, // Access key prefix @@ -165,9 +166,9 @@ */ 'updateTooltipAccessKeys' : function( nodeList ) { var $nodes; - if (nodeList instanceof jQuery) { + if ( nodeList instanceof jQuery ) { $nodes = nodeList; - } else if (nodeList) { + } else if ( nodeList ) { $nodes = $(nodeList); } else { // Rather than scanning all links, just the elements that contain the relevant links @@ -179,15 +180,15 @@ return; } - $nodes.each(function (i) { - var tip = $(this).attr('title'); - if (!!tip && mw.util.tooltipAccessKeyRegexp.exec(tip)) { - tip = tip.replace(mw.util.tooltipAccessKeyRegexp, '[' + mw.util.tooltipAccessKeyPrefix + "$5]"); - $(this).attr('title', tip); + $nodes.each(function ( i ) { + var tip = $(this).attr( 'title' ); + if ( !!tip && mw.util.tooltipAccessKeyRegexp.exec( tip ) ) { + tip = tip.replace( mw.util.tooltipAccessKeyRegexp, '[' + mw.util.tooltipAccessKeyPrefix + "$5]" ); + $(this).attr( 'title', tip ); } }); }, - + // jQuery object that refers to the page-content element // Populated by init() '$content' : null, @@ -217,83 +218,83 @@ * @return Node the DOM node of the new item (a LI element, or A element for older skins) or null */ 'addPortletLink' : function( portlet, href, text, id, tooltip, accesskey, nextnode ) { - + // Setup the anchor tag - var $link = $('').attr('href', href).text(text); - + var $link = $('').attr( 'href', href ).text( text ); + // Some skins don't have any portlets // just add it to the bottom of their 'sidebar' element as a fallback - switch (skin) { + switch ( skin ) { case 'standard' : case 'cologneblue' : - $("#quickbar").append($link.after('
')); + $("#quickbar").append($link.after( '
' )); return $link.get(0); case 'nostalgia' : - $("#searchform").before($link).before(' | '); + $("#searchform").before($link).before( ' | ' ); return $link.get(0); default : // Skins like chick, modern, monobook, myskin, simple, vector... - + // Select the specified portlet var $portlet = $('#' + portlet); - if ($portlet.length === 0) { + if ( $portlet.length === 0 ) { return null; } - // Select the first (most likely only) unordered list inside the portlet - var $ul = $portlet.find('ul').eq(0); - + // Select the first (most likely only) unordered list inside the portlet + var $ul = $portlet.find( 'ul' ).eq( 0 ); + // If it didn't have an unordered list yet, create it if ($ul.length === 0) { // If there's no
inside, append it to the portlet directly - if ($portlet.find('div').length === 0) { - $portlet.append('
    '); + if ($portlet.find( 'div' ).length === 0) { + $portlet.append( '
      ' ); } else { // otherwise if there's a div (such as div.body or div.pBody) append the
        to last (most likely only) div - $portlet.find('div').eq(-1).append('
          '); + $portlet.find( 'div' ).eq( -1 ).append( '
            ' ); } // Select the created element - $ul = $portlet.find('ul').eq(0); + $ul = $portlet.find( 'ul' ).eq( 0 ); } // Just in case.. - if ($ul.length === 0) { + if ( $ul.length === 0 ) { return null; } - + // Unhide portlet if it was hidden before - $portlet.removeClass('emptyPortlet'); - + $portlet.removeClass( 'emptyPortlet' ); + // Wrap the anchor tag in a and create a list item for it // and back up the selector to the list item - var $item = $link.wrap('
          • ').parent().parent(); + var $item = $link.wrap( '
          • ' ).parent().parent(); // Implement the properties passed to the function - if (id) { - $item.attr('id', id); + if ( id ) { + $item.attr( 'id', id ); } - if (accesskey) { - $link.attr('accesskey', accesskey); + if ( accesskey ) { + $link.attr( 'accesskey', accesskey ); tooltip += ' [' + accesskey + ']'; } - if (tooltip) { - $link.attr('title', tooltip); + if ( tooltip ) { + $link.attr( 'title', tooltip ); } - if (accesskey && tooltip) { - this.updateTooltipAccessKeys($link); + if ( accesskey && tooltip ) { + this.updateTooltipAccessKeys( $link ); } - + // Append using DOM-element passing - if (nextnode && nextnode.parentNode == $ul.get(0)) { - $(nextnode).before($item); + if ( nextnode && nextnode.parentNode == $ul.get( 0 ) ) { + $(nextnode).before( $item ); } else { // If the jQuery selector isn't found within the
              , just append it at the end - if ($ul.find(nextnode).length === 0) { - $ul.append($item); + if ( $ul.find( nextnode ).length === 0 ) { + $ul.append( $item ); } else { // Append using jQuery CSS selector - $ul.find(nextnode).eq(0).before($item); + $ul.find( nextnode ).eq( 0 ).before( $item ); } } - - return $item.get(0); + + return $item.get( 0 ); } } diff --git a/resources/mediawiki.util/mediawiki.util.test.js b/resources/mediawiki.util/mediawiki.util.test.js index 07a6345ad3..11a214d3e8 100644 --- a/resources/mediawiki.util/mediawiki.util.test.js +++ b/resources/mediawiki.util/mediawiki.util.test.js @@ -2,7 +2,7 @@ * mediaWiki.util Test Suit * * Available on "/Special:BlankPage?action=mwutiltest&debug=true") - * + * * @author Krinkle */ @@ -23,7 +23,7 @@ * @param String result Expected result in 'var (vartype)' form * @param String contain Important part of the result, if result is different but does contain this it will not return ERROR but PARTIALLY */ - 'addTest' : function (code, result, contain) { + 'addTest' : function( code, result, contain ) { if (!contain) { contain = result; } @@ -82,7 +82,7 @@ 'function (string)'); mw.test.addTest('mw.util.rawurlencode(\'Test: A&B/Here\')', 'Test%3A%20A%26B%2FHere (string)'); - mw.test.addTest('typeof mw.util.getWikilink', + mw.test.addTest('typeof mw.util.wfGetlink', 'function (string)'); mw.test.addTest('typeof mw.util.getParamValue', 'function (string)'); @@ -118,9 +118,9 @@ numberoferrors = 0, $testrows; $testrows = mw.test.$table.find('tr'); - $.each(mw.test.addedTests, (function (i) { + $.each(mw.test.addedTests, (function ( i ) { numberoftests++; - + exec = mw.test.addedTests[i][0]; shouldreturn = mw.test.addedTests[i][1]; shouldcontain = mw.test.addedTests[i][2]; @@ -128,7 +128,7 @@ doesreturn = doesreturn + ' (' + typeof doesreturn + ')'; $thisrow = $testrows.eq(i + 1); $thisrow.find('> td').eq(2).text(doesreturn); - + if (doesreturn.indexOf(shouldcontain) !== -1) { if (doesreturn == shouldreturn){ $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK'); -- 2.20.1