r61287 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61286‎ | r61287 | r61288 >
Date:02:31, 20 January 2010
Author:tparscal
Status:ok
Tags:
Comment:
Turns out, the selection on load in webkit is just invalid, so unhighlighting based on that selection is going to be problematic. This solves this problem by handling the invalid selection situation.
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.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -153,7 +153,7 @@
154154 array(
155155 'src' => 'js/plugins/jquery.wikiEditor.js',
156156 'class' => 'j.wikiEditor',
157 - 'version' => 56
 157+ 'version' => 57
158158 ),
159159 array(
160160 'src' => 'js/plugins/jquery.wikiEditor.highlight.js',
@@ -173,7 +173,7 @@
174174 array(
175175 'src' => 'js/plugins/jquery.wikiEditor.toc.js',
176176 'class' => 'j.wikiEditor.modules.toc',
177 - 'version' => 65
 177+ 'version' => 66
178178 ),
179179 array(
180180 'src' => 'js/plugins/jquery.wikiEditor.preview.js',
@@ -191,10 +191,10 @@
192192 'version' => 1 ),
193193 ),
194194 'combined' => array(
195 - array( 'src' => 'js/plugins.combined.js', 'version' => 160 ),
 195+ array( 'src' => 'js/plugins.combined.js', 'version' => 161 ),
196196 ),
197197 'minified' => array(
198 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 160 ),
 198+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 161 ),
