r61504 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61503‎ | r61504 | r61505 >
Date:23:09, 25 January 2010
Author:tparscal
Status:ok (Comments)
Tags:
Comment:
Added an insurance policy against IE loosing it's mind. Aparently sometimes the unhighlight function is called twice instead of once, the first time with an undefined parameter, the second time properly. This helps prevent the browser from choking, but it would be interesting to figure out what's causing this. No user interaction is broken by preventing this double call from running the first time.
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
@@ -155,7 +155,7 @@
156156 array(
157157 'src' => 'js/plugins/jquery.wikiEditor.toc.js',
158158 'class' => 'j.wikiEditor.modules.toc',
159 - 'version' => 70
 159+ 'version' => 71
160160 ),
161161 array(
162162 'src' => 'js/plugins/jquery.wikiEditor.preview.js',
@@ -173,10 +173,10 @@
174174 'version' => 1 ),
175175 ),
176176 'combined' => array(
177 - array( 'src' => 'js/plugins.combined.js', 'version' => 173 ),
 177+ array( 'src' => 'js/plugins.combined.js', 'version' => 172 ),
178178 ),
179179 'minified' => array(
180 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 173 ),
 180+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 172 ),
181181 ),
182182 ),
183183 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toc.js
@@ -242,7 +242,11 @@
243243 }
244244 },
245245 unhighlight: function( context ) {
246 - context.modules.toc.$toc.find( 'div' ).removeClass( 'current' );
 246+ // FIXME: In IE, sometimes the context is undefined here - investigate this when you have time please! In the
 247+ // mean time, the user interaction is working just fine
 248+ if ( context ) {
 249+ context.modules.toc.$toc.find( 'div' ).removeClass( 'current' );
 250+ }
247251 },
248252 /**
249253 * Highlight the section the cursor is currently within
@@ -398,7 +402,6 @@
399403 'start': 0,
400404 'startContainer': $(this).data( 'wrapper' )
401405 } );
402 -
403406 // Highlight the clicked link
404407 $.wikiEditor.modules.toc.fn.unhighlight( context );
405408 $( this ).addClass( 'current' );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -8134,6 +8134,7 @@
81358135 $( this ).html()
81368136 .replace( /\{\{/, '<span class="wikiEditor-template-start">{{</span><span class="wikiEditor-template-inner-text">' )
81378137 .replace( /\}\}$/, '</span><span class="wikiEditor-template-end">}}</span>' ) ) //grab the *last* {{
 8138+ .css('visibility', 'hidden')
81388139 .parent()
81398140 .addClass( 'wikiEditor-template-collapsed' )
81408141 .data( 'model', model );
@@ -8157,8 +8158,7 @@
81588159 .append( $( '<span>F</span>' ) )
81598160 .mousedown( function(){createDialog($template); return false;} ));
81608161
8161 -
8162 -
 8162+
81638163 // Expand
81648164 function expandTemplate( $displayDiv ) {
81658165 // Housekeeping
@@ -8515,7 +8515,7 @@
85168516 doneParsing = true;
85178517 }
85188518 nameMatch = sanatizedStr.substring( 0, divider ).match( /[^\s]/ );
8519 - if ( nameMatch != undefined ) {
 8519+ if ( nameMatch != null ) {
85208520 ranges.push( new Range( 0 ,nameMatch.index ) ); //whitespace and squiggles upto the name
85218521 nameEndMatch = sanatizedStr.substring( 0 , divider ).match( /[^\s]\s*$/ ); //last nonwhitespace character
85228522 templateNameIndex = ranges.push( new Range( nameMatch.index,
@@ -8524,6 +8524,10 @@
85258525 ranges[templateNameIndex].old = wikitext.substring( ranges[templateNameIndex].begin,
85268526 ranges[templateNameIndex].end );
85278527 }
 8528+ else{
 8529+ ranges.push(new Range(0,0));
 8530+ ranges[templateNameIndex].old = "";
 8531+ }
85288532 params.push( ranges[templateNameIndex].old ); //put something in params (0)
85298533 /*
85308534 * Start looping over params
@@ -8871,7 +8875,11 @@
88728876 }
88738877 },
88748878 unhighlight: function( context ) {
8875 - context.modules.toc.$toc.find( 'div' ).removeClass( 'current' );
 8879+ // FIXME: In IE, sometimes the context is undefined here - investigate this when you have time please! In the
 8880+ // mean time, the user interaction is working just fine
 8881+ if ( context ) {
 8882+ context.modules.toc.$toc.find( 'div' ).removeClass( 'current' );
 8883+ }
88768884 },
88778885 /**
88788886 * Highlight the section the cursor is currently within
@@ -9027,7 +9035,6 @@
90289036 'start': 0,
90299037 'startContainer': $(this).data( 'wrapper' )
90309038 } );
9031 -
90329039 // Highlight the clicked link
90339040 $.wikiEditor.modules.toc.fn.unhighlight( context );
90349041 $( this ).addClass( 'current' );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -544,7 +544,7 @@
545545 $('#wikiEditor-'+context.instance+'-dialog-watch').attr('checked','checked');$(this).find('form').submit(function(e){$(this).closest('.ui-dialog').find('button:first').click();e.preventDefault();});},dialog:{buttons:{'wikieditor-publish-dialog-publish':function(){var minorChecked=$('#wikiEditor-'+context.instance+'-dialog-minor').is(':checked')?'checked':'';var watchChecked=$('#wikiEditor-'+context.instance+'-dialog-watch').is(':checked')?'checked':'';$('#wpMinoredit').attr('checked',minorChecked);$('#wpWatchthis').attr('checked',watchChecked);$('#wpSummary').val($j('#wikiEditor-'+context.instance+'-dialog-summary').val());$('#editform').submit();},'wikieditor-publish-dialog-goback':function(){$(this).dialog('close');}},open:function(){$('#wikiEditor-'+context.instance+'-dialog-summary').focus();},width:500},resizeme:false}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-publish','action':function(){$('#'+dialogID).dialog('open');return false;}});context.fn.addButton({'captionMsg':'wikieditor-publish-button-cancel','action':function(){}});}}};})(jQuery);(function($){$.wikiEditor.modules.templateEditor={evt:{mark:function(context,event){var markers=context.modules.highlight.markers;var tokenArray=context.modules.highlight.tokenArray;var level=0;var tokenIndex=0;while(tokenIndex<tokenArray.length){while(tokenIndex<tokenArray.length&&tokenArray[tokenIndex].label!='TEMPLATE_BEGIN'){tokenIndex++;}
546546 if(tokenIndex<tokenArray.length){var beginIndex=tokenIndex;var endIndex=-1;var openTemplates=1;var templatesMatched=false;while(tokenIndex<tokenArray.length-1&&endIndex==-1){tokenIndex++;if(tokenArray[tokenIndex].label=='TEMPLATE_BEGIN'){openTemplates++;}else if(tokenArray[tokenIndex].label=='TEMPLATE_END'){openTemplates--;if(openTemplates==0){endIndex=tokenIndex;}}}
547547 if(endIndex!=-1){markers.push({start:tokenArray[beginIndex].offset,end:tokenArray[endIndex].offset,anchor:'wrap',afterWrap:$.wikiEditor.modules.templateEditor.fn.stylize,beforeUnwrap:function(node){$(node).data('display').remove();},onSkip:function(){},getAnchor:function(ca1,ca2){return $(ca1.parentNode).is('div.wikiEditor-template-text')&&$(ca1.parentNode.previousSibling).is('ul.wikiEditor-template-modes')&&ca1.parentNode.nextSibling==null?ca1.parentNode:null;}});}else{tokenArray[beginIndex].label='TEMPLATE_FALSE_BEGIN';tokenIndex=beginIndex;}}}}},exp:[{'regex':/{{/,'label':"TEMPLATE_BEGIN"},{'regex':/}}/,'label':"TEMPLATE_END",'markAfter':true}],cfg:{},fn:{create:function(context,config){context.modules.templateEditor={};},stylize:function(wrappedTemplate){$(wrappedTemplate).each(function(){if(typeof $(this).data('model')!='undefined'){return;}
548 -var model=new $.wikiEditor.modules.templateEditor.fn.model($(this).text());var $template=$(this).wrap('<div class="wikiEditor-template"></div>').addClass('wikiEditor-template-text wikiEditor-nodisplay').html($(this).html().replace(/\{\{/,'<span class="wikiEditor-template-start">{{</span><span class="wikiEditor-template-inner-text">').replace(/\}\}$/,'</span><span class="wikiEditor-template-end">}}</span>')).parent().addClass('wikiEditor-template-collapsed').data('model',model);$('<span />').addClass('wikiEditor-template-name wikiEditor-noinclude').text(model.getName()).mousedown(noEdit).prependTo($template);$template.find('.wikiEditor-template-end, .wikiEditor-template-start').mousedown(toggleWikiText);var $options=$('<ul />').addClass('wikiEditor-template-modes wikiEditor-noinclude').append($('<li />').addClass('wikiEditor-template-action-wikiText').append($('<img />').attr('src',$.wikiEditor.imgPath+'templateEditor/'+'wiki-text.png')).mousedown(toggleWikiText)).insertAfter($template.find('.wikiEditor-template-name'));$options.append($('<li />').addClass('wikiEditor-template-action-form').append($('<span>F</span>')).mousedown(function(){createDialog($template);return false;}));function expandTemplate($displayDiv){$displayDiv.removeClass('wikiEditor-template-collapsed');$displayDiv.addClass('wikiEditor-template-expanded');$displayDiv.unbind('mousedown');$keyValueTable=$('<table />').appendTo($displayDiv);$header_row=$('<tr />').appendTo($keyValueTable);$('<th />').attr('colspan','2').text(model.getName()).appendTo($header_row);for(param in model.getAllParamNames()){$keyVal_row=$('<tr />').appendTo($keyValueTable);$('<td />').text(param).appendTo($keyVal_row);$('<td />').text(model.getValue(param)).appendTo($keyVal_row);}};function collapseTemplate($displayDiv){$displayDiv.addClass('wikiEditor-template-collapsed');$displayDiv.removeClass('wikiEditor-template-expanded');$displayDiv.text(model.getName());};function createDialog($templateDiv){var templateModel=$templateDiv.data('model');var $dialog=$("<div></div>");var $title=$("<div>"+templateModel.getName()+"</div>").addClass('wikiEditor-template-dialog-title');var $table=$("<table></table>").addClass('wikiEditor-template-dialog-table').appendTo($dialog);var allInitialParams=templateModel.getAllInitialParams();for(var paramIndex in allInitialParams){var param=allInitialParams[paramIndex];if(typeof param.name=='undefined'){continue;}
 548+var model=new $.wikiEditor.modules.templateEditor.fn.model($(this).text());var $template=$(this).wrap('<div class="wikiEditor-template"></div>').addClass('wikiEditor-template-text wikiEditor-nodisplay').html($(this).html().replace(/\{\{/,'<span class="wikiEditor-template-start">{{</span><span class="wikiEditor-template-inner-text">').replace(/\}\}$/,'</span><span class="wikiEditor-template-end">}}</span>')).css('visibility','hidden').parent().addClass('wikiEditor-template-collapsed').data('model',model);$('<span />').addClass('wikiEditor-template-name wikiEditor-noinclude').text(model.getName()).mousedown(noEdit).prependTo($template);$template.find('.wikiEditor-template-end, .wikiEditor-template-start').mousedown(toggleWikiText);var $options=$('<ul />').addClass('wikiEditor-template-modes wikiEditor-noinclude').append($('<li />').addClass('wikiEditor-template-action-wikiText').append($('<img />').attr('src',$.wikiEditor.imgPath+'templateEditor/'+'wiki-text.png')).mousedown(toggleWikiText)).insertAfter($template.find('.wikiEditor-template-name'));$options.append($('<li />').addClass('wikiEditor-template-action-form').append($('<span>F</span>')).mousedown(function(){createDialog($template);return false;}));function expandTemplate($displayDiv){$displayDiv.removeClass('wikiEditor-template-collapsed');$displayDiv.addClass('wikiEditor-template-expanded');$displayDiv.unbind('mousedown');$keyValueTable=$('<table />').appendTo($displayDiv);$header_row=$('<tr />').appendTo($keyValueTable);$('<th />').attr('colspan','2').text(model.getName()).appendTo($header_row);for(param in model.getAllParamNames()){$keyVal_row=$('<tr />').appendTo($keyValueTable);$('<td />').text(param).appendTo($keyVal_row);$('<td />').text(model.getValue(param)).appendTo($keyVal_row);}};function collapseTemplate($displayDiv){$displayDiv.addClass('wikiEditor-template-collapsed');$displayDiv.removeClass('wikiEditor-template-expanded');$displayDiv.text(model.getName());};function createDialog($templateDiv){var templateModel=$templateDiv.data('model');var $dialog=$("<div></div>");var $title=$("<div>"+templateModel.getName()+"</div>").addClass('wikiEditor-template-dialog-title');var $table=$("<table></table>").addClass('wikiEditor-template-dialog-table').appendTo($dialog);var allInitialParams=templateModel.getAllInitialParams();for(var paramIndex in allInitialParams){var param=allInitialParams[paramIndex];if(typeof param.name=='undefined'){continue;}
549549 var $paramRow=$("<tr></tr>").addClass('wikiEditor-template-dialog-row');var $paramName=$("<td></td>").addClass('wikiEditor-template-dialog-name').text(param.name);var $paramVal=$("<td></td>").addClass('wikiEditor-template-dialog-value');var $paramInput=$("<input></input>").data('name',param.name).val(templateModel.getValue(param.name));$paramVal.append($paramInput);$paramRow.append($paramName).append($paramVal);$table.append($paramRow);}
550550 $("<button></button>").click(function(){$('.wikiEditor-template-dialog-value input').each(function(){templateModel.setValue($(this).data('name'),$(this).val());});$dialog.dialog('close');}).text("OK").appendTo($dialog);$dialog.dialog();};function toggleWikiText(){var $template=$(this).closest('.wikiEditor-template');$template.toggleClass('wikiEditor-template-collapsed').toggleClass('wikiEditor-template-expanded').children('.wikiEditor-template-text, .wikiEditor-template-name, .wikiEditor-template-modes').toggleClass('wikiEditor-nodisplay');if($template.hasClass('wikiEditor-template-collapsed')){var model=new $.wikiEditor.modules.templateEditor.fn.model($template.children('.wikiEditor-template-text').text());$template.data('model',model);$template.children('.wikiEditor-template-name').text(model.getName());}
551551 else{$template.children('.wikiEditor-template-text').children('.wikiEditor-template-inner-text').text($template.data('model').getText().replace(/\{\{/,'').replace(/\}\}$/,''));}
@@ -568,7 +568,8 @@
569569 while(sanatizedStr.indexOf('[[')!=-1){startIndex=sanatizedStr.indexOf('[[')+1;openBraces=2;endIndex=startIndex;while((openBraces>0)&&(endIndex<sanatizedStr.length)){var brace=sanatizedStr[++endIndex];openBraces+=brace==']'?-1:brace=='['?1:0;}
570570 sanatizedSegment=sanatizedStr.substring(startIndex,endIndex).replace(/[\[\]|=]/g,'X');sanatizedStr=sanatizedStr.substring(0,startIndex)+sanatizedSegment+sanatizedStr.substring(endIndex);}
571571 var ranges=[];var params=[];var templateNameIndex=0;var doneParsing=false;oldDivider=0;divider=sanatizedStr.indexOf('|',oldDivider);if(divider==-1){divider=sanatizedStr.length;doneParsing=true;}
572 -nameMatch=sanatizedStr.substring(0,divider).match(/[^\s]/);if(nameMatch!=undefined){ranges.push(new Range(0,nameMatch.index));nameEndMatch=sanatizedStr.substring(0,divider).match(/[^\s]\s*$/);templateNameIndex=ranges.push(new Range(nameMatch.index,nameEndMatch.index+1));templateNameIndex--;ranges[templateNameIndex].old=wikitext.substring(ranges[templateNameIndex].begin,ranges[templateNameIndex].end);}
 572+nameMatch=sanatizedStr.substring(0,divider).match(/[^\s]/);if(nameMatch!=null){ranges.push(new Range(0,nameMatch.index));nameEndMatch=sanatizedStr.substring(0,divider).match(/[^\s]\s*$/);templateNameIndex=ranges.push(new Range(nameMatch.index,nameEndMatch.index+1));templateNameIndex--;ranges[templateNameIndex].old=wikitext.substring(ranges[templateNameIndex].begin,ranges[templateNameIndex].end);}
 573+else{ranges.push(new Range(0,0));ranges[templateNameIndex].old="";}
573574 params.push(ranges[templateNameIndex].old);var currentParamNumber=0;var valueEndIndex=ranges[templateNameIndex].end;var paramsByName=[];while(!doneParsing){currentParamNumber++;oldDivider=divider;divider=sanatizedStr.indexOf('|',oldDivider+1);if(divider==-1){divider=sanatizedStr.length;doneParsing=true;}
574575 currentField=sanatizedStr.substring(oldDivider+1,divider);if(currentField.indexOf('=')==-1){valueBegin=currentField.match(/\S+/);if(valueBegin==null){continue;}
575576 valueBeginIndex=valueBegin.index+oldDivider+1;valueEnd=currentField.match(/[^\s]\s*$/);if(valueEnd==null){continue;}
@@ -588,7 +589,7 @@
589590 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':''});}
590591 $.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);}
591592 context.$ui.find('.wikiEditor-ui-right').hide();context.$ui.find('.wikiEditor-ui-left').css('marginRight','').children().css('marginRight','');}
592 -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)
 593+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)
593594 context.modules.toc.$toc.scrollTop(scrollTop+relTop);else if(relTop+sectionHeight>divHeight)
594595 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);}
595596 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;}

Follow-up revisions

RevisionCommit summaryAuthorDate
r61517UsabilityInitiative: Bump and recombine for r61508, whitespace changes for r6...catrope14:20, 26 January 2010

Comments

#Comment by Catrope (talk | contribs)   14:07, 26 January 2010
-				array( 'src' => 'js/plugins.combined.js', 'version' => 173 ),
+				array( 'src' => 'js/plugins.combined.js', 'version' => 172 ),

That's an interesting way of incrementing a value :)

Status & tagging log