Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ), |
74 | 74 | array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ), |
75 | 75 | 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 ), |
77 | 77 | array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 29 ), |
78 | 78 | array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 47 ), |
79 | 79 | array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 12 ), |
— | — | @@ -82,10 +82,10 @@ |
83 | 83 | array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ), |
84 | 84 | ), |
85 | 85 | 'combined' => array( |
86 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 214 ), |
| 86 | + array( 'src' => 'js/plugins.combined.js', 'version' => 215 ), |
87 | 87 | ), |
88 | 88 | 'minified' => array( |
89 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 214 ), |
| 89 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 215 ), |
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -210,9 +210,8 @@ |
211 | 211 | 'savedSelection': null, |
212 | 212 | // Stack of states in { html: [string] } form |
213 | 213 | 'history': [], |
| 214 | + // Current history state position - this is number of steps backwards, so it's always -1 or less |
214 | 215 | 'historyPosition': -1, |
215 | | - // Key states |
216 | | - 'keys': { 'control': false } |
217 | 216 | }; |
218 | 217 | |
219 | 218 | /* |
— | — | @@ -275,19 +274,29 @@ |
276 | 275 | */ |
277 | 276 | 'keydown': function( event ) { |
278 | 277 | switch ( event.which ) { |
279 | | - case 17: // ctrl |
280 | | - case 224: // command |
281 | | - context.keys.control = true; |
282 | | - break; |
283 | 278 | 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 { |
287 | 286 | // 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 |
288 | 292 | context.$content.html( |
289 | 293 | context.history[context.history.length + context.historyPosition].html |
290 | 294 | ); |
| 295 | + } else { |
| 296 | + // Normalize the historyPosition |
| 297 | + context.historyPosition = |
| 298 | + Math.max( -context.history.length, Math.min( context.historyPosition, -1 ) ); |
291 | 299 | } |
| 300 | + // Prevent the browser from getting in there and doing it's stuff |
292 | 301 | return false; |
293 | 302 | } |
294 | 303 | break; |
— | — | @@ -303,13 +312,12 @@ |
304 | 313 | event.data.scope = 'realchange'; |
305 | 314 | context.historyPosition = -1; |
306 | 315 | } |
| 316 | + // Are we deleting a <p> with one keystroke? if so, either remove preceding <br> or merge <p>s |
307 | 317 | switch ( event.which ) { |
308 | | - case 17: // ctrl |
309 | | - case 224: // command |
310 | | - context.keys.control = false; |
| 318 | + case 8: // backspace |
| 319 | + // do something here... |
311 | 320 | break; |
312 | 321 | } |
313 | | - // FIXME: Are we deleting a <p> with one keystroke? if so, either remove preceding <br> or merge <p>s |
314 | 322 | return true; |
315 | 323 | }, |
316 | 324 | 'delayedChange': function( event ) { |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -6643,9 +6643,8 @@ |
6644 | 6644 | 'savedSelection': null, |
6645 | 6645 | // Stack of states in { html: [string] } form |
6646 | 6646 | 'history': [], |
| 6647 | + // Current history state position - this is number of steps backwards, so it's always -1 or less |
6647 | 6648 | 'historyPosition': -1, |
6648 | | - // Key states |
6649 | | - 'keys': { 'control': false } |
6650 | 6649 | }; |
6651 | 6650 | |
6652 | 6651 | /* |
— | — | @@ -6708,19 +6707,29 @@ |
6709 | 6708 | */ |
6710 | 6709 | 'keydown': function( event ) { |
6711 | 6710 | switch ( event.which ) { |
6712 | | - case 17: // ctrl |
6713 | | - case 224: // command |
6714 | | - context.keys.control = true; |
6715 | | - break; |
6716 | 6711 | 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 { |
6720 | 6719 | // 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 |
6721 | 6725 | context.$content.html( |
6722 | 6726 | context.history[context.history.length + context.historyPosition].html |
6723 | 6727 | ); |
| 6728 | + } else { |
| 6729 | + // Normalize the historyPosition |
| 6730 | + context.historyPosition = |
| 6731 | + Math.max( -context.history.length, Math.min( context.historyPosition, -1 ) ); |
6724 | 6732 | } |
| 6733 | + // Prevent the browser from getting in there and doing it's stuff |
6725 | 6734 | return false; |
6726 | 6735 | } |
6727 | 6736 | break; |
— | — | @@ -6736,13 +6745,12 @@ |
6737 | 6746 | event.data.scope = 'realchange'; |
6738 | 6747 | context.historyPosition = -1; |
6739 | 6748 | } |
| 6749 | + // Are we deleting a <p> with one keystroke? if so, either remove preceding <br> or merge <p>s |
6740 | 6750 | switch ( event.which ) { |
6741 | | - case 17: // ctrl |
6742 | | - case 224: // command |
6743 | | - context.keys.control = false; |
| 6751 | + case 8: // backspace |
| 6752 | + // do something here... |
6744 | 6753 | break; |
6745 | 6754 | } |
6746 | | - // FIXME: Are we deleting a <p> with one keystroke? if so, either remove preceding <br> or merge <p>s |
6747 | 6755 | return true; |
6748 | 6756 | }, |
6749 | 6757 | 'delayedChange': function( event ) { |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -442,13 +442,14 @@ |
443 | 443 | 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;}}} |
444 | 444 | 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;} |
445 | 445 | 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;} |
447 | 447 | 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));} |
449 | 450 | return false;} |
450 | 451 | break;} |
451 | 452 | 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;} |
453 | 454 | 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();}} |
454 | 455 | return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};} |
455 | 456 | if(typeof event.data=='undefined'){event.data={};} |