r61989 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61988‎ | r61989 | r61990 >
Date:20:10, 4 February 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Remove the first of every sequence of empty <p>s in Firefox only. Don't know why exactly, Trevor made me do it
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)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -72,7 +72,7 @@
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' => 102 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 103 ),
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 ),
@@ -82,10 +82,10 @@
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 2 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 219 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 220 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 219 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 220 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -445,11 +445,14 @@
446446 html = html
447447 .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements
448448 .replace( /&nbsp;/g, " " ) // We inserted these to prevent IE from collapsing spaces
449 - .replace( /\<br[^\>]*\>\s*\<\/p\>/gi, '</p>' ) // Remove trailing <br> from <p>
450 - .replace( /\<p[^\>]*\>\s*\<\/p\>/gi, '' ) // Collapse empty <p>
 449+ .replace( /\<br[^\>]*\>\<\/p\>/gi, '</p>' ) // Remove trailing <br> from <p>
451450 .replace( /\<\/p\>\s*\<p[^\>]*\>/gi, "\n" ) // Easy case for <p> conversion
452451 .replace( /\<br[^\>]*\>/gi, "\n" ) // <br> conversion
453452 .replace( /\<\/p\>(\n*)\<p[^\>]*\>/gi, "$1\n" );
 453+ // TODO: Why do we do this? Trevor knows, please explain here
 454+ if ( $.browser.firefox ) {
 455+ html = html.replace( /\<p[^\>]*\>\<\/p\>(\<p[^\>]*\>\<\/p\>)*/gi, '$1' );
 456+ }
454457 // Save leading and trailing whitespace now and restore it later. IE eats it all, and even Firefox
455458 // won't leave everything alone
456459 var leading = html.match( /^\s*/ )[0];
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6878,11 +6878,14 @@
68796879 html = html
68806880 .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements
68816881 .replace( /&nbsp;/g, " " ) // We inserted these to prevent IE from collapsing spaces
6882 - .replace( /\<br[^\>]*\>\s*\<\/p\>/gi, '</p>' ) // Remove trailing <br> from <p>
6883 - .replace( /\<p[^\>]*\>\s*\<\/p\>/gi, '' ) // Collapse empty <p>
 6882+ .replace( /\<br[^\>]*\>\<\/p\>/gi, '</p>' ) // Remove trailing <br> from <p>
68846883 .replace( /\<\/p\>\s*\<p[^\>]*\>/gi, "\n" ) // Easy case for <p> conversion
68856884 .replace( /\<br[^\>]*\>/gi, "\n" ) // <br> conversion
68866885 .replace( /\<\/p\>(\n*)\<p[^\>]*\>/gi, "$1\n" );
 6886+ // TODO: Why do we do this? Trevor knows, please explain here
 6887+ if ( $.browser.firefox ) {
 6888+ html = html.replace( /\<p[^\>]*\>\<\/p\>(\<p[^\>]*\>\<\/p\>)*/gi, '$1' );
 6889+ }
