r57048 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57047‎ | r57048 | r57049 >
Date:10:26, 29 September 2009
Author:catrope
Status:ok
Tags:
Comment:
NavigableTOC: (bug 20871) Cursor doesn't go to the right line when clicking a section in the NTOC in Opera. Fixed by also applying fixOperaBrokenness() before NTOC processing; moved fixOperaBrokenness() to a more central place
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php (modified) (history)
  • /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)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -64,19 +64,19 @@
6565 array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
6666 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 4 ),
6767 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 12 ),
68 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 6 ),
 68+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 7 ),
6969 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 11 ),
7070 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 3 ),
71 - array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 10 ),
 71+ array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 11 ),
7272 // FIXME: jQuery UI doesn't belong here, should move to no_js2
7373 // once we figure out how to do jQuery UI properly in JS2
7474 array( 'src' => 'js/js2/jquery-ui-1.7.2.js', 'version' => '1.7.2y' ),
7575 ),
7676 'combined' => array(
77 - array( 'src' => 'js/plugins.combined.js', 'version' => 29 ),
 77+ array( 'src' => 'js/plugins.combined.js', 'version' => 30 ),
7878 ),
7979 'minified' => array(
80 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 29 ),
 80+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 30 ),
8181 ),
8282 ),
8383 );
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
@@ -1217,40 +1217,6 @@
12181218 dialog: {
12191219 buttons: {
12201220 'edittoolbar-tool-replace-button': function() {
1221 - function fixOperaBrokenness( s ) {
1222 - // This function works around Opera's
1223 - // broken newline handling in textareas.
1224 - // .val() has \n while selection functions
1225 - // treat newlines as \r\n
1226 -
1227 - if ( typeof $j.isOperaBroken == 'undefined' ) {
1228 - // Create a textarea inside a div
1229 - // with zero area, to hide it properly
1230 - var div = $j( '<div />' )
1231 - .height( 0 )
1232 - .width( 0 )
1233 - .insertBefore( $textarea );
1234 - var textarea = $j( '<textarea></textarea' )
1235 - .height( 0 )
1236 - .appendTo( div )
1237 - .val( "foo\r\nbar" );
1238 -
1239 - // Try to search&replace bar --> BAR
1240 - var index = textarea.val().indexOf( 'bar' );
1241 - textarea.select();
1242 - textarea.setSelection( index, index + 3 );
1243 - textarea.encapsulateSelection( '', 'BAR', '', false, true );
1244 - if ( textarea.val().substr( -1 ) == 'R' )
1245 - $j.isOperaBroken = false;
1246 - else
1247 - $j.isOperaBroken = true;
1248 - div.remove();
1249 - }
1250 - if ( $j.isOperaBroken )
1251 - s = s.replace( /\n/g, "\r\n" );
1252 - return s;
1253 - }
1254 -
12551221 $j( '#edittoolbar-replace-nomatch, #edittoolbar-replace-success' ).hide();
12561222 var searchStr = $j( '#edittoolbar-replace-search' ).val();
12571223 var replaceStr = $j( '#edittoolbar-replace-replace' ).val();
@@ -1267,7 +1233,7 @@
12681234 }
12691235 var regex = new RegExp( searchStr, flags );
12701236 var $textarea = $j(this).data( 'context' ).$textarea;
1271 - var text = fixOperaBrokenness( $textarea.val() );
 1237+ var text = $j.wikiEditor.fixOperaBrokenness( $textarea.val() );
12721238 var matches = text.match( regex );
12731239 if ( !matches ) {
12741240 $j( '#edittoolbar-replace-nomatch' ).show();
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php
@@ -19,7 +19,7 @@
2020 /* Configuration */
2121
2222 // Bump the version number every time you change any of the .css/.js files
23 -$wgEditToolbarStyleVersion = 43;
 23+$wgEditToolbarStyleVersion = 44;
2424
2525 // Set this to true to simply override the stock toolbar for everyone
2626 $wgEditToolbarGlobalEnable = false;
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -57,6 +57,40 @@
5858 }
5959 };
6060
 61+$.wikiEditor.fixOperaBrokenness = function( s ) {
 62+ // This function works around Opera's
 63+ // broken newline handling in textareas.
 64+ // .val() has \n while selection functions
 65+ // treat newlines as \r\n
 66+
 67+ if ( typeof $.isOperaBroken == 'undefined' && $.wikiEditor.instances.length > 0 ) {
 68+ // Create a textarea inside a div
 69+ // with zero area, to hide it properly
 70+ var div = $( '<div />' )
 71+ .height( 0 )
 72+ .width( 0 )
 73+ .insertBefore( $.wikiEditor.instances[0] );
 74+ var textarea = $( '<textarea></textarea' )
 75+ .height( 0 )
 76+ .appendTo( div )
 77+ .val( "foo\r\nbar" );
 78+
 79+ // Try to search&replace bar --> BAR
 80+ var index = textarea.val().indexOf( 'bar' );
 81+ textarea.select();
 82+ textarea.setSelection( index, index + 3 );
 83+ textarea.encapsulateSelection( '', 'BAR', '', false, true );
 84+ if ( textarea.val().substr( -1 ) == 'R' )
 85+ $.isOperaBroken = false;
 86+ else
 87+ $.isOperaBroken = true;
 88+ div.remove();
 89+ }
 90+ if ( $.isOperaBroken )
 91+ s = s.replace( /\n/g, "\r\n" );
 92+ return s;
 93+};
 94+
6195 $.fn.wikiEditor = function() {
6296
6397 /* Initialization */
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js
@@ -173,8 +173,8 @@
174174 }
175175 // Build outline from wikitext
176176 var outline = [];
177 - var wikitext = '\n' + context.$textarea.val() + '\n';
178 - var headings = wikitext.match( /\n={1,5}.*={1,5}(?=\n)/g );
 177+ var wikitext = '\n' + $.wikiEditor.fixOperaBrokenness( context.$textarea.val() ) + '\n';
 178+ var headings = wikitext.match( /(\r|\n)={1,5}.*={1,5}(?=(\r|\n))/g );
179179 var offset = 0;
180180 headings = $.makeArray( headings );
181181 for ( var h = 0; h < headings.length; h++ ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -1168,6 +1168,40 @@
11691169 }
11701170 };
11711171
 1172+$.wikiEditor.fixOperaBrokenness = function( s ) {
 1173+ // This function works around Opera's
 1174+ // broken newline handling in textareas.
 1175+ // .val() has \n while selection functions
 1176+ // treat newlines as \r\n
 1177+
 1178+ if ( typeof $.isOperaBroken == 'undefined' && $.wikiEditor.instances.length > 0 ) {
 1179+ // Create a textarea inside a div
 1180+ // with zero area, to hide it properly
 1181+ var div = $( '<div />' )
 1182+ .height( 0 )
 1183+ .width( 0 )
 1184+ .insertBefore( $.wikiEditor.instances[0] );
 1185+ var textarea = $( '<textarea></textarea' )
 1186+ .height( 0 )
 1187+ .appendTo( div )
 1188+ .val( "foo\r\nbar" );
 1189+
 1190+ // Try to search&replace bar --> BAR
 1191+ var index = textarea.val().indexOf( 'bar' );
 1192+ textarea.select();
 1193+ textarea.setSelection( index, index + 3 );
 1194+ textarea.encapsulateSelection( '', 'BAR', '', false, true );
 1195+ if ( textarea.val().substr( -1 ) == 'R' )
 1196+ $.isOperaBroken = false;
 1197+ else
 1198+ $.isOperaBroken = true;
 1199+ div.remove();
 1200+ }
 1201+ if ( $.isOperaBroken )
 1202+ s = s.replace( /\n/g, "\r\n" );
 1203+ return s;
 1204+};
 1205+
11721206 $.fn.wikiEditor = function() {
11731207
11741208 /* Initialization */
@@ -2137,8 +2171,8 @@
21382172 }
21392173 // Build outline from wikitext
21402174 var outline = [];
2141 - var wikitext = '\n' + context.$textarea.val() + '\n';
2142 - var headings = wikitext.match( /\n={1,5}.*={1,5}(?=\n)/g );
 2175+ var wikitext = '\n' + $.wikiEditor.fixOperaBrokenness( context.$textarea.val() ) + '\n';
 2176+ var headings = wikitext.match( /(\r|\n)={1,5}.*={1,5}(?=(\r|\n))/g );
21432177 var offset = 0;
21442178 headings = $.makeArray( headings );
21452179 for ( var h = 0; h < headings.length; h++ ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -76,7 +76,11 @@
7777 return($.os.name=='mac'?13:($.os.name=='linux'?15:16))*row;}
7878 return this.each(function(){$(this).focus();if(this.selectionStart||this.selectionStart=='0'){$(this).scrollTop(getCaretScrollPosition(this));}else if(document.selection&&document.selection.createRange){var range=document.selection.createRange();var pos=$(this).getCaretPosition();range.moveToElementText(this);range.collapse();range.move('character',pos+1);range.select();this.scrollTop+=range.offsetTop;range.move('character',-1);range.select();}
7979 $(this).trigger('scrollToPosition');});}});})(jQuery);(function($){$.wikiEditor={'modules':{},'instances':[],'supportedBrowsers':{'ltr':{'msie':7,'firefox':2,'opera':9,'safari':3,'chrome':1,'camino':1},'rtl':{'msie':8,'firefox':2,'opera':9,'safari':3,'chrome':1,'camino':1}},imgPath:wgScriptPath+'/extensions/UsabilityInitiative/images/wikiEditor/'};$.wikiEditor.isSupportKnown=function(){return(function(supportedBrowsers){return $.browser.name in supportedBrowsers;})($.wikiEditor.supportedBrowsers[$('body.rtl').size()?'rtl':'ltr']);};$.wikiEditor.isSupported=function(){return(function(supportedBrowsers){return $.browser.name in supportedBrowsers&&$.browser.versionNumber>=supportedBrowsers[$.browser.name];})($.wikiEditor.supportedBrowsers[$('body.rtl').size()?'rtl':'ltr']);};$.wikiEditor.autoMsg=function(object,property){if(typeof property=='object'){for(i in property){if(property[i]in object||property[i]+'Msg'in object){property=property[i];break;}}}
80 -if(property in object){return object[property];}else if(property+'Msg'in object){return gM(object[property+'Msg']);}else{return'';}};$.fn.wikiEditor=function(){var context=$(this).data('wikiEditor-context');if(typeof context=='undefined'){var instance=$.wikiEditor.instances.length;context={'$textarea':$(this),'modules':{},'data':{},'instance':instance};$.wikiEditor.instances[instance]=$(this);$(this).wrap($('<div></div>').addClass('wikiEditor-ui').attr('id','wikiEditor-ui')).wrap($('<div></div>').addClass('wikiEditor-ui-bottom').attr('id','wikiEditor-ui-bottom')).wrap($('<div></div>').addClass('wikiEditor-ui-text').attr('id','wikiEditor-ui-text'));context.$ui=$(this).parent().parent().parent();context.$ui.after($('<div style="clear:both;"></div>'));context.$ui.prepend($('<div></div>').addClass('wikiEditor-ui-top').attr('id','wikiEditor-ui-top'));context.api={addModule:function(context,data){function callModuleApi(module,call,data){if(module in $.wikiEditor.modules&&'fn'in $.wikiEditor.modules[module]&&call in $.wikiEditor.modules[module].fn){$.wikiEditor.modules[module].fn[call](context,data);}}
 80+if(property in object){return object[property];}else if(property+'Msg'in object){return gM(object[property+'Msg']);}else{return'';}};$.wikiEditor.fixOperaBrokenness=function(s){if(typeof $.isOperaBroken=='undefined'&&$.wikiEditor.instances.length>0){var div=$('<div />').height(0).width(0).insertBefore($.wikiEditor.instances[0]);var textarea=$('<textarea></textarea').height(0).appendTo(div).val("foo\r\nbar");var index=textarea.val().indexOf('bar');textarea.select();textarea.setSelection(index,index+3);textarea.encapsulateSelection('','BAR','',false,true);if(textarea.val().substr(-1)=='R')
 81+$.isOperaBroken=false;else
 82+$.isOperaBroken=true;div.remove();}
 83+if($.isOperaBroken)
 84+s=s.replace(/\n/g,"\r\n");return s;};$.fn.wikiEditor=function(){var context=$(this).data('wikiEditor-context');if(typeof context=='undefined'){var instance=$.wikiEditor.instances.length;context={'$textarea':$(this),'modules':{},'data':{},'instance':instance};$.wikiEditor.instances[instance]=$(this);$(this).wrap($('<div></div>').addClass('wikiEditor-ui').attr('id','wikiEditor-ui')).wrap($('<div></div>').addClass('wikiEditor-ui-bottom').attr('id','wikiEditor-ui-bottom')).wrap($('<div></div>').addClass('wikiEditor-ui-text').attr('id','wikiEditor-ui-text'));context.$ui=$(this).parent().parent().parent();context.$ui.after($('<div style="clear:both;"></div>'));context.$ui.prepend($('<div></div>').addClass('wikiEditor-ui-top').attr('id','wikiEditor-ui-top'));context.api={addModule:function(context,data){function callModuleApi(module,call,data){if(module in $.wikiEditor.modules&&'fn'in $.wikiEditor.modules[module]&&call in $.wikiEditor.modules[module].fn){$.wikiEditor.modules[module].fn[call](context,data);}}
8185 if(typeof data=='string'){callModuleApi(data,'create',{});}else if(typeof data=='object'){for(module in data){if(typeof module=='string'){callModuleApi(module,'create',data[module]);}}}}};for(module in $.wikiEditor.modules){if('api'in $.wikiEditor.modules[module]){for(call in $.wikiEditor.modules[module].api){if(!(call in context.api)){context.api[call]=$.wikiEditor.modules[module].api[call];}}}}
8286 context.$textarea.setSelection(0).scrollToCaretPosition();}
8387 if(arguments.length>0&&typeof arguments[0]=='object'){context.api.addModule(context,arguments[0]);}else{arguments=$.makeArray(arguments);if(arguments.length>0){var call=arguments.shift();if(call in context.api){context.api[call](context,arguments[0]==undefined?{}:arguments[0]);}}}
@@ -141,7 +145,7 @@
142146 function buildList(structure){var list=$('<ul></ul>');for(i in structure){var item=$('<li></li>').append($('<a></a>').attr('href','#').addClass('section-'+structure[i].index).data('textbox',context.$textarea).data('position',structure[i].position).click(function(event){$(this).data('textbox').setSelection($(this).data('position')).scrollToCaretPosition();event.preventDefault();}).text(structure[i].text));if(structure[i].sections!==undefined){item.append(buildList(structure[i].sections));}
143147 list.append(item);}
144148 return list;}
145 -var outline=[];var wikitext='\n'+context.$textarea.val()+'\n';var headings=wikitext.match(/\n={1,5}.*={1,5}(?=\n)/g);var offset=0;headings=$.makeArray(headings);for(var h=0;h<headings.length;h++){text=headings[h];var position=wikitext.indexOf(text,offset);if(position>offset){offset=position+1;}else if(position==-1){continue;}
 149+var outline=[];var wikitext='\n'+$.wikiEditor.fixOperaBrokenness(context.$textarea.val())+'\n';var headings=wikitext.match(/(\r|\n)={1,5}.*={1,5}(?=(\r|\n))/g);var offset=0;headings=$.makeArray(headings);for(var h=0;h<headings.length;h++){text=headings[h];var position=wikitext.indexOf(text,offset);if(position>offset){offset=position+1;}else if(position==-1){continue;}
146150 text=$.trim(text);var startLevel=0;for(var c=0;c<text.length;c++){if(text.charAt(c)=='='){startLevel++;}else{break;}}
147151 var endLevel=0;for(var c=text.length-1;c>=0;c--){if(text.charAt(c)=='='){endLevel++;}else{break;}}
148152 var level=Math.min(startLevel,endLevel);text=$.trim(text.substr(level,text.length-(level*2)));outline[h]={'text':text,'position':position,'level':level,'index':h+1};}

Status & tagging log