r51657 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51656‎ | r51657 | r51658 >
Date:18:27, 9 June 2009
Author:tparscal
Status:deferred
Tags:
Comment:
Changed approach to maintaining state to use cookies instead of form data.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.i18n.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/Resources/jquery.cookie.js (added) (history)
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -19,6 +19,7 @@
2020 $scripts = array(
2121 '/extensions/UsabilityInitiative/Resources/jquery.js',
2222 '/extensions/UsabilityInitiative/Resources/jquery.textSelection.js',
 23+ '/extensions/UsabilityInitiative/Resources/jquery.cookie.js',
2324 );
2425 foreach ( $scripts as $script ) {
2526 // Add javascript resources to document
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.hooks.php
@@ -102,14 +102,6 @@
103103 $messagesList = implode( ',', $messages );
104104 // Encapsulates list in javascript code to set them durring load
105105 $messagesJs = "loadGM({{$messagesList}});";
106 -
107 - // Ensure persistency of tabs' show/hide status between submits
108 - $persistentTabs = array( 'format' );
109 - $tabsJs = "";
110 - foreach( $persistentTabs as $tab )
111 - if( $wgRequest->wasPosted() && $wgRequest->getInt( "ET$tab" ) == 1 )
112 - $tabsJs .= "editToolbarConfiguration['$tab'].showInitially = '1';";
113 -
114106 // Appends javascript message setting code
115107 $toolbar .= Xml::element(
116108 'script', array( 'type' => $wgJsMimeType ), $messagesJs . $tabsJs
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
@@ -70,6 +70,8 @@
7171 .appendTo( $(this) );
7272 // Appends float-clearing div
7373 $(this).append( $( '<div style="clear:both"></div>' ) );
 74+ // Cookie name for storing section state
 75+ var sectionCookie = 'edittoolbar-' + $(this).attr( 'id' ) + '-section';
7476 // Loops over each section
7577 for ( section in tools ) {
7678 // Skips over main (was handled as special case already)
@@ -80,41 +82,42 @@
8183 var sectionDiv = $( '<div />')
8284 .attr( { 'class': 'section', 'id': $(this).attr( 'id' ) + '-section-' + section } )
8385 .appendTo( sectionsDiv );
 86+ // Respects state
 87+ var current = false;
 88+ if ( $.cookie( sectionCookie ) == sectionDiv.attr( 'id' ) ) {
 89+ sectionDiv.attr( 'style', 'display:block' );
 90+ current = true;
 91+ }
8492 // Appends toolbar to section div
8593 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 - });
11194 // Appends section tab
11295 tabDiv.append(
11396 $( '<div />' )
11497 .attr( 'class', 'tab' )
115 - .append( showHideLink )
 98+ .append(
 99+ $( '<a />' )
 100+ .text( tools[section].label || gM( tools[section].labelMsg ) )
 101+ .attr( { 'href': '#', 'rel': section, 'class': current ? 'current' : null } )
 102+ .data( 'sectionDiv', sectionDiv )
 103+ .data( 'sectionCookie', sectionCookie )
 104+ .click( function() {
 105+ $(this).blur();
 106+ var show = ( $(this).data( 'sectionDiv' ).css( 'display' ) == 'none' );
 107+ $(this).data( 'sectionDiv' ).parent().children().hide();
 108+ $(this).parent().parent().find( 'a' ).removeClass( 'current' );
 109+ if ( show ) {
 110+ $(this).data( 'sectionDiv' ).show();
 111+ $(this).addClass( 'current' );
 112+ }
 113+ // Sets or deletes cookie when sections are shown or hidden
 114+ $.cookie(
 115+ $(this).data( 'sectionCookie' ),
 116+ show ? $(this).data( 'sectionDiv' ).attr( 'id' ) : null
 117+ );
 118+ return false;
 119+ })
 120+ )
116121 );
117 - if( $( '#ET' + section ).val() != '0' )
118 - showHideLink.click();
119122 }
120123 });
121124 },
@@ -370,7 +373,6 @@
371374 },
372375 // Format section
373376 'format': {
374 - showInitially: '0',
375377 labelMsg: 'edittoolbar-section-format',
376378 groups: {
377379 'heading': {
@@ -535,7 +537,6 @@
536538 },
537539 // Insert section
538540 'insert': {
539 - showInitially: '0',
540541 labelMsg: 'edittoolbar-section-insert',
541542 groups: {
542543 'media': {
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.i18n.php
@@ -58,7 +58,7 @@
5959 'edittoolbar-section-insert' => 'Insert',
6060 'edittoolbar-group-insert-media' => 'Media',
6161 'edittoolbar-tool-insert-gallery' => 'Picture gallery',
62 - 'edittoolbar-tool-insert-gallery-example' => "Image:Example.jpg|Caption1\nImage:Example.jpg|Caption2",
 62+ 'edittoolbar-tool-insert-gallery-example' => "File:Example.jpg|Caption1\File:Example.jpg|Caption2",
6363 'edittoolbar-tool-insert-newline' => 'New line',
6464 /* Special Characters Section */
6565 'edittoolbar-section-characters' => 'Special Characters',
Index: trunk/extensions/UsabilityInitiative/Resources/jquery.cookie.js
@@ -0,0 +1,10 @@
 2+/**
 3+ * Cookie plugin
 4+ *
 5+ * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 6+ * Dual licensed under the MIT and GPL licenses:
 7+ * http://www.opensource.org/licenses/mit-license.php
 8+ * http://www.gnu.org/licenses/gpl.html
 9+ *
 10+ */
 11+eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('q.5=x(k,d,a){4(m d!=\'H\'){a=a||{};4(d===p){d=\'\';a=$.A({},a);a.3=-1}2 g=\'\';4(a.3&&(m a.3==\'u\'||a.3.s)){2 f;4(m a.3==\'u\'){f=F C();f.B(f.z()+(a.3*y*o*o*v))}n{f=a.3}g=\'; 3=\'+f.s()}2 b=a.7?\'; 7=\'+(a.7):\'\';2 e=a.9?\'; 9=\'+(a.9):\'\';2 l=a.t?\'; t\':\'\';6.5=[k,\'=\',L(d),g,b,e,l].K(\'\')}n{2 h=p;4(6.5&&6.5!=\'\'){2 c=6.5.E(\';\');D(2 i=0;i<c.8;i++){2 j=q.G(c[i]);4(j.r(0,k.8+1)==(k+\'=\')){h=I(j.r(k.8+1));J}}}w h}};',48,48,'||var|expires|if|cookie|document|path|length|domain|||||||||||||typeof|else|60|null|jQuery|substring|toUTCString|secure|number|1000|return|function|24|getTime|extend|setTime|Date|for|split|new|trim|undefined|decodeURIComponent|break|join|encodeURIComponent'.split('|'),0,{}))
\ No newline at end of file

Status & tagging log