r75578 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75577‎ | r75578 | r75579 >
Date:20:42, 27 October 2010
Author:krinkle
Status:ok
Tags:
Comment:
whitespace cleanup in mediawiki.util.js
Modified paths:
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.js (modified) (history)
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js
@@ -2,7 +2,7 @@
33 * mediaWiki.util Test Suit
44 *
55 * Available on "/Special:BlankPage?action=mwutiltest&debug=true")
6 - *
 6+ *
77 * @author Krinkle <krinklemail@gmail.com>
88 */
99
@@ -23,7 +23,7 @@
2424 * @param String result Expected result in 'var (vartype)' form
2525 * @param String contain Important part of the result, if result is different but does contain this it will not return ERROR but PARTIALLY
2626 */
27 - 'addTest' : function (code, result, contain) {
 27+ 'addTest' : function( code, result, contain ) {
2828 if (!contain) {
2929 contain = result;
3030 }
@@ -82,7 +82,7 @@
8383 'function (string)');
8484 mw.test.addTest('mw.util.rawurlencode(\'Test: A&B/Here\')',
8585 'Test%3A%20A%26B%2FHere (string)');
86 - mw.test.addTest('typeof mw.util.getWikilink',
 86+ mw.test.addTest('typeof mw.util.wfGetlink',
8787 'function (string)');
8888 mw.test.addTest('typeof mw.util.getParamValue',
8989 'function (string)');
@@ -118,9 +118,9 @@
119119 numberoferrors = 0,
120120 $testrows;
121121 $testrows = mw.test.$table.find('tr');
122 - $.each(mw.test.addedTests, (function (i) {
 122+ $.each(mw.test.addedTests, (function ( i ) {
123123 numberoftests++;
124 -
 124+
125125 exec = mw.test.addedTests[i][0];
126126 shouldreturn = mw.test.addedTests[i][1];
127127 shouldcontain = mw.test.addedTests[i][2];
@@ -128,7 +128,7 @@
129129 doesreturn = doesreturn + ' (' + typeof doesreturn + ')';
130130 $thisrow = $testrows.eq(i + 1);
131131 $thisrow.find('> td').eq(2).text(doesreturn);
132 -
 132+
133133 if (doesreturn.indexOf(shouldcontain) !== -1) {
134134 if (doesreturn == shouldreturn){
135135 $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK');
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js
@@ -9,33 +9,34 @@
1010 /* Initialisation */
1111 'initialised' : false,
1212 'init' : function () {
13 - if (this.initialised === false) {
 13+ if ( this.initialised === false ) {
1414 this.initialised = true;
1515
1616 // Set tooltipAccessKeyPrefix
17 - if (is_opera) {
 17+ if ( is_opera ) {
1818 this.tooltipAccessKeyPrefix = 'shift-esc-';
19 - } else if (is_chrome) {
 19+ } else if ( is_chrome ) {
2020 this.tooltipAccessKeyPrefix = is_chrome_mac ? 'ctrl-option-' : 'alt-';
21 - } else if (!is_safari_win && is_safari && webkit_version > 526) {
 21+ } else if ( !is_safari_win && is_safari && webkit_version > 526 ) {
2222 this.tooltipAccessKeyPrefix = 'ctrl-alt-';
23 - } else if (!is_safari_win &&
24 - (is_safari || clientPC.indexOf('mac') !== -1 || clientPC.indexOf('konqueror') !== -1)) {
 23+ } else if ( !is_safari_win && ( is_safari
 24+ || clientPC.indexOf('mac') !== -1
 25+ || clientPC.indexOf('konqueror') !== -1 ) ) {
2526 this.tooltipAccessKeyPrefix = 'ctrl-';
26 - } else if (is_ff2) {
 27+ } else if ( is_ff2 ) {
2728 this.tooltipAccessKeyPrefix = 'alt-shift-';
2829 }
2930
3031 // Any initialisation after the DOM is ready
3132 $(function () {
32 -
 33+
3334 // Enable CheckboxShiftClick
3435 $('input[type=checkbox]:not(.noshiftselect)').checkboxShiftClick();
35 -
 36+
3637 // Fill bodyContant var
37 - if ($('#bodyContent').length) {
 38+ if ( $('#bodyContent').length ) {
3839 mw.util.$content = $('#bodyContent');
39 - } else if ($('#article').length) {
 40+ } else if ( $('#article').length ) {
4041 mw.util.$content = $('#article');
4142 } else {
4243 mw.util.$content = $('#content');
@@ -57,8 +58,8 @@
5859 */
5960 'rawurlencode' : function( str ) {
6061 str = (str + '').toString();
61 - return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28')
62 - .replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/~/g, '%7E');
 62+ return encodeURIComponent( str ).replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' )
 63+ .replace( /\)/g, '%29' ).replace( /\*/g, '%2A' ).replace( /~/g, '%7E' );
6364 },
6465
6566 /**
@@ -69,7 +70,7 @@
7071 * @param String str string to be encoded
7172 */
7273 'wfUrlencode' : function( str ) {
73 - return this.rawurlencode(str).replace(/%20/g, '_').replace(/%3A/g, ':').replace(/%2F/g, '/');
 74+ return this.rawurlencode( str ).replace( /%20/g, '_' ).replace( /%3A/g, ':' ).replace( /%2F/g, '/' );
7475 },
7576
7677 /**
@@ -78,25 +79,25 @@
7980 * @param String str pagename to link to
8081 */
8182 'wfGetlink' : function( str ) {
82 - return wgServer + wgArticlePath.replace('$1', this.wfUrlencode(str));
 83+ return wgServer + wgArticlePath.replace( '$1', this.wfUrlencode( str ) );
8384 },
8485
8586 /**
8687 * Check is a variable is empty. Support for strings, booleans, arrays and objects.
87 - * String "0" is considered empty. String containing only whitespace (ie. " ") is considered not empty.
 88+ * String "0" is considered empty. String containing only whitespace (ie. " ") is considered not empty.
8889 *
8990 * @param Mixed v the variable to check for empty ness
9091 */
9192 'isEmpty' : function( v ) {
9293 var key;
93 - if (v === "" || v === 0 || v === "0" || v === null || v === false || typeof v === 'undefined') {
 94+ if ( v === "" || v === 0 || v === "0" || v === null || v === false || typeof v === 'undefined' ) {
9495 return true;
9596 }
96 - if (v.length === 0) {
 97+ if ( v.length === 0 ) {
9798 return true;
9899 }
99 - if (typeof v === 'object') {
100 - for (key in v) {
 100+ if ( typeof v === 'object' ) {
 101+ for ( key in v ) {
101102 return false;
102103 }
103104 return true;
@@ -114,10 +115,10 @@
115116 */
116117 'getParamValue' : function( param, url ) {
117118 url = url ? url : document.location.href;
118 - var re = new RegExp('[^#]*[&?]' + param.escapeRE() + '=([^&#]*)'); // Get last match, stop at hash
119 - var m = re.exec(url);
120 - if (m && m.length > 1) {
121 - return decodeURIComponent(m[1]);
 119+ var re = new RegExp( '[^#]*[&?]' + param.escapeRE() + '=([^&#]*)' ); // Get last match, stop at hash
 120+ var m = re.exec( url );
 121+ if ( m && m.length > 1 ) {
 122+ return decodeURIComponent( m[1] );
122123 }
123124 return null;
124125 },
@@ -129,12 +130,12 @@
130131 * @param Bool quotes if true escapes single and double quotes aswell (by default false)
131132 */
132133 'htmlEscape' : function( str, quotes ) {
133 - str = $('<div/>').text(str).html();
134 - if (typeof quotes === 'undefined') {
 134+ str = $('<div/>').text( str ).html();
 135+ if ( typeof quotes === 'undefined' ) {
135136 quotes = false;
136137 }
137 - if (quotes === true) {
138 - str = str.replace(/'/g, '&#039;').replace(/"/g, '&quot;');
 138+ if ( quotes === true ) {
 139+ str = str.replace( /'/g, '&#039;' ).replace( /"/g, '&quot;' );
139140 }
140141 return str;
141142 },
@@ -145,7 +146,7 @@
146147 * @param String str text to unescape
147148 */
148149 'htmlUnescape' : function( str ) {
149 - return $('<div/>').html(str).text();
 150+ return $('<div/>').html( str ).text();
150151 },
151152
152153 // Access key prefix
@@ -165,9 +166,9 @@
166167 */
167168 'updateTooltipAccessKeys' : function( nodeList ) {
168169 var $nodes;
169 - if (nodeList instanceof jQuery) {
 170+ if ( nodeList instanceof jQuery ) {
170171 $nodes = nodeList;
171 - } else if (nodeList) {
 172+ } else if ( nodeList ) {
172173 $nodes = $(nodeList);
173174 } else {
174175 // Rather than scanning all links, just the elements that contain the relevant links
@@ -179,15 +180,15 @@
180181 return;
181182 }
182183
183 - $nodes.each(function (i) {
184 - var tip = $(this).attr('title');
185 - if (!!tip && mw.util.tooltipAccessKeyRegexp.exec(tip)) {
186 - tip = tip.replace(mw.util.tooltipAccessKeyRegexp, '[' + mw.util.tooltipAccessKeyPrefix + "$5]");
187 - $(this).attr('title', tip);
 184+ $nodes.each(function ( i ) {
 185+ var tip = $(this).attr( 'title' );
 186+ if ( !!tip && mw.util.tooltipAccessKeyRegexp.exec( tip ) ) {
 187+ tip = tip.replace( mw.util.tooltipAccessKeyRegexp, '[' + mw.util.tooltipAccessKeyPrefix + "$5]" );
 188+ $(this).attr( 'title', tip );
188189 }
189190 });
190191 },
191 -
 192+
192193 // jQuery object that refers to the page-content element
193194 // Populated by init()
194195 '$content' : null,
@@ -217,83 +218,83 @@
218219 * @return Node the DOM node of the new item (a LI element, or A element for older skins) or null
219220 */
220221 'addPortletLink' : function( portlet, href, text, id, tooltip, accesskey, nextnode ) {
221 -
 222+
222223 // Setup the anchor tag
223 - var $link = $('<a />').attr('href', href).text(text);
224 -
 224+ var $link = $('<a />').attr( 'href', href ).text( text );
 225+
225226 // Some skins don't have any portlets
226227 // just add it to the bottom of their 'sidebar' element as a fallback
227 - switch (skin) {
 228+ switch ( skin ) {
228229 case 'standard' :
229230 case 'cologneblue' :
230 - $("#quickbar").append($link.after('<br />'));
 231+ $("#quickbar").append($link.after( '<br />' ));
231232 return $link.get(0);
232233 case 'nostalgia' :
233 - $("#searchform").before($link).before(' &#124; ');
 234+ $("#searchform").before($link).before( ' &#124; ' );
234235 return $link.get(0);
235236 default : // Skins like chick, modern, monobook, myskin, simple, vector...
236 -
 237+
237238 // Select the specified portlet
238239 var $portlet = $('#' + portlet);
239 - if ($portlet.length === 0) {
 240+ if ( $portlet.length === 0 ) {
240241 return null;
241242 }
242 - // Select the first (most likely only) unordered list inside the portlet
243 - var $ul = $portlet.find('ul').eq(0);
244 -
 243+ // Select the first (most likely only) unordered list inside the portlet
 244+ var $ul = $portlet.find( 'ul' ).eq( 0 );
 245+
245246 // If it didn't have an unordered list yet, create it
246247 if ($ul.length === 0) {
247248 // If there's no <div> inside, append it to the portlet directly
248 - if ($portlet.find('div').length === 0) {
249 - $portlet.append('<ul/>');
 249+ if ($portlet.find( 'div' ).length === 0) {
 250+ $portlet.append( '<ul/>' );
250251 } else {
251252 // otherwise if there's a div (such as div.body or div.pBody) append the <ul> to last (most likely only) div
252 - $portlet.find('div').eq(-1).append('<ul/>');
 253+ $portlet.find( 'div' ).eq( -1 ).append( '<ul/>' );
253254 }
254255 // Select the created element
255 - $ul = $portlet.find('ul').eq(0);
 256+ $ul = $portlet.find( 'ul' ).eq( 0 );
256257 }
257258 // Just in case..
258 - if ($ul.length === 0) {
 259+ if ( $ul.length === 0 ) {
259260 return null;
260261 }
261 -
 262+
262263 // Unhide portlet if it was hidden before
263 - $portlet.removeClass('emptyPortlet');
264 -
 264+ $portlet.removeClass( 'emptyPortlet' );
 265+
265266 // Wrap the anchor tag in a <span> and create a list item for it
266267 // and back up the selector to the list item
267 - var $item = $link.wrap('<li><span /></li>').parent().parent();
 268+ var $item = $link.wrap( '<li><span /></li>' ).parent().parent();
268269
269270 // Implement the properties passed to the function
270 - if (id) {
271 - $item.attr('id', id);
 271+ if ( id ) {
 272+ $item.attr( 'id', id );
272273 }
273 - if (accesskey) {
274 - $link.attr('accesskey', accesskey);
 274+ if ( accesskey ) {
 275+ $link.attr( 'accesskey', accesskey );
275276 tooltip += ' [' + accesskey + ']';
276277 }
277 - if (tooltip) {
278 - $link.attr('title', tooltip);
 278+ if ( tooltip ) {
 279+ $link.attr( 'title', tooltip );
279280 }
280 - if (accesskey && tooltip) {
281 - this.updateTooltipAccessKeys($link);
 281+ if ( accesskey && tooltip ) {
 282+ this.updateTooltipAccessKeys( $link );
282283 }
283 -
 284+
284285 // Append using DOM-element passing
285 - if (nextnode && nextnode.parentNode == $ul.get(0)) {
286 - $(nextnode).before($item);
 286+ if ( nextnode && nextnode.parentNode == $ul.get( 0 ) ) {
 287+ $(nextnode).before( $item );
287288 } else {
288289 // If the jQuery selector isn't found within the <ul>, just append it at the end
289 - if ($ul.find(nextnode).length === 0) {
290 - $ul.append($item);
 290+ if ( $ul.find( nextnode ).length === 0 ) {
 291+ $ul.append( $item );
291292 } else {
292293 // Append using jQuery CSS selector
293 - $ul.find(nextnode).eq(0).before($item);
 294+ $ul.find( nextnode ).eq( 0 ).before( $item );
294295 }
295296 }
296 -
297 - return $item.get(0);
 297+
 298+ return $item.get( 0 );
298299 }
299300 }
300301

Status & tagging log