diff --git a/wp-includes/js/tinymce/plugins/wpgallery/plugin.js b/wp-includes/js/tinymce/plugins/wpgallery/plugin.js index 2decd5b0ad..31705c2412 100644 --- a/wp-includes/js/tinymce/plugins/wpgallery/plugin.js +++ b/wp-includes/js/tinymce/plugins/wpgallery/plugin.js @@ -3,21 +3,36 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { function replaceGalleryShortcodes( content ) { return content.replace( /\[gallery([^\]]*)\]/g, function( match ) { - var data = window.encodeURIComponent( match ); - - return ''; + return html( 'wp-gallery', match ); }); } - function replaceAVShortcodes( content ) { - return content.replace( /\[(audio|video)[^\]]*\][\s\S]*?\[\/\1\]/g, function( match, type ) { - var data = window.encodeURIComponent( match ), - cls = 'wp-media mceItem wp-' + type; + function html( cls, data ) { + data = window.encodeURIComponent( data ); + return ''; + } - return ''; - }); + function replaceCallback( match, type, close ) { + var index; + + if ( close && close.indexOf( '[' + type ) > -1 ) { + index = match.length - close.length; + return html( 'wp-' + type, match.substring( 0, index ) ) + match.substring( index ); + } + + return html( 'wp-' + type, match ); + } + + function replaceAVShortcodes( content ) { + var testRegex = /\[(audio|video)[^\]]*\]/, + replaceRegex = /\[(audio|video)[^\]]*\]([\s\S]*?\[\/\1\])?/; + + while ( testRegex.test( content ) ) { + content = content.replace( replaceRegex, replaceCallback ); + } + + return content; } function restoreMediaShortcodes( content ) { @@ -61,7 +76,7 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { }); } else { // temp - window.console && console.log( 'Edit AV shortcode ' + window.decodeURIComponent( editor.dom.getAttrib( node, 'data-wp-media' ) ) ); + window.console && window.console.log( 'Edit AV shortcode ' + window.decodeURIComponent( editor.dom.getAttrib( node, 'data-wp-media' ) ) ); } } @@ -92,18 +107,22 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { var dom = editor.dom, node = event.target; + function unselect() { + dom.removeClass( dom.select( 'img.wp-media-selected' ), 'wp-media-selected' ); + } + if ( node.nodeName === 'IMG' && dom.getAttrib( node, 'data-wp-media' ) ) { // Don't trigger on right-click if ( event.button !== 2 ) { if ( dom.hasClass( node, 'wp-media-selected' ) ) { editMedia( node ); - dom.removeClass( node, 'wp-media-selected' ); } else { + unselect(); dom.addClass( node, 'wp-media-selected' ); } } } else { - dom.removeClass( dom.select( 'img.wp-media-selected' ), 'wp-media-selected' ); + unselect(); } }); diff --git a/wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js b/wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js index 56db54423d..94ec6d5640 100644 --- a/wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js +++ b/wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js @@ -1 +1 @@ -tinymce.PluginManager.add("wpgallery",function(a){function b(a){return a.replace(/\[gallery([^\]]*)\]/g,function(a){var b=window.encodeURIComponent(a);return''})}function c(a){return a.replace(/\[(audio|video)[^\]]*\][\s\S]*?\[\/\1\]/g,function(a,b){var c=window.encodeURIComponent(a),d="wp-media mceItem wp-"+b;return''})}function d(a){function b(a,b){return b=new RegExp(b+'="([^"]+)"').exec(a),b?window.decodeURIComponent(b[1]):""}return a.replace(/(?:]+)?>)*(]+>)(?:<\/p>)*/g,function(a,c){var d=b(c,"data-wp-media");return d?"

"+d+"

":a})}function e(b){var c,d,e;"IMG"===b.nodeName&&"undefined"!=typeof wp&&wp.media&&wp.media.gallery&&(a.dom.hasClass(b,"wp-gallery")?(c=wp.media.gallery,e=window.decodeURIComponent(a.dom.getAttrib(b,"data-wp-media")),d=c.edit(e),d.state("gallery-edit").on("update",function(d){var e=c.shortcode(d).string();a.dom.setAttrib(b,"data-wp-media",window.encodeURIComponent(e))})):window.console&&console.log("Edit AV shortcode "+window.decodeURIComponent(a.dom.getAttrib(b,"data-wp-media"))))}a.addCommand("WP_Gallery",function(){e(a.selection.getNode())}),a.on("mouseup",function(b){var c=a.dom,d=b.target;"IMG"===d.nodeName&&c.getAttrib(d,"data-wp-media")?2!==b.button&&(c.hasClass(d,"wp-media-selected")?(e(d),c.removeClass(d,"wp-media-selected")):c.addClass(d,"wp-media-selected")):c.removeClass(c.select("img.wp-media-selected"),"wp-media-selected")}),a.on("ResolveName",function(b){var c=a.dom,d=b.target;"IMG"===d.nodeName&&c.getAttrib(d,"data-wp-media")&&(c.hasClass(d,"wp-gallery")?b.name="gallery":c.hasClass(d,"wp-video")?b.name="video":c.hasClass(d,"wp-audio")&&(b.name="audio"))}),a.on("BeforeSetContent",function(a){a.content=b(a.content),a.content=c(a.content)}),a.on("PostProcess",function(a){a.get&&(a.content=d(a.content))})}); \ No newline at end of file +tinymce.PluginManager.add("wpgallery",function(a){function b(a){return a.replace(/\[gallery([^\]]*)\]/g,function(a){return c("wp-gallery",a)})}function c(a,b){return b=window.encodeURIComponent(b),''}function d(a,b,d){var e;return d&&d.indexOf("["+b)>-1?(e=a.length-d.length,c("wp-"+b,a.substring(0,e))+a.substring(e)):c("wp-"+b,a)}function e(a){for(var b=/\[(audio|video)[^\]]*\]/,c=/\[(audio|video)[^\]]*\]([\s\S]*?\[\/\1\])?/;b.test(a);)a=a.replace(c,d);return a}function f(a){function b(a,b){return b=new RegExp(b+'="([^"]+)"').exec(a),b?window.decodeURIComponent(b[1]):""}return a.replace(/(?:]+)?>)*(]+>)(?:<\/p>)*/g,function(a,c){var d=b(c,"data-wp-media");return d?"

"+d+"

":a})}function g(b){var c,d,e;"IMG"===b.nodeName&&"undefined"!=typeof wp&&wp.media&&wp.media.gallery&&(a.dom.hasClass(b,"wp-gallery")?(c=wp.media.gallery,e=window.decodeURIComponent(a.dom.getAttrib(b,"data-wp-media")),d=c.edit(e),d.state("gallery-edit").on("update",function(d){var e=c.shortcode(d).string();a.dom.setAttrib(b,"data-wp-media",window.encodeURIComponent(e))})):window.console&&window.console.log("Edit AV shortcode "+window.decodeURIComponent(a.dom.getAttrib(b,"data-wp-media"))))}a.addCommand("WP_Gallery",function(){g(a.selection.getNode())}),a.on("mouseup",function(b){function c(){d.removeClass(d.select("img.wp-media-selected"),"wp-media-selected")}var d=a.dom,e=b.target;"IMG"===e.nodeName&&d.getAttrib(e,"data-wp-media")?2!==b.button&&(d.hasClass(e,"wp-media-selected")?g(e):(c(),d.addClass(e,"wp-media-selected"))):c()}),a.on("ResolveName",function(b){var c=a.dom,d=b.target;"IMG"===d.nodeName&&c.getAttrib(d,"data-wp-media")&&(c.hasClass(d,"wp-gallery")?b.name="gallery":c.hasClass(d,"wp-video")?b.name="video":c.hasClass(d,"wp-audio")&&(b.name="audio"))}),a.on("BeforeSetContent",function(a){a.content=b(a.content),a.content=e(a.content)}),a.on("PostProcess",function(a){a.get&&(a.content=f(a.content))})}); \ No newline at end of file diff --git a/wp-includes/js/tinymce/skins/wordpress/wp-content.css b/wp-includes/js/tinymce/skins/wordpress/wp-content.css index f0b9a73f84..ee2b29a7cc 100644 --- a/wp-includes/js/tinymce/skins/wordpress/wp-content.css +++ b/wp-includes/js/tinymce/skins/wordpress/wp-content.css @@ -183,6 +183,10 @@ img::selection { outline: 1px solid #777; } +.mce-content-body img[data-mce-resize="false"] { + outline: 0; +} + img.wp-oembed { border: 1px dashed #888; background: #f7f5f2 url("images/embedded.png") no-repeat scroll center center; diff --git a/wp-includes/js/tinymce/wp-tinymce.js.gz b/wp-includes/js/tinymce/wp-tinymce.js.gz index 4856513f91..d75b080137 100644 Binary files a/wp-includes/js/tinymce/wp-tinymce.js.gz and b/wp-includes/js/tinymce/wp-tinymce.js.gz differ