From f6af16cd7617238ce8bc63d599707646f25ce938 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 13 Feb 2014 20:12:46 +0000 Subject: [PATCH] TinyMCE: add support for audio and video shortcodes without closing, fix jshint warning, see #27016. git-svn-id: https://develop.svn.wordpress.org/trunk@27177 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wpgallery/plugin.js | 47 +++++++++++++------ .../js/tinymce/skins/wordpress/wp-content.css | 4 ++ 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wpgallery/plugin.js b/src/wp-includes/js/tinymce/plugins/wpgallery/plugin.js index 2decd5b0ad..31705c2412 100644 --- a/src/wp-includes/js/tinymce/plugins/wpgallery/plugin.js +++ b/src/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/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css b/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css index f0b9a73f84..ee2b29a7cc 100644 --- a/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css +++ b/src/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;