diff --git a/wp-includes/js/tinymce/plugins/wpgallery/plugin.js b/wp-includes/js/tinymce/plugins/wpgallery/plugin.js index df2e8fca74..2decd5b0ad 100644 --- a/wp-includes/js/tinymce/plugins/wpgallery/plugin.js +++ b/wp-includes/js/tinymce/plugins/wpgallery/plugin.js @@ -1,53 +1,73 @@ /* global tinymce */ tinymce.PluginManager.add('wpgallery', function( editor ) { - function parseGallery( content ) { - return content.replace( /\[gallery([^\]]*)\]/g, function( match, attr ) { - var data = tinymce.DOM.encode( attr ); + function replaceGalleryShortcodes( content ) { + return content.replace( /\[gallery([^\]]*)\]/g, function( match ) { + var data = window.encodeURIComponent( match ); - return ''; + return ''; }); } - function getGallery( content ) { + 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 ''; + }); + } + + function restoreMediaShortcodes( content ) { function getAttr( str, name ) { - name = new RegExp( name + '=\"([^\"]+)\"', 'g' ).exec( str ); - return name ? tinymce.DOM.decode( name[1] ) : ''; + name = new RegExp( name + '=\"([^\"]+)\"' ).exec( str ); + return name ? window.decodeURIComponent( name[1] ) : ''; } - return content.replace( /(?:]*>)*(]+>)(?:<\/p>)*/g, function( match, image ) { - var cls = getAttr( image, 'class' ); + return content.replace( /(?:]+)?>)*(]+>)(?:<\/p>)*/g, function( match, image ) { + var data = getAttr( image, 'data-wp-media' ); - if ( cls.indexOf('wp-gallery') !== -1 ) { - return '

['+ tinymce.trim( getAttr( image, 'title' ) ) +']

'; + if ( data ) { + return '

' + data + '

'; } return match; }); } - // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...'); - editor.addCommand( 'WP_Gallery', function() { - var gallery, frame, node; + function editMedia( node ) { + var gallery, frame, data; + + if ( node.nodeName !== 'IMG' ) { + return; + } // Check if the `wp.media.gallery` API exists. if ( typeof wp === 'undefined' || ! wp.media || ! wp.media.gallery ) { return; } - node = editor.selection.getNode(); - gallery = wp.media.gallery; - // Make sure we've selected a gallery node. - if ( node.nodeName === 'IMG' && editor.dom.hasClass( node, 'wp-gallery' ) ) { - frame = gallery.edit( '[' + editor.dom.getAttrib( node, 'title' ) + ']' ); + if ( editor.dom.hasClass( node, 'wp-gallery' ) ) { + gallery = wp.media.gallery; + data = window.decodeURIComponent( editor.dom.getAttrib( node, 'data-wp-media' ) ); + frame = gallery.edit( data ); frame.state('gallery-edit').on( 'update', function( selection ) { - var shortcode = gallery.shortcode( selection ).string().slice( 1, -1 ); - editor.dom.setAttrib( node, 'title', shortcode ); + var shortcode = gallery.shortcode( selection ).string(); + editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) ); }); + } else { + // temp + window.console && console.log( 'Edit AV shortcode ' + window.decodeURIComponent( editor.dom.getAttrib( node, 'data-wp-media' ) ) ); } + } + + // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...'); + editor.addCommand( 'WP_Gallery', function() { + editMedia( editor.selection.getNode() ); }); /* editor.on( 'init', function( e ) { @@ -68,44 +88,49 @@ tinymce.PluginManager.add('wpgallery', function( editor ) { } }); */ - editor.on( 'mouseup', function( e ) { - if ( e.target.nodeName === 'IMG' && editor.dom.hasClass( e.target, 'wp-gallery' ) ) { + editor.on( 'mouseup', function( event ) { + var dom = editor.dom, + node = event.target; + + if ( node.nodeName === 'IMG' && dom.getAttrib( node, 'data-wp-media' ) ) { // Don't trigger on right-click - if ( e.button !== 2 ) { - if ( editor.dom.hasClass( e.target, 'wp-gallery-selected' ) ) { - editor.execCommand('WP_Gallery'); - editor.dom.removeClass( e.target, 'wp-gallery-selected' ); + if ( event.button !== 2 ) { + if ( dom.hasClass( node, 'wp-media-selected' ) ) { + editMedia( node ); + dom.removeClass( node, 'wp-media-selected' ); } else { - editor.dom.addClass( e.target, 'wp-gallery-selected' ); + dom.addClass( node, 'wp-media-selected' ); } } } else { - editor.dom.removeClass( editor.dom.select( 'img.wp-gallery-selected' ), 'wp-gallery-selected' ); + dom.removeClass( dom.select( 'img.wp-media-selected' ), 'wp-media-selected' ); } }); - // Display 'gallery' instead of img in element path - editor.on( 'ResolveName', function( e ) { + // Display gallery, audio or video instead of img in the element path + editor.on( 'ResolveName', function( event ) { var dom = editor.dom, - target = e.target; + node = event.target; - if ( target.nodeName === 'IMG' && dom.hasClass( target, 'wp-gallery' ) ) { - e.name = 'gallery'; + if ( node.nodeName === 'IMG' && dom.getAttrib( node, 'data-wp-media' ) ) { + if ( dom.hasClass( node, 'wp-gallery' ) ) { + event.name = 'gallery'; + } else if ( dom.hasClass( node, 'wp-video' ) ) { + event.name = 'video'; + } else if ( dom.hasClass( node, 'wp-audio' ) ) { + event.name = 'audio'; + } } }); - editor.on( 'BeforeSetContent', function( e ) { - e.content = parseGallery( e.content ); + editor.on( 'BeforeSetContent', function( event ) { + event.content = replaceGalleryShortcodes( event.content ); + event.content = replaceAVShortcodes( event.content ); }); - editor.on( 'PostProcess', function( e ) { - if ( e.get ) { - e.content = getGallery( e.content ); + editor.on( 'PostProcess', function( event ) { + if ( event.get ) { + event.content = restoreMediaShortcodes( event.content ); } }); - - return { - _do_gallery: parseGallery, - _get_gallery: getGallery - }; }); diff --git a/wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js b/wp-includes/js/tinymce/plugins/wpgallery/plugin.min.js index bca96b9e93..56db54423d 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,b){var c=tinymce.DOM.encode(b);return''})}function c(a){function b(a,b){return b=new RegExp(b+'="([^"]+)"',"g").exec(a),b?tinymce.DOM.decode(b[1]):""}return a.replace(/(?:]*>)*(]+>)(?:<\/p>)*/g,function(a,c){var d=b(c,"class");return-1!==d.indexOf("wp-gallery")?"

["+tinymce.trim(b(c,"title"))+"]

":a})}return a.addCommand("WP_Gallery",function(){var b,c,d;"undefined"!=typeof wp&&wp.media&&wp.media.gallery&&(d=a.selection.getNode(),b=wp.media.gallery,"IMG"===d.nodeName&&a.dom.hasClass(d,"wp-gallery")&&(c=b.edit("["+a.dom.getAttrib(d,"title")+"]"),c.state("gallery-edit").on("update",function(c){var e=b.shortcode(c).string().slice(1,-1);a.dom.setAttrib(d,"title",e)})))}),a.on("mouseup",function(b){"IMG"===b.target.nodeName&&a.dom.hasClass(b.target,"wp-gallery")?2!==b.button&&(a.dom.hasClass(b.target,"wp-gallery-selected")?(a.execCommand("WP_Gallery"),a.dom.removeClass(b.target,"wp-gallery-selected")):a.dom.addClass(b.target,"wp-gallery-selected")):a.dom.removeClass(a.dom.select("img.wp-gallery-selected"),"wp-gallery-selected")}),a.on("ResolveName",function(b){var c=a.dom,d=b.target;"IMG"===d.nodeName&&c.hasClass(d,"wp-gallery")&&(b.name="gallery")}),a.on("BeforeSetContent",function(a){a.content=b(a.content)}),a.on("PostProcess",function(a){a.get&&(a.content=c(a.content))}),{_do_gallery:b,_get_gallery:c}}); \ No newline at end of file +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 diff --git a/wp-includes/js/tinymce/skins/wordpress/images/audio.png b/wp-includes/js/tinymce/skins/wordpress/images/audio.png new file mode 100644 index 0000000000..e2fc8a5871 Binary files /dev/null and b/wp-includes/js/tinymce/skins/wordpress/images/audio.png differ diff --git a/wp-includes/js/tinymce/skins/wordpress/images/video.png b/wp-includes/js/tinymce/skins/wordpress/images/video.png new file mode 100644 index 0000000000..2cf0a30e77 Binary files /dev/null and b/wp-includes/js/tinymce/skins/wordpress/images/video.png differ diff --git a/wp-includes/js/tinymce/skins/wordpress/wp-content.css b/wp-includes/js/tinymce/skins/wordpress/wp-content.css index f9537a2932..f0b9a73f84 100644 --- a/wp-includes/js/tinymce/skins/wordpress/wp-content.css +++ b/wp-includes/js/tinymce/skins/wordpress/wp-content.css @@ -108,15 +108,41 @@ img::selection { border-top: 3px dotted #bbb; } -.mce-content-body img.wp-gallery { - border: 1px dashed #888; - background: #f2f2f2 url("images/gallery.png") no-repeat scroll center center; +/* Gallery, audio, vudeo placeholders */ +.mce-content-body img.wp-media { + border: 1px solid #aaa; + background-color: #f2f2f2; + background-repeat: no-repeat; + background-position: center center; width: 99%; height: 250px; outline: 0; cursor: pointer; } +.mce-content-body img.wp-media:hover { + background-color: #ededed; + border-color: #777; +} + +.mce-content-body img.wp-media.wp-media-selected { + background-color: #d8d8d8; + border-color: #777; +} + +.mce-content-body img.wp-media.wp-gallery { + background-image: url("images/gallery.png"); +} + +.mce-content-body img.wp-media.wp-video { + background-image: url("images/video.png"); +} + +.mce-content-body img.wp-media.wp-audio { + height: 70px; + background-image: url("images/audio.png"); +} + #wp-image-toolbar { position: absolute; } @@ -157,16 +183,6 @@ img::selection { outline: 1px solid #777; } -.mce-content-body img.wp-gallery:hover { - background-color: #ededed; - border-style: solid; -} - -.mce-content-body img.wp-gallery.wp-gallery-selected { - background-color: #d8d8d8; - border-style: solid; -} - 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 28904621b9..4856513f91 100644 Binary files a/wp-includes/js/tinymce/wp-tinymce.js.gz and b/wp-includes/js/tinymce/wp-tinymce.js.gz differ