Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.colorUtil.js |
— | — | @@ -1,11 +1,12 @@ |
2 | 2 | module( 'jquery.colorUtil.js' ); |
3 | 3 | |
4 | 4 | test( '-- Initial check', function(){ |
5 | | - |
| 5 | + expect(1); |
6 | 6 | ok( jQuery.colorUtil, 'jQuery.colorUtil defined' ); |
7 | 7 | }); |
8 | 8 | |
9 | 9 | test( 'getRGB', function(){ |
| 10 | + expect(18); |
10 | 11 | |
11 | 12 | equal( typeof jQuery.colorUtil.getRGB(), 'undefined', 'No arguments' ); |
12 | 13 | equal( typeof jQuery.colorUtil.getRGB( '' ), 'undefined', 'Empty string' ); |
— | — | @@ -32,6 +33,8 @@ |
33 | 34 | }); |
34 | 35 | |
35 | 36 | test( 'rgbToHsl', function(){ |
| 37 | + expect(4); |
| 38 | + |
36 | 39 | var hsl = jQuery.colorUtil.rgbToHsl( 144, 238, 144 ); |
37 | 40 | var dualDecimals = function(a,b){ |
38 | 41 | return Math.round(a*100)/100; |
— | — | @@ -45,6 +48,8 @@ |
46 | 49 | }); |
47 | 50 | |
48 | 51 | test( 'hslToRgb', function(){ |
| 52 | + expect(4); |
| 53 | + |
49 | 54 | var rgb = jQuery.colorUtil.hslToRgb( 0.3, 0.7, 0.8 ); |
50 | 55 | |
51 | 56 | ok( rgb, 'Basic return evaluation' ); |
— | — | @@ -55,6 +60,7 @@ |
56 | 61 | }); |
57 | 62 | |
58 | 63 | test( 'getColorBrightness', function(){ |
| 64 | + expect(2); |
59 | 65 | |
60 | 66 | var a = jQuery.colorUtil.getColorBrightness( 'red', +0.1 ); |
61 | 67 | |
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.mwPrototypes.js |
— | — | @@ -54,5 +54,5 @@ |
55 | 55 | ok( $j.compareObject( { foo: 1 }, { foo: 1 } ), 'compareObject: Two the same objects' ); |
56 | 56 | ok( !$j.compareObject( { bar: true }, { baz: false } ), |
57 | 57 | 'compareObject: Two different objects (false)' ); |
58 | | - |
| 58 | + |
59 | 59 | }); |
\ No newline at end of file |
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.js |
— | — | @@ -1,7 +1,7 @@ |
2 | 2 | module( 'jquery.autoEllipsis.js' ); |
3 | 3 | |
4 | 4 | test( '-- Initial check', function(){ |
5 | | - |
| 5 | + expect(1); |
6 | 6 | ok( jQuery.fn.autoEllipsis, 'jQuery.fn.autoEllipsis defined' ); |
7 | 7 | }); |
8 | 8 | |
— | — | @@ -21,6 +21,8 @@ |
22 | 22 | } |
23 | 23 | |
24 | 24 | test( 'Position right', function() { |
| 25 | + expect(3); |
| 26 | + |
25 | 27 | // We need this thing to be visible, so append it to the DOM |
26 | 28 | var origText = 'This is a really long random string and there is no way it fits in 100 pixels.'; |
27 | 29 | var $wrapper = createWrappedDiv( origText ); |
— | — | @@ -33,7 +35,7 @@ |
34 | 36 | |
35 | 37 | // Check that the text fits by turning on word wrapping |
36 | 38 | $span.css( 'whiteSpace', 'nowrap' ); |
37 | | - ok( $span.width() <= $span.parent().width(), "Text fits (span's width is no larger than its parent's width)" ); |
| 39 | + deepEqual( $span.width() <= $span.parent().width(), true, "Text fits (span's width is no larger than its parent's width)" ); |
38 | 40 | |
39 | 41 | // Add one character using scary black magic |
40 | 42 | var spanText = $span.text(); |
— | — | @@ -42,7 +44,7 @@ |
43 | 45 | |
44 | 46 | // Put this text in the span and verify it doesn't fit |
45 | 47 | $span.text( spanText ); |
46 | | - ok( $span.width() > $span.parent().width(), 'Fit is maximal (adding one character makes it not fit any more)' ); |
| 48 | + deepEqual( $span.width() > $span.parent().width(), true, 'Fit is maximal (adding one character makes it not fit any more)' ); |
47 | 49 | |
48 | 50 | // Clean up |
49 | 51 | $wrapper.remove(); |
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tabIndex.js |
— | — | @@ -1,6 +1,7 @@ |
2 | 2 | module( 'jquery.tabIndex.js' ); |
3 | 3 | |
4 | 4 | test( '-- Initial check', function(){ |
| 5 | + expect(2); |
5 | 6 | |
6 | 7 | ok( $.fn.firstTabIndex, '$.fn.firstTabIndex defined' ); |
7 | 8 | ok( $.fn.lastTabIndex, '$.fn.lastTabIndex defined' ); |
— | — | @@ -8,14 +9,15 @@ |
9 | 10 | }); |
10 | 11 | |
11 | 12 | test( 'firstTabIndex', function(){ |
| 13 | + expect(2); |
12 | 14 | |
13 | 15 | var testEnvironment = |
14 | | -'<form>\ |
15 | | - <input tabindex="7" />\ |
16 | | - <input tabindex="9" />\ |
17 | | - <textarea tabindex="2">Foobar</textarea>\ |
18 | | - <textarea tabindex="5">Foobar</textarea>\ |
19 | | -</form>'; |
| 16 | +'<form>' + |
| 17 | + '<input tabindex="7" />' + |
| 18 | + '<input tabindex="9" />' + |
| 19 | + '<textarea tabindex="2">Foobar</textarea>' + |
| 20 | + '<textarea tabindex="5">Foobar</textarea>' + |
| 21 | +'</form>'; |
20 | 22 | var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' ); |
21 | 23 | |
22 | 24 | deepEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' ); |
— | — | @@ -29,14 +31,15 @@ |
30 | 32 | }); |
31 | 33 | |
32 | 34 | test( 'lastTabIndex', function(){ |
| 35 | + expect(2); |
33 | 36 | |
34 | 37 | var testEnvironment = |
35 | | -'<form>\ |
36 | | - <input tabindex="7" />\ |
37 | | - <input tabindex="9" />\ |
38 | | - <textarea tabindex="2">Foobar</textarea>\ |
39 | | - <textarea tabindex="5">Foobar</textarea>\ |
40 | | -</form>'; |
| 38 | +'<form>' + |
| 39 | + '<input tabindex="7" />' + |
| 40 | + '<input tabindex="9" />' + |
| 41 | + '<textarea tabindex="2">Foobar</textarea>' + |
| 42 | + '<textarea tabindex="5">Foobar</textarea>' + |
| 43 | +'</form>'; |
41 | 44 | var $testA = $( '<div />' ).html( testEnvironment ).appendTo( 'body' ); |
42 | 45 | |
43 | 46 | deepEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' ); |
Index: trunk/phase3/tests/qunit/suites/resources/mediawiki.util/mediawiki.util.js |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | }); |
36 | 36 | |
37 | 37 | test( 'wikiScript', function(){ |
| 38 | + expect(2); |
38 | 39 | |
39 | 40 | mw.config.set({ |
40 | 41 | 'wgScript': '/w/index.php', |
— | — | @@ -41,29 +42,59 @@ |
42 | 43 | 'wgScriptExtension': '.php' |
43 | 44 | }); |
44 | 45 | |
45 | | - equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'Defaults to index.php and is equal to wgScript.' ); |
| 46 | + equal( mw.util.wikiScript(), mw.config.get( 'wgScript' ), 'Defaults to index.php and is equal to wgScript' ); |
| 47 | + deepEqual( mw.util.wikiScript( 'api' ), '/w/api.php' ); |
46 | 48 | |
47 | 49 | }); |
48 | 50 | |
49 | 51 | test( 'addCSS', function(){ |
| 52 | + expect(3); |
50 | 53 | |
51 | | - var a = mw.util.addCSS( '#bodyContent { visibility: hidden; }' ); |
| 54 | + window.a = mw.util.addCSS( '#bodyContent { visibility: hidden; }' ); |
52 | 55 | ok( a, 'function works' ); |
53 | 56 | deepEqual( a.disabled, false, 'property "disabled" is available and set to false' ); |
54 | 57 | |
55 | 58 | var $b = $('#bodyContent'); |
56 | | - equal( $b.css('visibility'), 'hidden', 'Added style properties are in effect.' ); |
| 59 | + equal( $b.css('visibility'), 'hidden', 'Added style properties are in effect' ); |
57 | 60 | |
58 | | - |
59 | 61 | }); |
60 | 62 | |
61 | | -/** |
62 | | - * @fixme this seems to only test for the existence of the function, and does not confirm that it works |
63 | | - */ |
64 | 63 | test( 'toggleToc', function(){ |
| 64 | + expect(3); |
65 | 65 | |
66 | | - ok( mw.util.toggleToc ); |
| 66 | + deepEqual( mw.util.toggleToc(), null, 'Return null if there is no table of contents on the page.' ); |
67 | 67 | |
| 68 | + var tocHtml = |
| 69 | + '<table id="toc" class="toc"><tr><td>' + |
| 70 | + '<div id="toctitle">' + |
| 71 | + '<h2>Contents</h2>' + |
| 72 | + '<span class="toctoggle"> [<a href="#" class="internal" id="togglelink">Hide</a> ]</span>' + |
| 73 | + '</div>' + |
| 74 | + '<ul><li></li></ul>' + |
| 75 | + '</td></tr></table>'; |
| 76 | + var $toc = $(tocHtml).appendTo( 'body' ); |
| 77 | + var $toggleLink = $( '#togglelink' ); |
| 78 | + |
| 79 | + // Toggle animation is asynchronous |
| 80 | + // QUnit should not finish this test() untill they are all done |
| 81 | + stop(); |
| 82 | + |
| 83 | + var actionC = function(){ |
| 84 | + start(); |
| 85 | + |
| 86 | + // Clean up |
| 87 | + $toc.remove(); |
| 88 | + }; |
| 89 | + var actionB = function(){ |
| 90 | + deepEqual( mw.util.toggleToc( $toggleLink, actionC ), true, 'Return boolean true if the TOC is now visible.' ); |
| 91 | + }; |
| 92 | + var actionA = function(){ |
| 93 | + deepEqual( mw.util.toggleToc( $toggleLink, actionB ), false, 'Return boolean false if the TOC is now hidden.' ); |
| 94 | + }; |
| 95 | + |
| 96 | + actionA(); |
| 97 | + |
| 98 | + |
68 | 99 | }); |
69 | 100 | |
70 | 101 | test( 'getParamValue', function(){ |
— | — | @@ -126,21 +157,23 @@ |
127 | 158 | }); |
128 | 159 | |
129 | 160 | test( 'validateEmail', function(){ |
| 161 | + expect(6); |
130 | 162 | |
131 | | - deepEqual( mw.util.validateEmail( "" ), null, 'Empty string should return null' ); |
132 | | - deepEqual( mw.util.validateEmail( "user@localhost" ), true ); |
| 163 | + deepEqual( mw.util.validateEmail( "" ), null, 'Should return null for empty string ' ); |
| 164 | + deepEqual( mw.util.validateEmail( "user@localhost" ), true, 'Return true for a valid e-mail address' ); |
133 | 165 | |
134 | 166 | // testEmailWithCommasAreInvalids |
135 | | - deepEqual( mw.util.validateEmail( "user,foo@example.org" ), false, 'Comma' ); |
136 | | - deepEqual( mw.util.validateEmail( "userfoo@ex,ample.org" ), false, 'Comma' ); |
| 167 | + deepEqual( mw.util.validateEmail( "user,foo@example.org" ), false, 'Emails with commas are invalid' ); |
| 168 | + deepEqual( mw.util.validateEmail( "userfoo@ex,ample.org" ), false, 'Emails with commas are invalid' ); |
137 | 169 | |
138 | 170 | // testEmailWithHyphens |
139 | | - deepEqual( mw.util.validateEmail( "user-foo@example.org" ), true, 'Hyphen' ); |
140 | | - deepEqual( mw.util.validateEmail( "userfoo@ex-ample.org" ), true, 'Hyphen' ); |
| 171 | + deepEqual( mw.util.validateEmail( "user-foo@example.org" ), true, 'Emails may contain a hyphen' ); |
| 172 | + deepEqual( mw.util.validateEmail( "userfoo@ex-ample.org" ), true, 'Emails may contain a hyphen' ); |
141 | 173 | |
142 | 174 | }); |
143 | 175 | |
144 | 176 | test( 'isIPv6Address', function(){ |
| 177 | + expect(6); |
145 | 178 | |
146 | 179 | // Based on IPTest.php > IPv6 |
147 | 180 | deepEqual( mw.util.isIPv6Address( "" ), false, 'Empty string is not an IP' ); |
— | — | @@ -153,6 +186,7 @@ |
154 | 187 | }); |
155 | 188 | |
156 | 189 | test( 'isIPv4Address', function(){ |
| 190 | + expect(3); |
157 | 191 | |
158 | 192 | // Based on IPTest.php > IPv4 |
159 | 193 | deepEqual( mw.util.isIPv4Address( "" ), false, 'Empty string is not an IP' ); |
Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.js |
— | — | @@ -13,6 +13,7 @@ |
14 | 14 | }); |
15 | 15 | |
16 | 16 | test( 'mw.Map', function(){ |
| 17 | + expect(20); |
17 | 18 | |
18 | 19 | ok( mw.Map, 'mw.Map defined' ); |
19 | 20 | ok( mw.Map.prototype.get, 'get prototype defined' ); |
— | — | @@ -25,53 +26,57 @@ |
26 | 27 | var arry = []; |
27 | 28 | var nummy = 7; |
28 | 29 | |
29 | | - deepEqual( conf.get( 'inexistantKey' ), null, 'Map.get() returns null if selection was a string and the key was not found.' ); |
30 | | - deepEqual( conf.set( 'myKey', 'myValue' ), true, 'Map.set() returns boolean true if a value was set for a valid key string.' ); |
31 | | - deepEqual( conf.set( funky, 'Funky' ), false, 'Map.set() returns boolean false if key was invalid (Function).' ); |
32 | | - deepEqual( conf.set( arry, 'Arry' ), false, 'Map.set() returns boolean false if key was invalid (Array).' ); |
33 | | - deepEqual( conf.set( nummy, 'Nummy' ), false, 'Map.set() returns boolean false if key was invalid (Number).' ); |
34 | | - equal( conf.get( 'myKey' ), 'myValue', 'Map.get() returns a single value value correctly.' ); |
| 30 | + deepEqual( conf.get( 'inexistantKey' ), null, 'Map.get() returns null if selection was a string and the key was not found' ); |
| 31 | + deepEqual( conf.set( 'myKey', 'myValue' ), true, 'Map.set() returns boolean true if a value was set for a valid key string' ); |
| 32 | + deepEqual( conf.set( funky, 'Funky' ), false, 'Map.set() returns boolean false if key was invalid (Function)' ); |
| 33 | + deepEqual( conf.set( arry, 'Arry' ), false, 'Map.set() returns boolean false if key was invalid (Array)' ); |
| 34 | + deepEqual( conf.set( nummy, 'Nummy' ), false, 'Map.set() returns boolean false if key was invalid (Number)' ); |
| 35 | + equal( conf.get( 'myKey' ), 'myValue', 'Map.get() returns a single value value correctly' ); |
35 | 36 | |
36 | 37 | var someValues = { |
37 | 38 | 'foo': 'bar', |
38 | 39 | 'lorem': 'ipsum', |
39 | 40 | 'MediaWiki': true |
40 | 41 | }; |
41 | | - deepEqual( conf.set( someValues ), true, 'Map.set() returns boolean true if multiple values were set by passing an object.' ); |
| 42 | + deepEqual( conf.set( someValues ), true, 'Map.set() returns boolean true if multiple values were set by passing an object' ); |
42 | 43 | deepEqual( conf.get( ['foo', 'lorem'] ), { |
43 | 44 | 'foo': 'bar', |
44 | 45 | 'lorem': 'ipsum' |
45 | | - }, 'Map.get() returns multiple values correctly as an object.' ); |
| 46 | + }, 'Map.get() returns multiple values correctly as an object' ); |
46 | 47 | |
47 | 48 | deepEqual( conf.get( ['foo', 'notExist'] ), { |
48 | 49 | 'foo': 'bar', |
49 | 50 | 'notExist': null |
50 | 51 | }, 'Map.get() return includes keys that were not found as null values' ); |
51 | 52 | |
52 | | - deepEqual( conf.exists( 'foo' ), true, 'Map.exists() returns boolean true if a key exists.' ); |
53 | | - deepEqual( conf.exists( 'notExist' ), false, 'Map.exists() returns boolean false if a key does not exists.' ); |
54 | | - deepEqual( conf.get() === conf.values, true, 'Map.get() returns the entire values object by reference (if called without arguments).' ); |
| 53 | + deepEqual( conf.exists( 'foo' ), true, 'Map.exists() returns boolean true if a key exists' ); |
| 54 | + deepEqual( conf.exists( 'notExist' ), false, 'Map.exists() returns boolean false if a key does not exists' ); |
| 55 | + deepEqual( conf.get() === conf.values, true, 'Map.get() returns the entire values object by reference (if called without arguments)' ); |
55 | 56 | |
56 | 57 | conf.set( 'globalMapChecker', 'Hi' ); |
57 | 58 | |
58 | | - deepEqual( 'globalMapChecker' in window, false, 'new mw.Map() did not store its values in the global window object by default.' ); |
59 | | - ok( !window.globalMapChecker, 'new mw.Map() did not store its values in the global window object by default.' ); |
| 59 | + deepEqual( 'globalMapChecker' in window, false, 'new mw.Map() did not store its values in the global window object by default' ); |
| 60 | + ok( !window.globalMapChecker, 'new mw.Map() did not store its values in the global window object by default' ); |
60 | 61 | |
61 | 62 | var globalConf = new mw.Map( true ); |
62 | 63 | globalConf.set( 'anotherGlobalMapChecker', 'Hello' ); |
63 | 64 | |
64 | | - deepEqual( 'anotherGlobalMapChecker' in window, true, 'new mw.Map( true ) did store its values in the global window object.' ) |
65 | | - ok( window.anotherGlobalMapChecker, 'new mw.Map( true ) did store its values in the global window object.' ) |
| 65 | + deepEqual( 'anotherGlobalMapChecker' in window, true, 'new mw.Map( true ) did store its values in the global window object' ); |
| 66 | + ok( window.anotherGlobalMapChecker, 'new mw.Map( true ) did store its values in the global window object' ); |
66 | 67 | |
67 | 68 | // Clean up |
68 | 69 | delete window.anotherGlobalMapChecker; |
69 | 70 | }); |
70 | 71 | |
71 | 72 | test( 'mw.config', function(){ |
| 73 | + expect(1); |
| 74 | + |
72 | 75 | deepEqual( mw.config instanceof mw.Map, true, 'mw.config instance of mw.Map' ); |
73 | 76 | }); |
74 | 77 | |
75 | 78 | test( 'mw.messages / mw.message / mw.msg', function(){ |
| 79 | + expect(18); |
| 80 | + |
76 | 81 | ok( mw.message, 'mw.message defined' ); |
77 | 82 | ok( mw.msg, 'mw.msg defined' ); |
78 | 83 | ok( mw.messages, 'messages defined' ); |
— | — | @@ -80,37 +85,39 @@ |
81 | 86 | |
82 | 87 | var hello = mw.message( 'hello' ); |
83 | 88 | |
84 | | - equal( hello.format, 'parse', 'Message property "format" defaults to "parse".' ); |
| 89 | + equal( hello.format, 'parse', 'Message property "format" defaults to "parse"' ); |
85 | 90 | deepEqual( hello.map === mw.messages, true, 'Message property "map" defaults to the global instance in mw.messages' ); |
86 | 91 | equal( hello.key, 'hello', 'Message property "key" (currect key)' ); |
87 | | - deepEqual( hello.parameters, [], 'Message property "parameters" defaults to an empty array.' ); |
| 92 | + deepEqual( hello.parameters, [], 'Message property "parameters" defaults to an empty array' ); |
88 | 93 | |
89 | 94 | // Todo |
90 | | - ok( hello.params, 'Message prototype "params".' ); |
| 95 | + ok( hello.params, 'Message prototype "params"' ); |
91 | 96 | |
92 | 97 | hello.format = 'plain'; |
93 | | - equal( hello.toString(), 'Hello <b>awesome</b> world', 'Message.toString() returns the message as a string with the current "format".' ); |
| 98 | + equal( hello.toString(), 'Hello <b>awesome</b> world', 'Message.toString() returns the message as a string with the current "format"' ); |
94 | 99 | |
95 | | - equal( hello.escaped(), 'Hello <b>awesome</b> world', 'Message.escaped() returns the escaped message.' ); |
96 | | - equal( hello.format, 'escaped', 'Message.escaped() correctly updated the "format" property.' ); |
| 100 | + equal( hello.escaped(), 'Hello <b>awesome</b> world', 'Message.escaped() returns the escaped message' ); |
| 101 | + equal( hello.format, 'escaped', 'Message.escaped() correctly updated the "format" property' ); |
97 | 102 | |
98 | | - hello.parse() |
99 | | - equal( hello.format, 'parse', 'Message.parse() correctly updated the "format" property.' ); |
| 103 | + hello.parse(); |
| 104 | + equal( hello.format, 'parse', 'Message.parse() correctly updated the "format" property' ); |
100 | 105 | |
101 | 106 | hello.plain(); |
102 | | - equal( hello.format, 'plain', 'Message.plain() correctly updated the "format" property.' ); |
| 107 | + equal( hello.format, 'plain', 'Message.plain() correctly updated the "format" property' ); |
103 | 108 | |
104 | | - deepEqual( hello.exists(), true, 'Message.exists() returns true for existing messages.' ); |
| 109 | + deepEqual( hello.exists(), true, 'Message.exists() returns true for existing messages' ); |
105 | 110 | |
106 | 111 | var goodbye = mw.message( 'goodbye' ); |
107 | | - deepEqual( goodbye.exists(), false, 'Message.exists() returns false for inexisting messages.' ); |
| 112 | + deepEqual( goodbye.exists(), false, 'Message.exists() returns false for inexisting messages' ); |
108 | 113 | |
109 | | - equal( goodbye.toString(), '<goodbye>', 'Message.toString() returns <key> if key does not exist.' ); |
| 114 | + equal( goodbye.toString(), '<goodbye>', 'Message.toString() returns <key> if key does not exist' ); |
110 | 115 | }); |
111 | 116 | |
112 | 117 | test( 'mw.msg', function(){ |
| 118 | + expect(2); |
| 119 | + |
113 | 120 | equal( mw.msg( 'hello' ), 'Hello <b>awesome</b> world', 'Gets message with default options (existing message)' ); |
114 | | - equal( mw.msg( 'goodbye' ), '<goodbye>', 'Gets message with default options (inexisting message).' ); |
| 121 | + equal( mw.msg( 'goodbye' ), '<goodbye>', 'Gets message with default options (inexisting message)' ); |
115 | 122 | }); |
116 | 123 | |
117 | 124 | test( 'mw.loader', function(){ |
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.jpegmeta.js |
— | — | @@ -723,11 +723,11 @@ |
724 | 724 | }; |
725 | 725 | |
726 | 726 | /* JsJpegMeta ends here */ |
727 | | - |
| 727 | + |
728 | 728 | mw.util = $.extend( mw.util || {}, { |
729 | 729 | jpegmeta: function( fileReaderResult, fileName ) { |
730 | 730 | return new JpegMeta.JpegFile( fileReaderResult, fileName ); |
731 | 731 | } |
732 | 732 | } ); |
733 | | - |
| 733 | + |
734 | 734 | } )( jQuery, mediaWiki ); |
\ No newline at end of file |
Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js |
— | — | @@ -6,6 +6,9 @@ |
7 | 7 | mw.util = $.extend( mw.util || {}, { |
8 | 8 | |
9 | 9 | /* Initialisation */ |
| 10 | + /** |
| 11 | + * @var boolean Wether or not already initialised |
| 12 | + */ |
10 | 13 | 'initialised' : false, |
11 | 14 | 'init' : function() { |
12 | 15 | if ( this.initialised === false ) { |
— | — | @@ -93,9 +96,11 @@ |
94 | 97 | // Only add it if there is a TOC and there is no toggle added already |
95 | 98 | if ( $tocContainer.size() && $tocTitle.size() && !$tocToggleLink.size() ) { |
96 | 99 | var hideTocCookie = $.cookie( 'mw_hidetoc' ); |
97 | | - $tocToggleLink = $( '<a href="#" class="internal" id="togglelink">' ).text( mw.msg( 'hidetoc' ) ).click( function(e){ |
98 | | - e.preventDefault(); |
99 | | - mw.util.toggleToc( $(this) ); |
| 100 | + $tocToggleLink = $( '<a href="#" class="internal" id="togglelink">' ) |
| 101 | + .text( mw.msg( 'hidetoc' ) ) |
| 102 | + .click( function(e){ |
| 103 | + e.preventDefault(); |
| 104 | + mw.util.toggleToc( $(this) ); |
100 | 105 | } ); |
101 | 106 | $tocTitle.append( $tocToggleLink.wrap( '<span class="toctoggle">' ).parent().prepend( ' [' ).append( '] ' ) ); |
102 | 107 | |
— | — | @@ -116,7 +121,7 @@ |
117 | 122 | /** |
118 | 123 | * Encode the string like PHP's rawurlencode |
119 | 124 | * |
120 | | - * @param str String to be encoded |
| 125 | + * @param str string String to be encoded |
121 | 126 | */ |
122 | 127 | 'rawurlencode' : function( str ) { |
123 | 128 | str = ( str + '' ).toString(); |
— | — | @@ -130,7 +135,7 @@ |
131 | 136 | * We want / and : to be included as literal characters in our title URLs |
132 | 137 | * as they otherwise fatally break the title |
133 | 138 | * |
134 | | - * @param str String to be encoded |
| 139 | + * @param str string String to be encoded |
135 | 140 | */ |
136 | 141 | 'wikiUrlencode' : function( str ) { |
137 | 142 | return this.rawurlencode( str ) |
— | — | @@ -140,7 +145,7 @@ |
141 | 146 | /** |
142 | 147 | * Get the link to a page name (relative to wgServer) |
143 | 148 | * |
144 | | - * @param str Page name to get the link for. |
| 149 | + * @param str string Page name to get the link for. |
145 | 150 | * @return string Location for a page with name of 'str' or boolean false on error. |
146 | 151 | */ |
147 | 152 | 'wikiGetlink' : function( str ) { |
— | — | @@ -152,8 +157,8 @@ |
153 | 158 | * Get address to a script in the wiki root. |
154 | 159 | * For index.php use mw.config.get( 'wgScript' ) |
155 | 160 | * |
156 | | - * @param str Name of script (eg. 'api'), defaults to 'index' |
157 | | - * @return str Address to script (eg. '/w/api.php' ) |
| 161 | + * @param str string Name of script (eg. 'api'), defaults to 'index' |
| 162 | + * @return string Address to script (eg. '/w/api.php' ) |
158 | 163 | */ |
159 | 164 | 'wikiScript' : function( str ) { |
160 | 165 | return mw.config.get( 'wgScriptPath' ) + '/' + ( str || 'index' ) + mw.config.get( 'wgScriptExtension' ); |
— | — | @@ -162,8 +167,8 @@ |
163 | 168 | /** |
164 | 169 | * Append a new style block to the head |
165 | 170 | * |
166 | | - * @param text String CSS to be appended |
167 | | - * @return CSSStyleSheet object |
| 171 | + * @param text string CSS to be appended |
| 172 | + * @return CSSStyleSheet |
168 | 173 | */ |
169 | 174 | 'addCSS' : function( text ) { |
170 | 175 | var s = document.createElement( 'style' ); |
— | — | @@ -174,24 +179,27 @@ |
175 | 180 | } else { |
176 | 181 | s.appendChild( document.createTextNode( text + '' ) ); // Safari sometimes borks on null |
177 | 182 | } |
178 | | - document.getElementsByTagName("head")[0].appendChild( s ); |
| 183 | + document.getElementsByTagName('head')[0].appendChild( s ); |
179 | 184 | return s.sheet || s; |
180 | 185 | }, |
181 | 186 | |
182 | 187 | /** |
183 | 188 | * Hide/show the table of contents element |
184 | 189 | * |
185 | | - * @param $toggleLink jQuery object of the toggle link |
186 | | - * @return String boolean visibility of the toc (true means it's visible) |
| 190 | + * @param $toggleLink jQuery A jQuery object of the toggle link. |
| 191 | + * @param callback function Function to be called after the toggle is |
| 192 | + * completed (including the animation) (optional) |
| 193 | + * @return mixed Boolean visibility of the toc (true if it's visible) |
| 194 | + * or Null if there was no table of contents. |
187 | 195 | */ |
188 | | - 'toggleToc' : function( $toggleLink ) { |
| 196 | + 'toggleToc' : function( $toggleLink, callback ) { |
189 | 197 | var $tocList = $( '#toc ul:first' ); |
190 | 198 | |
191 | 199 | // This function shouldn't be called if there's no TOC, |
192 | 200 | // but just in case... |
193 | 201 | if ( $tocList.size() ) { |
194 | 202 | if ( $tocList.is( ':hidden' ) ) { |
195 | | - $tocList.slideDown( 'fast' ); |
| 203 | + $tocList.slideDown( 'fast', callback ); |
196 | 204 | $toggleLink.text( mw.msg( 'hidetoc' ) ); |
197 | 205 | $.cookie( 'mw_hidetoc', null, { |
198 | 206 | expires: 30, |
— | — | @@ -199,7 +207,7 @@ |
200 | 208 | } ); |
201 | 209 | return true; |
202 | 210 | } else { |
203 | | - $tocList.slideUp( 'fast' ); |
| 211 | + $tocList.slideUp( 'fast', callback ); |
204 | 212 | $toggleLink.text( mw.msg( 'showtoc' ) ); |
205 | 213 | $.cookie( 'mw_hidetoc', '1', { |
206 | 214 | expires: 30, |
— | — | @@ -208,7 +216,7 @@ |
209 | 217 | return false; |
210 | 218 | } |
211 | 219 | } else { |
212 | | - return false; |
| 220 | + return null; |
213 | 221 | } |
214 | 222 | }, |
215 | 223 | |
— | — | @@ -216,8 +224,9 @@ |
217 | 225 | * Grab the URL parameter value for the given parameter. |
218 | 226 | * Returns null if not found. |
219 | 227 | * |
220 | | - * @param param The parameter name |
221 | | - * @param url URL to search through (optional) |
| 228 | + * @param param string The parameter name. |
| 229 | + * @param url string URL to search through (optional) |
| 230 | + * @return mixed Parameter value or null. |
222 | 231 | */ |
223 | 232 | 'getParamValue' : function( param, url ) { |
224 | 233 | url = url ? url : document.location.href; |
— | — | @@ -230,12 +239,17 @@ |
231 | 240 | return null; |
232 | 241 | }, |
233 | 242 | |
234 | | - // Access key prefix. |
235 | | - // Will be re-defined based on browser/operating system detection in |
236 | | - // mw.util.init(). |
| 243 | + /** |
| 244 | + * @var string |
| 245 | + * Access key prefix. Will be re-defined based on browser/operating system |
| 246 | + * detection in mw.util.init(). |
| 247 | + */ |
237 | 248 | 'tooltipAccessKeyPrefix' : 'alt-', |
238 | 249 | |
239 | | - // Regex to match accesskey tooltips |
| 250 | + /** |
| 251 | + * @var RegExp |
| 252 | + * Regex to match accesskey tooltips. |
| 253 | + */ |
240 | 254 | 'tooltipAccessKeyRegexp': /\[(ctrl-)?(alt-)?(shift-)?(esc-)?(.)\]$/, |
241 | 255 | |
242 | 256 | /** |
— | — | @@ -244,7 +258,7 @@ |
245 | 259 | * otherwise, all the nodes that will probably have accesskeys by |
246 | 260 | * default are updated. |
247 | 261 | * |
248 | | - * @param nodeList jQuery object, or array of elements |
| 262 | + * @param nodeList mixed A jQuery object, or array of elements to update. |
249 | 263 | */ |
250 | 264 | 'updateTooltipAccessKeys' : function( nodeList ) { |
251 | 265 | var $nodes; |
— | — | @@ -274,8 +288,11 @@ |
275 | 289 | } ); |
276 | 290 | }, |
277 | 291 | |
278 | | - // jQuery object that refers to the page-content element |
279 | | - // Populated by init() |
| 292 | + /* |
| 293 | + * @var jQuery |
| 294 | + * A jQuery object that refers to the page-content element |
| 295 | + * Populated by init(). |
| 296 | + */ |
280 | 297 | '$content' : null, |
281 | 298 | |
282 | 299 | /** |
— | — | @@ -284,8 +301,8 @@ |
285 | 302 | * p-cactions (Content actions), p-personal (Personal tools), |
286 | 303 | * p-navigation (Navigation), p-tb (Toolbox) |
287 | 304 | * |
288 | | - * The first three paramters are required, others are optionals. Though |
289 | | - * providing an id and tooltip is recommended. |
| 305 | + * The first three paramters are required, the others are optional and |
| 306 | + * may be null. Though providing an id and tooltip is recommended. |
290 | 307 | * |
291 | 308 | * By default the new link will be added to the end of the list. To |
292 | 309 | * add the link before a given existing item, pass the DOM node |
— | — | @@ -297,21 +314,21 @@ |
298 | 315 | * 'MediaWiki.org', 't-mworg', 'Go to MediaWiki.org ', 'm', '#t-print' |
299 | 316 | * ) |
300 | 317 | * |
301 | | - * @param portlet ID of the target portlet ( 'p-cactions' or 'p-personal' etc.) |
302 | | - * @param href Link URL |
303 | | - * @param text Link text |
304 | | - * @param id ID of the new item, should be unique and preferably have |
305 | | - * the appropriate prefix ( 'ca-', 'pt-', 'n-' or 't-' ) |
306 | | - * @param tooltip Text to show when hovering over the link, without accesskey suffix |
307 | | - * @param accesskey Access key to activate this link (one character, try |
308 | | - * to avoid conflicts. Use $( '[accesskey=x]' ).get() in the console to |
309 | | - * see if 'x' is already used. |
310 | | - * @param nextnode DOM node or jQuery-selector string of the item that the new |
311 | | - * item should be added before, should be another item in the same |
312 | | - * list, it will be ignored otherwise |
| 318 | + * @param portlet string ID of the target portlet ( 'p-cactions' or 'p-personal' etc.) |
| 319 | + * @param href string Link URL |
| 320 | + * @param text string Link text |
| 321 | + * @param id string ID of the new item, should be unique and preferably have |
| 322 | + * the appropriate prefix ( 'ca-', 'pt-', 'n-' or 't-' ) |
| 323 | + * @param tooltip string Text to show when hovering over the link, without accesskey suffix |
| 324 | + * @param accesskey string Access key to activate this link (one character, try |
| 325 | + * to avoid conflicts. Use $( '[accesskey=x]' ).get() in the console to |
| 326 | + * see if 'x' is already used. |
| 327 | + * @param nextnode mixed DOM Node or jQuery-selector string of the item that the new |
| 328 | + * item should be added before, should be another item in the same |
| 329 | + * list, it will be ignored otherwise |
313 | 330 | * |
314 | | - * @return The DOM node of the new item (a LI element, or A element for |
315 | | - * older skins) or null. |
| 331 | + * @return mixed The DOM Node of the added item (a ListItem or Anchor element, |
| 332 | + * depending on the skin) or null if no element was added to the document. |
316 | 333 | */ |
317 | 334 | 'addPortletLink' : function( portlet, href, text, id, tooltip, accesskey, nextnode ) { |
318 | 335 | |
— | — | @@ -399,8 +416,8 @@ |
400 | 417 | } else { |
401 | 418 | $ul.append( $item ); |
402 | 419 | } |
403 | | - |
404 | 420 | |
| 421 | + |
405 | 422 | return $item[0]; |
406 | 423 | } |
407 | 424 | }, |
— | — | @@ -412,8 +429,8 @@ |
413 | 430 | * |
414 | 431 | * @param message mixed The DOM-element or HTML-string to be put inside the message box. |
415 | 432 | * @param className string Used in adding a class; should be different for each call |
416 | | - * to allow CSS/JS to hide different boxes. null = no class used. |
417 | | - * @return boolean True on success, false on failure |
| 433 | + * to allow CSS/JS to hide different boxes. null = no class used. |
| 434 | + * @return boolean True on success, false on failure. |
418 | 435 | */ |
419 | 436 | 'jsMessage' : function( message, className ) { |
420 | 437 | |
— | — | @@ -457,7 +474,11 @@ |
458 | 475 | * according to HTML5 specification. Please note the specification |
459 | 476 | * does not validate a domain with one character. |
460 | 477 | * |
461 | | - * FIXME: should be moved to or replaced by a JavaScript validation module. |
| 478 | + * @todo FIXME: should be moved to or replaced by a JavaScript validation module. |
| 479 | + * |
| 480 | + * @param mailtxt string E-mail address to be validated. |
| 481 | + * @return mixed Null if mailtxt was an empty string, otherwise true/false |
| 482 | + * is determined by validation. |
462 | 483 | */ |
463 | 484 | 'validateEmail' : function( mailtxt ) { |
464 | 485 | if( mailtxt === '' ) { |
— | — | @@ -525,14 +546,27 @@ |
526 | 547 | ); |
527 | 548 | return (null !== mailtxt.match( HTML5_email_regexp ) ); |
528 | 549 | }, |
529 | | - // Note: borrows from IP::isIPv4 |
| 550 | + |
| 551 | + /** |
| 552 | + * Note: borrows from IP::isIPv4 |
| 553 | + * |
| 554 | + * @param address string |
| 555 | + * @param allowBlock boolean |
| 556 | + * @return boolean |
| 557 | + */ |
530 | 558 | 'isIPv4Address' : function( address, allowBlock ) { |
531 | 559 | var block = allowBlock ? '(?:\\/(?:3[0-2]|[12]?\\d))?' : ''; |
532 | 560 | var RE_IP_BYTE = '(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|0?[0-9]?[0-9])'; |
533 | 561 | var RE_IP_ADD = '(?:' + RE_IP_BYTE + '\\.){3}' + RE_IP_BYTE; |
534 | 562 | return address.search( new RegExp( '^' + RE_IP_ADD + block + '$' ) ) != -1; |
535 | 563 | }, |
536 | | - // Note: borrows from IP::isIPv6 |
| 564 | + /** |
| 565 | + * Note: borrows from IP::isIPv6 |
| 566 | + * |
| 567 | + * @param address string |
| 568 | + * @param allowBlock boolean |
| 569 | + * @return boolean |
| 570 | + */ |
537 | 571 | 'isIPv6Address' : function( address, allowBlock ) { |
538 | 572 | var block = allowBlock ? '(?:\\/(?:12[0-8]|1[01][0-9]|[1-9]?\\d))?' : ''; |
539 | 573 | var RE_IPV6_ADD = |
Index: trunk/phase3/resources/mediawiki/mediawiki.htmlform.js |
— | — | @@ -3,15 +3,27 @@ |
4 | 4 | */ |
5 | 5 | ( function( $ ) { |
6 | 6 | |
7 | | -// Fade or snap depending on argument |
| 7 | +/** |
| 8 | + * jQuery plugin to fade or snap to visible state. |
| 9 | + * |
| 10 | + * @param boolean instantToggle (optional) |
| 11 | + * @return jQuery |
| 12 | + */ |
8 | 13 | $.fn.goIn = function( instantToggle ) { |
9 | | - if ( typeof instantToggle != 'undefined' && instantToggle === true ) { |
| 14 | + if ( instantToggle !== undefined && instantToggle === true ) { |
10 | 15 | return $(this).show(); |
11 | 16 | } |
12 | 17 | return $(this).stop( true, true ).fadeIn(); |
13 | 18 | }; |
| 19 | + |
| 20 | +/** |
| 21 | + * jQuery plugin to fade or snap to hiding state. |
| 22 | + * |
| 23 | + * @param boolean instantToggle (optional) |
| 24 | + * @return jQuery |
| 25 | + */ |
14 | 26 | $.fn.goOut = function( instantToggle ) { |
15 | | - if ( typeof instantToggle != 'undefined' && instantToggle === true ) { |
| 27 | + if ( instantToggle !== undefined && instantToggle === true ) { |
16 | 28 | return $(this).hide(); |
17 | 29 | } |
18 | 30 | return $(this).stop( true, true ).fadeOut(); |
— | — | @@ -34,12 +46,12 @@ |
35 | 47 | // Document ready: |
36 | 48 | $( function() { |
37 | 49 | |
38 | | - // animate the SelectOrOther fields, to only show the text field when |
39 | | - // 'other' is selected |
| 50 | + // Animate the SelectOrOther fields, to only show the text field when |
| 51 | + // 'other' is selected. |
40 | 52 | $( '.mw-htmlform-select-or-other' ).liveAndTestAtStart( function( instant ) { |
41 | 53 | var $other = $( '#' + $(this).attr( 'id' ) + '-other' ); |
42 | 54 | $other = $other.add( $other.siblings( 'br' ) ); |
43 | | - if ( $(this).val() == 'other' ) { |
| 55 | + if ( $(this).val() === 'other' ) { |
44 | 56 | $other.goIn( instant ); |
45 | 57 | } else { |
46 | 58 | $other.goOut( instant ); |
— | — | @@ -49,4 +61,4 @@ |
50 | 62 | }); |
51 | 63 | |
52 | 64 | |
53 | | -})( jQuery ); |
\ No newline at end of file |
| 65 | +})( jQuery ); |
Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -210,7 +210,7 @@ |
211 | 211 | |
212 | 212 | /* |
213 | 213 | * Dummy function which in debug mode can be replaced with a function that |
214 | | - * emulates console.log in console-less environments. |
| 214 | + * emulates console.log in console-less environments. |
215 | 215 | */ |
216 | 216 | this.log = function() { }; |
217 | 217 | |
— | — | @@ -318,7 +318,8 @@ |
319 | 319 | return $marker; |
320 | 320 | } |
321 | 321 | mw.log( 'getMarker> No <meta name="ResourceLoaderDynamicStyles"> found, inserting dynamically.' ); |
322 | | - return $marker = $( '<meta>' ).attr( 'name', 'ResourceLoaderDynamicStyles' ).appendTo( 'head' ); |
| 322 | + $marker = $( '<meta>' ).attr( 'name', 'ResourceLoaderDynamicStyles' ).appendTo( 'head' ); |
| 323 | + return $marker; |
323 | 324 | } |
324 | 325 | } |
325 | 326 | |
— | — | @@ -512,7 +513,7 @@ |
513 | 514 | }; |
514 | 515 | if ( $.isArray( script ) ) { |
515 | 516 | var done = 0; |
516 | | - if (script.length == 0 ) { |
| 517 | + if ( script.length === 0 ) { |
517 | 518 | // No scripts in this module? Let's dive out early. |
518 | 519 | markModuleReady(); |
519 | 520 | } |
— | — | @@ -534,8 +535,8 @@ |
535 | 536 | if ( window.console && typeof window.console.log === 'function' ) { |
536 | 537 | console.log( _fn + 'Exception thrown by ' + module + ': ' + e.message ); |
537 | 538 | } |
| 539 | + registry[module].state = 'error'; |
538 | 540 | throw e; |
539 | | - registry[module].state = 'error'; |
540 | 541 | } |
541 | 542 | } |
542 | 543 | |
— | — | @@ -674,8 +675,8 @@ |
675 | 676 | !done |
676 | 677 | && ( |
677 | 678 | !this.readyState |
678 | | - || this.readyState === "loaded" |
679 | | - || this.readyState === "complete" |
| 679 | + || this.readyState === 'loaded' |
| 680 | + || this.readyState === 'complete' |
680 | 681 | ) |
681 | 682 | ) { |
682 | 683 | done = true; |
— | — | @@ -1031,7 +1032,7 @@ |
1032 | 1033 | */ |
1033 | 1034 | this.version = function() { |
1034 | 1035 | return mediaWiki.loader.getVersion.apply( mediaWiki.loader, arguments ); |
1035 | | - } |
| 1036 | + }; |
1036 | 1037 | |
1037 | 1038 | /** |
1038 | 1039 | * Gets the state of a module |
— | — | @@ -1120,7 +1121,7 @@ |
1121 | 1122 | } |
1122 | 1123 | // Regular open tag |
1123 | 1124 | s += '>'; |
1124 | | - if ( typeof contents === 'string') { |
| 1125 | + if ( typeof contents === 'string' ) { |
1125 | 1126 | // Escaped |
1126 | 1127 | s += this.escape( contents ); |
1127 | 1128 | } else if ( contents instanceof this.Raw ) { |
Index: trunk/phase3/resources/mediawiki/mediawiki.log.js |
— | — | @@ -13,16 +13,16 @@ |
14 | 14 | * |
15 | 15 | * @author Michael Dale <mdale@wikimedia.org> |
16 | 16 | * @author Trevor Parscal <tparscal@wikimedia.org> |
17 | | - * @param {string} string Message to output to console |
| 17 | + * @param logmsg string Message to output to console. |
18 | 18 | */ |
19 | | - mw.log = function( string ) { |
| 19 | + mw.log = function( msg ) { |
20 | 20 | // Allow log messages to use a configured prefix to identify the source window (ie. frame) |
21 | 21 | if ( mw.config.exists( 'mw.log.prefix' ) ) { |
22 | | - string = mw.config.get( 'mw.log.prefix' ) + '> ' + string; |
| 22 | + logmsg = mw.config.get( 'mw.log.prefix' ) + '> ' + logmsg; |
23 | 23 | } |
24 | 24 | // Try to use an existing console |
25 | | - if ( typeof window.console !== 'undefined' && typeof window.console.log == 'function' ) { |
26 | | - console.log( string ); |
| 25 | + if ( window.console !== undefined && $.isFunction( window.console.log ) ) { |
| 26 | + window.console.log( logmsg ); |
27 | 27 | } else { |
28 | 28 | // Set timestamp |
29 | 29 | var d = new Date(); |
— | — | @@ -58,7 +58,7 @@ |
59 | 59 | 'white-space': 'pre-wrap', |
60 | 60 | 'padding': '0.125em 0.25em' |
61 | 61 | } ) |
62 | | - .text( string ) |
| 62 | + .text( logmsg ) |
63 | 63 | .prepend( '<span style="float:right">[' + time + ']</span>' ) |
64 | 64 | ); |
65 | 65 | } |