r65646 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65645‎ | r65646 | r65647 >
Date:23:16, 28 April 2010
Author:pdhanda
Status:ok
Tags:
Comment:
Except for the cursor position in same cases and MSWord lists. Paste mostly works.
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.delayedBind.js', 'version' => 1 ),
7474 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 11 ),
7575 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 30 ),
76 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 182 ),
 76+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 183 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 52 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 59 ),
7979 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 24 ),
@@ -82,10 +82,10 @@
8383 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 5 ),
8484 ),
8585 'combined' => array(
86 - array( 'src' => 'js/plugins.combined.js', 'version' => 386 ),
 86+ array( 'src' => 'js/plugins.combined.js', 'version' => 387 ),
8787 ),
8888 'minified' => array(
89 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 386 ),
 89+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 387 ),
9090 ),
9191 ),
9292 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -444,57 +444,58 @@
445445 $(this).replaceWith( this.childNodes );
446446 } );
447447
 448+ // If the pasted content is plain text then wrap it in a <p> and adjust the <br> accordingly
448449 var pasteContent = context.fn.getOffset( cursorPos[0] ).node;
449450 var removeNextBR = false
450451 while ( pasteContent != null && ! $( pasteContent ).hasClass( 'wikiEditor' ) ) {
451452 var currentNode = pasteContent;
452453 pasteContent = pasteContent.nextSibling;
453 - if ( currentNode.nodeName == '#text' && currentNode.nodeValue == currentNode.wholeText ) {
454 - $( currentNode ).wrap( $( '<p></p>' ) );
 454+ if ( currentNode.nodeName == '#text' && currentNode.nodeValue == currentNode.wholeText ) {
 455+ var pWrapper = $( '<p></p>' ).addClass( 'wikiEditor' );
 456+ $( currentNode ).wrap( pWrapper );
455457 $( currentNode ).addClass( 'wikiEditor' );
456458 removeNextBR = true;
457 - } else if ( currentNode.nodeName == 'SPAN' ) {
458 - var text = $( currentNode ).text();
459 - if ( text.length == 0 ) {
460 - $( currentNode ).remove();
461 - }
 459+ } else if ( currentNode.nodeName == 'BR' && removeNextBR ) {
 460+ $( currentNode ).remove();
462461 removeNextBR = false;
463 - } else if ( currentNode.nodeName == 'BR' ) {
464 - if (removeNextBR ) {
465 - $( currentNode ).remove();
466 - } else {
467 - $( currentNode ).addClass( 'wikiEditor' );
468 - }
469 - removeNextBR = false;
470462 } else {
471463 removeNextBR = false;
472464 }
473 - }
474 -
 465+ }
