Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -67,16 +67,16 @@ |
68 | 68 | array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 6 ), |
69 | 69 | array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 11 ), |
70 | 70 | 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 ), |
72 | 72 | // FIXME: jQuery UI doesn't belong here, should move to no_js2 |
73 | 73 | // once we figure out how to do jQuery UI properly in JS2 |
74 | 74 | array( 'src' => 'js/js2/jquery-ui-1.7.2.js', 'version' => '1.7.2y' ), |
75 | 75 | ), |
76 | 76 | 'combined' => array( |
77 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 28 ), |
| 77 | + array( 'src' => 'js/plugins.combined.js', 'version' => 29 ), |
78 | 78 | ), |
79 | 79 | 'minified' => array( |
80 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 28 ), |
| 80 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 29 ), |
81 | 81 | ), |
82 | 82 | ), |
83 | 83 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js |
— | — | @@ -97,7 +97,20 @@ |
98 | 98 | } |
99 | 99 | section = Math.max( 0, section ); |
100 | 100 | } |
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 ); |
102 | 115 | } |
103 | 116 | }, |
104 | 117 | /** |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -2061,7 +2061,20 @@ |
2062 | 2062 | } |
2063 | 2063 | section = Math.max( 0, section ); |
2064 | 2064 | } |
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 ); |
2066 | 2079 | } |
2067 | 2080 | }, |
2068 | 2081 | /** |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -133,7 +133,9 @@ |
134 | 134 | $.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;} |
135 | 135 | 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++;} |
136 | 136 | 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;} |
138 | 140 | sections[sections.length]=outline[i];}else if(outline[i].nLevel<level){break;}} |
139 | 141 | return sections;} |
140 | 142 | 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));} |