r61951 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61950‎ | r61951 | r61952 >
Date:20:01, 3 February 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Added redo, made use of ctrlKey, metaKey and shiftKey rather than doing detection of my own.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -72,7 +72,7 @@
7373 array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
7474 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ),
7575 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 27 ),
76 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 97 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 98 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 29 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 47 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 12 ),
@@ -82,10 +82,10 @@
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 214 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 215 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 214 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 215 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -210,9 +210,8 @@
211211 'savedSelection': null,
212212 // Stack of states in { html: [string] } form
213213 'history': [],
 214+ // Current history state position - this is number of steps backwards, so it's always -1 or less
214215 'historyPosition': -1,
215 - // Key states
216 - 'keys': { 'control': false }
217216 };
218217
219218 /*
@@ -275,19 +274,29 @@
276275 */
277276 'keydown': function( event ) {
278277 switch ( event.which ) {
279 - case 17: // ctrl
280 - case 224: // command
281 - context.keys.control = true;
282 - break;
283278 case 90: // z
284 - if ( context.keys.control && context.history.length ) {
285 - context.historyPosition = Math.min( context.historyPosition - 1, -1 );
286 - if ( context.history.length + context.historyPosition >= 0 ) {
 279+ if ( ( event.ctrlKey || event.metaKey ) && context.history.length ) {
 280+ // HistoryPosition is a negetive number between -1 and -context.history.length, in other words
 281+ // it's the number of steps backwards from the latest state.
 282+ if ( event.shiftKey ) {
 283+ // Redo
 284+ context.historyPosition++;
 285+ } else {
287286 // Undo
 287+ context.historyPosition--;
 288+ }
 289+ // Only act if we are switching to a valid state
 290+ if ( context.history.length + context.historyPosition >= 0 && context.historyPosition < 0 ) {
 291+ // Change state
288292 context.$content.html(
289293 context.history[context.history.length + context.historyPosition].html
290294 );
 295+ } else {
 296+ // Normalize the historyPosition
 297+ context.historyPosition =
 298+ Math.max( -context.history.length, Math.min( context.historyPosition, -1 ) );
291299 }
 300+ // Prevent the browser from getting in there and doing it's stuff
292301 return false;
293302 }
294303 break;
@@ -303,13 +312,12 @@
304313 event.data.scope = 'realchange';
305314 context.historyPosition = -1;
306315 }
 316+ // Are we deleting a <p> with one keystroke? if so, either remove preceding <br> or merge <p>s
307317 switch ( event.which ) {
308 - case 17: // ctrl
309 - case 224: // command
310 - context.keys.control = false;
 318+ case 8: // backspace
 319+ // do something here...
311320 break;
312321 }
313 - // FIXME: Are we deleting a <p> with one keystroke? if so, either remove preceding <br> or merge <p>s
314322 return true;
315323 },
316324 'delayedChange': function( event ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6643,9 +6643,8 @@
66446644 'savedSelection': null,
66456645 // Stack of states in { html: [string] } form
66466646 'history': [],
 6647+ // Current history state position - this is number of steps backwards, so it's always -1 or less
66476648 'historyPosition': -1,
6648 - // Key states
6649 - 'keys': { 'control': false }
66506649 };
66516650
66526651 /*
@@ -6708,19 +6707,29 @@
67096708 */
67106709 'keydown': function( event ) {
67116710 switch ( event.which ) {
6712 - case 17: // ctrl
6713 - case 224: // command
6714 - context.keys.control = true;
6715 - break;
67166711 case 90: // z
6717 - if ( context.keys.control && context.history.length ) {
6718 - context.historyPosition = Math.min( context.historyPosition - 1, -1 );
6719 - if ( context.history.length + context.historyPosition >= 0 ) {
 6712+ if ( ( event.ctrlKey || event.metaKey ) && context.history.length ) {
 6713+ // HistoryPosition is a negetive number between -1 and -context.history.length, in other words
 6714+ // it's the number of steps backwards from the latest state.
 6715+ if ( event.shiftKey ) {
 6716+ // Redo
 6717+ context.historyPosition++;
 6718+ } else {
67206719 // Undo
 6720+ context.historyPosition--;
 6721+ }
 6722+ // Only act if we are switching to a valid state
 6723+ if ( context.history.length + context.historyPosition >= 0 && context.historyPosition < 0 ) {
 6724+ // Change state
67216725 context.$content.html(
67226726 context.history[context.history.length + context.historyPosition].html
67236727 );
 6728+ } else {
 6729+ // Normalize the historyPosition
 6730+ context.historyPosition =
 6731+ Math.max( -context.history.length, Math.min( context.historyPosition, -1 ) );
67246732 }
 6733+ // Prevent the browser from getting in there and doing it's stuff
67256734 return false;
67266735 }
67276736 break;
@@ -6736,13 +6745,12 @@
67376746 event.data.scope = 'realchange';
67386747 context.historyPosition = -1;
67396748 }
 6749+ // Are we deleting a <p> with one keystroke? if so, either remove preceding <br> or merge <p>s
67406750 switch ( event.which ) {
6741 - case 17: // ctrl
6742 - case 224: // command
6743 - context.keys.control = false;
 6751+ case 8: // backspace
 6752+ // do something here...
67446753 break;
67456754 }
6746 - // FIXME: Are we deleting a <p> with one keystroke? if so, either remove preceding <br> or merge <p>s
67476755 return true;
67486756 },
67496757 'delayedChange': function( event ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -442,13 +442,14 @@
443443 return $.wikiEditor.supported=true;},'autoMsg':function(object,property){if(typeof property=='object'){for(var i in property){if(property[i]in object||property[i]+'Msg'in object){property=property[i];break;}}}
444444 if(property in object){return object[property];}else if(property+'Msg'in object){if(typeof object[property+'Msg']=='object'){return mw.usability.getMsg.apply(mw.usability,object[property+'Msg']);}else{return mw.usability.getMsg(object[property+'Msg']);}}else{return'';}},'autoLang':function(object,lang){return object[lang||wgUserLanguage]||object['default']||object;},'autoIcon':function(icon,path,lang){var src=$.wikiEditor.autoLang(icon,lang);path=path||$.wikiEditor.imgPath;if(src.substr(0,7)!='http://'&&src.substr(0,8)!='https://'&&src[0]!='/'){src=path+src;}
445445 return src+'?'+wgWikiEditorIconVersion;}};$.fn.wikiEditor=function(){if(!$j.wikiEditor.isSupported()){return $(this);}
446 -var context=$(this).data('wikiEditor-context');if(typeof context=='undefined'){context={'$textarea':$(this),'views':{},'modules':{},'data':{},'instance':$.wikiEditor.instances.push($(this))-1,'offsets':null,'htmlToTextMap':{},'oldHTML':null,'oldDelayedHTML':null,'savedSelection':null,'history':[],'historyPosition':-1,'keys':{'control':false}};context.api={'addModule':function(context,data){var modules={};if(typeof data=='string'){modules[data]={};}else if(typeof data=='object'){modules=data;}
 446+var context=$(this).data('wikiEditor-context');if(typeof context=='undefined'){context={'$textarea':$(this),'views':{},'modules':{},'data':{},'instance':$.wikiEditor.instances.push($(this))-1,'offsets':null,'htmlToTextMap':{},'oldHTML':null,'oldDelayedHTML':null,'savedSelection':null,'history':[],'historyPosition':-1,};context.api={'addModule':function(context,data){var modules={};if(typeof data=='string'){modules[data]={};}else if(typeof data=='object'){modules=data;}
447447 for(var module in modules){if(typeof module=='string'&&module in $.wikiEditor.modules){if('api'in $.wikiEditor.modules[module]){for(var call in $.wikiEditor.modules[module].api){if(!(call in context.api)){context.api[call]=$.wikiEditor.modules[module].api[call];}}}
448 -if('fn'in $.wikiEditor.modules[module]&&'create'in $.wikiEditor.modules[module].fn){context.modules[module]={};$.wikiEditor.modules[module].fn.create(context,modules[module]);}}}}};context.evt={'keydown':function(event){switch(event.which){case 17:case 224:context.keys.control=true;break;case 90:if(context.keys.control&&context.history.length){context.historyPosition=Math.min(context.historyPosition-1,-1);if(context.history.length+context.historyPosition>=0){context.$content.html(context.history[context.history.length+context.historyPosition].html);}
 448+if('fn'in $.wikiEditor.modules[module]&&'create'in $.wikiEditor.modules[module].fn){context.modules[module]={};$.wikiEditor.modules[module].fn.create(context,modules[module]);}}}}};context.evt={'keydown':function(event){switch(event.which){case 90:if((event.ctrlKey||event.metaKey)&&context.history.length){if(event.shiftKey){context.historyPosition++;}else{context.historyPosition--;}
 449+if(context.history.length+context.historyPosition>=0&&context.historyPosition<0){context.$content.html(context.history[context.history.length+context.historyPosition].html);}else{context.historyPosition=Math.max(-context.history.length,Math.min(context.historyPosition,-1));}
449450 return false;}
450451 break;}
451452 return true;},'change':function(event){event.data.scope='division';var newHTML=context.$content.html();if(context.oldHTML!=newHTML){context.fn.purgeOffsets();context.oldHTML=newHTML;event.data.scope='realchange';context.historyPosition=-1;}
452 -switch(event.which){case 17:case 224:context.keys.control=false;break;}
 453+switch(event.which){case 8:break;}
453454 return true;},'delayedChange':function(event){event.data.scope='division';var newHTML=context.$content.html();if(context.oldDelayedHTML!=newHTML){context.fn.purgeOffsets();context.oldDelayedHTML=newHTML;event.data.scope='realchange';context.history.push({'html':newHTML});while(context.history.length>10){context.history.shift();}}
454455 return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};}
455456 if(typeof event.data=='undefined'){event.data={};}

Follow-up revisions

RevisionCommit summaryAuthorDate
r61952UsabilityInitiative: Fix r61951: rm trailing comma, add FIXME, polish IT Crow...catrope20:11, 3 February 2010

Comments

#Comment by Catrope (talk | contribs)   20:05, 3 February 2010

fdfdsf

Status & tagging log