r61692 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61691‎ | r61692 | r61693 >
Date:22:15, 29 January 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Fix IE issues with whitespace collapsing with the most ridiculous code ever
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' => 26 ),
76 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 88 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 89 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 26 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 45 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 11 ),
@@ -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' => 201 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 202 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 201 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 202 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -368,9 +368,10 @@
369369 html
370370 .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements
371371 .replace( / /g, " " ) // We inserted these to prevent IE from collapsing spaces
372 - .replace( /\<\/p\>\<p\>/gi, "\n" ) // Easy case for <p> conversion
373372 // Don't convert <br>s at the very start or end to prevent newline collapsing
374373 .replace( /(?!^)\<br[^\>]*\>(?!$)/gi, "\n" ) // Easy case for <br> conversion
 374+ .replace( /\<\/p\>\<p\>/gi, "\n" ) // Easy case for <p> conversion
 375+ .replace( /\<\/p\>(\n*)\<p\>/gi, "$1\n" )
375376 + '</pre>' );
376377 // TODO: Optimize this, maybe by converting <br>->\n when not at the beginning or end
377378 $pre.find( '.wikiEditor-noinclude' ).each( function() { $( this ).remove(); } );
@@ -401,12 +402,18 @@
402403 while ( t && t.node.nodeName != '#text' && t.node.nodeName != 'BR' && t.node.nodeName != 'P' ) {
403404 t = t.next();
404405 }
405 - if ( t && !t.inP && t.node.nodeName != 'P' ) {
 406+ if ( t && !t.inP && t.node.nodeName == '#text' && t.node.nodeValue[0] != '\n'
 407+ && t.node.nodeValue[0] != '\r' ) {
406408 text += "\n";
407409 }
408410 $( this ).text( text );
409411 }
410412 } );
 413+ // IE aggressively collapses whitespace in .text() after having done DOM manipulation,
 414+ // but for some crazy reason this does work
 415+ if ( $.browser.msie ) {
 416+ $pre = $( '<pre>' + $pre.html() + '</pre>' );
 417+ }
411418 return $pre.text();
412419 },
413420
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6792,9 +6792,10 @@
67936793 html
67946794 .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements
67956795 .replace( /&nbsp;/g, " " ) // We inserted these to prevent IE from collapsing spaces
6796 - .replace( /\<\/p\>\<p\>/gi, "\n" ) // Easy case for <p> conversion
67976796 // Don't convert <br>s at the very start or end to prevent newline collapsing
67986797 .replace( /(?!^)\<br[^\>]*\>(?!$)/gi, "\n" ) // Easy case for <br> conversion
 6798+ .replace( /\<\/p\>\<p\>/gi, "\n" ) // Easy case for <p> conversion
 6799+ .replace( /\<\/p\>(\n*)\<p\>/gi, "$1\n" )
67996800 + '</pre>' );
68006801 // TODO: Optimize this, maybe by converting <br>->\n when not at the beginning or end
68016802 $pre.find( '.wikiEditor-noinclude' ).each( function() { $( this ).remove(); } );
@@ -6825,12 +6826,18 @@
68266827 while ( t && t.node.nodeName != '#text' && t.node.nodeName != 'BR' && t.node.nodeName != 'P' ) {
68276828 t = t.next();
68286829 }
6829 - if ( t && !t.inP && t.node.nodeName != 'P' ) {
 6830+ if ( t && !t.inP && t.node.nodeName == '#text' && t.node.nodeValue[0] != '\n'
 6831+ && t.node.nodeValue[0] != '\r' ) {
68306832 text += "\n";
68316833 }
68326834 $( this ).text( text );
68336835 }
68346836 } );
 6837+ // IE aggressively collapses whitespace in .text() after having done DOM manipulation,
 6838+ // but for some crazy reason this does work
 6839+ if ( $.browser.msie ) {
 6840+ $pre = $( '<pre>' + $pre.html() + '</pre>' );
 6841+ }
68356842 return $pre.text();
68366843 },
68376844
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -449,12 +449,13 @@
450450 event.preventDefault();return false;}).text($.wikiEditor.autoMsg(options,'title'))).appendTo(context.$tabs);}
451451 if(!context.$tabs.children().size()){addTab({'name':'wikitext','titleMsg':'wikieditor-wikitext-tab'});}
452452 addTab(options);return $('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-'+options.name).hide().appendTo(context.$ui);},'htmlToText':function(html){var $pre=$('<pre>'+
453 -html.replace(/\r?\n/g,"").replace(/&nbsp;/g," ").replace(/\<\/p\>\<p\>/gi,"\n").replace(/(?!^)\<br[^\>]*\>(?!$)/gi,"\n")
 453+html.replace(/\r?\n/g,"").replace(/&nbsp;/g," ").replace(/(?!^)\<br[^\>]*\>(?!$)/gi,"\n").replace(/\<\/p\>\<p\>/gi,"\n").replace(/\<\/p\>(\n*)\<p\>/gi,"$1\n")
454454 +'</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(){if(this.previousSibling||this.parentNode!=$pre.get(0)){var text=$(this).text();var t=new context.fn.rawTraverser(this.firstChild,-10,this).prev();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.prev();}
455455 if(t){text="\n"+text;}
456456 t=new context.fn.rawTraverser(this.lastChild,-10,this).next();while(t&&t.node.nodeName!='#text'&&t.node.nodeName!='BR'&&t.node.nodeName!='P'){t=t.next();}
457 -if(t&&!t.inP&&t.node.nodeName!='P'){text+="\n";}
458 -$(this).text(text);}});return $pre.text();},'getContents':function(){return context.fn.htmlToText(context.$content.html());},'getSelection':function(){var retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();}else if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();}
 457+if(t&&!t.inP&&t.node.nodeName=='#text'&&t.node.nodeValue[0]!='\n'&&t.node.nodeValue[0]!='\r'){text+="\n";}
 458+$(this).text(text);}});if($.browser.msie){$pre=$('<pre>'+$pre.html()+'</pre>');}
 459+return $pre.text();},'getContents':function(){return context.fn.htmlToText(context.$content.html());},'getSelection':function(){var retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();}else if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();}
459460 if(typeof retval.text!='undefined'){retval=context.fn.htmlToText(retval.htmlText);}else if(retval.toString){retval=retval.toString();}
460461 return retval;},'encapsulateSelection':function(options){var selText=$(this).textSelection('getSelection');var selTextArr;var selectAfter=false;var pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else if(options.replace){selText=options.peri;}else if(selText.charAt(selText.length-1)==' '){selText=selText.substring(0,selText.length-1);post+=' ';}
461462 if(options.splitlines){selTextArr=selText.split(/\n/);}

Status & tagging log