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
This commit is contained in:
Andrew Ozz 2014-02-13 20:12:46 +00:00
parent f1e7635a2d
commit f6af16cd76
2 changed files with 37 additions and 14 deletions

View File

@ -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 '<img src="' + tinymce.Env.transparentSrc + '" class="wp-media wp-gallery mceItem" ' +
'data-wp-media="' + data + '" data-mce-resize="false" data-mce-placeholder="1" />';
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;
return '<img src="' + tinymce.Env.transparentSrc + '" class="' + cls + '" ' +
function html( cls, data ) {
data = window.encodeURIComponent( data );
return '<img src="' + tinymce.Env.transparentSrc + '" class="wp-media mceItem ' + cls + '" ' +
'data-wp-media="' + data + '" data-mce-resize="false" data-mce-placeholder="1" />';
});
}
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();
}
});

View File

@ -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;