r57022 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57021‎ | r57022 | r57023 >
Date:18:29, 28 September 2009
Author:catrope
Status:ok
Tags:
Comment:
NavigableTOC: When highlighting a section title in the NTOC that is not visible, scroll it into view.
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.toc.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -67,16 +67,16 @@
6868 array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 6 ),
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' => 9 ),
 71+ array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 10 ),
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' => 28 ),
 77+ array( 'src' => 'js/plugins.combined.js', 'version' => 29 ),
7878 ),
7979 'minified' => array(
80 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 28 ),
 80+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 29 ),
8181 ),
8282 ),
8383 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js
@@ -97,7 +97,20 @@
9898 }
9999 section = Math.max( 0, section );
100100 }
101 - context.modules.$toc.find( 'a.section-' + section ).addClass( 'currentSelection' );
 101+ var sectionLink = context.modules.$toc.find( 'a.section-' + section );
 102+ sectionLink.addClass( 'currentSelection' );
 103+
 104+ // Scroll the highlighted link into view if necessary
 105+ var relTop = sectionLink.offset().top - context.modules.$toc.offset().top;
 106+ var scrollTop = context.modules.$toc.scrollTop();
 107+ var divHeight = context.modules.$toc.height();
 108+ var sectionHeight = sectionLink.height();
 109+ if ( relTop < 0 )
 110+ // Scroll up
 111+ context.modules.$toc.scrollTop( scrollTop + relTop );
 112+ else if ( relTop + sectionHeight > divHeight )
 113+ // Scroll down
 114+ context.modules.$toc.scrollTop( scrollTop + relTop + sectionHeight - divHeight );
102115 }
103116 },
104117 /**
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -2061,7 +2061,20 @@
20622062 }
20632063 section = Math.max( 0, section );
20642064 }
2065 - context.modules.$toc.find( 'a.section-' + section ).addClass( 'currentSelection' );
 2065+ var sectionLink = context.modules.$toc.find( 'a.section-' + section );
 2066+ sectionLink.addClass( 'currentSelection' );
 2067+
 2068+ // Scroll the highlighted link into view if necessary
 2069+ var relTop = sectionLink.offset().top - context.modules.$toc.offset().top;
 2070+ var scrollTop = context.modules.$toc.scrollTop();
 2071+ var divHeight = context.modules.$toc.height();
 2072+ var sectionHeight = sectionLink.height();
 2073+ if ( relTop < 0 )
 2074+ // Scroll up
 2075+ context.modules.$toc.scrollTop( scrollTop + relTop );
 2076+ else if ( relTop + sectionHeight > divHeight )
 2077+ // Scroll down
 2078+ context.modules.$toc.scrollTop( scrollTop + relTop + sectionHeight - divHeight );
20662079 }
20672080 },
20682081 /**
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -133,7 +133,9 @@
134134 $.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;}
135135 context.modules.$toc=$('<div></div>').addClass('wikiEditor-ui-toc').attr('id','wikiEditor-ui-toc');$.wikiEditor.modules.toc.fn.build(context,config);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').css('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);$.wikiEditor.modules.toc.fn.update(context);context.$textarea.delayedBind(1000,'keyup encapsulateSelection',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',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++;}
136136 section=Math.max(0,section);}
137 -context.modules.$toc.find('a.section-'+section).addClass('currentSelection');}},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;}
 137+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)
 138+context.modules.$toc.scrollTop(scrollTop+relTop);else if(relTop+sectionHeight>divHeight)
 139+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;}
138140 sections[sections.length]=outline[i];}else if(outline[i].nLevel<level){break;}}
139141 return sections;}
140142 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));}

Status & tagging log