Index: trunk/phase3/resources/mediawiki/mediawiki.util.js |
— | — | @@ -12,7 +12,6 @@ |
13 | 13 | if (this.initialised === false) { |
14 | 14 | this.initialised = true; |
15 | 15 | |
16 | | - |
17 | 16 | // Set tooltipAccessKeyPrefix |
18 | 17 | if (is_opera) { |
19 | 18 | this.tooltipAccessKeyPrefix = 'shift-esc-'; |
— | — | @@ -52,7 +51,18 @@ |
53 | 52 | |
54 | 53 | // Any initialisation after the DOM is ready |
55 | 54 | $(function () { |
| 55 | + |
| 56 | + // Enable CheckboxShiftClick |
56 | 57 | $('input[type=checkbox]:not(.noshiftselect)').enableCheckboxShiftClick(); |
| 58 | + |
| 59 | + // Fill bodyContant var |
| 60 | + if ($('#bodyContent').length) { |
| 61 | + mw.util.$content = $('#bodyContent'); |
| 62 | + } else if ($('#article').length) { |
| 63 | + mw.util.$content = $('#article'); |
| 64 | + } else { |
| 65 | + mw.util.$content = $('#content'); |
| 66 | + } |
57 | 67 | }); |
58 | 68 | |
59 | 69 | |
— | — | @@ -200,6 +210,10 @@ |
201 | 211 | } |
202 | 212 | }); |
203 | 213 | }, |
| 214 | + |
| 215 | + // jQuery object that refers to the page-content element |
| 216 | + // Populated by init() |
| 217 | + '$content' : null, |
204 | 218 | |
205 | 219 | |
206 | 220 | /** |
— | — | @@ -223,60 +237,74 @@ |
224 | 238 | * @param String accesskey accesskey to activate this link (one character, try to avoid conflicts. Use $('[accesskey=x').get() in the console to see if 'x' is already used. |
225 | 239 | * @param mixed nextnode DOM node or jQuery-selector of the item that the new item should be added before, should be another item in the same list will be ignored if not the so |
226 | 240 | * |
227 | | - * @return Node the DOM node of the new item (a LI element) or null |
| 241 | + * @return Node the DOM node of the new item (a LI element, or A element for older skins) or null |
228 | 242 | */ |
229 | 243 | 'addPortletLink' : function (portlet, href, text, id, tooltip, accesskey, nextnode) { |
230 | | - var $portlet = $('#' + portlet); |
231 | | - if ($portlet.length === 0) { |
232 | | - return null; |
233 | | - } |
234 | | - var $ul = $portlet.find('ul').eq(0); |
235 | | - if ($ul.length === 0) { |
236 | | - if ($portlet.find('div').length === 0) { |
237 | | - $portlet.append('<ul />'); |
238 | | - } else { |
239 | | - $portlet.find('div').eq(-1).append('<ul />'); |
| 244 | + var $link = $('<a />').attr('href', href).text(text); |
| 245 | + |
| 246 | + // Some skins don't have portlets |
| 247 | + // Just add it to the bottom of their 'sidebar' element ignoring the specified portlet target |
| 248 | + switch (skin) { |
| 249 | + case 'standard' : |
| 250 | + case 'cologneblue' : |
| 251 | + $("#quickbar").append($link.after('<br />')); |
| 252 | + return $link.get(0); |
| 253 | + case 'nostalgia' : |
| 254 | + $("#searchform").before($link).before(' | '); |
| 255 | + return $link.get(0); |
| 256 | + default : // chick, modern, monobook, myskin, simple, vector... |
| 257 | + |
| 258 | + var $portlet = $('#' + portlet); |
| 259 | + if ($portlet.length === 0) { |
| 260 | + return null; |
240 | 261 | } |
241 | | - $ul = $portlet.find('ul').eq(0); |
242 | | - } |
243 | | - if ($ul.length === 0) { |
244 | | - return null; |
245 | | - } |
| 262 | + var $ul = $portlet.find('ul').eq(0); |
| 263 | + if ($ul.length === 0) { |
| 264 | + if ($portlet.find('div').length === 0) { |
| 265 | + $portlet.append('<ul />'); |
| 266 | + } else { |
| 267 | + $portlet.find('div').eq(-1).append('<ul />'); |
| 268 | + } |
| 269 | + $ul = $portlet.find('ul').eq(0); |
| 270 | + } |
| 271 | + if ($ul.length === 0) { |
| 272 | + return null; |
| 273 | + } |
| 274 | + |
| 275 | + // unhide portlet if it was hidden before |
| 276 | + $portlet.removeClass('emptyPortlet'); |
| 277 | + |
| 278 | + var $item = $link.wrap('<li><span /></li>').parent().parent(); |
246 | 279 | |
247 | | - // unhide portlet if it was hidden before |
248 | | - $portlet.removeClass('emptyPortlet'); |
249 | | - |
250 | | - var $link = $('<a />').attr('href', href).text(text); |
251 | | - var $item = $link.wrap('<li><span /></li>').parent().parent(); |
252 | | - |
253 | | - if (id) { |
254 | | - $item.attr('id', id); |
255 | | - } |
256 | | - if (accesskey) { |
257 | | - $link.attr('accesskey', accesskey); |
258 | | - tooltip += ' [' + accesskey + ']'; |
259 | | - } |
260 | | - if (tooltip) { |
261 | | - $link.attr('title', tooltip); |
262 | | - } |
263 | | - if (accesskey && tooltip) { |
264 | | - this.updateTooltipAccessKeys($link); |
265 | | - } |
266 | | - |
267 | | - // Append using DOM-element passing |
268 | | - if (nextnode && nextnode.parentNode == $ul.get(0)) { |
269 | | - $(nextnode).before($item); |
270 | | - } else { |
271 | | - // If the jQuery selector isn't found within the <ul>, just append it at the end |
272 | | - if ($ul.find(nextnode).length === 0) { |
273 | | - $ul.append($item); |
| 280 | + if (id) { |
| 281 | + $item.attr('id', id); |
| 282 | + } |
| 283 | + if (accesskey) { |
| 284 | + $link.attr('accesskey', accesskey); |
| 285 | + tooltip += ' [' + accesskey + ']'; |
| 286 | + } |
| 287 | + if (tooltip) { |
| 288 | + $link.attr('title', tooltip); |
| 289 | + } |
| 290 | + if (accesskey && tooltip) { |
| 291 | + this.updateTooltipAccessKeys($link); |
| 292 | + } |
| 293 | + |
| 294 | + // Append using DOM-element passing |
| 295 | + if (nextnode && nextnode.parentNode == $ul.get(0)) { |
| 296 | + $(nextnode).before($item); |
274 | 297 | } else { |
275 | | - // Append using jQuery CSS selector |
276 | | - $ul.find(nextnode).eq(0).before($item); |
| 298 | + // If the jQuery selector isn't found within the <ul>, just append it at the end |
| 299 | + if ($ul.find(nextnode).length === 0) { |
| 300 | + $ul.append($item); |
| 301 | + } else { |
| 302 | + // Append using jQuery CSS selector |
| 303 | + $ul.find(nextnode).eq(0).before($item); |
| 304 | + } |
277 | 305 | } |
| 306 | + |
| 307 | + return $item.get(0); |
278 | 308 | } |
279 | | - |
280 | | - return $item.get(0); |
281 | 309 | } |
282 | 310 | |
283 | 311 | }; |
Index: trunk/phase3/resources/mediawiki/mediawiki.utiltest.js |
— | — | @@ -8,7 +8,6 @@ |
9 | 9 | mediaWiki.test = { |
10 | 10 | |
11 | 11 | /* Variables */ |
12 | | - '$bodyContent' : null, |
13 | 12 | '$table' : null, |
14 | 13 | 'addedTests' : [], |
15 | 14 | |
— | — | @@ -18,10 +17,14 @@ |
19 | 18 | * Adds a row to the test-table |
20 | 19 | * |
21 | 20 | * @param String code Code of the test to be executed |
22 | | - * @param String result Expected result in 'var (vartype)' form. |
| 21 | + * @param String result Expected result in 'var (vartype)' form |
| 22 | + * @param String contain Important part of the result, if result is different but does contain this it will not return ERROR but PARTIALLY |
23 | 23 | */ |
24 | | - 'addTest' : function (code, result) { |
25 | | - this.addedTests.push([code, result]); |
| 24 | + 'addTest' : function (code, result, contain) { |
| 25 | + if (!contain) { |
| 26 | + contain = result; |
| 27 | + } |
| 28 | + this.addedTests.push([code, result, contain]); |
26 | 29 | this.$table.append('<tr><td>' + mw.util.htmlEscape(code) + '</td><td>' + mw.util.htmlEscape(result) + '<td></td></td><td>?</td></tr>'); |
27 | 30 | }, |
28 | 31 | |
— | — | @@ -36,8 +39,7 @@ |
37 | 40 | // Build page |
38 | 41 | document.title = 'mediaWiki.util JavaScript Test - ' + wgSiteName; |
39 | 42 | $('#firstHeading').text('mediaWiki.util JavaScript Test'); |
40 | | - mw.test.bodyContent = $('#bodyContent'); |
41 | | - mw.test.bodyContent.html( |
| 43 | + mw.util.$content.html( |
42 | 44 | '<p>Below is a list of tests to confirm proper functionality of the mediaWiki.util functions</p>' + |
43 | 45 | '<hr />' + |
44 | 46 | '<table id="mw-mwutiltest-table" class="wikitable sortable"><tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr></table>' |
— | — | @@ -95,14 +97,17 @@ |
96 | 98 | 'function (string)'); |
97 | 99 | mw.test.addTest('typeof mw.util.addPortletLink("p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print")', |
98 | 100 | 'object (string)'); |
99 | | - mw.test.addTest('mw.util.addPortletLink("p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print").outerHTML', |
100 | | - '<li id="t-mworg"><span><a href="http://mediawiki.org/" accesskey="m" title="Go to MediaWiki.org [ctrl-alt-m]">MediaWiki.org</a></span></li> (string)'); |
| 101 | + mw.test.addTest('a = mw.util.addPortletLink("p-tb", "http://mediawiki.org/", "MediaWiki.org", "t-mworg", "Go to MediaWiki.org ", "m", "#t-print"); if(a){ a.outerHTML; }', |
| 102 | + '<li id="t-mworg"><span><a href="http://mediawiki.org/" accesskey="m" title="Go to MediaWiki.org [ctrl-alt-m]">MediaWiki.org</a></span></li> (string)', |
| 103 | + 'href="http://mediawiki.org/"'); |
101 | 104 | |
102 | 105 | // Run tests and compare results |
103 | 106 | var exec, |
104 | 107 | result, |
105 | 108 | resulttype, |
106 | 109 | numberoftests = 0, |
| 110 | + numberofpasseds = 0, |
| 111 | + numberofpartials = 0, |
107 | 112 | numberoferrors = 0, |
108 | 113 | $testrows; |
109 | 114 | $testrows = mw.test.$table.find('tr'); |
— | — | @@ -111,13 +116,20 @@ |
112 | 117 | |
113 | 118 | exec = mw.test.addedTests[i][0]; |
114 | 119 | shouldreturn = mw.test.addedTests[i][1]; |
| 120 | + shouldcontain = mw.test.addedTests[i][2]; |
115 | 121 | doesreturn = eval(exec); |
116 | 122 | doesreturn = doesreturn + ' (' + typeof doesreturn + ')'; |
117 | 123 | $thisrow = $testrows.eq(i + 1); |
118 | 124 | $thisrow.find('> td').eq(2).text(doesreturn); |
119 | 125 | |
120 | | - if (shouldreturn === doesreturn) { |
121 | | - $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK'); |
| 126 | + if (doesreturn.indexOf(shouldcontain) !== -1) { |
| 127 | + if (doesreturn == shouldreturn){ |
| 128 | + $thisrow.find('> td').eq(3).css('background', '#EFE').text('OK'); |
| 129 | + numberofpasseds++; |
| 130 | + } else { |
| 131 | + $thisrow.find('> td').eq(3).css('background', '#FFE').html('<small>PARTIALLY</small>'); |
| 132 | + numberofpartials++; |
| 133 | + } |
122 | 134 | } else { |
123 | 135 | $thisrow.find('> td').eq(3).css('background', '#FEE').text('ERROR'); |
124 | 136 | numberoferrors++; |
— | — | @@ -125,7 +137,7 @@ |
126 | 138 | |
127 | 139 | }) |
128 | 140 | ); |
129 | | - mw.test.$table.before('<p><strong>Ran ' + numberoftests + ' tests. ' + numberoferrors + ' error(s). </p>'); |
| 141 | + mw.test.$table.before('<p><strong>Ran ' + numberoftests + ' tests. ' + numberofpasseds + ' passed test(s). ' + numberoferrors + ' error(s). ' + numberofpartials + ' partially passed test(s). </p>'); |
130 | 142 | |
131 | 143 | } |
132 | 144 | }); |