TinyMCE:
- Prevent applying Indent and Outdent while an image with a caption is selected. It doesn't do anything and breaks the caption elements. - Keep all of the text when a caption `<dl>` was somehow changed. Fixes #38313. git-svn-id: https://develop.svn.wordpress.org/trunk@38796 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
7ce67a141d
commit
53bacc01c2
@ -181,16 +181,10 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
|
|||||||
return content.replace( /(?:<div [^>]+mceTemp[^>]+>)?\s*(<dl [^>]+wp-caption[^>]+>[\s\S]+?<\/dl>)\s*(?:<\/div>)?/g, function( all, dl ) {
|
return content.replace( /(?:<div [^>]+mceTemp[^>]+>)?\s*(<dl [^>]+wp-caption[^>]+>[\s\S]+?<\/dl>)\s*(?:<\/div>)?/g, function( all, dl ) {
|
||||||
var out = '';
|
var out = '';
|
||||||
|
|
||||||
if ( dl.indexOf('<img ') === -1 ) {
|
if ( dl.indexOf('<img ') === -1 || dl.indexOf('</p>') !== -1 ) {
|
||||||
// Broken caption. The user managed to drag the image out?
|
// Broken caption. The user managed to drag the image out or type in the wrapper div?
|
||||||
// Try to return the caption text as a paragraph.
|
// Remove the <dl>, <dd> and <dt> and return the remaining text.
|
||||||
out = dl.match( /<dd [^>]+>([\s\S]+?)<\/dd>/i );
|
return dl.replace( /<d[ldt]( [^>]+)?>/g, '' ).replace( /<\/d[ldt]>/g, '' );
|
||||||
|
|
||||||
if ( out && out[1] ) {
|
|
||||||
return '<p>' + out[1] + '</p>';
|
|
||||||
}
|
|
||||||
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out = dl.replace( /\s*<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\s\S]*?)<\/dd>\s*<\/dl>\s*/gi, function( a, b, c, caption ) {
|
out = dl.replace( /\s*<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\s\S]*?)<\/dd>\s*<\/dl>\s*/gi, function( a, b, c, caption ) {
|
||||||
@ -896,26 +890,34 @@ tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
|
|||||||
cmd = event.command,
|
cmd = event.command,
|
||||||
dom = editor.dom;
|
dom = editor.dom;
|
||||||
|
|
||||||
if ( cmd === 'mceInsertContent' ) {
|
if ( cmd === 'mceInsertContent' || cmd === 'Indent' || cmd === 'Outdent' ) {
|
||||||
node = editor.selection.getNode();
|
node = editor.selection.getNode();
|
||||||
captionParent = dom.getParent( node, 'div.mceTemp' );
|
captionParent = dom.getParent( node, 'div.mceTemp' );
|
||||||
|
|
||||||
if ( captionParent ) {
|
if ( captionParent ) {
|
||||||
if ( pasteInCaption ) {
|
if ( cmd === 'mceInsertContent' ) {
|
||||||
pasteInCaption = false;
|
if ( pasteInCaption ) {
|
||||||
// We are in the caption element, and in 'paste' context,
|
pasteInCaption = false;
|
||||||
// and the pasted HTML was cleaned up on 'pastePostProcess' above.
|
// We are in the caption element, and in 'paste' context,
|
||||||
// Let it be pasted in the caption.
|
// and the pasted HTML was cleaned up on 'pastePostProcess' above.
|
||||||
return;
|
// Let it be pasted in the caption.
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// The paste is somewhere else in the caption DL element.
|
// The paste is somewhere else in the caption DL element.
|
||||||
// Prevent pasting in there as it will break the caption.
|
// Prevent pasting in there as it will break the caption.
|
||||||
// Make new paragraph under the caption DL and move the caret there.
|
// Make new paragraph under the caption DL and move the caret there.
|
||||||
p = dom.create( 'p' );
|
p = dom.create( 'p' );
|
||||||
dom.insertAfter( p, captionParent );
|
dom.insertAfter( p, captionParent );
|
||||||
editor.selection.setCursorLocation( p, 0 );
|
editor.selection.setCursorLocation( p, 0 );
|
||||||
editor.nodeChanged();
|
editor.nodeChanged();
|
||||||
|
} else {
|
||||||
|
// Clicking Indent or Outdent while an image with a caption is selected breaks the caption.
|
||||||
|
// See #38313.
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopImmediatePropagation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if ( cmd === 'JustifyLeft' || cmd === 'JustifyRight' || cmd === 'JustifyCenter' || cmd === 'wpAlignNone' ) {
|
} else if ( cmd === 'JustifyLeft' || cmd === 'JustifyRight' || cmd === 'JustifyCenter' || cmd === 'wpAlignNone' ) {
|
||||||
node = editor.selection.getNode();
|
node = editor.selection.getNode();
|
||||||
|
Loading…
Reference in New Issue
Block a user