<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[27169] trunk/src/wp-includes/js/tinymce: TinyMCE: add image based placeholders for audio and video shortcodes.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/27169">27169</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2014-02-13 05:09:04 +0000 (Thu, 13 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>TinyMCE: add image based placeholders for audio and video shortcodes. Props wonderboymusic, see <a href="http://core.trac.wordpress.org/ticket/27016">#27016</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesjstinymcepluginswpgallerypluginjs">trunk/src/wp-includes/js/tinymce/plugins/wpgallery/plugin.js</a></li>
<li><a href="#trunksrcwpincludesjstinymceskinswordpresswpcontentcss">trunk/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesjstinymceskinswordpressimagesaudiopng">trunk/src/wp-includes/js/tinymce/skins/wordpress/images/audio.png</a></li>
<li><a href="#trunksrcwpincludesjstinymceskinswordpressimagesvideopng">trunk/src/wp-includes/js/tinymce/skins/wordpress/images/video.png</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesjstinymcepluginswpgallerypluginjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/tinymce/plugins/wpgallery/plugin.js (27168 => 27169)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/tinymce/plugins/wpgallery/plugin.js     2014-02-12 20:39:21 UTC (rev 27168)
+++ trunk/src/wp-includes/js/tinymce/plugins/wpgallery/plugin.js        2014-02-13 05:09:04 UTC (rev 27169)
</span><span class="lines">@@ -1,53 +1,73 @@
</span><span class="cx"> /* global tinymce */
</span><span class="cx"> tinymce.PluginManager.add('wpgallery', function( editor ) {
</span><span class="cx"> 
</span><del>-       function parseGallery( content ) {
-               return content.replace( /\[gallery([^\]]*)\]/g, function( match, attr ) {
-                       var data = tinymce.DOM.encode( attr );
</del><ins>+        function replaceGalleryShortcodes( content ) {
+               return content.replace( /\[gallery([^\]]*)\]/g, function( match ) {
+                       var data = window.encodeURIComponent( match );
</ins><span class="cx"> 
</span><del>-                       return '<img src="' + tinymce.Env.transparentSrc + '" class="wp-gallery mceItem" ' +
-                               'title="gallery' + data + '" data-mce-resize="false" data-mce-placeholder="1" />';
</del><ins>+                        return '<img src="' + tinymce.Env.transparentSrc + '" class="wp-media wp-gallery mceItem" ' +
+                               'data-wp-media="' + data + '" data-mce-resize="false" data-mce-placeholder="1" />';
</ins><span class="cx">           });
</span><span class="cx">  }
</span><span class="cx"> 
</span><del>-       function getGallery( content ) {
</del><ins>+        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 + '" ' +
+                               'data-wp-media="' + data + '" data-mce-resize="false" data-mce-placeholder="1" />';
+               });
+       }
+
+       function restoreMediaShortcodes( content ) {
</ins><span class="cx">           function getAttr( str, name ) {
</span><del>-                       name = new RegExp( name + '=\"([^\"]+)\"', 'g' ).exec( str );
-                       return name ? tinymce.DOM.decode( name[1] ) : '';
</del><ins>+                        name = new RegExp( name + '=\"([^\"]+)\"' ).exec( str );
+                       return name ? window.decodeURIComponent( name[1] ) : '';
</ins><span class="cx">           }
</span><span class="cx"> 
</span><del>-               return content.replace( /(?:<p[^>]*>)*(<img[^>]+>)(?:<\/p>)*/g, function( match, image ) {
-                       var cls = getAttr( image, 'class' );
</del><ins>+                return content.replace( /(?:<p(?: [^>]+)?>)*(<img [^>]+>)(?:<\/p>)*/g, function( match, image ) {
+                       var data = getAttr( image, 'data-wp-media' );
</ins><span class="cx"> 
</span><del>-                       if ( cls.indexOf('wp-gallery') !== -1 ) {
-                               return '<p>['+ tinymce.trim( getAttr( image, 'title' ) ) +']</p>';
</del><ins>+                        if ( data ) {
+                               return '<p>' + data + '</p>';
</ins><span class="cx">                   }
</span><span class="cx"> 
</span><span class="cx">                  return match;
</span><span class="cx">          });
</span><span class="cx">  }
</span><span class="cx"> 
</span><del>-       // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
-       editor.addCommand( 'WP_Gallery', function() {
-               var gallery, frame, node;
</del><ins>+        function editMedia( node ) {
+               var gallery, frame, data;
</ins><span class="cx"> 
</span><ins>+               if ( node.nodeName !== 'IMG' ) {
+                       return;
+               }
+
</ins><span class="cx">           // Check if the `wp.media.gallery` API exists.
</span><span class="cx">          if ( typeof wp === 'undefined' || ! wp.media || ! wp.media.gallery ) {
</span><span class="cx">                  return;
</span><span class="cx">          }
</span><span class="cx"> 
</span><del>-               node = editor.selection.getNode();
-               gallery = wp.media.gallery;
-
</del><span class="cx">           // Make sure we've selected a gallery node.
</span><del>-               if ( node.nodeName === 'IMG' && editor.dom.hasClass( node, 'wp-gallery' ) ) {
-                       frame = gallery.edit( '[' + editor.dom.getAttrib( node, 'title' ) + ']' );
</del><ins>+                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 );
</ins><span class="cx"> 
</span><span class="cx">                  frame.state('gallery-edit').on( 'update', function( selection ) {
</span><del>-                               var shortcode = gallery.shortcode( selection ).string().slice( 1, -1 );
-                               editor.dom.setAttrib( node, 'title', shortcode );
</del><ins>+                                var shortcode = gallery.shortcode( selection ).string();
+                               editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) );
</ins><span class="cx">                   });
</span><ins>+               } else {
+                       // temp
+                       window.console && console.log( 'Edit AV shortcode ' + window.decodeURIComponent( editor.dom.getAttrib( node, 'data-wp-media' ) ) );
</ins><span class="cx">           }
</span><ins>+       }
+
+       // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
+       editor.addCommand( 'WP_Gallery', function() {
+               editMedia( editor.selection.getNode() );
</ins><span class="cx">   });
</span><span class="cx"> /*
</span><span class="cx">  editor.on( 'init', function( e ) {
</span><span class="lines">@@ -68,44 +88,49 @@
</span><span class="cx">          }
</span><span class="cx">  });
</span><span class="cx"> */
</span><del>-       editor.on( 'mouseup', function( e ) {
-               if ( e.target.nodeName === 'IMG' && editor.dom.hasClass( e.target, 'wp-gallery' ) ) {
</del><ins>+        editor.on( 'mouseup', function( event ) {
+               var dom = editor.dom,
+                       node = event.target;
+
+               if ( node.nodeName === 'IMG' && dom.getAttrib( node, 'data-wp-media' ) ) {
</ins><span class="cx">                   // Don't trigger on right-click
</span><del>-                       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' );
</del><ins>+                        if ( event.button !== 2 ) {
+                               if ( dom.hasClass( node, 'wp-media-selected' ) ) {
+                                       editMedia( node );
+                                       dom.removeClass( node, 'wp-media-selected' );
</ins><span class="cx">                           } else {
</span><del>-                                       editor.dom.addClass( e.target, 'wp-gallery-selected' );
</del><ins>+                                        dom.addClass( node, 'wp-media-selected' );
</ins><span class="cx">                           }
</span><span class="cx">                  }
</span><span class="cx">          } else {
</span><del>-                       editor.dom.removeClass( editor.dom.select( 'img.wp-gallery-selected' ), 'wp-gallery-selected' );
</del><ins>+                        dom.removeClass( dom.select( 'img.wp-media-selected' ), 'wp-media-selected' );
</ins><span class="cx">           }
</span><span class="cx">  });
</span><span class="cx"> 
</span><del>-       // Display 'gallery' instead of img in element path
-       editor.on( 'ResolveName', function( e ) {
</del><ins>+        // Display gallery, audio or video instead of img in the element path
+       editor.on( 'ResolveName', function( event ) {
</ins><span class="cx">           var dom = editor.dom,
</span><del>-                       target = e.target;
</del><ins>+                        node = event.target;
</ins><span class="cx"> 
</span><del>-               if ( target.nodeName === 'IMG' && dom.hasClass( target, 'wp-gallery' ) ) {
-                       e.name = 'gallery';
</del><ins>+                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';
+                       }
</ins><span class="cx">           }
</span><span class="cx">  });
</span><span class="cx"> 
</span><del>-       editor.on( 'BeforeSetContent', function( e ) {
-               e.content = parseGallery( e.content );
</del><ins>+        editor.on( 'BeforeSetContent', function( event ) {
+               event.content = replaceGalleryShortcodes( event.content );
+               event.content = replaceAVShortcodes( event.content );
</ins><span class="cx">   });
</span><span class="cx"> 
</span><del>-       editor.on( 'PostProcess', function( e ) {
-               if ( e.get ) {
-                       e.content = getGallery( e.content );
</del><ins>+        editor.on( 'PostProcess', function( event ) {
+               if ( event.get ) {
+                       event.content = restoreMediaShortcodes( event.content );
</ins><span class="cx">           }
</span><span class="cx">  });
</span><del>-
-       return {
-               _do_gallery: parseGallery,
-               _get_gallery: getGallery
-       };
</del><span class="cx"> });
</span></span></pre></div>
<a id="trunksrcwpincludesjstinymceskinswordpressimagesaudiopng"></a>
<div class="binary"><h4>Added: trunk/src/wp-includes/js/tinymce/skins/wordpress/images/audio.png</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Index: trunk/src/wp-includes/js/tinymce/skins/wordpress/images/audio.png
</span><span class="cx">===================================================================
</span><del>--- trunk/src/wp-includes/js/tinymce/skins/wordpress/images/audio.png   2014-02-12 20:39:21 UTC (rev 27168)
</del><ins>+++ trunk/src/wp-includes/js/tinymce/skins/wordpress/images/audio.png    2014-02-13 05:09:04 UTC (rev 27169)
</ins><span class="cx">Property changes on: trunk/src/wp-includes/js/tinymce/skins/wordpress/images/audio.png
</span><span class="cx">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<ins>+image/png
</ins><span class="cx">\ No newline at end of property
</span><a id="trunksrcwpincludesjstinymceskinswordpressimagesvideopng"></a>
<div class="binary"><h4>Added: trunk/src/wp-includes/js/tinymce/skins/wordpress/images/video.png</h4>
<pre class="diff"><span>
<span class="cx">(Binary files differ)
</span></span></pre></div>
<span class="cx">Index: trunk/src/wp-includes/js/tinymce/skins/wordpress/images/video.png
</span><span class="cx">===================================================================
</span><del>--- trunk/src/wp-includes/js/tinymce/skins/wordpress/images/video.png   2014-02-12 20:39:21 UTC (rev 27168)
</del><ins>+++ trunk/src/wp-includes/js/tinymce/skins/wordpress/images/video.png    2014-02-13 05:09:04 UTC (rev 27169)
</ins><span class="cx">Property changes on: trunk/src/wp-includes/js/tinymce/skins/wordpress/images/video.png
</span><span class="cx">___________________________________________________________________
</span><a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<ins>+image/png
</ins><span class="cx">\ No newline at end of property
</span><a id="trunksrcwpincludesjstinymceskinswordpresswpcontentcss"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css (27168 => 27169)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css  2014-02-12 20:39:21 UTC (rev 27168)
+++ trunk/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css     2014-02-13 05:09:04 UTC (rev 27169)
</span><span class="lines">@@ -108,15 +108,41 @@
</span><span class="cx">     border-top: 3px dotted #bbb;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-.mce-content-body img.wp-gallery {
-       border: 1px dashed #888;
-       background: #f2f2f2 url("images/gallery.png") no-repeat scroll center center;
</del><ins>+/* 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;
</ins><span class="cx">   width: 99%;
</span><span class="cx">  height: 250px;
</span><span class="cx">  outline: 0;
</span><span class="cx">  cursor: pointer;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+.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");
+}
+
</ins><span class="cx"> #wp-image-toolbar {
</span><span class="cx">  position: absolute;
</span><span class="cx"> }
</span><span class="lines">@@ -157,16 +183,6 @@
</span><span class="cx">  outline: 1px solid #777;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-.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;
-}
-
</del><span class="cx"> img.wp-oembed {
</span><span class="cx">  border: 1px dashed #888;
</span><span class="cx">  background: #f7f5f2 url("images/embedded.png") no-repeat scroll center center;
</span></span></pre>
</div>
</div>

</body>
</html>