68876890 // Save leading and trailing whitespace now and restore it later. IE eats it all, and even Firefox
68886891 // won't leave everything alone
68896892 var leading = html.match( /^\s*/ )[0];
@@ -8639,8 +8642,10 @@
86408643
86418644
86428645 function createDialog( $templateDiv ){
8643 - var templateModel = $templateDiv.data('model');
8644 - console.log(templateModel.getText());
 8646+ var $wikitext = $templateDiv.children('.wikiEditor-template-text');
 8647+ //TODO: check if template model has been changed
 8648+ var templateModel = new $.wikiEditor.modules.templateEditor.fn.model( $wikitext.text() );
 8649+ $templateDiv.data('model', templateModel);
86458650 var $dialog = $("<div></div>");
86468651 var $title = $("<div>" + templateModel.getName() + "</div>").addClass('wikiEditor-template-dialog-title');
86478652 var $table = $("<table></table>")
@@ -8669,6 +8674,9 @@
86708675 $('.wikiEditor-template-dialog-value input').each( function(){
86718676 templateModel.setValue( $(this).data('name'), $(this).val() );
86728677 });
 8678+ //keep text consistent
 8679+ $wikitext.text( templateModel.getText() );
 8680+
86738681 $dialog.dialog('close');
86748682
86758683 }).text("OK").appendTo($dialog);
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -460,7 +460,8 @@
461461 event.preventDefault();return false;}).text($.wikiEditor.autoMsg(options,'title'))).appendTo(context.$tabs);}
462462 if(!context.$tabs.children().size()){addTab({'name':'wikitext','titleMsg':'wikieditor-wikitext-tab'});}
463463 addTab(options);return $('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-'+options.name).hide().appendTo(context.$ui);},'htmlToText':function(html){if(html in context.htmlToTextMap){return context.htmlToTextMap[html];}
464 -var origHTML=html;html=html.replace(/\r?\n/g,"").replace(/&nbsp;/g," ").replace(/\<br[^\>]*\>\s*\<\/p\>/gi,'</p>').replace(/\<p[^\>]*\>\s*\<\/p\>/gi,'').replace(/\<\/p\>\s*\<p[^\>]*\>/gi,"\n").replace(/\<br[^\>]*\>/gi,"\n").replace(/\<\/p\>(\n*)\<p[^\>]*\>/gi,"$1\n");var leading=html.match(/^\s*/)[0];var trailing=html.match(/\s*$/)[0];html=html.substr(leading.length,html.length-leading.length-trailing.length);var $pre=$('<pre>'+html+'</pre>');$pre.find('.wikiEditor-noinclude').each(function(){$(this).remove();});$pre.find('.wikiEditor-tab').each(function(){$(this).text("\t");});$pre.find('br').each(function(){$(this).replaceWith("\n");});$pre.find('p').each(function(){var text=$(this).text();var t=new context.fn.rawTraverser(this.firstChild,0,this,$pre.get(0)).prev();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.prev();}
 464+var origHTML=html;html=html.replace(/\r?\n/g,"").replace(/&nbsp;/g," ").replace(/\<br[^\>]*\>\<\/p\>/gi,'</p>').replace(/\<\/p\>\s*\<p[^\>]*\>/gi,"\n").replace(/\<br[^\>]*\>/gi,"\n").replace(/\<\/p\>(\n*)\<p[^\>]*\>/gi,"$1\n");if($.browser.firefox){html=html.replace(/\<p[^\>]*\>\<\/p\>(\<p[^\>]*\>\<\/p\>)*/gi,'$1');}
 465+var leading=html.match(/^\s*/)[0];var trailing=html.match(/\s*$/)[0];html=html.substr(leading.length,html.length-leading.length-trailing.length);var $pre=$('<pre>'+html+'</pre>');$pre.find('.wikiEditor-noinclude').each(function(){$(this).remove();});$pre.find('.wikiEditor-tab').each(function(){$(this).text("\t");});$pre.find('br').each(function(){$(this).replaceWith("\n");});$pre.find('p').each(function(){var text=$(this).text();var t=new context.fn.rawTraverser(this.firstChild,0,this,$pre.get(0)).prev();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.prev();}
465466 if(t){text="\n"+text;}
466467 t=new context.fn.rawTraverser(this.lastChild,0,this,$pre.get(0)).next();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.next();}
467468 if(t&&!t.inP&&t.node.nodeName=='#text'&&t.node.nodeValue.charAt(0)!='\n'&&t.node.nodeValue.charAt(0)!='\r'){text+="\n";}
@@ -589,9 +590,9 @@
590591 var model=new $.wikiEditor.modules.templateEditor.fn.model($(this).text());if(!model.isCollapsible()){return;}
591592 var $template=$(this).wrap('<div class="wikiEditor-template"></div>').addClass('wikiEditor-template-text wikiEditor-nodisplay').parent().addClass('wikiEditor-template-collapsed').data('model',model);$('<span />').addClass('wikiEditor-template-name wikiEditor-noinclude').text(model.getName()).mousedown(function(){createDialog($template);}).prependTo($template);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(toggleWikiTextEditor)).insertAfter($template.find('.wikiEditor-template-name'));function toggleWikiTextEditor(){var $template=$(this).closest('.wikiEditor-template');$template.toggleClass('wikiEditor-template-expanded').toggleClass('wikiEditor-template-collapsed');var $wikitext=$template.children('.wikiEditor-template-text');$wikitext.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());}
592593 else{$wikitext.text($template.data('model').getText());}
593 -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');console.log(templateModel.getText());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;}
 594+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 $wikitext=$templateDiv.children('.wikiEditor-template-text');var templateModel=new $.wikiEditor.modules.templateEditor.fn.model($wikitext.text());$templateDiv.data('model',templateModel);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;}
594595 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);}
595 -$("<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();return false;};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());}
 596+$("<button></button>").click(function(){$('.wikiEditor-template-dialog-value input').each(function(){templateModel.setValue($(this).data('name'),$(this).val());});$wikitext.text(templateModel.getText());$dialog.dialog('close');}).text("OK").appendTo($dialog);$dialog.dialog();return false;};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());}
596597 else{$template.children('.wikiEditor-template-text').children('.wikiEditor-template-inner-text').text($template.data('model').getText().replace(/\{\{/,'').replace(/\}\}$/,''));}
597598 return false;}
598599 function noEdit(){return false;}});},getTemplateInfo:function(templateName){var templateInfo='';return $(templateInfo);},model:function(wikitext){var collapsible=true;function Param(name,value,number,nameIndex,equalsIndex,valueIndex){this.name=name;this.value=value;this.number=number;this.nameIndex=nameIndex;this.equalsIndex=equalsIndex;this.valueIndex=valueIndex;}

Status & tagging log