Edit File by line
/home/barbar84/www/wp-inclu.../js/tinymce/plugins/wpeditim...
File: plugin.js
/* global tinymce */
[0] Fix | Delete
tinymce.PluginManager.add( 'wpeditimage', function( editor ) {
[1] Fix | Delete
var toolbar, serializer, touchOnImage, pasteInCaption,
[2] Fix | Delete
each = tinymce.each,
[3] Fix | Delete
trim = tinymce.trim,
[4] Fix | Delete
iOS = tinymce.Env.iOS;
[5] Fix | Delete
[6] Fix | Delete
function isPlaceholder( node ) {
[7] Fix | Delete
return !! ( editor.dom.getAttrib( node, 'data-mce-placeholder' ) || editor.dom.getAttrib( node, 'data-mce-object' ) );
[8] Fix | Delete
}
[9] Fix | Delete
[10] Fix | Delete
editor.addButton( 'wp_img_remove', {
[11] Fix | Delete
tooltip: 'Remove',
[12] Fix | Delete
icon: 'dashicon dashicons-no',
[13] Fix | Delete
onclick: function() {
[14] Fix | Delete
removeImage( editor.selection.getNode() );
[15] Fix | Delete
}
[16] Fix | Delete
} );
[17] Fix | Delete
[18] Fix | Delete
editor.addButton( 'wp_img_edit', {
[19] Fix | Delete
tooltip: 'Edit|button', // '|button' is not displayed, only used for context.
[20] Fix | Delete
icon: 'dashicon dashicons-edit',
[21] Fix | Delete
onclick: function() {
[22] Fix | Delete
editImage( editor.selection.getNode() );
[23] Fix | Delete
}
[24] Fix | Delete
} );
[25] Fix | Delete
[26] Fix | Delete
each( {
[27] Fix | Delete
alignleft: 'Align left',
[28] Fix | Delete
aligncenter: 'Align center',
[29] Fix | Delete
alignright: 'Align right',
[30] Fix | Delete
alignnone: 'No alignment'
[31] Fix | Delete
}, function( tooltip, name ) {
[32] Fix | Delete
var direction = name.slice( 5 );
[33] Fix | Delete
[34] Fix | Delete
editor.addButton( 'wp_img_' + name, {
[35] Fix | Delete
tooltip: tooltip,
[36] Fix | Delete
icon: 'dashicon dashicons-align-' + direction,
[37] Fix | Delete
cmd: 'alignnone' === name ? 'wpAlignNone' : 'Justify' + direction.slice( 0, 1 ).toUpperCase() + direction.slice( 1 ),
[38] Fix | Delete
onPostRender: function() {
[39] Fix | Delete
var self = this;
[40] Fix | Delete
[41] Fix | Delete
editor.on( 'NodeChange', function( event ) {
[42] Fix | Delete
var node;
[43] Fix | Delete
[44] Fix | Delete
// Don't bother.
[45] Fix | Delete
if ( event.element.nodeName !== 'IMG' ) {
[46] Fix | Delete
return;
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
node = editor.dom.getParent( event.element, '.wp-caption' ) || event.element;
[50] Fix | Delete
[51] Fix | Delete
if ( 'alignnone' === name ) {
[52] Fix | Delete
self.active( ! /\balign(left|center|right)\b/.test( node.className ) );
[53] Fix | Delete
} else {
[54] Fix | Delete
self.active( editor.dom.hasClass( node, name ) );
[55] Fix | Delete
}
[56] Fix | Delete
} );
[57] Fix | Delete
}
[58] Fix | Delete
} );
[59] Fix | Delete
} );
[60] Fix | Delete
[61] Fix | Delete
editor.once( 'preinit', function() {
[62] Fix | Delete
if ( editor.wp && editor.wp._createToolbar ) {
[63] Fix | Delete
toolbar = editor.wp._createToolbar( [
[64] Fix | Delete
'wp_img_alignleft',
[65] Fix | Delete
'wp_img_aligncenter',
[66] Fix | Delete
'wp_img_alignright',
[67] Fix | Delete
'wp_img_alignnone',
[68] Fix | Delete
'wp_img_edit',
[69] Fix | Delete
'wp_img_remove'
[70] Fix | Delete
] );
[71] Fix | Delete
}
[72] Fix | Delete
} );
[73] Fix | Delete
[74] Fix | Delete
editor.on( 'wptoolbar', function( event ) {
[75] Fix | Delete
if ( event.element.nodeName === 'IMG' && ! isPlaceholder( event.element ) ) {
[76] Fix | Delete
event.toolbar = toolbar;
[77] Fix | Delete
}
[78] Fix | Delete
} );
[79] Fix | Delete
[80] Fix | Delete
function isNonEditable( node ) {
[81] Fix | Delete
var parent = editor.$( node ).parents( '[contenteditable]' );
[82] Fix | Delete
return parent && parent.attr( 'contenteditable' ) === 'false';
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
// Safari on iOS fails to select images in contentEditoble mode on touch.
[86] Fix | Delete
// Select them again.
[87] Fix | Delete
if ( iOS ) {
[88] Fix | Delete
editor.on( 'init', function() {
[89] Fix | Delete
editor.on( 'touchstart', function( event ) {
[90] Fix | Delete
if ( event.target.nodeName === 'IMG' && ! isNonEditable( event.target ) ) {
[91] Fix | Delete
touchOnImage = true;
[92] Fix | Delete
}
[93] Fix | Delete
});
[94] Fix | Delete
[95] Fix | Delete
editor.dom.bind( editor.getDoc(), 'touchmove', function() {
[96] Fix | Delete
touchOnImage = false;
[97] Fix | Delete
});
[98] Fix | Delete
[99] Fix | Delete
editor.on( 'touchend', function( event ) {
[100] Fix | Delete
if ( touchOnImage && event.target.nodeName === 'IMG' && ! isNonEditable( event.target ) ) {
[101] Fix | Delete
var node = event.target;
[102] Fix | Delete
[103] Fix | Delete
touchOnImage = false;
[104] Fix | Delete
[105] Fix | Delete
window.setTimeout( function() {
[106] Fix | Delete
editor.selection.select( node );
[107] Fix | Delete
editor.nodeChanged();
[108] Fix | Delete
}, 100 );
[109] Fix | Delete
} else if ( toolbar ) {
[110] Fix | Delete
toolbar.hide();
[111] Fix | Delete
}
[112] Fix | Delete
});
[113] Fix | Delete
});
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
function parseShortcode( content ) {
[117] Fix | Delete
return content.replace( /(?:<p>)?\[(?:wp_)?caption([^\]]+)\]([\s\S]+?)\[\/(?:wp_)?caption\](?:<\/p>)?/g, function( a, b, c ) {
[118] Fix | Delete
var id, align, classes, caption, img, width;
[119] Fix | Delete
[120] Fix | Delete
id = b.match( /id=['"]([^'"]*)['"] ?/ );
[121] Fix | Delete
if ( id ) {
[122] Fix | Delete
b = b.replace( id[0], '' );
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
align = b.match( /align=['"]([^'"]*)['"] ?/ );
[126] Fix | Delete
if ( align ) {
[127] Fix | Delete
b = b.replace( align[0], '' );
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
classes = b.match( /class=['"]([^'"]*)['"] ?/ );
[131] Fix | Delete
if ( classes ) {
[132] Fix | Delete
b = b.replace( classes[0], '' );
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
width = b.match( /width=['"]([0-9]*)['"] ?/ );
[136] Fix | Delete
if ( width ) {
[137] Fix | Delete
b = b.replace( width[0], '' );
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
c = trim( c );
[141] Fix | Delete
img = c.match( /((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)([\s\S]*)/i );
[142] Fix | Delete
[143] Fix | Delete
if ( img && img[2] ) {
[144] Fix | Delete
caption = trim( img[2] );
[145] Fix | Delete
img = trim( img[1] );
[146] Fix | Delete
} else {
[147] Fix | Delete
// Old captions shortcode style.
[148] Fix | Delete
caption = trim( b ).replace( /caption=['"]/, '' ).replace( /['"]$/, '' );
[149] Fix | Delete
img = c;
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
id = ( id && id[1] ) ? id[1].replace( /[<>&]+/g, '' ) : '';
[153] Fix | Delete
align = ( align && align[1] ) ? align[1] : 'alignnone';
[154] Fix | Delete
classes = ( classes && classes[1] ) ? ' ' + classes[1].replace( /[<>&]+/g, '' ) : '';
[155] Fix | Delete
[156] Fix | Delete
if ( ! width && img ) {
[157] Fix | Delete
width = img.match( /width=['"]([0-9]*)['"]/ );
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
if ( width && width[1] ) {
[161] Fix | Delete
width = width[1];
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
if ( ! width || ! caption ) {
[165] Fix | Delete
return c;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
width = parseInt( width, 10 );
[169] Fix | Delete
if ( ! editor.getParam( 'wpeditimage_html5_captions' ) ) {
[170] Fix | Delete
width += 10;
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
return '<div class="mceTemp"><dl id="' + id + '" class="wp-caption ' + align + classes + '" style="width: ' + width + 'px">' +
[174] Fix | Delete
'<dt class="wp-caption-dt">'+ img +'</dt><dd class="wp-caption-dd">'+ caption +'</dd></dl></div>';
[175] Fix | Delete
});
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
function getShortcode( content ) {
[179] Fix | Delete
return content.replace( /(?:<div [^>]+mceTemp[^>]+>)?\s*(<dl [^>]+wp-caption[^>]+>[\s\S]+?<\/dl>)\s*(?:<\/div>)?/g, function( all, dl ) {
[180] Fix | Delete
var out = '';
[181] Fix | Delete
[182] Fix | Delete
if ( dl.indexOf('<img ') === -1 || dl.indexOf('</p>') !== -1 ) {
[183] Fix | Delete
// Broken caption. The user managed to drag the image out or type in the wrapper div?
[184] Fix | Delete
// Remove the <dl>, <dd> and <dt> and return the remaining text.
[185] Fix | Delete
return dl.replace( /<d[ldt]( [^>]+)?>/g, '' ).replace( /<\/d[ldt]>/g, '' );
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
out = dl.replace( /\s*<dl ([^>]+)>\s*<dt [^>]+>([\s\S]+?)<\/dt>\s*<dd [^>]+>([\s\S]*?)<\/dd>\s*<\/dl>\s*/gi, function( a, b, c, caption ) {
[189] Fix | Delete
var id, classes, align, width;
[190] Fix | Delete
[191] Fix | Delete
width = c.match( /width="([0-9]*)"/ );
[192] Fix | Delete
width = ( width && width[1] ) ? width[1] : '';
[193] Fix | Delete
[194] Fix | Delete
classes = b.match( /class="([^"]*)"/ );
[195] Fix | Delete
classes = ( classes && classes[1] ) ? classes[1] : '';
[196] Fix | Delete
align = classes.match( /align[a-z]+/i ) || 'alignnone';
[197] Fix | Delete
[198] Fix | Delete
if ( ! width || ! caption ) {
[199] Fix | Delete
if ( 'alignnone' !== align[0] ) {
[200] Fix | Delete
c = c.replace( /><img/, ' class="' + align[0] + '"><img' );
[201] Fix | Delete
}
[202] Fix | Delete
return c;
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
id = b.match( /id="([^"]*)"/ );
[206] Fix | Delete
id = ( id && id[1] ) ? id[1] : '';
[207] Fix | Delete
[208] Fix | Delete
classes = classes.replace( /wp-caption ?|align[a-z]+ ?/gi, '' );
[209] Fix | Delete
[210] Fix | Delete
if ( classes ) {
[211] Fix | Delete
classes = ' class="' + classes + '"';
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
caption = caption.replace( /\r\n|\r/g, '\n' ).replace( /<[a-zA-Z0-9]+( [^<>]+)?>/g, function( a ) {
[215] Fix | Delete
// No line breaks inside HTML tags.
[216] Fix | Delete
return a.replace( /[\r\n\t]+/, ' ' );
[217] Fix | Delete
});
[218] Fix | Delete
[219] Fix | Delete
// Convert remaining line breaks to <br>.
[220] Fix | Delete
caption = caption.replace( /\s*\n\s*/g, '<br />' );
[221] Fix | Delete
[222] Fix | Delete
return '[caption id="' + id + '" align="' + align + '" width="' + width + '"' + classes + ']' + c + ' ' + caption + '[/caption]';
[223] Fix | Delete
});
[224] Fix | Delete
[225] Fix | Delete
if ( out.indexOf('[caption') === -1 ) {
[226] Fix | Delete
// The caption html seems broken, try to find the image that may be wrapped in a link
[227] Fix | Delete
// and may be followed by <p> with the caption text.
[228] Fix | Delete
out = dl.replace( /[\s\S]*?((?:<a [^>]+>)?<img [^>]+>(?:<\/a>)?)(<p>[\s\S]*<\/p>)?[\s\S]*/gi, '<p>$1</p>$2' );
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
return out;
[232] Fix | Delete
});
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
function extractImageData( imageNode ) {
[236] Fix | Delete
var classes, extraClasses, metadata, captionBlock, caption, link, width, height,
[237] Fix | Delete
captionClassName = [],
[238] Fix | Delete
dom = editor.dom,
[239] Fix | Delete
isIntRegExp = /^\d+$/;
[240] Fix | Delete
[241] Fix | Delete
// Default attributes.
[242] Fix | Delete
metadata = {
[243] Fix | Delete
attachment_id: false,
[244] Fix | Delete
size: 'custom',
[245] Fix | Delete
caption: '',
[246] Fix | Delete
align: 'none',
[247] Fix | Delete
extraClasses: '',
[248] Fix | Delete
link: false,
[249] Fix | Delete
linkUrl: '',
[250] Fix | Delete
linkClassName: '',
[251] Fix | Delete
linkTargetBlank: false,
[252] Fix | Delete
linkRel: '',
[253] Fix | Delete
title: ''
[254] Fix | Delete
};
[255] Fix | Delete
[256] Fix | Delete
metadata.url = dom.getAttrib( imageNode, 'src' );
[257] Fix | Delete
metadata.alt = dom.getAttrib( imageNode, 'alt' );
[258] Fix | Delete
metadata.title = dom.getAttrib( imageNode, 'title' );
[259] Fix | Delete
[260] Fix | Delete
width = dom.getAttrib( imageNode, 'width' );
[261] Fix | Delete
height = dom.getAttrib( imageNode, 'height' );
[262] Fix | Delete
[263] Fix | Delete
if ( ! isIntRegExp.test( width ) || parseInt( width, 10 ) < 1 ) {
[264] Fix | Delete
width = imageNode.naturalWidth || imageNode.width;
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
if ( ! isIntRegExp.test( height ) || parseInt( height, 10 ) < 1 ) {
[268] Fix | Delete
height = imageNode.naturalHeight || imageNode.height;
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
metadata.customWidth = metadata.width = width;
[272] Fix | Delete
metadata.customHeight = metadata.height = height;
[273] Fix | Delete
[274] Fix | Delete
classes = tinymce.explode( imageNode.className, ' ' );
[275] Fix | Delete
extraClasses = [];
[276] Fix | Delete
[277] Fix | Delete
tinymce.each( classes, function( name ) {
[278] Fix | Delete
[279] Fix | Delete
if ( /^wp-image/.test( name ) ) {
[280] Fix | Delete
metadata.attachment_id = parseInt( name.replace( 'wp-image-', '' ), 10 );
[281] Fix | Delete
} else if ( /^align/.test( name ) ) {
[282] Fix | Delete
metadata.align = name.replace( 'align', '' );
[283] Fix | Delete
} else if ( /^size/.test( name ) ) {
[284] Fix | Delete
metadata.size = name.replace( 'size-', '' );
[285] Fix | Delete
} else {
[286] Fix | Delete
extraClasses.push( name );
[287] Fix | Delete
}
[288] Fix | Delete
[289] Fix | Delete
} );
[290] Fix | Delete
[291] Fix | Delete
metadata.extraClasses = extraClasses.join( ' ' );
[292] Fix | Delete
[293] Fix | Delete
// Extract caption.
[294] Fix | Delete
captionBlock = dom.getParents( imageNode, '.wp-caption' );
[295] Fix | Delete
[296] Fix | Delete
if ( captionBlock.length ) {
[297] Fix | Delete
captionBlock = captionBlock[0];
[298] Fix | Delete
[299] Fix | Delete
classes = captionBlock.className.split( ' ' );
[300] Fix | Delete
tinymce.each( classes, function( name ) {
[301] Fix | Delete
if ( /^align/.test( name ) ) {
[302] Fix | Delete
metadata.align = name.replace( 'align', '' );
[303] Fix | Delete
} else if ( name && name !== 'wp-caption' ) {
[304] Fix | Delete
captionClassName.push( name );
[305] Fix | Delete
}
[306] Fix | Delete
} );
[307] Fix | Delete
[308] Fix | Delete
metadata.captionClassName = captionClassName.join( ' ' );
[309] Fix | Delete
[310] Fix | Delete
caption = dom.select( 'dd.wp-caption-dd', captionBlock );
[311] Fix | Delete
if ( caption.length ) {
[312] Fix | Delete
caption = caption[0];
[313] Fix | Delete
[314] Fix | Delete
metadata.caption = editor.serializer.serialize( caption )
[315] Fix | Delete
.replace( /<br[^>]*>/g, '$&\n' ).replace( /^<p>/, '' ).replace( /<\/p>$/, '' );
[316] Fix | Delete
}
[317] Fix | Delete
}
[318] Fix | Delete
[319] Fix | Delete
// Extract linkTo.
[320] Fix | Delete
if ( imageNode.parentNode && imageNode.parentNode.nodeName === 'A' ) {
[321] Fix | Delete
link = imageNode.parentNode;
[322] Fix | Delete
metadata.linkUrl = dom.getAttrib( link, 'href' );
[323] Fix | Delete
metadata.linkTargetBlank = dom.getAttrib( link, 'target' ) === '_blank' ? true : false;
[324] Fix | Delete
metadata.linkRel = dom.getAttrib( link, 'rel' );
[325] Fix | Delete
metadata.linkClassName = link.className;
[326] Fix | Delete
}
[327] Fix | Delete
[328] Fix | Delete
return metadata;
[329] Fix | Delete
}
[330] Fix | Delete
[331] Fix | Delete
function hasTextContent( node ) {
[332] Fix | Delete
return node && !! ( node.textContent || node.innerText ).replace( /\ufeff/g, '' );
[333] Fix | Delete
}
[334] Fix | Delete
[335] Fix | Delete
// Verify HTML in captions.
[336] Fix | Delete
function verifyHTML( caption ) {
[337] Fix | Delete
if ( ! caption || ( caption.indexOf( '<' ) === -1 && caption.indexOf( '>' ) === -1 ) ) {
[338] Fix | Delete
return caption;
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
if ( ! serializer ) {
[342] Fix | Delete
serializer = new tinymce.html.Serializer( {}, editor.schema );
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
return serializer.serialize( editor.parser.parse( caption, { forced_root_block: false } ) );
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
function updateImage( $imageNode, imageData ) {
[349] Fix | Delete
var classes, className, node, html, parent, wrap, linkNode, imageNode,
[350] Fix | Delete
captionNode, dd, dl, id, attrs, linkAttrs, width, height, align,
[351] Fix | Delete
$imageNode, srcset, src,
[352] Fix | Delete
dom = editor.dom;
[353] Fix | Delete
[354] Fix | Delete
if ( ! $imageNode || ! $imageNode.length ) {
[355] Fix | Delete
return;
[356] Fix | Delete
}
[357] Fix | Delete
[358] Fix | Delete
imageNode = $imageNode[0];
[359] Fix | Delete
classes = tinymce.explode( imageData.extraClasses, ' ' );
[360] Fix | Delete
[361] Fix | Delete
if ( ! classes ) {
[362] Fix | Delete
classes = [];
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
if ( ! imageData.caption ) {
[366] Fix | Delete
classes.push( 'align' + imageData.align );
[367] Fix | Delete
}
[368] Fix | Delete
[369] Fix | Delete
if ( imageData.attachment_id ) {
[370] Fix | Delete
classes.push( 'wp-image-' + imageData.attachment_id );
[371] Fix | Delete
if ( imageData.size && imageData.size !== 'custom' ) {
[372] Fix | Delete
classes.push( 'size-' + imageData.size );
[373] Fix | Delete
}
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
width = imageData.width;
[377] Fix | Delete
height = imageData.height;
[378] Fix | Delete
[379] Fix | Delete
if ( imageData.size === 'custom' ) {
[380] Fix | Delete
width = imageData.customWidth;
[381] Fix | Delete
height = imageData.customHeight;
[382] Fix | Delete
}
[383] Fix | Delete
[384] Fix | Delete
attrs = {
[385] Fix | Delete
src: imageData.url,
[386] Fix | Delete
width: width || null,
[387] Fix | Delete
height: height || null,
[388] Fix | Delete
title: imageData.title || null,
[389] Fix | Delete
'class': classes.join( ' ' ) || null
[390] Fix | Delete
};
[391] Fix | Delete
[392] Fix | Delete
dom.setAttribs( imageNode, attrs );
[393] Fix | Delete
[394] Fix | Delete
// Preserve empty alt attributes.
[395] Fix | Delete
$imageNode.attr( 'alt', imageData.alt || '' );
[396] Fix | Delete
[397] Fix | Delete
linkAttrs = {
[398] Fix | Delete
href: imageData.linkUrl,
[399] Fix | Delete
rel: imageData.linkRel || null,
[400] Fix | Delete
target: imageData.linkTargetBlank ? '_blank': null,
[401] Fix | Delete
'class': imageData.linkClassName || null
[402] Fix | Delete
};
[403] Fix | Delete
[404] Fix | Delete
if ( imageNode.parentNode && imageNode.parentNode.nodeName === 'A' && ! hasTextContent( imageNode.parentNode ) ) {
[405] Fix | Delete
// Update or remove an existing link wrapped around the image.
[406] Fix | Delete
if ( imageData.linkUrl ) {
[407] Fix | Delete
dom.setAttribs( imageNode.parentNode, linkAttrs );
[408] Fix | Delete
} else {
[409] Fix | Delete
dom.remove( imageNode.parentNode, true );
[410] Fix | Delete
}
[411] Fix | Delete
} else if ( imageData.linkUrl ) {
[412] Fix | Delete
if ( linkNode = dom.getParent( imageNode, 'a' ) ) {
[413] Fix | Delete
// The image is inside a link together with other nodes,
[414] Fix | Delete
// or is nested in another node, move it out.
[415] Fix | Delete
dom.insertAfter( imageNode, linkNode );
[416] Fix | Delete
}
[417] Fix | Delete
[418] Fix | Delete
// Add link wrapped around the image.
[419] Fix | Delete
linkNode = dom.create( 'a', linkAttrs );
[420] Fix | Delete
imageNode.parentNode.insertBefore( linkNode, imageNode );
[421] Fix | Delete
linkNode.appendChild( imageNode );
[422] Fix | Delete
}
[423] Fix | Delete
[424] Fix | Delete
captionNode = editor.dom.getParent( imageNode, '.mceTemp' );
[425] Fix | Delete
[426] Fix | Delete
if ( imageNode.parentNode && imageNode.parentNode.nodeName === 'A' && ! hasTextContent( imageNode.parentNode ) ) {
[427] Fix | Delete
node = imageNode.parentNode;
[428] Fix | Delete
} else {
[429] Fix | Delete
node = imageNode;
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
if ( imageData.caption ) {
[433] Fix | Delete
imageData.caption = verifyHTML( imageData.caption );
[434] Fix | Delete
[435] Fix | Delete
id = imageData.attachment_id ? 'attachment_' + imageData.attachment_id : null;
[436] Fix | Delete
align = 'align' + ( imageData.align || 'none' );
[437] Fix | Delete
className = 'wp-caption ' + align;
[438] Fix | Delete
[439] Fix | Delete
if ( imageData.captionClassName ) {
[440] Fix | Delete
className += ' ' + imageData.captionClassName.replace( /[<>&]+/g, '' );
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
if ( ! editor.getParam( 'wpeditimage_html5_captions' ) ) {
[444] Fix | Delete
width = parseInt( width, 10 );
[445] Fix | Delete
width += 10;
[446] Fix | Delete
}
[447] Fix | Delete
[448] Fix | Delete
if ( captionNode ) {
[449] Fix | Delete
dl = dom.select( 'dl.wp-caption', captionNode );
[450] Fix | Delete
[451] Fix | Delete
if ( dl.length ) {
[452] Fix | Delete
dom.setAttribs( dl, {
[453] Fix | Delete
id: id,
[454] Fix | Delete
'class': className,
[455] Fix | Delete
style: 'width: ' + width + 'px'
[456] Fix | Delete
} );
[457] Fix | Delete
}
[458] Fix | Delete
[459] Fix | Delete
dd = dom.select( '.wp-caption-dd', captionNode );
[460] Fix | Delete
[461] Fix | Delete
if ( dd.length ) {
[462] Fix | Delete
dom.setHTML( dd[0], imageData.caption );
[463] Fix | Delete
}
[464] Fix | Delete
[465] Fix | Delete
} else {
[466] Fix | Delete
id = id ? 'id="'+ id +'" ' : '';
[467] Fix | Delete
[468] Fix | Delete
// Should create a new function for generating the caption markup.
[469] Fix | Delete
html = '<dl ' + id + 'class="' + className +'" style="width: '+ width +'px">' +
[470] Fix | Delete
'<dt class="wp-caption-dt"></dt><dd class="wp-caption-dd">'+ imageData.caption +'</dd></dl>';
[471] Fix | Delete
[472] Fix | Delete
wrap = dom.create( 'div', { 'class': 'mceTemp' }, html );
[473] Fix | Delete
[474] Fix | Delete
if ( parent = dom.getParent( node, 'p' ) ) {
[475] Fix | Delete
parent.parentNode.insertBefore( wrap, parent );
[476] Fix | Delete
} else {
[477] Fix | Delete
node.parentNode.insertBefore( wrap, node );
[478] Fix | Delete
}
[479] Fix | Delete
[480] Fix | Delete
editor.$( wrap ).find( 'dt.wp-caption-dt' ).append( node );
[481] Fix | Delete
[482] Fix | Delete
if ( parent && dom.isEmpty( parent ) ) {
[483] Fix | Delete
dom.remove( parent );
[484] Fix | Delete
}
[485] Fix | Delete
}
[486] Fix | Delete
} else if ( captionNode ) {
[487] Fix | Delete
// Remove the caption wrapper and place the image in new paragraph.
[488] Fix | Delete
parent = dom.create( 'p' );
[489] Fix | Delete
captionNode.parentNode.insertBefore( parent, captionNode );
[490] Fix | Delete
parent.appendChild( node );
[491] Fix | Delete
dom.remove( captionNode );
[492] Fix | Delete
}
[493] Fix | Delete
[494] Fix | Delete
$imageNode = editor.$( imageNode );
[495] Fix | Delete
srcset = $imageNode.attr( 'srcset' );
[496] Fix | Delete
src = $imageNode.attr( 'src' );
[497] Fix | Delete
[498] Fix | Delete
// Remove srcset and sizes if the image file was edited or the image was replaced.
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function