r51652 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51651‎ | r51652 | r51653 >
Date:17:30, 9 June 2009
Author:catrope
Status:deferred
Tags:
Comment:
EditToolbar: Making show/hide status of format bar persistent across previews using dynamically added hidden form fields
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php
@@ -15,7 +15,7 @@
1616 * Intercept the display of the toolbar, replacing the content of $toolbar
1717 */
1818 public static function intercept( &$toolbar ) {
19 - global $wgUser, $wgOut, $wgJsMimeType;
 19+ global $wgUser, $wgOut, $wgJsMimeType, $wgRequest;
2020 global $wgEditToolbarGlobalEnable, $wgEditToolbarUserEnable;
2121
2222 // Checks if...
@@ -98,9 +98,17 @@
9999 $messagesList = implode( ',', $messages );
100100 // Encapsulates list in javascript code to set them durring load
101101 $messagesJs = "loadGM({{$messagesList}});";
 102+
 103+ // Ensure persistency of tabs' show/hide status between submits
 104+ $persistentTabs = array( 'format' );
 105+ $tabsJs = "";
 106+ foreach( $persistentTabs as $tab )
 107+ if( $wgRequest->wasPosted() && $wgRequest->getInt( "ET$tab" ) == 1 )
 108+ $tabsJs .= "editToolbarConfiguration['$tab'].showInitially = '1';";
 109+
102110 // Appends javascript message setting code
103111 $toolbar .= Xml::element(
104 - 'script', array( 'type' => $wgJsMimeType ), $messagesJs
 112+ 'script', array( 'type' => $wgJsMimeType ), $messagesJs . $tabsJs
105113 );
106114 // Continue
107115 return true;
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
@@ -81,29 +81,40 @@
8282 .attr( { 'class': 'section', 'id': $(this).attr( 'id' ) + '-section-' + section } )
8383 .appendTo( sectionsDiv );
8484 // Appends toolbar to section div
85 - sectionDiv.addToolbarSection( tools[section], textbox )
 85+ sectionDiv.addToolbarSection( tools[section], textbox );
 86+ // Add hidden form field used for show/hide persistency
 87+ if( $( '#ET' + section ).length == 0 )
 88+ textbox.parent( 'form' ).append(
 89+ $( '<input />' )
 90+ .attr( { 'type': 'hidden',
 91+ 'id': 'ET' + section,
 92+ 'name': 'ET' + section } )
 93+ .val( tools[section].showInitially )
 94+ );
 95+ var showHideLink = $( '<a />' )
 96+ .text( tools[section].label || gM( tools[section].labelMsg ) )
 97+ .attr( { 'href': '#', 'rel': section } )
 98+ .data( 'sectionDiv', sectionDiv )
 99+ .click( function() {
 100+ $(this).blur();
 101+ var show = ( $(this).data( 'sectionDiv' ).css( 'display' ) == 'none' );
 102+ $(this).data( 'sectionDiv' ).parent().children().hide();
 103+ $(this).parent().parent().find( 'a' ).removeClass( 'current' );
 104+ if ( show ) {
 105+ $(this).data( 'sectionDiv' ).show();
 106+ $(this).addClass( 'current' );
 107+ }
 108+ $( '#ET' + section ).val( ( show ? '1' : '0' ) );
 109+ return false;
 110+ });
86111 // Appends section tab
87112 tabDiv.append(
88113 $( '<div />' )
89114 .attr( 'class', 'tab' )
90 - .append(
91 - $( '<a />' )
92 - .text( tools[section].label || gM( tools[section].labelMsg ) )
93 - .attr( { 'href': '#', 'rel': section } )
94 - .data( 'sectionDiv', sectionDiv )
95 - .click( function() {
96 - $(this).blur();
97 - var show = ( $(this).data( 'sectionDiv' ).css( 'display' ) == 'none' );
98 - $(this).data( 'sectionDiv' ).parent().children().hide();
99 - $(this).parent().parent().find( 'a' ).removeClass( 'current' );
100 - if ( show ) {
101 - $(this).data( 'sectionDiv' ).show();
102 - $(this).addClass( 'current' );
103 - }
104 - return false;
105 - })
106 - )
 115+ .append( showHideLink )
107116 );
 117+ if( $( '#ET' + section ).val() != '0' )
 118+ showHideLink.click();
108119 }
109120 });
110121 },
@@ -359,6 +370,7 @@
360371 },
361372 // Format section
362373 'format': {
 374+ showInitially: '0',
363375 labelMsg: 'edittoolbar-section-format',
364376 groups: {
365377 'heading': {
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php
@@ -30,7 +30,7 @@
3131 );
3232
3333 // Bump the version number every time you change any of the .css/.js files
34 -$wgEditToolbarStyleVersion = 0;
 34+$wgEditToolbarStyleVersion = 1;
3535
3636 // Set this to true to simply override the stock toolbar for everyone
3737 $wgEditToolbarGlobalEnable = false;

Status & tagging log