Index: trunk/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -29,79 +29,81 @@ |
30 | 30 | return this; |
31 | 31 | } |
32 | 32 | |
33 | | - /** |
34 | | - * Get the value of one or multiple a keys. |
35 | | - * |
36 | | - * If called with no arguments, all values will be returned. |
37 | | - * |
38 | | - * @param selection mixed String key or array of keys to get values for. |
39 | | - * @param fallback mixed Value to use in case key(s) do not exist (optional). |
40 | | - * @return mixed If selection was a string returns the value or null, |
41 | | - * If selection was an array, returns an object of key/values (value is null if not found), |
42 | | - * If selection was not passed or invalid, will return the 'values' object member (be careful as |
43 | | - * objects are always passed by reference in JavaScript!). |
44 | | - * @return Values as a string or object, null if invalid/inexistant. |
45 | | - */ |
46 | | - Map.prototype.get = function( selection, fallback ) { |
47 | | - if ( $.isArray( selection ) ) { |
48 | | - selection = $.makeArray( selection ); |
49 | | - var results = {}; |
50 | | - for ( var i = 0; i < selection.length; i++ ) { |
51 | | - results[selection[i]] = this.get( selection[i], fallback ); |
52 | | - } |
53 | | - return results; |
54 | | - } else if ( typeof selection === 'string' ) { |
55 | | - if ( this.values[selection] === undefined ) { |
56 | | - if ( fallback !== undefined ) { |
57 | | - return fallback; |
| 33 | + Map.prototype = { |
| 34 | + /** |
| 35 | + * Get the value of one or multiple a keys. |
| 36 | + * |
| 37 | + * If called with no arguments, all values will be returned. |
| 38 | + * |
| 39 | + * @param selection mixed String key or array of keys to get values for. |
| 40 | + * @param fallback mixed Value to use in case key(s) do not exist (optional). |
| 41 | + * @return mixed If selection was a string returns the value or null, |
| 42 | + * If selection was an array, returns an object of key/values (value is null if not found), |
| 43 | + * If selection was not passed or invalid, will return the 'values' object member (be careful as |
| 44 | + * objects are always passed by reference in JavaScript!). |
| 45 | + * @return Values as a string or object, null if invalid/inexistant. |
| 46 | + */ |
| 47 | + get: function( selection, fallback ) { |
| 48 | + if ( $.isArray( selection ) ) { |
| 49 | + selection = $.makeArray( selection ); |
| 50 | + var results = {}; |
| 51 | + for ( var i = 0; i < selection.length; i++ ) { |
| 52 | + results[selection[i]] = this.get( selection[i], fallback ); |
58 | 53 | } |
59 | | - return null; |
| 54 | + return results; |
| 55 | + } else if ( typeof selection === 'string' ) { |
| 56 | + if ( this.values[selection] === undefined ) { |
| 57 | + if ( fallback !== undefined ) { |
| 58 | + return fallback; |
| 59 | + } |
| 60 | + return null; |
| 61 | + } |
| 62 | + return this.values[selection]; |
60 | 63 | } |
61 | | - return this.values[selection]; |
62 | | - } |
63 | | - if ( selection === undefined ) { |
64 | | - return this.values; |
65 | | - } else { |
66 | | - return null; // invalid selection key |
67 | | - } |
68 | | - }; |
| 64 | + if ( selection === undefined ) { |
| 65 | + return this.values; |
| 66 | + } else { |
| 67 | + return null; // invalid selection key |
| 68 | + } |
| 69 | + }, |
69 | 70 | |
70 | | - /** |
71 | | - * Sets one or multiple key/value pairs. |
72 | | - * |
73 | | - * @param selection mixed String key or array of keys to set values for. |
74 | | - * @param value mixed Value to set (optional, only in use when key is a string) |
75 | | - * @return bool This returns true on success, false on failure. |
76 | | - */ |
77 | | - Map.prototype.set = function( selection, value ) { |
78 | | - if ( $.isPlainObject( selection ) ) { |
79 | | - for ( var s in selection ) { |
80 | | - this.values[s] = selection[s]; |
| 71 | + /** |
| 72 | + * Sets one or multiple key/value pairs. |
| 73 | + * |
| 74 | + * @param selection mixed String key or array of keys to set values for. |
| 75 | + * @param value mixed Value to set (optional, only in use when key is a string) |
| 76 | + * @return bool This returns true on success, false on failure. |
| 77 | + */ |
| 78 | + set: function( selection, value ) { |
| 79 | + if ( $.isPlainObject( selection ) ) { |
| 80 | + for ( var s in selection ) { |
| 81 | + this.values[s] = selection[s]; |
| 82 | + } |
| 83 | + return true; |
| 84 | + } else if ( typeof selection === 'string' && value !== undefined ) { |
| 85 | + this.values[selection] = value; |
| 86 | + return true; |
81 | 87 | } |
82 | | - return true; |
83 | | - } else if ( typeof selection === 'string' && value !== undefined ) { |
84 | | - this.values[selection] = value; |
85 | | - return true; |
86 | | - } |
87 | | - return false; |
88 | | - }; |
| 88 | + return false; |
| 89 | + }, |
89 | 90 | |
90 | | - /** |
91 | | - * Checks if one or multiple keys exist. |
92 | | - * |
93 | | - * @param selection mixed String key or array of keys to check |
94 | | - * @return boolean Existence of key(s) |
95 | | - */ |
96 | | - Map.prototype.exists = function( selection ) { |
97 | | - if ( typeof selection === 'object' ) { |
98 | | - for ( var s = 0; s < selection.length; s++ ) { |
99 | | - if ( !( selection[s] in this.values ) ) { |
100 | | - return false; |
| 91 | + /** |
| 92 | + * Checks if one or multiple keys exist. |
| 93 | + * |
| 94 | + * @param selection mixed String key or array of keys to check |
| 95 | + * @return boolean Existence of key(s) |
| 96 | + */ |
| 97 | + exists: function( selection ) { |
| 98 | + if ( typeof selection === 'object' ) { |
| 99 | + for ( var s = 0; s < selection.length; s++ ) { |
| 100 | + if ( !( selection[s] in this.values ) ) { |
| 101 | + return false; |
| 102 | + } |
101 | 103 | } |
| 104 | + return true; |
| 105 | + } else { |
| 106 | + return selection in this.values; |
102 | 107 | } |
103 | | - return true; |
104 | | - } else { |
105 | | - return selection in this.values; |
106 | 108 | } |
107 | 109 | }; |
108 | 110 | |
— | — | @@ -124,93 +126,95 @@ |
125 | 127 | return this; |
126 | 128 | } |
127 | 129 | |
128 | | - /** |
129 | | - * Appends (does not replace) parameters for replacement to the .parameters property. |
130 | | - * |
131 | | - * @param parameters Array |
132 | | - * @return Message |
133 | | - */ |
134 | | - Message.prototype.params = function( parameters ) { |
135 | | - for ( var i = 0; i < parameters.length; i++ ) { |
136 | | - this.parameters.push( parameters[i] ); |
137 | | - } |
138 | | - return this; |
139 | | - }; |
| 130 | + Message.prototype = { |
| 131 | + /** |
| 132 | + * Appends (does not replace) parameters for replacement to the .parameters property. |
| 133 | + * |
| 134 | + * @param parameters Array |
| 135 | + * @return Message |
| 136 | + */ |
| 137 | + params: function( parameters ) { |
| 138 | + for ( var i = 0; i < parameters.length; i++ ) { |
| 139 | + this.parameters.push( parameters[i] ); |
| 140 | + } |
| 141 | + return this; |
| 142 | + }, |
140 | 143 | |
141 | | - /** |
142 | | - * Converts message object to it's string form based on the state of format. |
143 | | - * |
144 | | - * @return string Message as a string in the current form or <key> if key does not exist. |
145 | | - */ |
146 | | - Message.prototype.toString = function() { |
147 | | - if ( !this.map.exists( this.key ) ) { |
148 | | - // Return <key> if key does not exist |
149 | | - return '<' + this.key + '>'; |
150 | | - } |
151 | | - var text = this.map.get( this.key ), |
152 | | - parameters = this.parameters; |
| 144 | + /** |
| 145 | + * Converts message object to it's string form based on the state of format. |
| 146 | + * |
| 147 | + * @return string Message as a string in the current form or <key> if key does not exist. |
| 148 | + */ |
| 149 | + toString: function() { |
| 150 | + if ( !this.map.exists( this.key ) ) { |
| 151 | + // Return <key> if key does not exist |
| 152 | + return '<' + this.key + '>'; |
| 153 | + } |
| 154 | + var text = this.map.get( this.key ), |
| 155 | + parameters = this.parameters; |
153 | 156 | |
154 | | - text = text.replace( /\$(\d+)/g, function( string, match ) { |
155 | | - var index = parseInt( match, 10 ) - 1; |
156 | | - return index in parameters ? parameters[index] : '$' + match; |
157 | | - } ); |
| 157 | + text = text.replace( /\$(\d+)/g, function( string, match ) { |
| 158 | + var index = parseInt( match, 10 ) - 1; |
| 159 | + return index in parameters ? parameters[index] : '$' + match; |
| 160 | + } ); |
158 | 161 | |
159 | | - if ( this.format === 'plain' ) { |
| 162 | + if ( this.format === 'plain' ) { |
| 163 | + return text; |
| 164 | + } |
| 165 | + if ( this.format === 'escaped' ) { |
| 166 | + // According to Message.php this needs {{-transformation, which is |
| 167 | + // still todo |
| 168 | + return mw.html.escape( text ); |
| 169 | + } |
| 170 | + |
| 171 | + /* This should be fixed up when we have a parser |
| 172 | + if ( this.format === 'parse' && 'language' in mw ) { |
| 173 | + text = mw.language.parse( text ); |
| 174 | + } |
| 175 | + */ |
160 | 176 | return text; |
161 | | - } |
162 | | - if ( this.format === 'escaped' ) { |
163 | | - // According to Message.php this needs {{-transformation, which is |
164 | | - // still todo |
165 | | - return mw.html.escape( text ); |
166 | | - } |
| 177 | + }, |
167 | 178 | |
168 | | - /* This should be fixed up when we have a parser |
169 | | - if ( this.format === 'parse' && 'language' in mw ) { |
170 | | - text = mw.language.parse( text ); |
171 | | - } |
172 | | - */ |
173 | | - return text; |
174 | | - }; |
| 179 | + /** |
| 180 | + * Changes format to parse and converts message to string |
| 181 | + * |
| 182 | + * @return {string} String form of parsed message |
| 183 | + */ |
| 184 | + parse: function() { |
| 185 | + this.format = 'parse'; |
| 186 | + return this.toString(); |
| 187 | + }, |
175 | 188 | |
176 | | - /** |
177 | | - * Changes format to parse and converts message to string |
178 | | - * |
179 | | - * @return {string} String form of parsed message |
180 | | - */ |
181 | | - Message.prototype.parse = function() { |
182 | | - this.format = 'parse'; |
183 | | - return this.toString(); |
184 | | - }; |
| 189 | + /** |
| 190 | + * Changes format to plain and converts message to string |
| 191 | + * |
| 192 | + * @return {string} String form of plain message |
| 193 | + */ |
| 194 | + plain: function() { |
| 195 | + this.format = 'plain'; |
| 196 | + return this.toString(); |
| 197 | + }, |
185 | 198 | |
186 | | - /** |
187 | | - * Changes format to plain and converts message to string |
188 | | - * |
189 | | - * @return {string} String form of plain message |
190 | | - */ |
191 | | - Message.prototype.plain = function() { |
192 | | - this.format = 'plain'; |
193 | | - return this.toString(); |
194 | | - }; |
| 199 | + /** |
| 200 | + * Changes the format to html escaped and converts message to string |
| 201 | + * |
| 202 | + * @return {string} String form of html escaped message |
| 203 | + */ |
| 204 | + escaped: function() { |
| 205 | + this.format = 'escaped'; |
| 206 | + return this.toString(); |
| 207 | + }, |
195 | 208 | |
196 | | - /** |
197 | | - * Changes the format to html escaped and converts message to string |
198 | | - * |
199 | | - * @return {string} String form of html escaped message |
200 | | - */ |
201 | | - Message.prototype.escaped = function() { |
202 | | - this.format = 'escaped'; |
203 | | - return this.toString(); |
| 209 | + /** |
| 210 | + * Checks if message exists |
| 211 | + * |
| 212 | + * @return {string} String form of parsed message |
| 213 | + */ |
| 214 | + exists: function() { |
| 215 | + return this.map.exists( this.key ); |
| 216 | + } |
204 | 217 | }; |
205 | 218 | |
206 | | - /** |
207 | | - * Checks if message exists |
208 | | - * |
209 | | - * @return {string} String form of parsed message |
210 | | - */ |
211 | | - Message.prototype.exists = function() { |
212 | | - return this.map.exists( this.key ); |
213 | | - }; |
214 | | - |
215 | 219 | /* Public Members */ |
216 | 220 | |
217 | 221 | /* |
— | — | @@ -360,7 +364,7 @@ |
361 | 365 | return [a < 10 ? '0' + a : a, b < 10 ? '0' + b : b, c < 10 ? '0' + c : c].join( '' ); |
362 | 366 | }, |
363 | 367 | d = new Date(); |
364 | | - d.setTime( timestamp * 1000 ); |
| 368 | + d.setTime( timestamp * 1000 ); |
365 | 369 | return [ |
366 | 370 | pad( d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate() ), 'T', |
367 | 371 | pad( d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds() ), 'Z' |
— | — | @@ -501,11 +505,10 @@ |
502 | 506 | } ) ); |
503 | 507 | } |
504 | 508 | } else if ( typeof style === 'string' ) { |
505 | | - getMarker().before( mw.html.element( |
506 | | - 'style', |
507 | | - { 'type': 'text/css', 'media': media }, |
508 | | - new mw.html.Cdata( style ) |
509 | | - ) ); |
| 509 | + getMarker().before( mw.html.element( 'style', { |
| 510 | + 'type': 'text/css', |
| 511 | + 'media': media |
| 512 | + }, new mw.html.Cdata( style ) ) ); |
510 | 513 | } |
511 | 514 | } |
512 | 515 | } |
— | — | @@ -673,12 +676,12 @@ |
674 | 677 | * @param callback Function: Optional callback which will be run when the script is done |
675 | 678 | */ |
676 | 679 | function addScript( src, callback ) { |
| 680 | + var done = false, script; |
677 | 681 | if ( ready ) { |
678 | 682 | // jQuery's getScript method is NOT better than doing this the old-fassioned way |
679 | 683 | // because jQuery will eval the script's code, and errors will not have sane |
680 | 684 | // line numbers. |
681 | | - var done = false, |
682 | | - script = document.createElement( 'script' ); |
| 685 | + script = document.createElement( 'script' ); |
683 | 686 | script.setAttribute( 'src', src ); |
684 | 687 | script.setAttribute( 'type', 'text/javascript' ); |
685 | 688 | if ( $.isFunction( callback ) ) { |
— | — | @@ -1163,8 +1166,7 @@ |
1164 | 1167 | // Alias $j to jQuery for backwards compatibility |
1165 | 1168 | window.$j = jQuery; |
1166 | 1169 | |
1167 | | -/* Auto-register from pre-loaded startup scripts */ |
1168 | | - |
| 1170 | +// Auto-register from pre-loaded startup scripts |
1169 | 1171 | if ( jQuery.isFunction( startUp ) ) { |
1170 | 1172 | startUp(); |
1171 | 1173 | delete startUp; |