475466 var $selection = context.$content.find( ':not(.wikiEditor)' );
476467 while ( $selection.length && $selection.length > 0 ) {
477468 var $currentElement = $selection.eq( 0 );
478469 while ( !$currentElement.parent().is( 'body' ) && !$currentElement.parent().is( '.wikiEditor' ) ) {
479470 $currentElement = $currentElement.parent();
480471 }
481 - var html = $( '<div></div>' ).text( $currentElement.text().replace( /\r|\n/g, ' ' ) ).html();
482 - if ( $currentElement.is( 'p' ) || $currentElement.is( 'div' ) ) {
483 - $newElement = $( '<p></p>' )
484 - .addClass( 'wikiEditor' )
485 - .insertAfter( $currentElement );
486 - if ( html.length ) {
487 - $newElement.html( html );
 472+
 473+ var $newElement;
 474+ if ( $currentElement.is( 'p' ) || $currentElement.is( 'div' ) || $currentElement.is( 'pre' ) ) {
 475+ //Convert all <div>, <p> and <pre> that was pasted into a <p> element
 476+ $newElement = $( '<p></p>' );
 477+ } else {
 478+ // everything else becomes a <span>
 479+ $newElement = $( '<span></span>' ).addClass( 'wikiEditor' );
 480+ }
 481+
 482+ // If the pasted content was html, just convert it into text and <br>
 483+ var text = $.trim( $currentElement.text() );
 484+ var pieces = text.split('\n');
 485+ for ( var i = 0; i < pieces.length; i++ ) {
 486+ if ( pieces[i] ) {
 487+ $newElement.html( $newElement.html() + $.trim( pieces[i] ) );
488488 } else {
489 - $newElement.append( $( '<br>' ).addClass( 'wikiEditor' ) );
 489+ var $brElement = $( '<span></span>' ).html( '<br class = "wikiEditor" />' );
 490+ $newElement.html( $newElement.html() + $brElement.html() );
490491 }
491 - $currentElement.remove();
492 - } else {
493 - $newElement = $( '<span></span>' ).html( html ).insertAfter( $currentElement );
494 - $newElement.replaceWith( $newElement[0].childNodes );
495 - $currentElement.remove();
496 - }
 492+ }
 493+ $newElement.insertAfter( $currentElement );
 494+ $newElement.addClass( 'wikiEditor' );
 495+ $currentElement.remove();
 496+
497497 $selection = context.$content.find( ':not(.wikiEditor)' );
498498 }
 499+
499500 context.$content.find( '.wikiEditor' ).removeClass( 'wikiEditor' );
500501 if ( $.layout.name !== 'webkit' ) {
501502 context.$content.removeClass( 'pasting' );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -7029,57 +7029,58 @@
70307030 $(this).replaceWith( this.childNodes );
70317031 } );
70327032
 7033+ // If the pasted content is plain text then wrap it in a <p> and adjust the <br> accordingly
70337034 var pasteContent = context.fn.getOffset( cursorPos[0] ).node;
70347035 var removeNextBR = false
70357036 while ( pasteContent != null && ! $( pasteContent ).hasClass( 'wikiEditor' ) ) {
70367037 var currentNode = pasteContent;
70377038 pasteContent = pasteContent.nextSibling;
7038 - if ( currentNode.nodeName == '#text' && currentNode.nodeValue == currentNode.wholeText ) {
7039 - $( currentNode ).wrap( $( '<p></p>' ) );
 7039+ if ( currentNode.nodeName == '#text' && currentNode.nodeValue == currentNode.wholeText ) {
 7040+ var pWrapper = $( '<p></p>' ).addClass( 'wikiEditor' );
 7041+ $( currentNode ).wrap( pWrapper );
70407042 $( currentNode ).addClass( 'wikiEditor' );
70417043 removeNextBR = true;
7042 - } else if ( currentNode.nodeName == 'SPAN' ) {
7043 - var text = $( currentNode ).text();
7044 - if ( text.length == 0 ) {
7045 - $( currentNode ).remove();
7046 - }
 7044+ } else if ( currentNode.nodeName == 'BR' && removeNextBR ) {
 7045+ $( currentNode ).remove();
70477046 removeNextBR = false;
7048 - } else if ( currentNode.nodeName == 'BR' ) {
7049 - if (removeNextBR ) {
7050 - $( currentNode ).remove();
7051 - } else {
7052 - $( currentNode ).addClass( 'wikiEditor' );
7053 - }
7054 - removeNextBR = false;
70557047 } else {
70567048 removeNextBR = false;
70577049 }
7058 - }
7059 -
 7050+ }
