Index: trunk/phase3/resources/mediawiki/mediawiki.util.js |
— | — | @@ -11,11 +11,8 @@ |
12 | 12 | * Initialisation |
13 | 13 | * (don't call before document ready) |
14 | 14 | */ |
15 | | - init: function() { |
16 | | - var profile = $.client.profile(), |
17 | | - $tocTitle = $( '#toctitle' ), |
18 | | - $tocToggleLink = $( '#togglelink' ), |
19 | | - hideTocCookie; |
| 15 | + init: function () { |
| 16 | + var profile, $tocTitle, $tocToggleLink, hideTocCookie; |
20 | 17 | |
21 | 18 | /* Set up $.messageBox */ |
22 | 19 | $.messageBoxNew( { |
— | — | @@ -24,6 +21,7 @@ |
25 | 22 | } ); |
26 | 23 | |
27 | 24 | /* Set tooltipAccessKeyPrefix */ |
| 25 | + profile = $.client.profile(); |
28 | 26 | |
29 | 27 | // Opera on any platform |
30 | 28 | if ( profile.name === 'opera' ) { |
— | — | @@ -76,12 +74,14 @@ |
77 | 75 | } |
78 | 76 | |
79 | 77 | // Table of contents toggle |
| 78 | + $tocTitle = $( '#toctitle' ); |
| 79 | + $tocToggleLink = $( '#togglelink' ); |
80 | 80 | // Only add it if there is a TOC and there is no toggle added already |
81 | 81 | if ( $( '#toc' ).length && $tocTitle.length && !$tocToggleLink.length ) { |
82 | 82 | hideTocCookie = $.cookie( 'mw_hidetoc' ); |
83 | 83 | $tocToggleLink = $( '<a href="#" class="internal" id="togglelink"></a>' ) |
84 | 84 | .text( mw.msg( 'hidetoc' ) ) |
85 | | - .click( function( e ) { |
| 85 | + .click( function ( e ) { |
86 | 86 | e.preventDefault(); |
87 | 87 | util.toggleToc( $(this) ); |
88 | 88 | } ); |
— | — | @@ -106,7 +106,7 @@ |
107 | 107 | * |
108 | 108 | * @param str string String to be encoded |
109 | 109 | */ |
110 | | - rawurlencode: function( str ) { |
| 110 | + rawurlencode: function ( str ) { |
111 | 111 | str = String( str ); |
112 | 112 | return encodeURIComponent( str ) |
113 | 113 | .replace( /!/g, '%21' ).replace( /'/g, '%27' ).replace( /\(/g, '%28' ) |
— | — | @@ -120,7 +120,7 @@ |
121 | 121 | * |
122 | 122 | * @param str string String to be encoded |
123 | 123 | */ |
124 | | - wikiUrlencode: function( str ) { |
| 124 | + wikiUrlencode: function ( str ) { |
125 | 125 | return this.rawurlencode( str ) |
126 | 126 | .replace( /%20/g, '_' ).replace( /%3A/g, ':' ).replace( /%2F/g, '/' ); |
127 | 127 | }, |
— | — | @@ -131,7 +131,7 @@ |
132 | 132 | * @param str string Page name to get the link for. |
133 | 133 | * @return string Location for a page with name of 'str' or boolean false on error. |
134 | 134 | */ |
135 | | - wikiGetlink: function( str ) { |
| 135 | + wikiGetlink: function ( str ) { |
136 | 136 | return mw.config.get( 'wgArticlePath' ).replace( '$1', |
137 | 137 | this.wikiUrlencode( str || mw.config.get( 'wgPageName' ) ) ); |
138 | 138 | }, |
— | — | @@ -143,7 +143,7 @@ |
144 | 144 | * @param str string Name of script (eg. 'api'), defaults to 'index' |
145 | 145 | * @return string Address to script (eg. '/w/api.php' ) |
146 | 146 | */ |
147 | | - wikiScript: function( str ) { |
| 147 | + wikiScript: function ( str ) { |
148 | 148 | return mw.config.get( 'wgScriptPath' ) + '/' + ( str || 'index' ) + |
149 | 149 | mw.config.get( 'wgScriptExtension' ); |
150 | 150 | }, |
— | — | @@ -154,7 +154,7 @@ |
155 | 155 | * @param text string CSS to be appended |
156 | 156 | * @return CSSStyleSheet |
157 | 157 | */ |
158 | | - addCSS: function( text ) { |
| 158 | + addCSS: function ( text ) { |
159 | 159 | var s = document.createElement( 'style' ); |
160 | 160 | s.type = 'text/css'; |
161 | 161 | s.rel = 'stylesheet'; |
— | — | @@ -164,7 +164,7 @@ |
165 | 165 | s.styleSheet.cssText = text; // IE |
166 | 166 | } else { |
167 | 167 | // Safari sometimes borks on null |
168 | | - s.appendChild( document.createTextNode( text + '' ) ); |
| 168 | + s.appendChild( document.createTextNode( String( text ) ) ); |
169 | 169 | } |
170 | 170 | return s.sheet || s; |
171 | 171 | }, |
— | — | @@ -178,7 +178,7 @@ |
179 | 179 | * @return mixed Boolean visibility of the toc (true if it's visible) |
180 | 180 | * or Null if there was no table of contents. |
181 | 181 | */ |
182 | | - toggleToc: function( $toggleLink, callback ) { |
| 182 | + toggleToc: function ( $toggleLink, callback ) { |
183 | 183 | var $tocList = $( '#toc ul:first' ); |
184 | 184 | |
185 | 185 | // This function shouldn't be called if there's no TOC, |
— | — | @@ -216,7 +216,7 @@ |
217 | 217 | * @param url string URL to search through (optional) |
218 | 218 | * @return mixed Parameter value or null. |
219 | 219 | */ |
220 | | - getParamValue: function( param, url ) { |
| 220 | + getParamValue: function ( param, url ) { |
221 | 221 | url = url || document.location.href; |
222 | 222 | // Get last match, stop at hash |
223 | 223 | var re = new RegExp( '^[^#]*[&?]' + $.escapeRE( param ) + '=([^&#]*)' ), |
— | — | @@ -251,7 +251,7 @@ |
252 | 252 | * @param $nodes {Array|jQuery} [optional] A jQuery object, or array |
253 | 253 | * of elements to update. |
254 | 254 | */ |
255 | | - updateTooltipAccessKeys: function( $nodes ) { |
| 255 | + updateTooltipAccessKeys: function ( $nodes ) { |
256 | 256 | if ( !$nodes ) { |
257 | 257 | // Rather than going into a loop of all anchor tags, limit to few elements that |
258 | 258 | // contain the relevant anchor tags. |
— | — | @@ -261,7 +261,7 @@ |
262 | 262 | $nodes = $( $nodes ); |
263 | 263 | } |
264 | 264 | |
265 | | - $nodes.attr( 'title', function( i, val ) { |
| 265 | + $nodes.attr( 'title', function ( i, val ) { |
266 | 266 | if ( val && util.tooltipAccessKeyRegexp.exec( val ) ) { |
267 | 267 | return val.replace( util.tooltipAccessKeyRegexp, |
268 | 268 | '[' + util.tooltipAccessKeyPrefix + '$5]' ); |
— | — | @@ -312,7 +312,7 @@ |
313 | 313 | * @return mixed The DOM Node of the added item (a ListItem or Anchor element, |
314 | 314 | * depending on the skin) or null if no element was added to the document. |
315 | 315 | */ |
316 | | - addPortletLink: function( portlet, href, text, id, tooltip, accesskey, nextnode ) { |
| 316 | + addPortletLink: function ( portlet, href, text, id, tooltip, accesskey, nextnode ) { |
317 | 317 | var $item, $link, $portlet, $ul; |
318 | 318 | |
319 | 319 | // Check if there's atleast 3 arguments to prevent a TypeError |
— | — | @@ -328,14 +328,14 @@ |
329 | 329 | // Some skins don't have any portlets |
330 | 330 | // just add it to the bottom of their 'sidebar' element as a fallback |
331 | 331 | switch ( mw.config.get( 'skin' ) ) { |
332 | | - case 'standard' : |
333 | | - case 'cologneblue' : |
| 332 | + case 'standard': |
| 333 | + case 'cologneblue': |
334 | 334 | $( '#quickbar' ).append( $link.after( '<br/>' ) ); |
335 | 335 | return $link[0]; |
336 | | - case 'nostalgia' : |
| 336 | + case 'nostalgia': |
337 | 337 | $( '#searchform' ).before( $link ).before( ' | ' ); |
338 | 338 | return $link[0]; |
339 | | - default : // Skins like chick, modern, monobook, myskin, simple, vector... |
| 339 | + default: // Skins like chick, modern, monobook, myskin, simple, vector... |
340 | 340 | |
341 | 341 | // Select the specified portlet |
342 | 342 | $portlet = $( '#' + portlet ); |
— | — | @@ -418,7 +418,7 @@ |
419 | 419 | * to allow CSS/JS to hide different boxes. null = no class used. |
420 | 420 | * @return {Boolean} True on success, false on failure. |
421 | 421 | */ |
422 | | - jsMessage: function( message, className ) { |
| 422 | + jsMessage: function ( message, className ) { |
423 | 423 | if ( !arguments.length || message === '' || message === null ) { |
424 | 424 | $( '#mw-js-message' ).empty().hide(); |
425 | 425 | return true; // Emptying and hiding message is intended behaviour, return true |
— | — | @@ -464,8 +464,10 @@ |
465 | 465 | * @return mixed Null if mailtxt was an empty string, otherwise true/false |
466 | 466 | * is determined by validation. |
467 | 467 | */ |
468 | | - validateEmail: function( mailtxt ) { |
469 | | - if( mailtxt === '' ) { |
| 468 | + validateEmail: function ( mailtxt ) { |
| 469 | + var rfc5322_atext, rfc1034_ldh_str, HTML5_email_regexp; |
| 470 | + |
| 471 | + if ( mailtxt === '' ) { |
470 | 472 | return null; |
471 | 473 | } |
472 | 474 | |
— | — | @@ -481,7 +483,7 @@ |
482 | 484 | */ |
483 | 485 | |
484 | 486 | /** |
485 | | - * First, define the RFC 5322 'atext' which is pretty easy : |
| 487 | + * First, define the RFC 5322 'atext' which is pretty easy: |
486 | 488 | * atext = ALPHA / DIGIT / ; Printable US-ASCII |
487 | 489 | "!" / "#" / ; characters not including |
488 | 490 | "$" / "%" / ; specials. Used for atoms. |
— | — | @@ -494,7 +496,7 @@ |
495 | 497 | "|" / "}" / |
496 | 498 | "~" |
497 | 499 | */ |
498 | | - var rfc5322_atext = "a-z0-9!#$%&'*+\\-/=?^_`{|}~", |
| 500 | + rfc5322_atext = "a-z0-9!#$%&'*+\\-/=?^_`{|}~"; |
499 | 501 | |
500 | 502 | /** |
501 | 503 | * Next define the RFC 1034 'ldh-str' |
— | — | @@ -505,29 +507,29 @@ |
506 | 508 | * <let-dig-hyp> ::= <let-dig> | "-" |
507 | 509 | * <let-dig> ::= <letter> | <digit> |
508 | 510 | */ |
509 | | - rfc1034_ldh_str = "a-z0-9\\-", |
| 511 | + rfc1034_ldh_str = "a-z0-9\\-"; |
510 | 512 | |
511 | | - HTML5_email_regexp = new RegExp( |
512 | | - // start of string |
513 | | - '^' |
514 | | - + |
515 | | - // User part which is liberal :p |
516 | | - '[' + rfc5322_atext + '\\.]+' |
517 | | - + |
518 | | - // 'at' |
519 | | - '@' |
520 | | - + |
521 | | - // Domain first part |
522 | | - '[' + rfc1034_ldh_str + ']+' |
523 | | - + |
524 | | - // Optional second part and following are separated by a dot |
525 | | - '(?:\\.[' + rfc1034_ldh_str + ']+)*' |
526 | | - + |
527 | | - // End of string |
528 | | - '$', |
529 | | - // RegExp is case insensitive |
530 | | - 'i' |
531 | | - ); |
| 513 | + HTML5_email_regexp = new RegExp( |
| 514 | + // start of string |
| 515 | + '^' |
| 516 | + + |
| 517 | + // User part which is liberal :p |
| 518 | + '[' + rfc5322_atext + '\\.]+' |
| 519 | + + |
| 520 | + // 'at' |
| 521 | + '@' |
| 522 | + + |
| 523 | + // Domain first part |
| 524 | + '[' + rfc1034_ldh_str + ']+' |
| 525 | + + |
| 526 | + // Optional second part and following are separated by a dot |
| 527 | + '(?:\\.[' + rfc1034_ldh_str + ']+)*' |
| 528 | + + |
| 529 | + // End of string |
| 530 | + '$', |
| 531 | + // RegExp is case insensitive |
| 532 | + 'i' |
| 533 | + ); |
532 | 534 | return (null !== mailtxt.match( HTML5_email_regexp ) ); |
533 | 535 | }, |
534 | 536 | |
— | — | @@ -538,7 +540,7 @@ |
539 | 541 | * @param allowBlock boolean |
540 | 542 | * @return boolean |
541 | 543 | */ |
542 | | - isIPv4Address: function( address, allowBlock ) { |
| 544 | + isIPv4Address: function ( address, allowBlock ) { |
543 | 545 | if ( typeof address !== 'string' ) { |
544 | 546 | return false; |
545 | 547 | } |
— | — | @@ -557,7 +559,7 @@ |
558 | 560 | * @param allowBlock boolean |
559 | 561 | * @return boolean |
560 | 562 | */ |
561 | | - isIPv6Address: function( address, allowBlock ) { |
| 563 | + isIPv6Address: function ( address, allowBlock ) { |
562 | 564 | if ( typeof address !== 'string' ) { |
563 | 565 | return false; |
564 | 566 | } |