r51714 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51713‎ | r51714 | r51715 >
Date:22:41, 10 June 2009
Author:catrope
Status:deferred
Tags:
Comment:
EditToolbar: Add a Special characters tab. The actual characters need to be added by the wiki in a JS file like Common.js; to import from an old-style charinsert object, use editToolbarConfiguration['specialchars'].pages = $().parseCharinsert( charinsert );
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
@@ -96,6 +96,13 @@
9797 function msg( object, property ) {
9898 return object[property] || gM( object[property + 'Msg'] );
9999 }
 100+ // Creates generic action
 101+ var action = function() {
 102+ $(this).useTool(
 103+ $(this).data( 'context' ).tool,
 104+ $(this).data( 'context' ).textbox
 105+ );
 106+ };
100107 switch ( section.type ) {
101108 case 'toolbar':
102109 // Check for groups
@@ -116,13 +123,6 @@
117124 .text( msg( section.groups[group], 'label' ) )
118125 )
119126 }
120 - // Creates generic action
121 - var action = function() {
122 - $(this).useTool(
123 - $(this).data( 'context' ).tool,
124 - $(this).data( 'context' ).textbox
125 - );
126 - };
127127 // Loops over each tool
128128 for ( tool in section.groups[group].tools ) {
129129 // Filters are jQuery selectors which must select 1 or more
@@ -256,6 +256,31 @@
257257 }
258258 }
259259 break;
 260+ case 'specialchar':
 261+ // Appends special character adders
 262+ var chars = section.pages[page].chars;
 263+ for ( char in chars ) {
 264+ switch( chars[char].type ) {
 265+ case 'break':
 266+ pageDiv.append( $( '<br />' ) );
 267+ break;
 268+ case 'link':
 269+ var context = {
 270+ 'tool' : chars[char],
 271+ 'textbox': textbox
 272+ };
 273+ pageDiv.append( $( '<a />' )
 274+ .attr( chars[char].attrs )
 275+ .attr( { 'href': '#', 'rel': char } )
 276+ .text( chars[char].text )
 277+ .data( 'context', context)
 278+ .click( action )
 279+ .click( function() { return false; } )
 280+ );
 281+ pageDiv.append( '&nbsp;' );
 282+ }
 283+ }
 284+ break;
260285 default: break;
261286 }
262287 }
@@ -287,6 +312,7 @@
288313 }
289314 switch ( tool.type ) {
290315 case 'button':
 316+ case 'link':
291317 performAction( tool.action, textbox );
292318 break;
293319 case 'select':
@@ -298,6 +324,55 @@
299325 break;
300326 default: break;
301327 }
 328+ },
 329+
 330+ /**
 331+ * Converts a charinsert array like the one used on dewiki to
 332+ * the format expected in editToolbarConfiguration
 333+ */
 334+ parseCharinsert: function( charinsert ) {
 335+ var retval = {};
 336+ for( page in charinsert ) {
 337+ var chars = [], attrs = {};
 338+ var i = 0;
 339+ for( line in charinsert[page] ) {
 340+ if( !( charinsert[page][line] instanceof Array ) ) {
 341+ attrs = charinsert[page][line];
 342+ continue;
 343+ }
 344+ for( chr in charinsert[page][line] ) {
 345+ var tool = {
 346+ type: 'link',
 347+ attrs: attrs,
 348+ text: '',
 349+ action: {
 350+ type: 'encapsulate',
 351+ options: {
 352+ pre: '',
 353+ post: ''
 354+ }
 355+ }
 356+ };
 357+ if( charinsert[page][line][chr] instanceof Array ) {
 358+ tool.action.options.pre = charinsert[page][line][chr][0];
 359+ tool.action.options.post = charinsert[page][line][chr][1];
 360+ //tool.text = charinsert[page][line][chr][0] + charinsert[page][line][chr][1];
 361+ } else {
 362+ tool.action.options.pre = charinsert[page][line][chr];
 363+ //tool.text = charinsert[page][line][chr];
 364+ }
 365+ tool.text = tool.action.options.pre + tool.action.options.post;
 366+ chars[i++] = tool;
 367+ }
 368+ chars[i++] = { type: 'break' };
 369+ }
 370+ retval[page] = {
 371+ label: page,
 372+ layout: 'specialchar',
 373+ chars: chars
 374+ };
 375+ }
 376+ return retval;
302377 }
303378 });
304379 })(jQuery);
@@ -805,5 +880,11 @@
806881 ]
807882 }
808883 }
 884+ },
 885+ 'specialchars': {
 886+ label: 'Special characters',
 887+ labelMsg: 'edittoolbar-section-specialchars',
 888+ type: 'booklet',
 889+ pages: {} // Set by the document.ready handler
809890 }
810891 };
\ No newline at end of file
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 = 1;
 22+$wgEditToolbarStyleVersion = 2;
2323
2424 // Set this to true to simply override the stock toolbar for everyone
2525 $wgEditToolbarGlobalEnable = false;

Status & tagging log