Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | array( 'src' => 'js/plugins/jquery.delayedBind.js', 'version' => 1 ), |
74 | 74 | array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 11 ), |
75 | 75 | 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 ), |
77 | 77 | array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 52 ), |
78 | 78 | array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 59 ), |
79 | 79 | array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 24 ), |
— | — | @@ -82,10 +82,10 @@ |
83 | 83 | array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 5 ), |
84 | 84 | ), |
85 | 85 | 'combined' => array( |
86 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 386 ), |
| 86 | + array( 'src' => 'js/plugins.combined.js', 'version' => 387 ), |
87 | 87 | ), |
88 | 88 | 'minified' => array( |
89 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 386 ), |
| 89 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 387 ), |
90 | 90 | ), |
91 | 91 | ), |
92 | 92 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -444,57 +444,58 @@ |
445 | 445 | $(this).replaceWith( this.childNodes ); |
446 | 446 | } ); |
447 | 447 | |
| 448 | + // If the pasted content is plain text then wrap it in a <p> and adjust the <br> accordingly |
448 | 449 | var pasteContent = context.fn.getOffset( cursorPos[0] ).node; |
449 | 450 | var removeNextBR = false |
450 | 451 | while ( pasteContent != null && ! $( pasteContent ).hasClass( 'wikiEditor' ) ) { |
451 | 452 | var currentNode = pasteContent; |
452 | 453 | 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 ); |
455 | 457 | $( currentNode ).addClass( 'wikiEditor' ); |
456 | 458 | 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(); |
462 | 461 | removeNextBR = false; |
463 | | - } else if ( currentNode.nodeName == 'BR' ) { |
464 | | - if (removeNextBR ) { |
465 | | - $( currentNode ).remove(); |
466 | | - } else { |
467 | | - $( currentNode ).addClass( 'wikiEditor' ); |
468 | | - } |
469 | | - removeNextBR = false; |
470 | 462 | } else { |
471 | 463 | removeNextBR = false; |
472 | 464 | } |
473 | | - } |
474 | | - |
| 465 | + } |
475 | 466 | var $selection = context.$content.find( ':not(.wikiEditor)' ); |
476 | 467 | while ( $selection.length && $selection.length > 0 ) { |
477 | 468 | var $currentElement = $selection.eq( 0 ); |
478 | 469 | while ( !$currentElement.parent().is( 'body' ) && !$currentElement.parent().is( '.wikiEditor' ) ) { |
479 | 470 | $currentElement = $currentElement.parent(); |
480 | 471 | } |
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] ) ); |
488 | 488 | } else { |
489 | | - $newElement.append( $( '<br>' ).addClass( 'wikiEditor' ) ); |
| 489 | + var $brElement = $( '<span></span>' ).html( '<br class = "wikiEditor" />' ); |
| 490 | + $newElement.html( $newElement.html() + $brElement.html() ); |
490 | 491 | } |
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 | + |
497 | 497 | $selection = context.$content.find( ':not(.wikiEditor)' ); |
498 | 498 | } |
| 499 | + |
499 | 500 | context.$content.find( '.wikiEditor' ).removeClass( 'wikiEditor' ); |
500 | 501 | if ( $.layout.name !== 'webkit' ) { |
501 | 502 | context.$content.removeClass( 'pasting' ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -7029,57 +7029,58 @@ |
7030 | 7030 | $(this).replaceWith( this.childNodes ); |
7031 | 7031 | } ); |
7032 | 7032 | |
| 7033 | + // If the pasted content is plain text then wrap it in a <p> and adjust the <br> accordingly |
7033 | 7034 | var pasteContent = context.fn.getOffset( cursorPos[0] ).node; |
7034 | 7035 | var removeNextBR = false |
7035 | 7036 | while ( pasteContent != null && ! $( pasteContent ).hasClass( 'wikiEditor' ) ) { |
7036 | 7037 | var currentNode = pasteContent; |
7037 | 7038 | 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 ); |
7040 | 7042 | $( currentNode ).addClass( 'wikiEditor' ); |
7041 | 7043 | 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(); |
7047 | 7046 | removeNextBR = false; |
7048 | | - } else if ( currentNode.nodeName == 'BR' ) { |
7049 | | - if (removeNextBR ) { |
7050 | | - $( currentNode ).remove(); |
7051 | | - } else { |
7052 | | - $( currentNode ).addClass( 'wikiEditor' ); |
7053 | | - } |
7054 | | - removeNextBR = false; |
7055 | 7047 | } else { |
7056 | 7048 | removeNextBR = false; |
7057 | 7049 | } |
7058 | | - } |
7059 | | - |
| 7050 | + } |
7060 | 7051 | var $selection = context.$content.find( ':not(.wikiEditor)' ); |
7061 | 7052 | while ( $selection.length && $selection.length > 0 ) { |
7062 | 7053 | var $currentElement = $selection.eq( 0 ); |
7063 | 7054 | while ( !$currentElement.parent().is( 'body' ) && !$currentElement.parent().is( '.wikiEditor' ) ) { |
7064 | 7055 | $currentElement = $currentElement.parent(); |
7065 | 7056 | } |
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] ) ); |
7073 | 7073 | } else { |
7074 | | - $newElement.append( $( '<br>' ).addClass( 'wikiEditor' ) ); |
| 7074 | + var $brElement = $( '<span></span>' ).html( '<br class = "wikiEditor" />' ); |
| 7075 | + $newElement.html( $newElement.html() + $brElement.html() ); |
7075 | 7076 | } |
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 | + |
7082 | 7082 | $selection = context.$content.find( ':not(.wikiEditor)' ); |
7083 | 7083 | } |
| 7084 | + |
7084 | 7085 | context.$content.find( '.wikiEditor' ).removeClass( 'wikiEditor' ); |
7085 | 7086 | if ( $.layout.name !== 'webkit' ) { |
7086 | 7087 | context.$content.removeClass( 'pasting' ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -468,13 +468,11 @@ |
469 | 469 | 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]});}} |
470 | 470 | 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');} |
471 | 471 | 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'&¤tNode.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'&¤tNode.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;}} |
475 | 473 | 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)');} |
479 | 477 | context.$content.find('.wikiEditor').removeClass('wikiEditor');if($.layout.name!=='webkit'){context.$content.removeClass('pasting');} |
480 | 478 | 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'};} |
481 | 479 | if(typeof event.data=='undefined'){event.data={};} |