Edit File by line
/home/barbar84/www/wp-inclu.../js/tinymce/plugins/wpgaller...
File: plugin.js
/* global tinymce */
[0] Fix | Delete
tinymce.PluginManager.add('wpgallery', function( editor ) {
[1] Fix | Delete
[2] Fix | Delete
function replaceGalleryShortcodes( content ) {
[3] Fix | Delete
return content.replace( /\[gallery([^\]]*)\]/g, function( match ) {
[4] Fix | Delete
return html( 'wp-gallery', match );
[5] Fix | Delete
});
[6] Fix | Delete
}
[7] Fix | Delete
[8] Fix | Delete
function html( cls, data ) {
[9] Fix | Delete
data = window.encodeURIComponent( data );
[10] Fix | Delete
return '<img src="' + tinymce.Env.transparentSrc + '" class="wp-media mceItem ' + cls + '" ' +
[11] Fix | Delete
'data-wp-media="' + data + '" data-mce-resize="false" data-mce-placeholder="1" alt="" />';
[12] Fix | Delete
}
[13] Fix | Delete
[14] Fix | Delete
function restoreMediaShortcodes( content ) {
[15] Fix | Delete
function getAttr( str, name ) {
[16] Fix | Delete
name = new RegExp( name + '=\"([^\"]+)\"' ).exec( str );
[17] Fix | Delete
return name ? window.decodeURIComponent( name[1] ) : '';
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
return content.replace( /(?:<p(?: [^>]+)?>)*(<img [^>]+>)(?:<\/p>)*/g, function( match, image ) {
[21] Fix | Delete
var data = getAttr( image, 'data-wp-media' );
[22] Fix | Delete
[23] Fix | Delete
if ( data ) {
[24] Fix | Delete
return '<p>' + data + '</p>';
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
return match;
[28] Fix | Delete
});
[29] Fix | Delete
}
[30] Fix | Delete
[31] Fix | Delete
function editMedia( node ) {
[32] Fix | Delete
var gallery, frame, data;
[33] Fix | Delete
[34] Fix | Delete
if ( node.nodeName !== 'IMG' ) {
[35] Fix | Delete
return;
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
// Check if the `wp.media` API exists.
[39] Fix | Delete
if ( typeof wp === 'undefined' || ! wp.media ) {
[40] Fix | Delete
return;
[41] Fix | Delete
}
[42] Fix | Delete
[43] Fix | Delete
data = window.decodeURIComponent( editor.dom.getAttrib( node, 'data-wp-media' ) );
[44] Fix | Delete
[45] Fix | Delete
// Make sure we've selected a gallery node.
[46] Fix | Delete
if ( editor.dom.hasClass( node, 'wp-gallery' ) && wp.media.gallery ) {
[47] Fix | Delete
gallery = wp.media.gallery;
[48] Fix | Delete
frame = gallery.edit( data );
[49] Fix | Delete
[50] Fix | Delete
frame.state('gallery-edit').on( 'update', function( selection ) {
[51] Fix | Delete
var shortcode = gallery.shortcode( selection ).string();
[52] Fix | Delete
editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) );
[53] Fix | Delete
frame.detach();
[54] Fix | Delete
});
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...').
[59] Fix | Delete
editor.addCommand( 'WP_Gallery', function() {
[60] Fix | Delete
editMedia( editor.selection.getNode() );
[61] Fix | Delete
});
[62] Fix | Delete
[63] Fix | Delete
editor.on( 'mouseup', function( event ) {
[64] Fix | Delete
var dom = editor.dom,
[65] Fix | Delete
node = event.target;
[66] Fix | Delete
[67] Fix | Delete
function unselect() {
[68] Fix | Delete
dom.removeClass( dom.select( 'img.wp-media-selected' ), 'wp-media-selected' );
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
if ( node.nodeName === 'IMG' && dom.getAttrib( node, 'data-wp-media' ) ) {
[72] Fix | Delete
// Don't trigger on right-click.
[73] Fix | Delete
if ( event.button !== 2 ) {
[74] Fix | Delete
if ( dom.hasClass( node, 'wp-media-selected' ) ) {
[75] Fix | Delete
editMedia( node );
[76] Fix | Delete
} else {
[77] Fix | Delete
unselect();
[78] Fix | Delete
dom.addClass( node, 'wp-media-selected' );
[79] Fix | Delete
}
[80] Fix | Delete
}
[81] Fix | Delete
} else {
[82] Fix | Delete
unselect();
[83] Fix | Delete
}
[84] Fix | Delete
});
[85] Fix | Delete
[86] Fix | Delete
// Display gallery, audio or video instead of img in the element path.
[87] Fix | Delete
editor.on( 'ResolveName', function( event ) {
[88] Fix | Delete
var dom = editor.dom,
[89] Fix | Delete
node = event.target;
[90] Fix | Delete
[91] Fix | Delete
if ( node.nodeName === 'IMG' && dom.getAttrib( node, 'data-wp-media' ) ) {
[92] Fix | Delete
if ( dom.hasClass( node, 'wp-gallery' ) ) {
[93] Fix | Delete
event.name = 'gallery';
[94] Fix | Delete
}
[95] Fix | Delete
}
[96] Fix | Delete
});
[97] Fix | Delete
[98] Fix | Delete
editor.on( 'BeforeSetContent', function( event ) {
[99] Fix | Delete
// 'wpview' handles the gallery shortcode when present.
[100] Fix | Delete
if ( ! editor.plugins.wpview || typeof wp === 'undefined' || ! wp.mce ) {
[101] Fix | Delete
event.content = replaceGalleryShortcodes( event.content );
[102] Fix | Delete
}
[103] Fix | Delete
});
[104] Fix | Delete
[105] Fix | Delete
editor.on( 'PostProcess', function( event ) {
[106] Fix | Delete
if ( event.get ) {
[107] Fix | Delete
event.content = restoreMediaShortcodes( event.content );
[108] Fix | Delete
}
[109] Fix | Delete
});
[110] Fix | Delete
});
[111] Fix | Delete
[112] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function