199199 ),
200200 ),
201201 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js
@@ -231,10 +231,7 @@
232232 }
233233 },
234234 unhighlight: function( context ) {
235 - // FIXME: I don't know why this is undefined sometimes in Webkit, but it is, and this helps
236 - if ( context ) {
237 - context.modules.toc.$toc.find( 'div' ).removeClass( 'current' );
238 - }
 235+ context.modules.toc.$toc.find( 'div' ).removeClass( 'current' );
239236 },
240237 /**
241238 * Highlight the section the cursor is currently within
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -589,13 +589,15 @@
590590 var e;
591591 if ( context.$iframe[0].contentWindow.getSelection ) {
592592 // Firefox and Opera
593 - // This needs to be here for webkit, or the selection is invalid
594 - context.$iframe[0].contentWindow.focus();
595 - var range = context.$iframe[0].contentWindow.getSelection().getRangeAt( 0 );
596 - // Start at the selection's start and traverse the DOM backwards
597 - // This is done by traversing an element's children first, then the
598 - // element itself, then its parent
599 - e = range.startContainer;
 593+ var selection = context.$iframe[0].contentWindow.getSelection();
 594+ // On load, webkit seems to not have a valid selection
 595+ if ( selection.baseNode !== null ) {
 596+ // Start at the selection's start and traverse the DOM backwards
 597+ // This is done by traversing an element's children first, then the element itself, then its parent
 598+ e = selection.getRangeAt( 0 ).startContainer;
 599+ } else {
 600+ return $( [] );
 601+ }
600602 } else if ( context.$iframe[0].contentWindow.document.selection ) {
601603 // IE
602604 // TODO
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -7070,13 +7070,15 @@
70717071 var e;
70727072 if ( context.$iframe[0].contentWindow.getSelection ) {
70737073 // Firefox and Opera
7074 - // This needs to be here for webkit, or the selection is invalid
7075 - context.$iframe[0].contentWindow.focus();
7076 - var range = context.$iframe[0].contentWindow.getSelection().getRangeAt( 0 );
7077 - // Start at the selection's start and traverse the DOM backwards
7078 - // This is done by traversing an element's children first, then the
7079 - // element itself, then its parent
7080 - e = range.startContainer;
 7074+ var selection = context.$iframe[0].contentWindow.getSelection();
 7075+ // On load, webkit seems to not have a valid selection
 7076+ if ( selection.baseNode !== null ) {
 7077+ // Start at the selection's start and traverse the DOM backwards
 7078+ // This is done by traversing an element's children first, then the element itself, then its parent
 7079+ e = selection.getRangeAt( 0 ).startContainer;
 7080+ } else {
 7081+ return $( [] );
 7082+ }
70817083 } else if ( context.$iframe[0].contentWindow.document.selection ) {
70827084 // IE
70837085 // TODO
@@ -8808,10 +8810,7 @@
88098811 }
88108812 },
88118813 unhighlight: function( context ) {
8812 - // FIXME: I don't know why this is undefined sometimes in Webkit, but it is, and this helps
8813 - if ( context ) {
8814 - context.modules.toc.$toc.find( 'div' ).removeClass( 'current' );
8815 - }
 8814+ context.modules.toc.$toc.find( 'div' ).removeClass( 'current' );
88168815 },
88178816 /**
88188817 * Highlight the section the cursor is currently within
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -463,7 +463,7 @@
464464 var range=context.$iframe[0].contentWindow.document.createRange();range.setStart(sc,options.start);range.setEnd(ec,options.end);sel.removeAllRanges();sel.addRange(range);context.$iframe[0].contentWindow.focus();}else if(context.$iframe[0].contentWindow.document.body.createTextRange){var range=context.$iframe[0].contentWindow.document.body.createTextRange();range.moveToElementText(sc);range.moveStart('character',options.start);var range2=context.$iframe[0].contentWindow.document.body.createTextRange();range2.moveToElementText(ec);range2.collapse();range2.moveEnd('character',options.end);range.setEndPoint('EndToEnd',range2);range.select();}},'scrollToCaretPosition':function(options){},'scrollToTop':function($element,force){var html=context.$content.closest('html'),body=context.$content.closest('body'),parentHtml=$('html'),parentBody=$('body');var y=$element.offset().top;if(!$.browser.msie){y=parentHtml.scrollTop()>0?y+html.scrollTop()-parentHtml.scrollTop():y;y=parentBody.scrollTop()>0?y+body.scrollTop()-parentBody.scrollTop():y;}
465465 var topBound=html.scrollTop()>body.scrollTop()?html.scrollTop():body.scrollTop(),bottomBound=topBound+context.$iframe.height();if(force||y<topBound||y>bottomBound){html.scrollTop(y);body.scrollTop(y);}
466466 $element.trigger('scrollToTop');},'beforeSelection':function(selector,strict){if(typeof selector=='undefined'){selector='*';}
467 -var e;if(context.$iframe[0].contentWindow.getSelection){context.$iframe[0].contentWindow.focus();var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);e=range.startContainer;}else if(context.$iframe[0].contentWindow.document.selection){return $([]);}
 467+var e;if(context.$iframe[0].contentWindow.getSelection){var selection=context.$iframe[0].contentWindow.getSelection();if(selection.baseNode!==null){e=selection.getRangeAt(0).startContainer;}else{return $([]);}}else if(context.$iframe[0].contentWindow.document.selection){return $([]);}
468468 if(e.nodeName!='#text'){var newE=e.firstChild;for(var i=0;i<range.startOffset-1&&newE;i++){newE=newE.nextSibling;}
469469 while(newE&&newE.lastChild){newE=newE.lastChild;}
470470 e=newE;}
@@ -583,7 +583,7 @@
584584 context.$wikitext.css({'position':'','height':''});context.$ui.find('.wikiEditor-ui-right').css({'marginRight':'','position':'','left':'','right':'','float':'','top':'','height':''});context.$ui.find('.wikiEditor-ui-left').css({'width':'','position':'','left':'','float':'','right':''});}
585585 $.wikiEditor.modules.toc.fn.redraw(context,width);},disable:function(context){if(context.modules.toc.$toc.data('collapsed')){context.$ui.find('.wikiEditor-ui-toc-expandControl').hide();}else{if(context.modules.toc.$toc.data('positionMode')=='goofy'){$.wikiEditor.modules.toc.fn.switchLayout(context);}
586586 context.$ui.find('.wikiEditor-ui-right').hide();context.$ui.find('.wikiEditor-ui-left').css('marginRight','').children().css('marginRight','');}
587 -context.modules.toc.$toc.data('positionMode','disabled');},enable:function(context){context.modules.toc.$toc.data('positionMode','regular');if(context.modules.toc.$toc.data('collapsed')){context.$ui.find('.wikiEditor-ui-toc-expandControl').show();}else{context.$ui.find('.wikiEditor-ui-right').show();$.wikiEditor.modules.toc.fn.redraw(context,$.wikiEditor.modules.toc.cfg.minimumWidth);context.modules.toc.$toc.find('div').autoEllipsis({'position':'right','tooltip':true,'restoreText':true});}},unhighlight:function(context){if(context){context.modules.toc.$toc.find('div').removeClass('current');}},update:function(context){$.wikiEditor.modules.toc.fn.unhighlight(context);var div=context.fn.beforeSelection('div.wikiEditor-toc-header');var section=div.data('section')||0;if(context.data.outline.length>0){var sectionLink=context.modules.toc.$toc.find('div.section-'+section);sectionLink.addClass('current');var relTop=sectionLink.offset().top-context.modules.toc.$toc.offset().top;var scrollTop=context.modules.toc.$toc.scrollTop();var divHeight=context.modules.toc.$toc.height();var sectionHeight=sectionLink.height();if(relTop<0)
 587+context.modules.toc.$toc.data('positionMode','disabled');},enable:function(context){context.modules.toc.$toc.data('positionMode','regular');if(context.modules.toc.$toc.data('collapsed')){context.$ui.find('.wikiEditor-ui-toc-expandControl').show();}else{context.$ui.find('.wikiEditor-ui-right').show();$.wikiEditor.modules.toc.fn.redraw(context,$.wikiEditor.modules.toc.cfg.minimumWidth);context.modules.toc.$toc.find('div').autoEllipsis({'position':'right','tooltip':true,'restoreText':true});}},unhighlight:function(context){context.modules.toc.$toc.find('div').removeClass('current');},update:function(context){$.wikiEditor.modules.toc.fn.unhighlight(context);var div=context.fn.beforeSelection('div.wikiEditor-toc-header');var section=div.data('section')||0;if(context.data.outline.length>0){var sectionLink=context.modules.toc.$toc.find('div.section-'+section);sectionLink.addClass('current');var relTop=sectionLink.offset().top-context.modules.toc.$toc.offset().top;var scrollTop=context.modules.toc.$toc.scrollTop();var divHeight=context.modules.toc.$toc.height();var sectionHeight=sectionLink.height();if(relTop<0)
588588 context.modules.toc.$toc.scrollTop(scrollTop+relTop);else if(relTop+sectionHeight>divHeight)
589589 context.modules.toc.$toc.scrollTop(scrollTop+relTop+sectionHeight-divHeight);}},collapse:function(event){var $this=$(this),context=$this.data('context');if(context.modules.toc.$toc.data('positionMode')=='goofy'){$.wikiEditor.modules.toc.fn.switchLayout(context);}
590590 var pT=$this.parent().position().top-1;context.modules.toc.$toc.data('collapsed',true);context.$ui.find('.wikiEditor-ui-left').animate({'marginRight':'-1px'},'fast',function(){$(this).css('marginRight',0);}).children().animate({'marginRight':'1px'},'fast',function(){$(this).css('marginRight',0);});context.$ui.find('.wikiEditor-ui-right').css({'marginTop':'1px','position':'absolute','left':$.wikiEditor.modules.toc.cfg.rtl?0:'auto','right':$.wikiEditor.modules.toc.cfg.rtl?'auto':0,'top':pT}).fadeOut('fast',function(){$(this).hide().css({'marginTop':'0','width':'1px'});context.$ui.find('.wikiEditor-ui-toc-expandControl').fadeIn('fast');context.fn.trigger('tocCollapse');context.fn.trigger('resize');});$.cookie('wikiEditor-'+context.instance+'-toc-width',0);return false;},expand:function(event){var $this=$(this),context=$this.data('context'),openWidth=parseFloat(context.modules.toc.$toc.data('openWidth')),availableSpace=context.$wikitext.width()-parseFloat($.wikiEditor.modules.toc.cfg.textMinimumWidth);if(availableSpace<$.wikiEditor.modules.toc.cfg.textMinmumWidth)return false;context.modules.toc.$toc.data('collapsed',false);if(availableSpace<openWidth)openWidth=availableSpace;context.$ui.find('.wikiEditor-ui-toc-expandControl').hide();context.$ui.find('.wikiEditor-ui-left').animate({'marginRight':(parseFloat(openWidth)*-1)},'fast').children().animate({'marginRight':openWidth},'fast');context.$ui.find('.wikiEditor-ui-right').show().css('marginTop','1px').animate({'width':openWidth},'fast',function(){context.$content.trigger('mouseup');$(this).css({'marginTop':'0','position':'relative','right':'auto','left':'auto','top':'auto'});context.fn.trigger('tocExpand');context.fn.trigger('resize');});$.cookie('wikiEditor-'+context.instance+'-toc-width',context.modules.toc.$toc.data('openWidth'));return false;},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;}

Status & tagging log