70607051 var $selection = context.$content.find( ':not(.wikiEditor)' );
70617052 while ( $selection.length && $selection.length > 0 ) {
70627053 var $currentElement = $selection.eq( 0 );
70637054 while ( !$currentElement.parent().is( 'body' ) && !$currentElement.parent().is( '.wikiEditor' ) ) {
70647055 $currentElement = $currentElement.parent();
70657056 }
7066 - var html = $( '<div></div>' ).text( $currentElement.text().replace( /\r|\n/g, ' ' ) ).html();
7067 - if ( $currentElement.is( 'p' ) || $currentElement.is( 'div' ) ) {
7068 - $newElement = $( '<p></p>' )
7069 - .addClass( 'wikiEditor' )
7070 - .insertAfter( $currentElement );
7071 - if ( html.length ) {
7072 - $newElement.html( html );
 7057+
 7058+ var $newElement;
 7059+ if ( $currentElement.is( 'p' ) || $currentElement.is( 'div' ) || $currentElement.is( 'pre' ) ) {
 7060+ //Convert all <div>, <p> and <pre> that was pasted into a <p> element
 7061+ $newElement = $( '<p></p>' );
 7062+ } else {
 7063+ // everything else becomes a <span>
 7064+ $newElement = $( '<span></span>' ).addClass( 'wikiEditor' );
 7065+ }
 7066+
 7067+ // If the pasted content was html, just convert it into text and <br>
 7068+ var text = $.trim( $currentElement.text() );
 7069+ var pieces = text.split('\n');
 7070+ for ( var i = 0; i < pieces.length; i++ ) {
 7071+ if ( pieces[i] ) {
 7072+ $newElement.html( $newElement.html() + $.trim( pieces[i] ) );
70737073 } else {
7074 - $newElement.append( $( '<br>' ).addClass( 'wikiEditor' ) );
 7074+ var $brElement = $( '<span></span>' ).html( '<br class = "wikiEditor" />' );
 7075+ $newElement.html( $newElement.html() + $brElement.html() );
70757076 }
7076 - $currentElement.remove();
7077 - } else {
7078 - $newElement = $( '<span></span>' ).html( html ).insertAfter( $currentElement );
7079 - $newElement.replaceWith( $newElement[0].childNodes );
7080 - $currentElement.remove();
7081 - }
 7077+ }
 7078+ $newElement.insertAfter( $currentElement );
 7079+ $newElement.addClass( 'wikiEditor' );
 7080+ $currentElement.remove();
 7081+
70827082 $selection = context.$content.find( ':not(.wikiEditor)' );
70837083 }
 7084+
70847085 context.$content.find( '.wikiEditor' ).removeClass( 'wikiEditor' );
70857086 if ( $.layout.name !== 'webkit' ) {
70867087 context.$content.removeClass( 'pasting' );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -468,13 +468,11 @@
469469 return true;},'delayedChange':function(event){event.data.scope='division';var newHTML=context.$content.html();if(context.oldDelayedHTML!=newHTML){context.oldDelayedHTML=newHTML;event.data.scope='realchange';var cursorPos=context.fn.getCaretPosition();var t=context.fn.getOffset(cursorPos[0]);if(t&&t.node.nodeName=='#text'&&t.node.parentNode.nodeName.toLowerCase()=='body'){$(t.node).wrap("<p></p>");context.fn.purgeOffsets();context.fn.setSelection({start:cursorPos[0],end:cursorPos[1]});}}
470470 context.fn.updateHistory(event.data.scope=='realchange');return true;},'cut':function(event){setTimeout(function(){context.$content.find('br').each(function(){if($(this).parent().is('body')){$(this).wrap($('<p></p>'));}});},100);return true;},'paste':function(event){var cursorPos=context.fn.getCaretPosition();var oldLength=context.fn.getContents().length-(cursorPos[1]-cursorPos[0]);context.$content.find(':not(.wikiEditor)').addClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.addClass('pasting');}
471471 setTimeout(function(){context.$content.find('script,style,img,input,select,textarea,hr,button,link,meta').remove();context.$content.find('*').each(function(){if($(this).children().length==0&&this.childNodes.length>0){$(this).text($(this).text());}});context.$content.find('p:not(.wikiEditor) p:not(.wikiEditor)').each(function(){var outerParent=$(this).parent();outerParent.replaceWith(outerParent.childNodes);});context.$content.find('span.Apple-style-span').each(function(){$(this).replaceWith(this.childNodes);});var pasteContent=context.fn.getOffset(cursorPos[0]).node;var removeNextBR=false
472 -while(pasteContent!=null&&!$(pasteContent).hasClass('wikiEditor')){var currentNode=pasteContent;pasteContent=pasteContent.nextSibling;if(currentNode.nodeName=='#text'&&currentNode.nodeValue==currentNode.wholeText){$(currentNode).wrap($('<p></p>'));$(currentNode).addClass('wikiEditor');removeNextBR=true;}else if(currentNode.nodeName=='SPAN'){var text=$(currentNode).text();if(text.length==0){$(currentNode).remove();}
473 -removeNextBR=false;}else if(currentNode.nodeName=='BR'){if(removeNextBR){$(currentNode).remove();}else{$(currentNode).addClass('wikiEditor');}
474 -removeNextBR=false;}else{removeNextBR=false;}}
 472+while(pasteContent!=null&&!$(pasteContent).hasClass('wikiEditor')){var currentNode=pasteContent;pasteContent=pasteContent.nextSibling;if(currentNode.nodeName=='#text'&&currentNode.nodeValue==currentNode.wholeText){var pWrapper=$('<p></p>').addClass('wikiEditor');$(currentNode).wrap(pWrapper);$(currentNode).addClass('wikiEditor');removeNextBR=true;}else if(currentNode.nodeName=='BR'&&removeNextBR){$(currentNode).remove();removeNextBR=false;}else{removeNextBR=false;}}
475473 var $selection=context.$content.find(':not(.wikiEditor)');while($selection.length&&$selection.length>0){var $currentElement=$selection.eq(0);while(!$currentElement.parent().is('body')&&!$currentElement.parent().is('.wikiEditor')){$currentElement=$currentElement.parent();}
476 -var html=$('<div></div>').text($currentElement.text().replace(/\r|\n/g,' ')).html();if($currentElement.is('p')||$currentElement.is('div')){$newElement=$('<p></p>').addClass('wikiEditor').insertAfter($currentElement);if(html.length){$newElement.html(html);}else{$newElement.append($('<br>').addClass('wikiEditor'));}
477 -$currentElement.remove();}else{$newElement=$('<span></span>').html(html).insertAfter($currentElement);$newElement.replaceWith($newElement[0].childNodes);$currentElement.remove();}
478 -$selection=context.$content.find(':not(.wikiEditor)');}
 474+var $newElement;if($currentElement.is('p')||$currentElement.is('div')||$currentElement.is('pre')){$newElement=$('<p></p>');}else{$newElement=$('<span></span>').addClass('wikiEditor');}
 475+var text=$.trim($currentElement.text());var pieces=text.split('\n');for(var i=0;i<pieces.length;i++){if(pieces[i]){$newElement.html($newElement.html()+$.trim(pieces[i]));}else{var $brElement=$('<span></span>').html('<br class = "wikiEditor" />');$newElement.html($newElement.html()+$brElement.html());}}
 476+$newElement.insertAfter($currentElement);$newElement.addClass('wikiEditor');$currentElement.remove();$selection=context.$content.find(':not(.wikiEditor)');}
479477 context.$content.find('.wikiEditor').removeClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.removeClass('pasting');}
480478 context.fn.purgeOffsets();var newLength=context.fn.getContents().length;var restoreTo=cursorPos[0]+newLength-oldLength;context.fn.setSelection({start:restoreTo,end:restoreTo});},0);return true;},'ready':function(event){context.history.push({'html':context.$content.html(),'sel':context.fn.getCaretPosition()});return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};}
481479 if(typeof event.data=='undefined'){event.data={};}

Follow-up revisions

RevisionCommit summaryAuthorDate
r65763UsabilityInitiative: Various fixes...catrope21:14, 1 May 2010

Status & tagging log