r61992 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61991‎ | r61992 | r61993 >
Date:22:00, 4 February 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Sort of fix Opera bug where putting the cursor on an empty line unhighlights the TOC. We have no way of figuring out where the cursor is, but the least we can do in this case is not change the highlight state rather than unhighlighting
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
@@ -72,20 +72,20 @@
7373 array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
7474 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 7 ),
7575 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 27 ),
76 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 104 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 105 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 29 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 47 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 12 ),
80 - array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 78 ),
 80+ array( 'src' => 'js/plugins/jquery.wikiEditor.toc.js', 'version' => 79 ),
8181 array( 'src' => 'js/plugins/jquery.wikiEditor.preview.js', 'version' => 10 ),
8282 array( 'src' => 'js/plugins/jquery.wikiEditor.templateEditor.js', 'version' => 17 ),
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 221 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 222 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 221 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 222 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js
@@ -257,9 +257,13 @@
258258 * @param {Object} context
259259 */
260260 update: function( context ) {
 261+ var div = context.fn.beforeSelection( 'wikiEditor-toc-header' );
 262+ if ( div === null ) {
 263+ // beforeSelection couldn't figure it out, keep the old highlight state
 264+ return;
 265+ }
 266+
261267 $.wikiEditor.modules.toc.fn.unhighlight( context );
262 -
263 - var div = context.fn.beforeSelection( 'wikiEditor-toc-header' );
264268 var section = div.data( 'section' ) || 0;
265269 if ( context.data.outline.length > 0 ) {
266270 var sectionLink = context.modules.toc.$toc.find( 'div.section-' + section );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -833,13 +833,13 @@
834834 * Get the first element before the selection that's in a certain class
835835 * @param classname Class to match. Defaults to '', meaning any class
836836 * @param strict If true, the element the selection starts in cannot match (default: false)
837 - * @return jQuery object
 837+ * @return jQuery object or null if unknown
838838 */
839839 'beforeSelection': function( classname, strict ) {
840840 if ( typeof classname == 'undefined' ) {
841841 classname = '';
842842 }
843 - var e, offset;
 843+ var e = null, offset = null;
844844 if ( context.$iframe[0].contentWindow.getSelection ) {
845845 // Firefox and Opera
846846 var selection = context.$iframe[0].contentWindow.getSelection();
@@ -850,9 +850,17 @@
851851 e = selection.getRangeAt( 0 ).startContainer;
852852 offset = selection.getRangeAt( 0 ).startOffset;
853853 } else {
854 - return $( [] );
 854+ return null;
855855 }
856 - } else if ( context.$iframe[0].contentWindow.document.selection ) {
 856+
 857+ // When the cursor is on an empty line, Opera gives us a bogus range object with
 858+ // startContainer=endContainer=body and startOffset=endOffset=1
 859+ var body = context.$iframe[0].contentWindow.document.body;
 860+ if ( $.browser.opera && e == body && offset == 1 ) {
 861+ return null;
 862+ }
 863+ }
 864+ if ( !e && context.$iframe[0].contentWindow.document.selection ) {
857865 // IE
858866 // Because there's nothing like range.startContainer in IE, we need to do a DOM traversal
859867 // to find the element the start of the selection is in
@@ -864,14 +872,14 @@
865873 try {
866874 range2.setEndPoint( 'EndToStart', range );
867875 } catch ( ex ) {
868 - return $( [] );
 876+ return null;
869877 }
870878 var seekPos = context.fn.htmlToText( range2.htmlText ).length;
871879 var offset = context.fn.getOffset( seekPos );
872880 e = offset ? offset.node : null;
873881 offset = offset ? offset.offset : null;
874882 if ( !e ) {
875 - return $( [] );
 883+ return null;
876884 }
877885 }
878886 if ( e.nodeName != '#text' ) {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -7266,13 +7266,13 @@
72677267 * Get the first element before the selection that's in a certain class
72687268 * @param classname Class to match. Defaults to '', meaning any class
72697269 * @param strict If true, the element the selection starts in cannot match (default: false)
7270 - * @return jQuery object
 7270+ * @return jQuery object or null if unknown
72717271 */
72727272 'beforeSelection': function( classname, strict ) {
72737273 if ( typeof classname == 'undefined' ) {
72747274 classname = '';
72757275 }
7276 - var e, offset;
 7276+ var e = null, offset = null;
72777277 if ( context.$iframe[0].contentWindow.getSelection ) {
72787278 // Firefox and Opera
72797279 var selection = context.$iframe[0].contentWindow.getSelection();
@@ -7283,9 +7283,17 @@
72847284 e = selection.getRangeAt( 0 ).startContainer;
72857285 offset = selection.getRangeAt( 0 ).startOffset;
72867286 } else {
7287 - return $( [] );
 7287+ return null;
72887288 }
7289 - } else if ( context.$iframe[0].contentWindow.document.selection ) {
 7289+
 7290+ // When the cursor is on an empty line, Opera gives us a bogus range object with
 7291+ // startContainer=endContainer=body and startOffset=endOffset=1
 7292+ var body = context.$iframe[0].contentWindow.document.body;
 7293+ if ( $.browser.opera && e == body && offset == 1 ) {
 7294+ return null;
 7295+ }
 7296+ }
 7297+ if ( !e && context.$iframe[0].contentWindow.document.selection ) {
72907298 // IE
72917299 // Because there's nothing like range.startContainer in IE, we need to do a DOM traversal
72927300 // to find the element the start of the selection is in
@@ -7297,14 +7305,14 @@
72987306 try {
72997307 range2.setEndPoint( 'EndToStart', range );
73007308 } catch ( ex ) {
7301 - return $( [] );
 7309+ return null;
73027310 }
73037311 var seekPos = context.fn.htmlToText( range2.htmlText ).length;
73047312 var offset = context.fn.getOffset( seekPos );
73057313 e = offset ? offset.node : null;
73067314 offset = offset ? offset.offset : null;
73077315 if ( !e ) {
7308 - return $( [] );
 7316+ return null;
73097317 }
73107318 }
73117319 if ( e.nodeName != '#text' ) {
@@ -9357,9 +9365,13 @@
93589366 * @param {Object} context
93599367 */
93609368 update: function( context ) {
 9369+ var div = context.fn.beforeSelection( 'wikiEditor-toc-header' );
 9370+ if ( div === null ) {
 9371+ // beforeSelection couldn't figure it out, keep the old highlight state
 9372+ return;
 9373+ }
 9374+
93619375 $.wikiEditor.modules.toc.fn.unhighlight( context );
9362 -
9363 - var div = context.fn.beforeSelection( 'wikiEditor-toc-header' );
93649376 var section = div.data( 'section' ) || 0;
93659377 if ( context.data.outline.length > 0 ) {
93669378 var sectionLink = context.modules.toc.$toc.find( 'div.section-' + section );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -496,8 +496,10 @@
497497 return context.$textarea;},'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&&!$element.is('body')){y=parentHtml.scrollTop()>0?y+html.scrollTop()-parentHtml.scrollTop():y;y=parentBody.scrollTop()>0?y+body.scrollTop()-parentBody.scrollTop():y;}
498498 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);}
499499 $element.trigger('scrollToTop');},'beforeSelection':function(classname,strict){if(typeof classname=='undefined'){classname='';}
500 -var e,offset;if(context.$iframe[0].contentWindow.getSelection){var selection=context.$iframe[0].contentWindow.getSelection();if(selection.baseNode!==null){e=selection.getRangeAt(0).startContainer;offset=selection.getRangeAt(0).startOffset;}else{return $([]);}}else if(context.$iframe[0].contentWindow.document.selection){var range=context.$iframe[0].contentWindow.document.selection.createRange();var range2=context.$iframe[0].contentWindow.document.body.createTextRange();try{range2.setEndPoint('EndToStart',range);}catch(ex){return $([]);}
501 -var seekPos=context.fn.htmlToText(range2.htmlText).length;var offset=context.fn.getOffset(seekPos);e=offset?offset.node:null;offset=offset?offset.offset:null;if(!e){return $([]);}}
 500+var e=null,offset=null;if(context.$iframe[0].contentWindow.getSelection){var selection=context.$iframe[0].contentWindow.getSelection();if(selection.baseNode!==null){e=selection.getRangeAt(0).startContainer;offset=selection.getRangeAt(0).startOffset;}else{return null;}
 501+var body=context.$iframe[0].contentWindow.document.body;if($.browser.opera&&e==body&&offset==1){return null;}}
 502+if(!e&&context.$iframe[0].contentWindow.document.selection){var range=context.$iframe[0].contentWindow.document.selection.createRange();var range2=context.$iframe[0].contentWindow.document.body.createTextRange();try{range2.setEndPoint('EndToStart',range);}catch(ex){return null;}
 503+var seekPos=context.fn.htmlToText(range2.htmlText).length;var offset=context.fn.getOffset(seekPos);e=offset?offset.node:null;offset=offset?offset.offset:null;if(!e){return null;}}
502504 if(e.nodeName!='#text'){var newE=e.firstChild;for(var i=0;i<offset-1&&newE;i++){newE=newE.nextSibling;}
503505 while(newE&&newE.lastChild){newE=newE.lastChild;}
504506 e=newE||e;}
@@ -637,7 +639,8 @@
638640 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':''});}
639641 $.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);}
640642 context.$ui.find('.wikiEditor-ui-right').hide();context.$ui.find('.wikiEditor-ui-left').css('marginRight','').children().css('marginRight','');}
641 -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('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)
 643+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){var div=context.fn.beforeSelection('wikiEditor-toc-header');if(div===null){return;}
 644+$.wikiEditor.modules.toc.fn.unhighlight(context);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)
642645 context.modules.toc.$toc.scrollTop(scrollTop+relTop);else if(relTop+sectionHeight>divHeight)
643646 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);}
644647 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