Index: branches/RL2/extensions/Gadgets/Gadgets.i18n.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | |
21 | 21 | # For Special:Preferences |
22 | 22 | 'prefs-gadgets' => 'Gadgets', |
23 | | - 'prefs-gadgets-shared' => 'Shared gadgets', |
| 23 | + 'prefs-gadgetsshared' => 'Shared gadgets', |
24 | 24 | 'gadgets-prefstext' => 'Below is a list of gadgets you can enable for your account. |
25 | 25 | These gadgets are mostly based on JavaScript, so JavaScript has to be enabled in your browser for them to work. |
26 | 26 | Note that these gadgets will have no effect on this preferences page. |
Index: branches/RL2/extensions/Gadgets/Gadgets.php |
— | — | @@ -235,6 +235,9 @@ |
236 | 236 | 'ext.gadgets.preferences' => $gadResourceTemplate + array( |
237 | 237 | 'scripts' => 'ext.gadgets.preferences.js', |
238 | 238 | ), |
| 239 | + 'ext.gadgets.preferences.style' => $gadResourceTemplate + array( |
| 240 | + 'styles' => 'ext.gadgets.preferences.css', |
| 241 | + ), |
239 | 242 | 'jquery.formBuilder' => $gadResourceTemplate + array( |
240 | 243 | 'scripts' => array( 'jquery.formBuilder.js' ), |
241 | 244 | 'styles' => array( 'jquery.formBuilder.css' ), |
Index: branches/RL2/extensions/Gadgets/Gadgets.hooks.php |
— | — | @@ -290,20 +290,28 @@ |
291 | 291 | 'default' => Xml::tags( 'tr', array(), |
292 | 292 | Xml::tags( 'td', array( 'colspan' => 2 ), |
293 | 293 | wfMsgExt( 'gadgets-sharedprefstext', 'parse' ) ) ), |
294 | | - 'section' => 'gadgets-shared', |
| 294 | + 'section' => 'gadgetsshared', |
295 | 295 | 'raw' => 1, |
296 | 296 | 'rawrow' => 1, |
297 | 297 | ); |
298 | | - $preferences['gadgets-shared'] = |
| 298 | + |
| 299 | + // Build an array with all the shared gadget preferences with dummy descriptions. |
| 300 | + // These descriptions will be completed by JavaScript |
| 301 | + $remoteGadgets = GadgetRepo::getAllRemoteGadgetIDs(); |
| 302 | + $sharedOptions = array(); |
| 303 | + foreach ( $remoteGadgets as $id ) { |
| 304 | + // Use the gadget name as a dummy description |
| 305 | + $sharedOptions[$id] = $id; |
| 306 | + } |
| 307 | + $preferences['gadgetsshared'] = |
299 | 308 | array( |
300 | 309 | 'type' => 'multiselect', |
301 | | - //'options' => array(), // TODO: Maybe fill in stuff anyway? The backend may need that |
302 | | - 'options' => $GLOBALS['wgRequest']->getCheck( 'ryanscrewedchadover' ) ? array_combine( explode( '|', $GLOBALS['wgRequest']->getVal( 'ryanscrewedchadover' ) ), |
303 | | - explode( '|', $GLOBALS['wgRequest']->getVal( 'ryanscrewedchadover2' ) ) ) : array(), |
304 | | - 'section' => 'gadgets-shared', |
| 310 | + 'options' => $sharedOptions, |
| 311 | + 'section' => 'gadgetsshared', |
305 | 312 | 'label' => ' ', |
306 | 313 | 'prefix' => 'gadget-', |
307 | 314 | 'default' => array(), |
| 315 | + 'cssclass' => 'mw-gadgetsshared-item-unloaded', |
308 | 316 | ); |
309 | 317 | return true; |
310 | 318 | } |
— | — | @@ -338,6 +346,7 @@ |
339 | 347 | // Add preferences JS if we're on Special:Preferences |
340 | 348 | if ( $out->getTitle()->isSpecial( 'Preferences' ) ) { |
341 | 349 | $out->addModules( 'ext.gadgets.preferences' ); |
| 350 | + $out->addModuleStyles( 'ext.gadgets.preferences.style' ); |
342 | 351 | } |
343 | 352 | |
344 | 353 | wfProfileOut( __METHOD__ ); |
Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.preferences.css |
— | — | @@ -0,0 +1,3 @@ |
| 2 | +.client-js .mw-gadgetsshared-item-unloaded .mw-input { |
| 3 | + display: none; |
| 4 | +} |
Property changes on: branches/RL2/extensions/Gadgets/modules/ext.gadgets.preferences.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 5 | + native |
Index: branches/RL2/extensions/Gadgets/modules/ext.gadgets.preferences.js |
— | — | @@ -6,64 +6,57 @@ |
7 | 7 | * @license GNU General Public Licence 2.0 or later |
8 | 8 | */ |
9 | 9 | ( function( $ ) { |
10 | | - function buildPref( id, text ) { |
11 | | - var $div = $( '<div class="mw-htmlform-multiselect-item"></div>' ), |
12 | | - // TODO: checked state should represent preference |
13 | | - $input = $( '<input>', { |
14 | | - 'type': 'checkbox', |
15 | | - 'name': 'wpgadgets-shared[]', |
16 | | - 'id': 'mw-input-wpgadgets-shared-' + id, |
17 | | - 'value': id |
18 | | - } ); |
19 | | - if ( mw.user.options.get( 'gadget-' + id ) == "1" ) { |
20 | | - $input.prop( 'checked', true ); |
21 | | - } |
22 | | - $label = $( '<label>', { for: 'mw-input-wpgadgets-shared-' + id } ) |
23 | | - .text( text ); |
24 | | - return $div.append( $input ).append( ' ' ).append( $label ); |
25 | | - } |
26 | | - |
27 | | - function buildForm( gadgetsByCategory, categoryNames ) { |
28 | | - var ryanscrewedchadover = [], ryanscrewedchadover2 = []; |
29 | | - var $container = $( '#mw-prefsection-gadgets-shared .mw-input' ), |
30 | | - // Detach the container from the DOM, so we can fill it without visible build-up. |
31 | | - // This is faster, too. In order to put it back where it was, we need to store its parent. |
32 | | - $containerParent = $container.parent(); |
33 | | - $container.detach(); |
34 | | - |
35 | | - for ( var category in gadgetsByCategory ) { |
| 10 | + /** |
| 11 | + * Fixes the description and the categorization for shared gadgets in the preferences form. |
| 12 | + * This hides the container td for shared gadgets preferences, reorders them by moving them |
| 13 | + * into a new td in the right order, updates their label texts, then replaces the old td with |
| 14 | + * the new one. |
| 15 | + * @param gadgetsByCategory {Object} Map of { categoryID: { gadgetID: gadgetDescription } } |
| 16 | + * @param categoryNames {Object} Map of { categoryID: categoryDescription } |
| 17 | + */ |
| 18 | + function fixPreferenceForm( gadgetsByCategory, categoryNames ) { |
| 19 | + var $oldContainer = $( '#mw-prefsection-gadgetsshared .mw-input' ), |
| 20 | + $newContainer = $( '<td>' ).addClass( 'mw-input' ), |
| 21 | + category, gadget, $oldItem; |
| 22 | + for ( category in gadgetsByCategory ) { |
36 | 23 | if ( category !== '' ) { |
37 | | - $container.append( $( '<h1>' ).text( categoryNames[category] ) ); |
| 24 | + $newContainer.append( $( '<h1>' ).text( categoryNames[category] ) ); |
38 | 25 | } |
39 | | - for ( var gadget in gadgetsByCategory[category] ) { |
40 | | - $container.append( buildPref( gadget, gadgetsByCategory[category][gadget] ) ); |
41 | | - ryanscrewedchadover.push( 'wpgadgets-shared-id-' + gadget ); |
42 | | - ryanscrewedchadover2.push( gadgetsByCategory[category][gadget] ); |
| 26 | + for ( gadget in gadgetsByCategory[category] ) { |
| 27 | + // Find the item belonging to this gadget in $oldContainer |
| 28 | + $oldItem = $oldContainer |
| 29 | + .find( '#mw-input-wpgadgetsshared-' + gadget ) |
| 30 | + .closest( '.mw-htmlform-multiselect-item' ); |
| 31 | + // Update the label text |
| 32 | + $oldItem.find( 'label' ).text( gadgetsByCategory[category][gadget] ); |
| 33 | + // Move the item from $oldContainer to $newContainer |
| 34 | + $newContainer.append( $oldItem ); |
43 | 35 | } |
44 | 36 | } |
45 | | - // Re-attach the container |
46 | | - $containerParent.append( $container ); |
47 | | - $containerParent.closest( 'form' ).append( $( '<input>' ).attr( { 'type': 'hidden', 'name': 'ryanscrewedchadover' } ).val( ryanscrewedchadover.join( '|' ) ) ); |
48 | | - $containerParent.closest( 'form' ).append( $( '<input>' ).attr( { 'type': 'hidden', 'name': 'ryanscrewedchadover2' } ).val( ryanscrewedchadover2.join( '|' ) ) ); |
| 37 | + $oldContainer.replaceWith( $newContainer ); |
| 38 | + // Unhide the container by removing the unloaded class |
| 39 | + // TODO: We need to have a spinner or something for this |
| 40 | + $newContainer.closest( '.mw-gadgetsshared-item-unloaded' ).removeClass( 'mw-gadgetsshared-item-unloaded' ); |
49 | 41 | } |
50 | 42 | |
51 | 43 | // Temporary testing data |
52 | 44 | var categoryNames = { |
53 | 45 | 'foo': 'The Foreign Category of Foo' |
54 | 46 | }; |
| 47 | + // TODO: Actually fetch this info using AJAX |
55 | 48 | // TODO: This structure allows cross-pollination of categories when multiple foreign repos are involved, do we want that? |
56 | 49 | // I guess probably not, because we wouldn't even know where to pull the category message from to begin with. |
57 | 50 | // Probably needs an extra level for the repo. |
58 | 51 | var gadgetsByCategory = { |
59 | 52 | '': { |
60 | 53 | 'b': 'Gadget B', |
61 | | - 'UTCLiveClock': 'UTCLiveClock' |
| 54 | + 'UTCLiveClock': 'A clock that displays UTC time blah blah blah' |
62 | 55 | }, |
63 | 56 | 'foo': { |
64 | 57 | 'a': 'Gadget A' |
65 | 58 | } |
66 | 59 | }; |
67 | 60 | |
68 | | - $( function() { buildForm( gadgetsByCategory, categoryNames ) } ); |
| 61 | + $( function() { fixPreferenceForm( gadgetsByCategory, categoryNames ) } ); |
69 | 62 | |
70 | 63 | } )( jQuery ); |