Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | * mediaWiki.util Test Suit |
4 | 4 | * |
5 | 5 | * Available on "/Special:BlankPage?action=mwutiltest&debug=true") |
6 | | - * |
| 6 | + * |
7 | 7 | * @author Krinkle <krinklemail@gmail.com> |
8 | 8 | */ |
9 | 9 | |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | * @param String result Expected result in 'var (vartype)' form |
25 | 25 | * @param String contain Important part of the result, if result is different but does contain this it will not return ERROR but PARTIALLY |
26 | 26 | */ |
27 | | - 'addTest' : function (code, result, contain) { |
| 27 | + 'addTest' : function( code, result, contain ) { |
28 | 28 | if (!contain) { |
29 | 29 | contain = result; |
30 | 30 | } |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | 'function (string)'); |
84 | 84 | mw.test.addTest('mw.util.rawurlencode(\'Test: A&B/Here\')', |
85 | 85 | 'Test%3A%20A%26B%2FHere (string)'); |
86 | | - mw.test.addTest('typeof mw.util.getWikilink', |
| 86 | + mw.test.addTest('typeof mw.util.wfGetlink', |
87 | 87 | 'function (string)'); |
88 | 88 | mw.test.addTest('typeof mw.util.getParamValue', |
89 | 89 | 'function (string)'); |
— | — | @@ -118,9 +118,9 @@ |
119 | 119 | numberoferrors = 0, |
120 | 120 | $testrows; |
121 | 121 | $testrows = mw.test.$table.find('tr'); |
122 | | - $.each(mw.test.addedTests, (function (i) { |
| 122 | + $.each(mw.test.addedTests, (function ( i ) { |
123 | 123 | numberoftests++; |
124 | | - |
| 124 | + |
125 | 125 | exec = mw.test.addedTests[i][0]; |
126 | 126 | shouldreturn = mw.test.addedTests[i][1]; |
127 | 127 | shouldcontain = mw.test.addedTests[i][2]; |
— | — | @@ -128,7 +128,7 @@ |
129 | 129 | doesreturn = doesreturn + ' (' + typeof doesreturn + ')'; |
130 | 130 | $thisrow = $testrows.eq(i + 1); |
131 | 131 | $thisrow.find('> td').eq(2).text(doesreturn); |
132 | | - |
| 132 | + |
133 | 133 | if (doesreturn.indexOf(shouldcontain) !== -1) { |
134 | 134 | if (doesreturn == shouldreturn){ |
135 | 135 | $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK'); |
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js |
— | — | @@ -9,33 +9,34 @@ |
10 | 10 | /* Initialisation */ |
11 | 11 | 'initialised' : false, |
12 | 12 | 'init' : function () { |
13 | | - if (this.initialised === false) { |
| 13 | + if ( this.initialised === false ) { |
14 | 14 | this.initialised = true; |
15 | 15 | |
16 | 16 | // Set tooltipAccessKeyPrefix |
17 | | - if (is_opera) { |
| 17 | + if ( is_opera ) { |
18 | 18 | this.tooltipAccessKeyPrefix = 'shift-esc-'; |
19 | | - } else if (is_chrome) { |
| 19 | + } else if ( is_chrome ) { |
20 | 20 | 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 ) { |
22 | 22 | 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 ) ) { |
25 | 26 | this.tooltipAccessKeyPrefix = 'ctrl-'; |
26 | | - } else if (is_ff2) { |
| 27 | + } else if ( is_ff2 ) { |
27 | 28 | this.tooltipAccessKeyPrefix = 'alt-shift-'; |
28 | 29 | } |
29 | 30 | |
30 | 31 | // Any initialisation after the DOM is ready |
31 | 32 | $(function () { |
32 | | - |
| 33 | + |
33 | 34 | // Enable CheckboxShiftClick |
34 | 35 | $('input[type=checkbox]:not(.noshiftselect)').checkboxShiftClick(); |
35 | | - |
| 36 | + |
36 | 37 | // Fill bodyContant var |
37 | | - if ($('#bodyContent').length) { |
| 38 | + if ( $('#bodyContent').length ) { |
38 | 39 | mw.util.$content = $('#bodyContent'); |
39 | | - } else if ($('#article').length) { |
| 40 | + } else if ( $('#article').length ) { |
40 | 41 | mw.util.$content = $('#article'); |
41 | 42 | } else { |
42 | 43 | mw.util.$content = $('#content'); |
— | — | @@ -57,8 +58,8 @@ |
58 | 59 | */ |
59 | 60 | 'rawurlencode' : function( str ) { |
60 | 61 | 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' ); |
63 | 64 | }, |
64 | 65 | |
65 | 66 | /** |
— | — | @@ -69,7 +70,7 @@ |
70 | 71 | * @param String str string to be encoded |
71 | 72 | */ |
72 | 73 | '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, '/' ); |
74 | 75 | }, |
75 | 76 | |
76 | 77 | /** |
— | — | @@ -78,25 +79,25 @@ |
79 | 80 | * @param String str pagename to link to |
80 | 81 | */ |
81 | 82 | 'wfGetlink' : function( str ) { |
82 | | - return wgServer + wgArticlePath.replace('$1', this.wfUrlencode(str)); |
| 83 | + return wgServer + wgArticlePath.replace( '$1', this.wfUrlencode( str ) ); |
83 | 84 | }, |
84 | 85 | |
85 | 86 | /** |
86 | 87 | * 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. |
88 | 89 | * |
89 | 90 | * @param Mixed v the variable to check for empty ness |
90 | 91 | */ |
91 | 92 | 'isEmpty' : function( v ) { |
92 | 93 | 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' ) { |
94 | 95 | return true; |
95 | 96 | } |
96 | | - if (v.length === 0) { |
| 97 | + if ( v.length === 0 ) { |
97 | 98 | return true; |
98 | 99 | } |
99 | | - if (typeof v === 'object') { |
100 | | - for (key in v) { |
| 100 | + if ( typeof v === 'object' ) { |
| 101 | + for ( key in v ) { |
101 | 102 | return false; |
102 | 103 | } |
103 | 104 | return true; |
— | — | @@ -114,10 +115,10 @@ |
115 | 116 | */ |
116 | 117 | 'getParamValue' : function( param, url ) { |
117 | 118 | 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] ); |
122 | 123 | } |
123 | 124 | return null; |
124 | 125 | }, |
— | — | @@ -129,12 +130,12 @@ |
130 | 131 | * @param Bool quotes if true escapes single and double quotes aswell (by default false) |
131 | 132 | */ |
132 | 133 | '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' ) { |
135 | 136 | quotes = false; |
136 | 137 | } |
137 | | - if (quotes === true) { |
138 | | - str = str.replace(/'/g, ''').replace(/"/g, '"'); |
| 138 | + if ( quotes === true ) { |
| 139 | + str = str.replace( /'/g, ''' ).replace( /"/g, '"' ); |
139 | 140 | } |
140 | 141 | return str; |
141 | 142 | }, |
— | — | @@ -145,7 +146,7 @@ |
146 | 147 | * @param String str text to unescape |
147 | 148 | */ |
148 | 149 | 'htmlUnescape' : function( str ) { |
149 | | - return $('<div/>').html(str).text(); |
| 150 | + return $('<div/>').html( str ).text(); |
150 | 151 | }, |
151 | 152 | |
152 | 153 | // Access key prefix |
— | — | @@ -165,9 +166,9 @@ |
166 | 167 | */ |
167 | 168 | 'updateTooltipAccessKeys' : function( nodeList ) { |
168 | 169 | var $nodes; |
169 | | - if (nodeList instanceof jQuery) { |
| 170 | + if ( nodeList instanceof jQuery ) { |
170 | 171 | $nodes = nodeList; |
171 | | - } else if (nodeList) { |
| 172 | + } else if ( nodeList ) { |
172 | 173 | $nodes = $(nodeList); |
173 | 174 | } else { |
174 | 175 | // Rather than scanning all links, just the elements that contain the relevant links |
— | — | @@ -179,15 +180,15 @@ |
180 | 181 | return; |
181 | 182 | } |
182 | 183 | |
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 ); |
188 | 189 | } |
189 | 190 | }); |
190 | 191 | }, |
191 | | - |
| 192 | + |
192 | 193 | // jQuery object that refers to the page-content element |
193 | 194 | // Populated by init() |
194 | 195 | '$content' : null, |
— | — | @@ -217,83 +218,83 @@ |
218 | 219 | * @return Node the DOM node of the new item (a LI element, or A element for older skins) or null |
219 | 220 | */ |
220 | 221 | 'addPortletLink' : function( portlet, href, text, id, tooltip, accesskey, nextnode ) { |
221 | | - |
| 222 | + |
222 | 223 | // Setup the anchor tag |
223 | | - var $link = $('<a />').attr('href', href).text(text); |
224 | | - |
| 224 | + var $link = $('<a />').attr( 'href', href ).text( text ); |
| 225 | + |
225 | 226 | // Some skins don't have any portlets |
226 | 227 | // just add it to the bottom of their 'sidebar' element as a fallback |
227 | | - switch (skin) { |
| 228 | + switch ( skin ) { |
228 | 229 | case 'standard' : |
229 | 230 | case 'cologneblue' : |
230 | | - $("#quickbar").append($link.after('<br />')); |
| 231 | + $("#quickbar").append($link.after( '<br />' )); |
231 | 232 | return $link.get(0); |
232 | 233 | case 'nostalgia' : |
233 | | - $("#searchform").before($link).before(' | '); |
| 234 | + $("#searchform").before($link).before( ' | ' ); |
234 | 235 | return $link.get(0); |
235 | 236 | default : // Skins like chick, modern, monobook, myskin, simple, vector... |
236 | | - |
| 237 | + |
237 | 238 | // Select the specified portlet |
238 | 239 | var $portlet = $('#' + portlet); |
239 | | - if ($portlet.length === 0) { |
| 240 | + if ( $portlet.length === 0 ) { |
240 | 241 | return null; |
241 | 242 | } |
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 | + |
245 | 246 | // If it didn't have an unordered list yet, create it |
246 | 247 | if ($ul.length === 0) { |
247 | 248 | // 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/>' ); |
250 | 251 | } else { |
251 | 252 | // 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/>' ); |
253 | 254 | } |
254 | 255 | // Select the created element |
255 | | - $ul = $portlet.find('ul').eq(0); |
| 256 | + $ul = $portlet.find( 'ul' ).eq( 0 ); |
256 | 257 | } |
257 | 258 | // Just in case.. |
258 | | - if ($ul.length === 0) { |
| 259 | + if ( $ul.length === 0 ) { |
259 | 260 | return null; |
260 | 261 | } |
261 | | - |
| 262 | + |
262 | 263 | // Unhide portlet if it was hidden before |
263 | | - $portlet.removeClass('emptyPortlet'); |
264 | | - |
| 264 | + $portlet.removeClass( 'emptyPortlet' ); |
| 265 | + |
265 | 266 | // Wrap the anchor tag in a <span> and create a list item for it |
266 | 267 | // 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(); |
268 | 269 | |
269 | 270 | // Implement the properties passed to the function |
270 | | - if (id) { |
271 | | - $item.attr('id', id); |
| 271 | + if ( id ) { |
| 272 | + $item.attr( 'id', id ); |
272 | 273 | } |
273 | | - if (accesskey) { |
274 | | - $link.attr('accesskey', accesskey); |
| 274 | + if ( accesskey ) { |
| 275 | + $link.attr( 'accesskey', accesskey ); |
275 | 276 | tooltip += ' [' + accesskey + ']'; |
276 | 277 | } |
277 | | - if (tooltip) { |
278 | | - $link.attr('title', tooltip); |
| 278 | + if ( tooltip ) { |
| 279 | + $link.attr( 'title', tooltip ); |
279 | 280 | } |
280 | | - if (accesskey && tooltip) { |
281 | | - this.updateTooltipAccessKeys($link); |
| 281 | + if ( accesskey && tooltip ) { |
| 282 | + this.updateTooltipAccessKeys( $link ); |
282 | 283 | } |
283 | | - |
| 284 | + |
284 | 285 | // 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 ); |
287 | 288 | } else { |
288 | 289 | // 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 ); |
291 | 292 | } else { |
292 | 293 | // Append using jQuery CSS selector |
293 | | - $ul.find(nextnode).eq(0).before($item); |
| 294 | + $ul.find( nextnode ).eq( 0 ).before( $item ); |
294 | 295 | } |
295 | 296 | } |
296 | | - |
297 | | - return $item.get(0); |
| 297 | + |
| 298 | + return $item.get( 0 ); |
298 | 299 | } |
299 | 300 | } |
300 | 301 | |