<!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>[28095] trunk/src/wp-includes: Add hooks to the wpeditimage tinymce plugin and to the image details portion of the media modal.</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/28095">28095</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2014-04-13 04:01:53 +0000 (Sun, 13 Apr 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add hooks to the wpeditimage tinymce plugin and to the image details portion of the media modal.
- Add wp.media.events which is intended to be a global media event bus.
- Add a post-render event to the ImageDetails view that third-party code can leverage to add subviews.
- Performance improvement for the initialization of the PostImage model.
- A bit more markup to the image details template to make it easier to add a view to the advanced options.
Props gcorne, fixes <a href="http://core.trac.wordpress.org/ticket/27698">#27698</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludescssmediaviewscss">trunk/src/wp-includes/css/media-views.css</a></li>
<li><a href="#trunksrcwpincludesjsmediamodelsjs">trunk/src/wp-includes/js/media-models.js</a></li>
<li><a href="#trunksrcwpincludesjsmediaviewsjs">trunk/src/wp-includes/js/media-views.js</a></li>
<li><a href="#trunksrcwpincludesjstinymcepluginswpeditimagepluginjs">trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js</a></li>
<li><a href="#trunksrcwpincludesmediatemplatephp">trunk/src/wp-includes/media-template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludescssmediaviewscss"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/css/media-views.css (28094 => 28095)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/css/media-views.css 2014-04-13 00:22:56 UTC (rev 28094)
+++ trunk/src/wp-includes/css/media-views.css 2014-04-13 04:01:53 UTC (rev 28095)
</span><span class="lines">@@ -1807,7 +1807,7 @@
</span><span class="cx"> left: 440px;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-.advanced,
</del><ins>+.advanced-section,
</ins><span class="cx"> .link-settings {
</span><span class="cx"> margin-top: 10px;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunksrcwpincludesjsmediamodelsjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/media-models.js (28094 => 28095)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/media-models.js 2014-04-13 00:22:56 UTC (rev 28094)
+++ trunk/src/wp-includes/js/media-models.js 2014-04-13 04:01:53 UTC (rev 28095)
</span><span class="lines">@@ -360,7 +360,12 @@
</span><span class="cx">
</span><span class="cx"> if ( attributes.attachment_id ) {
</span><span class="cx"> this.attachment = Attachment.get( attributes.attachment_id );
</span><del>- this.dfd = this.attachment.fetch();
</del><ins>+ if ( this.attachment.get( 'url' ) ) {
+ this.dfd = $.Deferred();
+ this.dfd.resolve();
+ } else {
+ this.dfd = this.attachment.fetch();
+ }
</ins><span class="cx"> this.bindAttachmentListeners();
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunksrcwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/media-views.js (28094 => 28095)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/media-views.js 2014-04-13 00:22:56 UTC (rev 28094)
+++ trunk/src/wp-includes/js/media-views.js 2014-04-13 04:01:53 UTC (rev 28095)
</span><span class="lines">@@ -32,6 +32,13 @@
</span><span class="cx"> }());
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * A shared event bus used to provide events into
+ * the media workflows that 3rd-party devs can use to hook
+ * in.
+ */
+ media.events = _.extend( {}, Backbone.Events );
+
+ /**
</ins><span class="cx"> * Makes it easier to bind events using transitions.
</span><span class="cx"> *
</span><span class="cx"> * @param {string} selector
</span><span class="lines">@@ -2753,7 +2760,7 @@
</span><span class="cx"> bindHandlers: function() {
</span><span class="cx"> media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments );
</span><span class="cx"> this.on( 'menu:create:image-details', this.createMenu, this );
</span><del>- this.on( 'content:render:image-details', this.renderImageDetailsContent, this );
</del><ins>+ this.on( 'content:create:image-details', this.imageDetailsContent, this );
</ins><span class="cx"> this.on( 'content:render:edit-image', this.editImageContent, this );
</span><span class="cx"> this.on( 'menu:render:image-details', this.renderMenu, this );
</span><span class="cx"> this.on( 'toolbar:render:image-details', this.renderImageDetailsToolbar, this );
</span><span class="lines">@@ -2786,15 +2793,12 @@
</span><span class="cx"> ]);
</span><span class="cx"> },
</span><span class="cx">
</span><del>- renderImageDetailsContent: function() {
- var view = new media.view.ImageDetails({
</del><ins>+ imageDetailsContent: function( options ) {
+ options.view = new media.view.ImageDetails({
</ins><span class="cx"> controller: this,
</span><span class="cx"> model: this.state().image,
</span><span class="cx"> attachment: this.state().image.attachment
</span><del>- }).render();
-
- this.content.set( view );
-
</del><ins>+ });
</ins><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> editImageContent: function() {
</span><span class="lines">@@ -6256,23 +6260,26 @@
</span><span class="cx"> if ( this.model.attachment && 'pending' === this.model.dfd.state() ) {
</span><span class="cx"> this.model.dfd.done( function() {
</span><span class="cx"> media.view.Settings.AttachmentDisplay.prototype.render.apply( self, args );
</span><del>- self.resetFocus();
- self.toggleLinkSettings();
</del><ins>+ self.postRender();
</ins><span class="cx"> } ).fail( function() {
</span><span class="cx"> self.model.attachment = false;
</span><span class="cx"> media.view.Settings.AttachmentDisplay.prototype.render.apply( self, args );
</span><del>- self.resetFocus();
- self.toggleLinkSettings();
</del><ins>+ self.postRender();
</ins><span class="cx"> } );
</span><span class="cx"> } else {
</span><span class="cx"> media.view.Settings.AttachmentDisplay.prototype.render.apply( this, arguments );
</span><del>- setTimeout( function() { self.resetFocus(); }, 10 );
- self.toggleLinkSettings();
</del><ins>+ this.postRender();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> return this;
</span><span class="cx"> },
</span><span class="cx">
</span><ins>+ postRender: function() {
+ setTimeout( _.bind( this.resetFocus, this ), 10 );
+ this.toggleLinkSettings();
+ this.trigger( 'post-render' );
+ },
+
</ins><span class="cx"> resetFocus: function() {
</span><span class="cx"> this.$( '.link-to-custom' ).blur();
</span><span class="cx"> this.$( '.embed-media-settings' ).scrollTop( 0 );
</span><span class="lines">@@ -6323,14 +6330,14 @@
</span><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> toggleAdvanced: function( event ) {
</span><del>- var $advanced = $( event.target ).closest( '.advanced' );
</del><ins>+ var $advanced = $( event.target ).closest( '.advanced-section' );
</ins><span class="cx"> event.preventDefault();
</span><span class="cx"> if ( $advanced.hasClass('advanced-visible') ) {
</span><span class="cx"> $advanced.removeClass('advanced-visible');
</span><del>- $advanced.find('div').addClass('hidden');
</del><ins>+ $advanced.find('.advanced-settings').addClass('hidden');
</ins><span class="cx"> } else {
</span><span class="cx"> $advanced.addClass('advanced-visible');
</span><del>- $advanced.find('div').removeClass('hidden');
</del><ins>+ $advanced.find('.advanced-settings').removeClass('hidden');
</ins><span class="cx"> }
</span><span class="cx"> },
</span><span class="cx">
</span></span></pre></div>
<a id="trunksrcwpincludesjstinymcepluginswpeditimagepluginjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js (28094 => 28095)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js 2014-04-13 00:22:56 UTC (rev 28094)
+++ trunk/src/wp-includes/js/tinymce/plugins/wpeditimage/plugin.js 2014-04-13 04:01:53 UTC (rev 28095)
</span><span class="lines">@@ -338,25 +338,44 @@
</span><span class="cx"> dom.remove( captionNode );
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ if ( wp.media.events ) {
+ wp.media.events.trigger( 'editor:image-update', {
+ editor: editor,
+ metadata: imageData,
+ image: imageNode
+ } );
+ }
+
</ins><span class="cx"> editor.nodeChanged();
</span><span class="cx"> // Refresh the toolbar
</span><span class="cx"> addToolbar( imageNode );
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function editImage( img ) {
</span><del>- var frame, callback;
</del><ins>+ var frame, callback, metadata;
</ins><span class="cx">
</span><span class="cx"> if ( typeof wp === 'undefined' || ! wp.media ) {
</span><span class="cx"> editor.execCommand( 'mceImage' );
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ metadata = extractImageData( img );
+
+ // Manipulate the metadata by reference that is fed into the PostImage model used in the media modal
+ wp.media.events.trigger( 'editor:image-edit', {
+ editor: editor,
+ metadata: metadata,
+ image: img
+ } );
+
</ins><span class="cx"> frame = wp.media({
</span><span class="cx"> frame: 'image',
</span><span class="cx"> state: 'image-details',
</span><del>- metadata: extractImageData( img )
</del><ins>+ metadata: metadata
</ins><span class="cx"> } );
</span><span class="cx">
</span><ins>+ wp.media.events.trigger( 'editor:frame-create', { frame: frame } );
+
</ins><span class="cx"> callback = function( imageData ) {
</span><span class="cx"> editor.focus();
</span><span class="cx"> editor.undoManager.transact( function() {
</span></span></pre></div>
<a id="trunksrcwpincludesmediatemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/media-template.php (28094 => 28095)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/media-template.php 2014-04-13 00:22:56 UTC (rev 28094)
+++ trunk/src/wp-includes/media-template.php 2014-04-13 04:01:53 UTC (rev 28095)
</span><span class="lines">@@ -755,28 +755,32 @@
</span><span class="cx"> </select>
</span><span class="cx"> <input type="text" class="link-to-custom" data-setting="linkUrl" />
</span><span class="cx"> </div>
</span><del>- <div class="advanced">
</del><ins>+ <div class="advanced-section">
</ins><span class="cx"> <h3><a class="advanced-toggle" href="#"><?php _e('Advanced Options'); ?></a></h3>
</span><del>- <div class="hidden">
- <label class="setting title-text">
- <span><?php _e('Image Title Attribute'); ?></span>
- <input type="text" data-setting="title" value="{{ data.model.title }}" />
- </label>
- <label class="setting extra-classes">
- <span><?php _e('Image CSS Class'); ?></span>
- <input type="text" data-setting="extraClasses" value="{{ data.model.extraClasses }}" />
- </label>
- <div class="setting link-target">
- <label><input type="checkbox" data-setting="linkTargetBlank" value="_blank" <# if ( data.model.linkTargetBlank ) { #>checked="checked"<# } #>><?php _e( 'Open link in a new window/tab' ); ?></label>
</del><ins>+ <div class="advanced-settings hidden">
+ <div class="advanced-image">
+ <label class="setting title-text">
+ <span><?php _e('Image Title Attribute'); ?></span>
+ <input type="text" data-setting="title" value="{{ data.model.title }}" />
+ </label>
+ <label class="setting extra-classes">
+ <span><?php _e('Image CSS Class'); ?></span>
+ <input type="text" data-setting="extraClasses" value="{{ data.model.extraClasses }}" />
+ </label>
</ins><span class="cx"> </div>
</span><del>- <label class="setting link-rel">
- <span><?php _e('Link Rel'); ?></span>
- <input type="text" data-setting="linkRel" value="{{ data.model.linkClassName }}" />
- </label>
- <label class="setting link-class-name">
- <span><?php _e('Link CSS Class'); ?></span>
- <input type="text" data-setting="linkClassName" value="{{ data.model.linkClassName }}" />
- </label>
</del><ins>+ <div class="advanced-link">
+ <div class="setting link-target">
+ <label><input type="checkbox" data-setting="linkTargetBlank" value="_blank" <# if ( data.model.linkTargetBlank ) { #>checked="checked"<# } #>><?php _e( 'Open link in a new window/tab' ); ?></label>
+ </div>
+ <label class="setting link-rel">
+ <span><?php _e('Link Rel'); ?></span>
+ <input type="text" data-setting="linkRel" value="{{ data.model.linkClassName }}" />
+ </label>
+ <label class="setting link-class-name">
+ <span><?php _e('Link CSS Class'); ?></span>
+ <input type="text" data-setting="linkClassName" value="{{ data.model.linkClassName }}" />
+ </label>
+ </div>
</ins><span class="cx"> </div>
</span><span class="cx"> </div>
</span><span class="cx"> </div>
</span></span></pre>
</div>
</div>
</body>
</html>