r52078 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52077‎ | r52078 | r52079 >
Date:21:53, 17 June 2009
Author:catrope
Status:deferred
Tags:
Comment:
EditToolbar: Preserve booklet state using cookies
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
@@ -18,7 +18,7 @@
1919 // Checks if main section is in the structure
2020 if ( 'main' in tools ) {
2121 // Adds main section to toolbar
22 - $(this).addToolbarSection( tools.main, textbox );
 22+ $(this).addToolbarSection( tools.main, textbox, 'main' );
2323 }
2424 // Appends additional section tabs
2525 var tabDiv = $( '<div />' )
@@ -97,7 +97,7 @@
9898 $.eachAsync( sectionQueue, {
9999 bulk: 0,
100100 loop: function( index, value ) {
101 - value.sectionDiv.addToolbarSection( value.tools, value.textbox );
 101+ value.sectionDiv.addToolbarSection( value.tools, value.textbox, index );
102102 value.sectionDiv.removeClass( 'loading' )
103103 }
104104 } )
@@ -107,8 +107,9 @@
108108 * Adds a toolbar section to a containing div
109109 * @param {Object} section Section data to build toolbar from
110110 * @param {Object} textbox
 111+ * @param {String} section ID (used for cookies)
111112 */
112 - addToolbarSection: function( section, textbox ) {
 113+ addToolbarSection: function( section, textbox, id ) {
113114 // Path to images (THIS WILL HAVE TO CHANGE IF YOU MOVE THIS INTO CORE)
114115 var imagePath = wgScriptPath +
115116 '/extensions/UsabilityInitiative/EditToolbar/images/';
@@ -212,25 +213,29 @@
213214 var indexDiv = $( '<div />' )
214215 .attr( 'class', 'index' )
215216 .appendTo( $(this) );
216 - // THIS SHOULD BE REPLACED WITH SOMETHING THAT USES A COOKIE
217 - // TO DETECT THE STATE OF THE LAST VIEW
218 - var first = true;
 217+
 218+ var bookletCookie = 'edittoolbar-' + $(this).attr( 'id' ) + '-booklet-' + id;
 219+ var selectedID = $.cookie( bookletCookie );
 220+
219221 // Loops over each page
220222 for ( page in section.pages ) {
221223 // Appends index entry
222224 indexDiv.append(
223225 $( '<div />' )
224 - .attr( 'class', first ? 'current' : null )
 226+ .attr( 'class', page == selectedID ? 'current' : null )
225227 .text( msg( section.pages[page], 'label' ) )
226228 .data( 'page', page )
 229+ .data( 'cookie', bookletCookie )
227230 .click( function() {
228231 $(this).parent().parent().find( 'div.pages > div.page' ).hide();
229232 $(this).parent().find( 'div' ).removeClass( 'current' );
230233 $(this).parent().parent().find( 'div.pages > div.page-' + $(this).data( 'page' ) ).show();
231234 $(this).addClass( 'current' );
 235+
 236+ // Update cookie
 237+ $.cookie( $(this).data( 'cookie'), $(this).data( 'page' ) );
232238 } )
233239 );
234 - first = false;
235240 }
236241 var pagesDiv = $( '<div />' )
237242 .attr( 'class', 'pages' )
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php
@@ -18,7 +18,7 @@
1919 /* Configuration */
2020
2121 // Bump the version number every time you change any of the .css/.js files
22 -$wgEditToolbarStyleVersion = 6;
 22+$wgEditToolbarStyleVersion = 7;
2323
2424 // Set this to true to simply override the stock toolbar for everyone
2525 $wgEditToolbarGlobalEnable = false;
Index: trunk/extensions/UsabilityInitiative/OptIn/SpecialOptIn.php
@@ -25,7 +25,6 @@
2626 }
2727
2828 if ( $wgRequest->wasPosted() ) {
29 - // Is the weak comparison intentional?
3029 if ( $wgRequest->getVal( 'opt' ) == 'in' ) {
3130 $this->optIn( $wgUser );
3231 $wgOut->addWikiMsg( 'optin-success-in' );

Status & tagging log