Revision: 51652 Author: catrope Date: 2009-06-09 17:30:11 +0000 (Tue, 09 Jun 2009)
Log Message: ----------- 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 trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php Modified: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php =================================================================== --- trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php 2009-06-09 17:08:59 UTC (rev 51651) +++ trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php 2009-06-09 17:30:11 UTC (rev 51652) @@ -15,7 +15,7 @@ * Intercept the display of the toolbar, replacing the content of $toolbar */ public static function intercept( &$toolbar ) { - global $wgUser, $wgOut, $wgJsMimeType; + global $wgUser, $wgOut, $wgJsMimeType, $wgRequest; global $wgEditToolbarGlobalEnable, $wgEditToolbarUserEnable; // Checks if... @@ -98,9 +98,17 @@ $messagesList = implode( ',', $messages ); // Encapsulates list in javascript code to set them durring load $messagesJs = "loadGM({{$messagesList}});"; + + // Ensure persistency of tabs' show/hide status between submits + $persistentTabs = array( 'format' ); + $tabsJs = ""; + foreach( $persistentTabs as $tab ) + if( $wgRequest->wasPosted() && $wgRequest->getInt( "ET$tab" ) == 1 ) + $tabsJs .= "editToolbarConfiguration['$tab'].showInitially = '1';"; + // Appends javascript message setting code $toolbar .= Xml::element( - 'script', array( 'type' => $wgJsMimeType ), $messagesJs + 'script', array( 'type' => $wgJsMimeType ), $messagesJs . $tabsJs ); // Continue return true; Modified: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js =================================================================== --- trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js 2009-06-09 17:08:59 UTC (rev 51651) +++ trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js 2009-06-09 17:30:11 UTC (rev 51652) @@ -81,29 +81,40 @@ .attr( { 'class': 'section', 'id': $(this).attr( 'id' ) + '-section-' + section } ) .appendTo( sectionsDiv ); // Appends toolbar to section div - sectionDiv.addToolbarSection( tools[section], textbox ) + sectionDiv.addToolbarSection( tools[section], textbox ); + // Add hidden form field used for show/hide persistency + if( $( '#ET' + section ).length == 0 ) + textbox.parent( 'form' ).append( + $( '<input />' ) + .attr( { 'type': 'hidden', + 'id': 'ET' + section, + 'name': 'ET' + section } ) + .val( tools[section].showInitially ) + ); + var showHideLink = $( '<a />' ) + .text( tools[section].label || gM( tools[section].labelMsg ) ) + .attr( { 'href': '#', 'rel': section } ) + .data( 'sectionDiv', sectionDiv ) + .click( function() { + $(this).blur(); + var show = ( $(this).data( 'sectionDiv' ).css( 'display' ) == 'none' ); + $(this).data( 'sectionDiv' ).parent().children().hide(); + $(this).parent().parent().find( 'a' ).removeClass( 'current' ); + if ( show ) { + $(this).data( 'sectionDiv' ).show(); + $(this).addClass( 'current' ); + } + $( '#ET' + section ).val( ( show ? '1' : '0' ) ); + return false; + }); // Appends section tab tabDiv.append( $( '<div />' ) .attr( 'class', 'tab' ) - .append( - $( '<a />' ) - .text( tools[section].label || gM( tools[section].labelMsg ) ) - .attr( { 'href': '#', 'rel': section } ) - .data( 'sectionDiv', sectionDiv ) - .click( function() { - $(this).blur(); - var show = ( $(this).data( 'sectionDiv' ).css( 'display' ) == 'none' ); - $(this).data( 'sectionDiv' ).parent().children().hide(); - $(this).parent().parent().find( 'a' ).removeClass( 'current' ); - if ( show ) { - $(this).data( 'sectionDiv' ).show(); - $(this).addClass( 'current' ); - } - return false; - }) - ) + .append( showHideLink ) ); + if( $( '#ET' + section ).val() != '0' ) + showHideLink.click(); } }); }, @@ -359,6 +370,7 @@ }, // Format section 'format': { + showInitially: '0', labelMsg: 'edittoolbar-section-format', groups: { 'heading': { Modified: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php =================================================================== --- trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php 2009-06-09 17:08:59 UTC (rev 51651) +++ trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php 2009-06-09 17:30:11 UTC (rev 51652) @@ -30,7 +30,7 @@ ); // Bump the version number every time you change any of the .css/.js files -$wgEditToolbarStyleVersion = 0; +$wgEditToolbarStyleVersion = 1; // Set this to true to simply override the stock toolbar for everyone $wgEditToolbarGlobalEnable = false; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs