r57409 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57408‎ | r57409 | r57410 >
Date:21:43, 5 October 2009
Author:catrope
Status:deferred
Tags:
Comment:
EditToolbar: (bug 20900) Tables inserted on top regardless of cursor position in IE. Also recombine and bump style versions for r57403
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/css/combined.css (modified) (history)
  • /trunk/extensions/UsabilityInitiative/css/combined.min.css (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.textSelection.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
@@ -22,15 +22,15 @@
2323 array( 'src' => 'css/wikiEditor.css', 'version' => 4 ),
2424 array( 'src' => 'css/wikiEditor.toolbar.css', 'version' => 5 ),
2525 array( 'src' => 'css/wikiEditor.dialogs.css', 'version' => 2 ),
26 - array( 'src' => 'css/wikiEditor.toc.css', 'version' => 5 ),
 26+ array( 'src' => 'css/wikiEditor.toc.css', 'version' => 6 ),
2727 array( 'src' => 'css/vector/jquery-ui-1.7.2.css', 'version' => '1.7.2' ),
2828 ),
2929 'combined' => array(
30 - array( 'src' => 'css/combined.css', 'version' => 9 ),
 30+ array( 'src' => 'css/combined.css', 'version' => 10 ),
3131 array( 'src' => 'css/vector/jquery-ui-1.7.2.css', 'version' => '1.7.2' ),
3232 ),
3333 'minified' => array(
34 - array( 'src' => 'css/combined.min.css', 'version' => 9 ),
 34+ array( 'src' => 'css/combined.min.css', 'version' => 10 ),
3535 array( 'src' => 'css/vector/jquery-ui-1.7.2.css', 'version' => '1.7.2' ),
3636 ),
3737 )
@@ -63,20 +63,20 @@
6464 array( 'src' => 'js/plugins/jquery.delayedBind.js', 'version' => 1 ),
6565 array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
6666 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 4 ),
67 - array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 15 ),
68 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 9 ),
 67+ array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 16 ),
 68+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 10 ),
6969 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 11 ),
7070 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 4 ),
71 - array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 17 ),
 71+ array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 18 ),
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' => 39 ),
 77+ array( 'src' => 'js/plugins.combined.js', 'version' => 40 ),
7878 ),
7979 'minified' => array(
80 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 39 ),
 80+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 40 ),
8181 ),
8282 ),
8383 );
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 = 50;
 23+$wgEditToolbarStyleVersion = 51;
2424
2525 // Set this to true to simply override the stock toolbar for everyone
2626 $wgEditToolbarGlobalEnable = false;
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
@@ -1144,7 +1144,7 @@
11451145 $j.wikiEditor.modules.toolbar.fn.doAction(
11461146 $j(this).data( 'context' ),
11471147 {
1148 - type: 'encapsulate',
 1148+ type: 'replace',
11491149 options: {
11501150 pre: "{|\n",
11511151 peri: table,
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.textSelection.js
@@ -118,9 +118,9 @@
119119 * Get the position (in resolution of bytes not nessecarily characters)
120120 * in a textarea
121121 */
122 - getCaretPosition: function() {
 122+ getCaretPosition: function( startAndEnd ) {
123123 function getCaret( e ) {
124 - var caretPos = 0;
 124+ var caretPos = 0, endPos = 0;
125125 if ( $.browser.msie ) {
126126 // IE Support
127127 var postFinished = false;
@@ -190,11 +190,13 @@
191191 }
192192 } while ( ( !postFinished || !periFinished || !postFinished ) );
193193 caretPos = rawPreText.replace( /\r\n/g, "\n" ).length;
 194+ endPos = caretPos + rawPeriText.replace( /\r\n/g, "\n" ).length;
194195 } else if ( e.selectionStart || e.selectionStart == '0' ) {
195196 // Firefox support
196197 caretPos = e.selectionStart;
 198+ endPos = e.selectionEnd;
197199 }
198 - return caretPos;
 200+ return startAndEnd ? [ caretPos, endPos ] : caretPos;
199201 }
200202 return getCaret( this.get( 0 ) );
201203 },
@@ -280,7 +282,6 @@
281283 return ( $.os.name == 'mac' ? 13 : ( $.os.name == 'linux' ? 15 : 16 ) ) * row;
282284 }
283285 return this.each(function() {
284 - $(this).focus();
285286 if ( this.selectionStart || this.selectionStart == '0' ) {
286287 // Mozilla
287288 var scroll = getCaretScrollPosition( this );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -118,6 +118,18 @@
119119 // Attach a container in the top
120120 context.$ui.prepend( $( '<div></div>' ).addClass( 'wikiEditor-ui-top' ).attr( 'id', 'wikiEditor-ui-top' ) );
121121
 122+ // Some browsers don't restore the cursor position on refocus properly
 123+ // Do it for them
 124+ $(this)
 125+ .focus( function() {
 126+ var pos = $(this).data( 'wikiEditor-cursor' );
 127+ if ( typeof pos != 'undefined' )
 128+ $(this).setSelection( pos[0], pos[1] );
 129+ })
 130+ .blur( function() {
 131+ $(this).data( 'wikiEditor-cursor', $(this).getCaretPosition( true ) );
 132+ });
 133+
122134 // Create a set of standard methods for internal and external use
123135 context.api = {
124136 /**
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js
@@ -156,6 +156,7 @@
157157 .data( 'position', structure[i].position )
158158 .click( function( event ) {
159159 $(this).data( 'textbox' )
 160+ .focus()
160161 .setSelection( $(this).data( 'position' ) )
161162 .scrollToCaretPosition( true );
162163 event.preventDefault();
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -942,9 +942,9 @@
943943 * Get the position (in resolution of bytes not nessecarily characters)
944944 * in a textarea
945945 */
946 - getCaretPosition: function() {
 946+ getCaretPosition: function( startAndEnd ) {
947947 function getCaret( e ) {
948 - var caretPos = 0;
 948+ var caretPos = 0, endPos = 0;
949949 if ( $.browser.msie ) {
950950 // IE Support
951951 var postFinished = false;
@@ -1014,11 +1014,13 @@
10151015 }
10161016 } while ( ( !postFinished || !periFinished || !postFinished ) );
10171017 caretPos = rawPreText.replace( /\r\n/g, "\n" ).length;
 1018+ endPos = caretPos + rawPeriText.replace( /\r\n/g, "\n" ).length;
10181019 } else if ( e.selectionStart || e.selectionStart == '0' ) {
10191020 // Firefox support
10201021 caretPos = e.selectionStart;
 1022+ endPos = e.selectionEnd;
10211023 }
1022 - return caretPos;
 1024+ return startAndEnd ? [ caretPos, endPos ] : caretPos;
10231025 }
10241026 return getCaret( this.get( 0 ) );
10251027 },
@@ -1104,7 +1106,6 @@
11051107 return ( $.os.name == 'mac' ? 13 : ( $.os.name == 'linux' ? 15 : 16 ) ) * row;
11061108 }
11071109 return this.each(function() {
1108 - $(this).focus();
11091110 if ( this.selectionStart || this.selectionStart == '0' ) {
11101111 // Mozilla
11111112 var scroll = getCaretScrollPosition( this );
@@ -1259,6 +1260,18 @@
12601261 // Attach a container in the top
12611262 context.$ui.prepend( $( '<div></div>' ).addClass( 'wikiEditor-ui-top' ).attr( 'id', 'wikiEditor-ui-top' ) );
12621263
 1264+ // Some browsers don't restore the cursor position on refocus properly
 1265+ // Do it for them
 1266+ $(this)
 1267+ .focus( function() {
 1268+ var pos = $(this).data( 'wikiEditor-cursor' );
 1269+ if ( typeof pos != 'undefined' )
 1270+ $(this).setSelection( pos[0], pos[1] );
 1271+ })
 1272+ .blur( function() {
 1273+ $(this).data( 'wikiEditor-cursor', $(this).getCaretPosition( true ) );
 1274+ });
 1275+
12631276 // Create a set of standard methods for internal and external use
12641277 context.api = {
12651278 /**
@@ -2055,6 +2068,8 @@
20562069 context.modules.$toc = $( '<div />' )
20572070 .addClass( 'wikiEditor-ui-toc' )
20582071 .attr( 'id', 'wikiEditor-ui-toc' );
 2072+ // If we ask for this later (after we insert the TOC) then in IE this measurement will be incorrect
 2073+ var height = context.$ui.find( '.wikiEditor-ui-bottom' ).height()
20592074 context.$ui.find( '.wikiEditor-ui-bottom' )
20602075 .append( context.modules.$toc );
20612076 context.modules.$toc.height(
@@ -2062,10 +2077,7 @@
20632078 );
20642079 // Make some css modifications to make room for the toc on the right...
20652080 // Perhaps this could be configurable?
2066 - context.modules.$toc
2067 - .css( { 'width': '12em',
2068 - 'marginTop': -( context.$ui.find( '.wikiEditor-ui-bottom' ).height() )
2069 - } );
 2081+ context.modules.$toc.css( { 'width': '12em', 'marginTop': -( height ) } );
20702082 context.$ui.find( '.wikiEditor-ui-text' )
20712083 .css( ( $( 'body.rtl' ).size() ? 'marginLeft' : 'marginRight' ), '12em' );
20722084 // Add the TOC to the document
@@ -2186,6 +2198,7 @@
21872199 .data( 'position', structure[i].position )
21882200 .click( function( event ) {
21892201 $(this).data( 'textbox' )
 2202+ .focus()
21902203 .setSelection( $(this).data( 'position' ) )
21912204 .scrollToCaretPosition( true );
21922205 event.preventDefault();
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -61,13 +61,13 @@
6262 var range3=document.selection.createRange();range3.collapse(false);range3.moveEnd('character',1);if(range3.text!="\r"&&range3.text!="\n"&&range3.text!=""){post+="\n";}}
6363 checkSelectedText();range.text=pre+selText+post;if(isSample&&range.moveStart){range.moveStart('character',-post.length-selText.length);range.moveEnd('character',-post.length);}
6464 range.select();}
65 -$(this).scrollToCaretPosition();$(this).trigger('encapsulateSelection',[pre,peri,post,ownline,replace]);});},getCaretPosition:function(){function getCaret(e){var caretPos=0;if($.browser.msie){var postFinished=false;var periFinished=false;var postFinished=false;var preText,rawPreText,periText;var rawPeriText,postText,rawPostText;var periRange=document.selection.createRange().duplicate();var preRange=document.body.createTextRange();preRange.moveToElementText(e);preRange.setEndPoint("EndToStart",periRange);var postRange=document.body.createTextRange();postRange.moveToElementText(e);postRange.setEndPoint("StartToEnd",periRange);preText=rawPreText=preRange.text;periText=rawPeriText=periRange.text;postText=rawPostText=postRange.text;do{if(!postFinished){if(preRange.compareEndPoints("StartToEnd",preRange)==0){postFinished=true;}else{preRange.moveEnd("character",-1)
 65+$(this).scrollToCaretPosition();$(this).trigger('encapsulateSelection',[pre,peri,post,ownline,replace]);});},getCaretPosition:function(startAndEnd){function getCaret(e){var caretPos=0,endPos=0;if($.browser.msie){var postFinished=false;var periFinished=false;var postFinished=false;var preText,rawPreText,periText;var rawPeriText,postText,rawPostText;var periRange=document.selection.createRange().duplicate();var preRange=document.body.createTextRange();preRange.moveToElementText(e);preRange.setEndPoint("EndToStart",periRange);var postRange=document.body.createTextRange();postRange.moveToElementText(e);postRange.setEndPoint("StartToEnd",periRange);preText=rawPreText=preRange.text;periText=rawPeriText=periRange.text;postText=rawPostText=postRange.text;do{if(!postFinished){if(preRange.compareEndPoints("StartToEnd",preRange)==0){postFinished=true;}else{preRange.moveEnd("character",-1)
6666 if(preRange.text==preText){rawPreText+="\r\n";}else{postFinished=true;}}}
6767 if(!periFinished){if(periRange.compareEndPoints("StartToEnd",periRange)==0){periFinished=true;}else{periRange.moveEnd("character",-1)
6868 if(periRange.text==periText){rawPeriText+="\r\n";}else{periFinished=true;}}}
6969 if(!postFinished){if(postRange.compareEndPoints("StartToEnd",postRange)==0){postFinished=true;}else{postRange.moveEnd("character",-1)
70 -if(postRange.text==postText){rawPostText+="\r\n";}else{postFinished=true;}}}}while((!postFinished||!periFinished||!postFinished));caretPos=rawPreText.replace(/\r\n/g,"\n").length;}else if(e.selectionStart||e.selectionStart=='0'){caretPos=e.selectionStart;}
71 -return caretPos;}
 70+if(postRange.text==postText){rawPostText+="\r\n";}else{postFinished=true;}}}}while((!postFinished||!periFinished||!postFinished));caretPos=rawPreText.replace(/\r\n/g,"\n").length;endPos=caretPos+rawPeriText.replace(/\r\n/g,"\n").length;}else if(e.selectionStart||e.selectionStart=='0'){caretPos=e.selectionStart;endPos=e.selectionEnd;}
 71+return startAndEnd?[caretPos,endPos]:caretPos;}
7272 return getCaret(this.get(0));},setSelection:function(start,end){if(typeof end=='undefined')
7373 end=start;return this.each(function(){if(this.selectionStart||this.selectionStart=='0'){if(start>this.selectionEnd){this.selectionEnd=end;this.selectionStart=start;}else{this.selectionStart=start;this.selectionEnd=end;}}else if(document.body.createTextRange){var selection=document.body.createTextRange();selection.moveToElementText(this);var length=selection.text.length;selection.moveStart('character',start);selection.moveEnd('character',-length+end);selection.select();}});},scrollToCaretPosition:function(force){function getLineLength(e){return Math.floor(e.scrollWidth/($.os.name=='linux'?7:8));}
7474 function getCaretScrollPosition(e){var text=e.value.replace(/\r/g,"");var caret=$(e).getCaretPosition();var lineLength=getLineLength(e);var row=0;var charInLine=0;var lastSpaceInLine=0;for(i=0;i<caret;i++){charInLine++;if(text.charAt(i)==" "){lastSpaceInLine=charInLine;}else if(text.charAt(i)=="\n"){lastSpaceInLine=0;charInLine=0;row++;}
@@ -75,7 +75,7 @@
7676 var nextSpace=0;for(j=caret;j<caret+lineLength;j++){if(text.charAt(j)==" "||text.charAt(j)=="\n"||caret==text.length){nextSpace=j;break;}}
7777 if(nextSpace>lineLength&&caret<=lineLength){charInLine=caret-lastSpaceInLine;row++;}
7878 return($.os.name=='mac'?13:($.os.name=='linux'?15:16))*row;}
79 -return this.each(function(){$(this).focus();if(this.selectionStart||this.selectionStart=='0'){var scroll=getCaretScrollPosition(this);if(force||scroll<$(this).scrollTop()||scroll>$(this).scrollTop()+$(this).height())
 79+return this.each(function(){if(this.selectionStart||this.selectionStart=='0'){var scroll=getCaretScrollPosition(this);if(force||scroll<$(this).scrollTop()||scroll>$(this).scrollTop()+$(this).height())
8080 $(this).scrollTop(scroll);}else if(document.selection&&document.selection.createRange){var range=document.selection.createRange();var pos=$(this).getCaretPosition();var oldScrollTop=this.scrollTop;range.moveToElementText(this);range.collapse();range.move('character',pos+1);range.select();if(this.scrollTop!=oldScrollTop)
8181 this.scrollTop+=range.offsetTop;else if(force){range.move('character',-1);range.select();}}
8282 $(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;}}}
@@ -83,7 +83,8 @@
8484 $.isOperaBroken=false;else
8585 $.isOperaBroken=true;div.remove();}
8686 if($.isOperaBroken)
87 -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);}}
 87+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'));$(this).focus(function(){var pos=$(this).data('wikiEditor-cursor');if(typeof pos!='undefined')
 88+$(this).setSelection(pos[0],pos[1]);}).blur(function(){$(this).data('wikiEditor-cursor',$(this).getCaretPosition(true));});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);}}
8889 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];}}}}}
8990 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]);}}}
9091 return $(this).data('wikiEditor-context',context);};})(jQuery);RegExp.escape=function(s){return s.replace(/([.*+?^${}()|\/\\[\]])/g,'\\$1');};(function($){$.wikiEditor.modules.dialogs={api:{addDialog:function(context,data){$.wikiEditor.modules.dialogs.fn.create(context,{'modules':data})},openDialog:function(context,data){if(data.dialog in $.wikiEditor.modules.dialogs.modules){$('#'+$.wikiEditor.modules.dialogs.modules[data.dialog].id).dialog('open');}},closeDialog:function(context,data){if(data.dialog in $.wikiEditor.modules.dialogs.modules){$('#'+$.wikiEditor.modules.dialogs.modules[data.dialog].id).dialog('close');}}},fn:{create:function(context,config){for(module in config){$.wikiEditor.modules.dialogs.modules[module]=config[module];}
@@ -138,14 +139,15 @@
139140 return $section;},updateBookletSelection:function(context,id,$pages,$index){var cookie='wikiEditor-'+context.instance+'-booklet-'+id+'-page';var selected=$.cookie(cookie);var $selectedIndex=$index.find('*[rel='+selected+']');if($selectedIndex.size()==0){selected=$index.children().eq(0).attr('rel');$.cookie(cookie,selected);}
140141 $pages.children().hide();$pages.find('*[rel='+selected+']').show();$index.children().removeClass('current');$selectedIndex.addClass('current');},build:function(context,config){var $tabs=$('<div />').addClass('tabs').appendTo(context.modules.$toolbar);var $sections=$('<div />').addClass('sections').appendTo(context.modules.$toolbar);context.modules.$toolbar.append($('<div />').css('clear','both'));var sectionQueue=[];for(section in config){if(section=='main'){context.modules.$toolbar.prepend($.wikiEditor.modules.toolbar.fn.buildSection(context,section,config[section]));}else{sectionQueue.push({'$sections':$sections,'context':context,'id':section,'config':config[section]});$tabs.append($.wikiEditor.modules.toolbar.fn.buildTab(context,section,config[section]));}}
141142 $.eachAsync(sectionQueue,{'bulk':0,'end':function(){$('body').css('position','static');$('body').css('position','relative');},'loop':function(i,s){s.$sections.append($.wikiEditor.modules.toolbar.fn.buildSection(s.context,s.id,s.config));}});}}};})(jQuery);(function($){$.wikiEditor.modules.toc={api:{},fn:{create:function(context,config){if('$toc'in context.modules){return;}
142 -context.modules.$toc=$('<div />').addClass('wikiEditor-ui-toc').attr('id','wikiEditor-ui-toc');context.$ui.find('.wikiEditor-ui-bottom').append(context.modules.$toc);context.modules.$toc.height(context.$ui.find('.wikiEditor-ui-bottom').height());context.modules.$toc.css({'width':'12em','marginTop':-(context.$ui.find('.wikiEditor-ui-bottom').height())});context.$ui.find('.wikiEditor-ui-text').css(($('body.rtl').size()?'marginLeft':'marginRight'),'12em');$.wikiEditor.modules.toc.fn.build(context,config);context.$textarea.delayedBind(1000,'keyup encapsulateSelection change',function(event){var context=$(this).data('wikiEditor-context');$(this).eachAsync({bulk:0,loop:function(){$.wikiEditor.modules.toc.fn.build(context);$.wikiEditor.modules.toc.fn.update(context);}});}).bind('mouseup scrollToPosition focus keyup encapsulateSelection change',function(event){var context=$(this).data('wikiEditor-context');$(this).eachAsync({bulk:0,loop:function(){$.wikiEditor.modules.toc.fn.update(context);}});}).blur(function(){var context=$(this).data('wikiEditor-context');$.wikiEditor.modules.toc.fn.unhighlight(context);});},unhighlight:function(context){context.modules.$toc.find('a').removeClass('currentSelection');},update:function(context){$.wikiEditor.modules.toc.fn.unhighlight(context);var position=context.$textarea.getCaretPosition();var section=0;if(context.data.outline.length>0){if(!(position<context.data.outline[0].position-1)){while(section<context.data.outline.length&&context.data.outline[section].position-1<position){section++;}
 143+context.modules.$toc=$('<div />').addClass('wikiEditor-ui-toc').attr('id','wikiEditor-ui-toc');var height=context.$ui.find('.wikiEditor-ui-bottom').height()
 144+context.$ui.find('.wikiEditor-ui-bottom').append(context.modules.$toc);context.modules.$toc.height(context.$ui.find('.wikiEditor-ui-bottom').height());context.modules.$toc.css({'width':'12em','marginTop':-(height)});context.$ui.find('.wikiEditor-ui-text').css(($('body.rtl').size()?'marginLeft':'marginRight'),'12em');$.wikiEditor.modules.toc.fn.build(context,config);context.$textarea.delayedBind(1000,'keyup encapsulateSelection change',function(event){var context=$(this).data('wikiEditor-context');$(this).eachAsync({bulk:0,loop:function(){$.wikiEditor.modules.toc.fn.build(context);$.wikiEditor.modules.toc.fn.update(context);}});}).bind('mouseup scrollToPosition focus keyup encapsulateSelection change',function(event){var context=$(this).data('wikiEditor-context');$(this).eachAsync({bulk:0,loop:function(){$.wikiEditor.modules.toc.fn.update(context);}});}).blur(function(){var context=$(this).data('wikiEditor-context');$.wikiEditor.modules.toc.fn.unhighlight(context);});},unhighlight:function(context){context.modules.$toc.find('a').removeClass('currentSelection');},update:function(context){$.wikiEditor.modules.toc.fn.unhighlight(context);var position=context.$textarea.getCaretPosition();var section=0;if(context.data.outline.length>0){if(!(position<context.data.outline[0].position-1)){while(section<context.data.outline.length&&context.data.outline[section].position-1<position){section++;}
143145 section=Math.max(0,section);}
144146 var sectionLink=context.modules.$toc.find('a.section-'+section);sectionLink.addClass('currentSelection');var relTop=sectionLink.offset().top-context.modules.$toc.offset().top;var scrollTop=context.modules.$toc.scrollTop();var divHeight=context.modules.$toc.height();var sectionHeight=sectionLink.height();if(relTop<0)
145147 context.modules.$toc.scrollTop(scrollTop+relTop);else if(relTop+sectionHeight>divHeight)
146148 context.modules.$toc.scrollTop(scrollTop+relTop+sectionHeight-divHeight);}},build:function(context){function buildStructure(outline,offset,level){if(offset==undefined)offset=0;if(level==undefined)level=1;var sections=[];for(var i=offset;i<outline.length;i++){if(outline[i].nLevel==level){var sub=buildStructure(outline,i+1,level+1);if(sub.length){outline[i].sections=sub;}
147149 sections[sections.length]=outline[i];}else if(outline[i].nLevel<level){break;}}
148150 return sections;}
149 -function buildList(structure){var list=$('<ul />');for(i in structure){var item=$('<li />').append($('<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(true);event.preventDefault();}).text(structure[i].text));if(structure[i].sections!==undefined){item.append(buildList(structure[i].sections));}
 151+function buildList(structure){var list=$('<ul />');for(i in structure){var item=$('<li />').append($('<a />').attr('href','#').addClass('section-'+structure[i].index).data('textbox',context.$textarea).data('position',structure[i].position).click(function(event){$(this).data('textbox').focus().setSelection($(this).data('position')).scrollToCaretPosition(true);event.preventDefault();}).text(structure[i].text));if(structure[i].sections!==undefined){item.append(buildList(structure[i].sections));}
150152 list.append(item);}
151153 return list;}
152154 var outline=[];var wikitext=$.wikiEditor.fixOperaBrokenness(context.$textarea.val());var headings=wikitext.match(/^={1,6}.+={1,6}\s*$/gm);var offset=0;headings=$.makeArray(headings);for(var h=0;h<headings.length;h++){text=$.trim(headings[h]);var position=wikitext.indexOf(text,offset);if(position>=offset){offset=position+1;}else if(position==-1){continue;}
Index: trunk/extensions/UsabilityInitiative/css/combined.css
@@ -127,6 +127,10 @@
128128 padding: 0;
129129 margin: 0.5em 1em;
130130 list-style: none;
 131+ /* IE needs to be told in great detail how to act, or it misbehaves */
 132+ list-style-image: none;
 133+ list-style-position: outside;
 134+ list-style-type: none;
131135 }
132136 .wikiEditor-ui-toc ul ul {
133137 padding: 0;
Index: trunk/extensions/UsabilityInitiative/css/combined.min.css
@@ -115,6 +115,9 @@
116116 padding:0;
117117 margin:0.5em 1em;
118118 list-style:none;
 119+list-style-image:none;
 120+list-style-position:outside;
 121+list-style-type:none;
119122 }
120123 .wikiEditor-ui-toc ul ul{
121124 padding:0;

Follow-up revisions

RevisionCommit summaryAuthorDate
r57424EditToolbar: (bug 21013, bug 21014, bug 21018) Fix some weird replacenext-rel...catrope12:55, 6 October 2009
r57719wmf-deployment: Merge babaco fixes from trunk...catrope20:20, 14 October 2009

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r57100* EditToolbar: (bug 20901) Cursor doesn't move to end of inserted table in Op...catrope13:01, 30 September 2009
r57403Fixes bug that cause the table of contents to be rendered partially offscreen...tparscal20:41, 5 October 2009

Status & tagging log