Edit File by line
/home/barbar84/www/wp-inclu.../js/tinymce/plugins/wpeditim...
File: plugin.js
if ( srcset && src ) {
[500] Fix | Delete
src = src.replace( /[?#].*/, '' );
[501] Fix | Delete
[502] Fix | Delete
if ( srcset.indexOf( src ) === -1 ) {
[503] Fix | Delete
$imageNode.attr( 'srcset', null ).attr( 'sizes', null );
[504] Fix | Delete
}
[505] Fix | Delete
}
[506] Fix | Delete
[507] Fix | Delete
if ( wp.media.events ) {
[508] Fix | Delete
wp.media.events.trigger( 'editor:image-update', {
[509] Fix | Delete
editor: editor,
[510] Fix | Delete
metadata: imageData,
[511] Fix | Delete
image: imageNode
[512] Fix | Delete
} );
[513] Fix | Delete
}
[514] Fix | Delete
[515] Fix | Delete
editor.nodeChanged();
[516] Fix | Delete
}
[517] Fix | Delete
[518] Fix | Delete
function editImage( img ) {
[519] Fix | Delete
var frame, callback, metadata, imageNode;
[520] Fix | Delete
[521] Fix | Delete
if ( typeof wp === 'undefined' || ! wp.media ) {
[522] Fix | Delete
editor.execCommand( 'mceImage' );
[523] Fix | Delete
return;
[524] Fix | Delete
}
[525] Fix | Delete
[526] Fix | Delete
metadata = extractImageData( img );
[527] Fix | Delete
[528] Fix | Delete
// Mark the image node so we can select it later.
[529] Fix | Delete
editor.$( img ).attr( 'data-wp-editing', 1 );
[530] Fix | Delete
[531] Fix | Delete
// Manipulate the metadata by reference that is fed into the PostImage model used in the media modal.
[532] Fix | Delete
wp.media.events.trigger( 'editor:image-edit', {
[533] Fix | Delete
editor: editor,
[534] Fix | Delete
metadata: metadata,
[535] Fix | Delete
image: img
[536] Fix | Delete
} );
[537] Fix | Delete
[538] Fix | Delete
frame = wp.media({
[539] Fix | Delete
frame: 'image',
[540] Fix | Delete
state: 'image-details',
[541] Fix | Delete
metadata: metadata
[542] Fix | Delete
} );
[543] Fix | Delete
[544] Fix | Delete
wp.media.events.trigger( 'editor:frame-create', { frame: frame } );
[545] Fix | Delete
[546] Fix | Delete
callback = function( imageData ) {
[547] Fix | Delete
editor.undoManager.transact( function() {
[548] Fix | Delete
updateImage( imageNode, imageData );
[549] Fix | Delete
} );
[550] Fix | Delete
frame.detach();
[551] Fix | Delete
};
[552] Fix | Delete
[553] Fix | Delete
frame.state('image-details').on( 'update', callback );
[554] Fix | Delete
frame.state('replace-image').on( 'replace', callback );
[555] Fix | Delete
frame.on( 'close', function() {
[556] Fix | Delete
editor.focus();
[557] Fix | Delete
frame.detach();
[558] Fix | Delete
[559] Fix | Delete
/*
[560] Fix | Delete
* `close` fires first...
[561] Fix | Delete
* To be able to update the image node, we need to find it here,
[562] Fix | Delete
* and use it in the callback.
[563] Fix | Delete
*/
[564] Fix | Delete
imageNode = editor.$( 'img[data-wp-editing]' )
[565] Fix | Delete
imageNode.removeAttr( 'data-wp-editing' );
[566] Fix | Delete
});
[567] Fix | Delete
[568] Fix | Delete
frame.open();
[569] Fix | Delete
}
[570] Fix | Delete
[571] Fix | Delete
function removeImage( node ) {
[572] Fix | Delete
var wrap = editor.dom.getParent( node, 'div.mceTemp' );
[573] Fix | Delete
[574] Fix | Delete
if ( ! wrap && node.nodeName === 'IMG' ) {
[575] Fix | Delete
wrap = editor.dom.getParent( node, 'a' );
[576] Fix | Delete
}
[577] Fix | Delete
[578] Fix | Delete
if ( wrap ) {
[579] Fix | Delete
if ( wrap.nextSibling ) {
[580] Fix | Delete
editor.selection.select( wrap.nextSibling );
[581] Fix | Delete
} else if ( wrap.previousSibling ) {
[582] Fix | Delete
editor.selection.select( wrap.previousSibling );
[583] Fix | Delete
} else {
[584] Fix | Delete
editor.selection.select( wrap.parentNode );
[585] Fix | Delete
}
[586] Fix | Delete
[587] Fix | Delete
editor.selection.collapse( true );
[588] Fix | Delete
editor.dom.remove( wrap );
[589] Fix | Delete
} else {
[590] Fix | Delete
editor.dom.remove( node );
[591] Fix | Delete
}
[592] Fix | Delete
[593] Fix | Delete
editor.nodeChanged();
[594] Fix | Delete
editor.undoManager.add();
[595] Fix | Delete
}
[596] Fix | Delete
[597] Fix | Delete
editor.on( 'init', function() {
[598] Fix | Delete
var dom = editor.dom,
[599] Fix | Delete
captionClass = editor.getParam( 'wpeditimage_html5_captions' ) ? 'html5-captions' : 'html4-captions';
[600] Fix | Delete
[601] Fix | Delete
dom.addClass( editor.getBody(), captionClass );
[602] Fix | Delete
[603] Fix | Delete
// Prevent IE11 from making dl.wp-caption resizable.
[604] Fix | Delete
if ( tinymce.Env.ie && tinymce.Env.ie > 10 ) {
[605] Fix | Delete
// The 'mscontrolselect' event is supported only in IE11+.
[606] Fix | Delete
dom.bind( editor.getBody(), 'mscontrolselect', function( event ) {
[607] Fix | Delete
if ( event.target.nodeName === 'IMG' && dom.getParent( event.target, '.wp-caption' ) ) {
[608] Fix | Delete
// Hide the thick border with resize handles around dl.wp-caption.
[609] Fix | Delete
editor.getBody().focus(); // :(
[610] Fix | Delete
} else if ( event.target.nodeName === 'DL' && dom.hasClass( event.target, 'wp-caption' ) ) {
[611] Fix | Delete
// Trigger the thick border with resize handles...
[612] Fix | Delete
// This will make the caption text editable.
[613] Fix | Delete
event.target.focus();
[614] Fix | Delete
}
[615] Fix | Delete
});
[616] Fix | Delete
}
[617] Fix | Delete
});
[618] Fix | Delete
[619] Fix | Delete
editor.on( 'ObjectResized', function( event ) {
[620] Fix | Delete
var node = event.target;
[621] Fix | Delete
[622] Fix | Delete
if ( node.nodeName === 'IMG' ) {
[623] Fix | Delete
editor.undoManager.transact( function() {
[624] Fix | Delete
var parent, width,
[625] Fix | Delete
dom = editor.dom;
[626] Fix | Delete
[627] Fix | Delete
node.className = node.className.replace( /\bsize-[^ ]+/, '' );
[628] Fix | Delete
[629] Fix | Delete
if ( parent = dom.getParent( node, '.wp-caption' ) ) {
[630] Fix | Delete
width = event.width || dom.getAttrib( node, 'width' );
[631] Fix | Delete
[632] Fix | Delete
if ( width ) {
[633] Fix | Delete
width = parseInt( width, 10 );
[634] Fix | Delete
[635] Fix | Delete
if ( ! editor.getParam( 'wpeditimage_html5_captions' ) ) {
[636] Fix | Delete
width += 10;
[637] Fix | Delete
}
[638] Fix | Delete
[639] Fix | Delete
dom.setStyle( parent, 'width', width + 'px' );
[640] Fix | Delete
}
[641] Fix | Delete
}
[642] Fix | Delete
});
[643] Fix | Delete
}
[644] Fix | Delete
});
[645] Fix | Delete
[646] Fix | Delete
editor.on( 'pastePostProcess', function( event ) {
[647] Fix | Delete
// Pasting in a caption node.
[648] Fix | Delete
if ( editor.dom.getParent( editor.selection.getNode(), 'dd.wp-caption-dd' ) ) {
[649] Fix | Delete
// Remove "non-block" elements that should not be in captions.
[650] Fix | Delete
editor.$( 'img, audio, video, object, embed, iframe, script, style', event.node ).remove();
[651] Fix | Delete
[652] Fix | Delete
editor.$( '*', event.node ).each( function( i, node ) {
[653] Fix | Delete
if ( editor.dom.isBlock( node ) ) {
[654] Fix | Delete
// Insert <br> where the blocks used to be. Makes it look better after pasting in the caption.
[655] Fix | Delete
if ( tinymce.trim( node.textContent || node.innerText ) ) {
[656] Fix | Delete
editor.dom.insertAfter( editor.dom.create( 'br' ), node );
[657] Fix | Delete
editor.dom.remove( node, true );
[658] Fix | Delete
} else {
[659] Fix | Delete
editor.dom.remove( node );
[660] Fix | Delete
}
[661] Fix | Delete
}
[662] Fix | Delete
});
[663] Fix | Delete
[664] Fix | Delete
// Trim <br> tags.
[665] Fix | Delete
editor.$( 'br', event.node ).each( function( i, node ) {
[666] Fix | Delete
if ( ! node.nextSibling || node.nextSibling.nodeName === 'BR' ||
[667] Fix | Delete
! node.previousSibling || node.previousSibling.nodeName === 'BR' ) {
[668] Fix | Delete
[669] Fix | Delete
editor.dom.remove( node );
[670] Fix | Delete
}
[671] Fix | Delete
} );
[672] Fix | Delete
[673] Fix | Delete
// Pasted HTML is cleaned up for inserting in the caption.
[674] Fix | Delete
pasteInCaption = true;
[675] Fix | Delete
}
[676] Fix | Delete
});
[677] Fix | Delete
[678] Fix | Delete
editor.on( 'BeforeExecCommand', function( event ) {
[679] Fix | Delete
var node, p, DL, align, replacement, captionParent,
[680] Fix | Delete
cmd = event.command,
[681] Fix | Delete
dom = editor.dom;
[682] Fix | Delete
[683] Fix | Delete
if ( cmd === 'mceInsertContent' || cmd === 'Indent' || cmd === 'Outdent' ) {
[684] Fix | Delete
node = editor.selection.getNode();
[685] Fix | Delete
captionParent = dom.getParent( node, 'div.mceTemp' );
[686] Fix | Delete
[687] Fix | Delete
if ( captionParent ) {
[688] Fix | Delete
if ( cmd === 'mceInsertContent' ) {
[689] Fix | Delete
if ( pasteInCaption ) {
[690] Fix | Delete
pasteInCaption = false;
[691] Fix | Delete
/*
[692] Fix | Delete
* We are in the caption element, and in 'paste' context,
[693] Fix | Delete
* and the pasted HTML was cleaned up on 'pastePostProcess' above.
[694] Fix | Delete
* Let it be pasted in the caption.
[695] Fix | Delete
*/
[696] Fix | Delete
return;
[697] Fix | Delete
}
[698] Fix | Delete
[699] Fix | Delete
/*
[700] Fix | Delete
* The paste is somewhere else in the caption DL element.
[701] Fix | Delete
* Prevent pasting in there as it will break the caption.
[702] Fix | Delete
* Make new paragraph under the caption DL and move the caret there.
[703] Fix | Delete
*/
[704] Fix | Delete
p = dom.create( 'p' );
[705] Fix | Delete
dom.insertAfter( p, captionParent );
[706] Fix | Delete
editor.selection.setCursorLocation( p, 0 );
[707] Fix | Delete
[708] Fix | Delete
/*
[709] Fix | Delete
* If the image is selected and the user pastes "over" it,
[710] Fix | Delete
* replace both the image and the caption elements with the pasted content.
[711] Fix | Delete
* This matches the behavior when pasting over non-caption images.
[712] Fix | Delete
*/
[713] Fix | Delete
if ( node.nodeName === 'IMG' ) {
[714] Fix | Delete
editor.$( captionParent ).remove();
[715] Fix | Delete
}
[716] Fix | Delete
[717] Fix | Delete
editor.nodeChanged();
[718] Fix | Delete
} else {
[719] Fix | Delete
// Clicking Indent or Outdent while an image with a caption is selected breaks the caption.
[720] Fix | Delete
// See #38313.
[721] Fix | Delete
event.preventDefault();
[722] Fix | Delete
event.stopImmediatePropagation();
[723] Fix | Delete
return false;
[724] Fix | Delete
}
[725] Fix | Delete
}
[726] Fix | Delete
} else if ( cmd === 'JustifyLeft' || cmd === 'JustifyRight' || cmd === 'JustifyCenter' || cmd === 'wpAlignNone' ) {
[727] Fix | Delete
node = editor.selection.getNode();
[728] Fix | Delete
align = 'align' + cmd.slice( 7 ).toLowerCase();
[729] Fix | Delete
DL = editor.dom.getParent( node, '.wp-caption' );
[730] Fix | Delete
[731] Fix | Delete
if ( node.nodeName !== 'IMG' && ! DL ) {
[732] Fix | Delete
return;
[733] Fix | Delete
}
[734] Fix | Delete
[735] Fix | Delete
node = DL || node;
[736] Fix | Delete
[737] Fix | Delete
if ( editor.dom.hasClass( node, align ) ) {
[738] Fix | Delete
replacement = ' alignnone';
[739] Fix | Delete
} else {
[740] Fix | Delete
replacement = ' ' + align;
[741] Fix | Delete
}
[742] Fix | Delete
[743] Fix | Delete
node.className = trim( node.className.replace( / ?align(left|center|right|none)/g, '' ) + replacement );
[744] Fix | Delete
[745] Fix | Delete
editor.nodeChanged();
[746] Fix | Delete
event.preventDefault();
[747] Fix | Delete
[748] Fix | Delete
if ( toolbar ) {
[749] Fix | Delete
toolbar.reposition();
[750] Fix | Delete
}
[751] Fix | Delete
[752] Fix | Delete
editor.fire( 'ExecCommand', {
[753] Fix | Delete
command: cmd,
[754] Fix | Delete
ui: event.ui,
[755] Fix | Delete
value: event.value
[756] Fix | Delete
} );
[757] Fix | Delete
}
[758] Fix | Delete
});
[759] Fix | Delete
[760] Fix | Delete
editor.on( 'keydown', function( event ) {
[761] Fix | Delete
var node, wrap, P, spacer,
[762] Fix | Delete
selection = editor.selection,
[763] Fix | Delete
keyCode = event.keyCode,
[764] Fix | Delete
dom = editor.dom,
[765] Fix | Delete
VK = tinymce.util.VK;
[766] Fix | Delete
[767] Fix | Delete
if ( keyCode === VK.ENTER ) {
[768] Fix | Delete
// When pressing Enter inside a caption move the caret to a new parapraph under it.
[769] Fix | Delete
node = selection.getNode();
[770] Fix | Delete
wrap = dom.getParent( node, 'div.mceTemp' );
[771] Fix | Delete
[772] Fix | Delete
if ( wrap ) {
[773] Fix | Delete
dom.events.cancel( event ); // Doesn't cancel all :(
[774] Fix | Delete
[775] Fix | Delete
// Remove any extra dt and dd cleated on pressing Enter...
[776] Fix | Delete
tinymce.each( dom.select( 'dt, dd', wrap ), function( element ) {
[777] Fix | Delete
if ( dom.isEmpty( element ) ) {
[778] Fix | Delete
dom.remove( element );
[779] Fix | Delete
}
[780] Fix | Delete
});
[781] Fix | Delete
[782] Fix | Delete
spacer = tinymce.Env.ie && tinymce.Env.ie < 11 ? '' : '<br data-mce-bogus="1" />';
[783] Fix | Delete
P = dom.create( 'p', null, spacer );
[784] Fix | Delete
[785] Fix | Delete
if ( node.nodeName === 'DD' ) {
[786] Fix | Delete
dom.insertAfter( P, wrap );
[787] Fix | Delete
} else {
[788] Fix | Delete
wrap.parentNode.insertBefore( P, wrap );
[789] Fix | Delete
}
[790] Fix | Delete
[791] Fix | Delete
editor.nodeChanged();
[792] Fix | Delete
selection.setCursorLocation( P, 0 );
[793] Fix | Delete
}
[794] Fix | Delete
} else if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) {
[795] Fix | Delete
node = selection.getNode();
[796] Fix | Delete
[797] Fix | Delete
if ( node.nodeName === 'DIV' && dom.hasClass( node, 'mceTemp' ) ) {
[798] Fix | Delete
wrap = node;
[799] Fix | Delete
} else if ( node.nodeName === 'IMG' || node.nodeName === 'DT' || node.nodeName === 'A' ) {
[800] Fix | Delete
wrap = dom.getParent( node, 'div.mceTemp' );
[801] Fix | Delete
}
[802] Fix | Delete
[803] Fix | Delete
if ( wrap ) {
[804] Fix | Delete
dom.events.cancel( event );
[805] Fix | Delete
removeImage( node );
[806] Fix | Delete
return false;
[807] Fix | Delete
}
[808] Fix | Delete
}
[809] Fix | Delete
});
[810] Fix | Delete
[811] Fix | Delete
/*
[812] Fix | Delete
* After undo/redo FF seems to set the image height very slowly when it is set to 'auto' in the CSS.
[813] Fix | Delete
* This causes image.getBoundingClientRect() to return wrong values and the resize handles are shown in wrong places.
[814] Fix | Delete
* Collapse the selection to remove the resize handles.
[815] Fix | Delete
*/
[816] Fix | Delete
if ( tinymce.Env.gecko ) {
[817] Fix | Delete
editor.on( 'undo redo', function() {
[818] Fix | Delete
if ( editor.selection.getNode().nodeName === 'IMG' ) {
[819] Fix | Delete
editor.selection.collapse();
[820] Fix | Delete
}
[821] Fix | Delete
});
[822] Fix | Delete
}
[823] Fix | Delete
[824] Fix | Delete
editor.wpSetImgCaption = function( content ) {
[825] Fix | Delete
return parseShortcode( content );
[826] Fix | Delete
};
[827] Fix | Delete
[828] Fix | Delete
editor.wpGetImgCaption = function( content ) {
[829] Fix | Delete
return getShortcode( content );
[830] Fix | Delete
};
[831] Fix | Delete
[832] Fix | Delete
editor.on( 'beforeGetContent', function( event ) {
[833] Fix | Delete
if ( event.format !== 'raw' ) {
[834] Fix | Delete
editor.$( 'img[id="__wp-temp-img-id"]' ).removeAttr( 'id' );
[835] Fix | Delete
}
[836] Fix | Delete
});
[837] Fix | Delete
[838] Fix | Delete
editor.on( 'BeforeSetContent', function( event ) {
[839] Fix | Delete
if ( event.format !== 'raw' ) {
[840] Fix | Delete
event.content = editor.wpSetImgCaption( event.content );
[841] Fix | Delete
}
[842] Fix | Delete
});
[843] Fix | Delete
[844] Fix | Delete
editor.on( 'PostProcess', function( event ) {
[845] Fix | Delete
if ( event.get ) {
[846] Fix | Delete
event.content = editor.wpGetImgCaption( event.content );
[847] Fix | Delete
}
[848] Fix | Delete
});
[849] Fix | Delete
[850] Fix | Delete
( function() {
[851] Fix | Delete
var wrap;
[852] Fix | Delete
[853] Fix | Delete
editor.on( 'dragstart', function() {
[854] Fix | Delete
var node = editor.selection.getNode();
[855] Fix | Delete
[856] Fix | Delete
if ( node.nodeName === 'IMG' ) {
[857] Fix | Delete
wrap = editor.dom.getParent( node, '.mceTemp' );
[858] Fix | Delete
[859] Fix | Delete
if ( ! wrap && node.parentNode.nodeName === 'A' && ! hasTextContent( node.parentNode ) ) {
[860] Fix | Delete
wrap = node.parentNode;
[861] Fix | Delete
}
[862] Fix | Delete
}
[863] Fix | Delete
} );
[864] Fix | Delete
[865] Fix | Delete
editor.on( 'drop', function( event ) {
[866] Fix | Delete
var dom = editor.dom,
[867] Fix | Delete
rng = tinymce.dom.RangeUtils.getCaretRangeFromPoint( event.clientX, event.clientY, editor.getDoc() );
[868] Fix | Delete
[869] Fix | Delete
// Don't allow anything to be dropped in a captioned image.
[870] Fix | Delete
if ( rng && dom.getParent( rng.startContainer, '.mceTemp' ) ) {
[871] Fix | Delete
event.preventDefault();
[872] Fix | Delete
} else if ( wrap ) {
[873] Fix | Delete
event.preventDefault();
[874] Fix | Delete
[875] Fix | Delete
editor.undoManager.transact( function() {
[876] Fix | Delete
if ( rng ) {
[877] Fix | Delete
editor.selection.setRng( rng );
[878] Fix | Delete
}
[879] Fix | Delete
[880] Fix | Delete
editor.selection.setNode( wrap );
[881] Fix | Delete
dom.remove( wrap );
[882] Fix | Delete
} );
[883] Fix | Delete
}
[884] Fix | Delete
[885] Fix | Delete
wrap = null;
[886] Fix | Delete
} );
[887] Fix | Delete
} )();
[888] Fix | Delete
[889] Fix | Delete
// Add to editor.wp.
[890] Fix | Delete
editor.wp = editor.wp || {};
[891] Fix | Delete
editor.wp.isPlaceholder = isPlaceholder;
[892] Fix | Delete
[893] Fix | Delete
// Back-compat.
[894] Fix | Delete
return {
[895] Fix | Delete
_do_shcode: parseShortcode,
[896] Fix | Delete
_get_shcode: getShortcode
[897] Fix | Delete
};
[898] Fix | Delete
});
[899] Fix | Delete
[900] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function