<!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>[27479] trunk/src/wp-includes/js/media-views.js: Add `wp.media.view.MediaFrame.MediaDetails`, which `wp.media.view.MediaFrame.AudioDetails` and `media.view.MediaFrame.VideoDetails` extend.</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/27479">27479</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-03-09 06:04:29 +0000 (Sun, 09 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add `wp.media.view.MediaFrame.MediaDetails`, which `wp.media.view.MediaFrame.AudioDetails` and `media.view.MediaFrame.VideoDetails` extend. The subclasses subsequently only need to set `createStates()` and `bindHandlers()`, as well as any missing toolbar views.

See <a href="http://core.trac.wordpress.org/ticket/27016">#27016</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesjsmediaviewsjs">trunk/src/wp-includes/js/media-views.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/media-views.js (27478 => 27479)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/media-views.js  2014-03-09 05:24:10 UTC (rev 27478)
+++ trunk/src/wp-includes/js/media-views.js     2014-03-09 06:04:29 UTC (rev 27479)
</span><span class="lines">@@ -2697,7 +2697,7 @@
</span><span class="cx">  });
</span><span class="cx"> 
</span><span class="cx">  /**
</span><del>-        * wp.media.view.MediaFrame.AudioDetails
</del><ins>+         * wp.media.view.MediaFrame.MediaDetails
</ins><span class="cx">    *
</span><span class="cx">   * @constructor
</span><span class="cx">   * @augments wp.media.view.MediaFrame.Select
</span><span class="lines">@@ -2708,66 +2708,40 @@
</span><span class="cx">   * @augments Backbone.View
</span><span class="cx">   * @mixes wp.media.controller.StateMachine
</span><span class="cx">   */
</span><del>-       media.view.MediaFrame.AudioDetails = media.view.MediaFrame.Select.extend({
</del><ins>+        media.view.MediaFrame.MediaDetails = media.view.MediaFrame.Select.extend({
</ins><span class="cx">           defaults: {
</span><del>-                       id:      'audio',
</del><ins>+                        id:      'media',
</ins><span class="cx">                   url:     '',
</span><del>-                       menu:    'audio-details',
-                       content: 'audio-details',
-                       toolbar: 'audio-details',
</del><ins>+                        menu:    'media-details',
+                       content: 'media-details',
+                       toolbar: 'media-details',
</ins><span class="cx">                   type:    'link',
</span><del>-                       title:    l10n.audioDetailsTitle,
</del><span class="cx">                   priority: 120
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          initialize: function( options ) {
</span><ins>+                       this.DetailsView = options.DetailsView;
+                       this.cancelText = options.cancelText;
+                       this.addText = options.addText;
+
</ins><span class="cx">                   this.media = new media.model.PostMedia( options.metadata );
</span><span class="cx">                  this.options.selection = new media.model.Selection( this.media.attachment, { multiple: false } );
</span><span class="cx">                  media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments );
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          bindHandlers: function() {
</span><ins>+                       var menu = this.defaults.menu;
+
</ins><span class="cx">                   media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments );
</span><del>-                       this.on( 'menu:create:audio-details', this.createMenu, this );
-                       this.on( 'content:render:audio-details', this.renderAudioDetailsContent, this );
-                       this.on( 'menu:render:audio-details', this.renderMenu, this );
-                       this.on( 'toolbar:render:audio-details', this.renderAudioDetailsToolbar, this );
-                       // override the select toolbar
-                       this.on( 'toolbar:render:replace-audio', this.renderReplaceAudioToolbar, this );
-                       this.on( 'toolbar:render:add-audio-source', this.renderAddAudioSourceToolbar, this );
-               },
</del><span class="cx"> 
</span><del>-               createStates: function() {
-                       this.states.add([
-                               new media.controller.AudioDetails( {
-                                       media: this.media,
-                                       editable: false,
-                                       menu: 'audio-details'
-                               } ),
-
-                               new media.controller.MediaLibrary( {
-                                       type: 'audio',
-                                       id: 'replace-audio',
-                                       title: l10n.audioReplaceTitle,
-                                       toolbar: 'replace-audio',
-                                       media: this.media,
-                                       menu: 'audio-details'
-                               } ),
-
-
-                               new media.controller.MediaLibrary( {
-                                       type: 'audio',
-                                       id: 'add-audio-source',
-                                       title: l10n.audioAddSourceTitle,
-                                       toolbar: 'add-audio-source',
-                                       media: this.media,
-                                       menu: 'audio-details'
-                               } )
-                       ]);
</del><ins>+                        this.on( 'menu:create:' + menu, this.createMenu, this );
+                       this.on( 'content:render:' + menu, this.renderDetailsContent, this );
+                       this.on( 'menu:render:' + menu, this.renderMenu, this );
+                       this.on( 'toolbar:render:' + menu, this.renderDetailsToolbar, this );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><del>-               renderAudioDetailsContent: function() {
-                       var view = new media.view.AudioDetails({
</del><ins>+                renderDetailsContent: function() {
+                       var view = new this.DetailsView({
</ins><span class="cx">                           controller: this,
</span><span class="cx">                          model: this.state().media,
</span><span class="cx">                          attachment: this.state().media.attachment
</span><span class="lines">@@ -2783,7 +2757,7 @@
</span><span class="cx"> 
</span><span class="cx">                  view.set({
</span><span class="cx">                          cancel: {
</span><del>-                                       text:     l10n.audioDetailsCancel,
</del><ins>+                                        text:     this.cancelText,
</ins><span class="cx">                                   priority: 20,
</span><span class="cx">                                  click:    function() {
</span><span class="cx">                                          if ( previous ) {
</span><span class="lines">@@ -2801,7 +2775,7 @@
</span><span class="cx"> 
</span><span class="cx">          },
</span><span class="cx"> 
</span><del>-               renderAudioDetailsToolbar: function() {
</del><ins>+                renderDetailsToolbar: function() {
</ins><span class="cx">                   this.toolbar.set( new media.view.Toolbar({
</span><span class="cx">                          controller: this,
</span><span class="cx">                          items: {
</span><span class="lines">@@ -2827,7 +2801,7 @@
</span><span class="cx">                  }) );
</span><span class="cx">          },
</span><span class="cx"> 
</span><del>-               renderReplaceAudioToolbar: function() {
</del><ins>+                renderReplaceToolbar: function() {
</ins><span class="cx">                   this.toolbar.set( new media.view.Toolbar({
</span><span class="cx">                          controller: this,
</span><span class="cx">                          items: {
</span><span class="lines">@@ -2844,8 +2818,6 @@
</span><span class="cx"> 
</span><span class="cx">                                                  controller.media.changeAttachment( attachment, state.display( attachment ) );
</span><span class="cx"> 
</span><del>-                                                       // not sure if we want to use wp.media.string.image which will create a shortcode or
-                                                       // perhaps wp.html.string to at least to build the <img />
</del><span class="cx">                                                   state.trigger( 'replace', controller.media.toJSON() );
</span><span class="cx"> 
</span><span class="cx">                                                  // Restore and reset the default state.
</span><span class="lines">@@ -2857,13 +2829,13 @@
</span><span class="cx">                  }) );
</span><span class="cx">          },
</span><span class="cx"> 
</span><del>-               renderAddAudioSourceToolbar: function() {
</del><ins>+                renderAddSourceToolbar: function() {
</ins><span class="cx">                   this.toolbar.set( new media.view.Toolbar({
</span><span class="cx">                          controller: this,
</span><span class="cx">                          items: {
</span><span class="cx">                                  replace: {
</span><span class="cx">                                          style:    'primary',
</span><del>-                                               text:     l10n.audioAddSourceTitle,
</del><ins>+                                                text:     this.addText,
</ins><span class="cx">                                           priority: 80,
</span><span class="cx"> 
</span><span class="cx">                                          click: function() {
</span><span class="lines">@@ -2887,9 +2859,80 @@
</span><span class="cx">  });
</span><span class="cx"> 
</span><span class="cx">  /**
</span><ins>+        * wp.media.view.MediaFrame.AudioDetails
+        *
+        * @constructor
+        * @augments wp.media.view.MediaFrame.MediaDetails
+        * @augments wp.media.view.MediaFrame.Select
+        * @augments wp.media.view.MediaFrame
+        * @augments wp.media.view.Frame
+        * @augments wp.media.View
+        * @augments wp.Backbone.View
+        * @augments Backbone.View
+        * @mixes wp.media.controller.StateMachine
+        */
+       media.view.MediaFrame.AudioDetails = media.view.MediaFrame.MediaDetails.extend({
+               defaults: {
+                       id:      'audio',
+                       url:     '',
+                       menu:    'audio-details',
+                       content: 'audio-details',
+                       toolbar: 'audio-details',
+                       type:    'link',
+                       title:    l10n.audioDetailsTitle,
+                       priority: 120
+               },
+
+               initialize: function( options ) {
+                       options.DetailsView = media.view.AudioDetails;
+                       options.cancelText = l10n.audioDetailsCancel;
+                       options.addText = l10n.audioAddSourceTitle;
+
+                       media.view.MediaFrame.MediaDetails.prototype.initialize.call( this, options );
+               },
+
+               bindHandlers: function() {
+                       media.view.MediaFrame.MediaDetails.prototype.bindHandlers.apply( this, arguments );
+
+                       this.on( 'toolbar:render:replace-audio', this.renderReplaceToolbar, this );
+                       this.on( 'toolbar:render:add-audio-source', this.renderAddSourceToolbar, this );
+               },
+
+               createStates: function() {
+                       this.states.add([
+                               new media.controller.AudioDetails( {
+                                       media: this.media,
+                                       editable: false,
+                                       menu: 'audio-details'
+                               } ),
+
+                               new media.controller.MediaLibrary( {
+                                       type: 'audio',
+                                       id: 'replace-audio',
+                                       title: l10n.audioReplaceTitle,
+                                       toolbar: 'replace-audio',
+                                       media: this.media,
+                                       menu: 'audio-details'
+                               } ),
+
+
+                               new media.controller.MediaLibrary( {
+                                       type: 'audio',
+                                       id: 'add-audio-source',
+                                       title: l10n.audioAddSourceTitle,
+                                       toolbar: 'add-audio-source',
+                                       media: this.media,
+                                       menu: 'audio-details'
+                               } )
+                       ]);
+               }
+       });
+
+       /**
</ins><span class="cx">    * wp.media.view.MediaFrame.VideoDetails
</span><span class="cx">   *
</span><span class="cx">   * @constructor
</span><ins>+        * @augments wp.media.view.MediaFrame.MediaDetails
</ins><span class="cx">    * @augments wp.media.view.MediaFrame.Select
</span><span class="cx">   * @augments wp.media.view.MediaFrame
</span><span class="cx">   * @augments wp.media.view.Frame
</span><span class="lines">@@ -2898,7 +2941,7 @@
</span><span class="cx">   * @augments Backbone.View
</span><span class="cx">   * @mixes wp.media.controller.StateMachine
</span><span class="cx">   */
</span><del>-       media.view.MediaFrame.VideoDetails = media.view.MediaFrame.Select.extend({
</del><ins>+        media.view.MediaFrame.VideoDetails = media.view.MediaFrame.MediaDetails.extend({
</ins><span class="cx">           defaults: {
</span><span class="cx">                  id:      'video',
</span><span class="cx">                  url:     '',
</span><span class="lines">@@ -2911,20 +2954,18 @@
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="cx">          initialize: function( options ) {
</span><del>-                       this.media = new media.model.PostMedia( options.metadata );
-                       this.options.selection = new media.model.Selection( this.media.attachment, { multiple: false } );
-                       media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments );
</del><ins>+                        options.DetailsView = media.view.VideoDetails;
+                       options.cancelText = l10n.videoDetailsCancel;
+                       options.addText = l10n.videoAddSourceTitle;
+
+                       media.view.MediaFrame.MediaDetails.prototype.initialize.call( this, options );
</ins><span class="cx">           },
</span><span class="cx"> 
</span><span class="cx">          bindHandlers: function() {
</span><del>-                       media.view.MediaFrame.Select.prototype.bindHandlers.apply( this, arguments );
-                       this.on( 'menu:create:video-details', this.createMenu, this );
-                       this.on( 'content:render:video-details', this.renderVideoDetailsContent, this );
-                       this.on( 'menu:render:video-details', this.renderMenu, this );
-                       this.on( 'toolbar:render:video-details', this.renderVideoDetailsToolbar, this );
-                       // override the select toolbar
-                       this.on( 'toolbar:render:replace-video', this.renderReplaceVideoToolbar, this );
-                       this.on( 'toolbar:render:add-video-source', this.renderAddVideoSourceToolbar, this );
</del><ins>+                        media.view.MediaFrame.MediaDetails.prototype.bindHandlers.apply( this, arguments );
+
+                       this.on( 'toolbar:render:replace-video', this.renderReplaceToolbar, this );
+                       this.on( 'toolbar:render:add-video-source', this.renderAddSourceToolbar, this );
</ins><span class="cx">                   this.on( 'toolbar:render:select-poster-image', this.renderSelectPosterImageToolbar, this );
</span><span class="cx">          },
</span><span class="cx"> 
</span><span class="lines">@@ -2965,125 +3006,6 @@
</span><span class="cx">                  ]);
</span><span class="cx">          },
</span><span class="cx"> 
</span><del>-               renderVideoDetailsContent: function() {
-                       var view = new media.view.VideoDetails({
-                               controller: this,
-                               model: this.state().media,
-                               attachment: this.state().media.attachment
-                       }).render();
-
-                       this.content.set( view );
-               },
-
-               renderMenu: function( view ) {
-                       var lastState = this.lastState(),
-                               previous = lastState && lastState.id,
-                               frame = this;
-
-                       view.set({
-                               cancel: {
-                                       text:     l10n.videoDetailsCancel,
-                                       priority: 20,
-                                       click:    function() {
-                                               if ( previous ) {
-                                                       frame.setState( previous );
-                                               } else {
-                                                       frame.close();
-                                               }
-                                       }
-                               },
-                               separateCancel: new media.View({
-                                       className: 'separator',
-                                       priority: 40
-                               })
-                       });
-
-               },
-
-               renderVideoDetailsToolbar: function() {
-                       this.toolbar.set( new media.view.Toolbar({
-                               controller: this,
-                               items: {
-                                       select: {
-                                               style:    'primary',
-                                               text:     l10n.update,
-                                               priority: 80,
-
-                                               click: function() {
-                                                       var controller = this.controller,
-                                                               state = controller.state();
-
-                                                       controller.close();
-
-                                                       // not sure if we want to use wp.media.string.image which will create a shortcode or
-                                                       // perhaps wp.html.string to at least to build the <img />
-                                                       state.trigger( 'update', controller.media.toJSON() );
-
-                                                       // Restore and reset the default state.
-                                                       controller.setState( controller.options.state );
-                                                       controller.reset();
-                                               }
-                                       }
-                               }
-                       }) );
-               },
-
-               renderReplaceVideoToolbar: function() {
-                       this.toolbar.set( new media.view.Toolbar({
-                               controller: this,
-                               items: {
-                                       replace: {
-                                               style:    'primary',
-                                               text:     l10n.replace,
-                                               priority: 80,
-
-                                               click: function() {
-                                                       var controller = this.controller,
-                                                               state = controller.state(),
-                                                               selection = state.get( 'selection' ),
-                                                               attachment = selection.single();
-
-                                                       controller.media.changeAttachment( attachment, state.display( attachment ) );
-
-                                                       state.trigger( 'replace', controller.media.toJSON() );
-
-                                                       // Restore and reset the default state.
-                                                       controller.setState( controller.options.state );
-                                                       controller.reset();
-                                               }
-                                       }
-                               }
-                       }) );
-               },
-
-               renderAddVideoSourceToolbar: function() {
-                       this.toolbar.set( new media.view.Toolbar({
-                               controller: this,
-                               items: {
-                                       replace: {
-                                               style:    'primary',
-                                               text:     l10n.videoAddSourceTitle,
-                                               priority: 80,
-
-                                               click: function() {
-                                                       var controller = this.controller,
-                                                               state = controller.state(),
-                                                               selection = state.get( 'selection' ),
-                                                               attachment = selection.single();
-
-                                                       controller.media.setSource( attachment, state.display( attachment ) );
-
-                                                       state.trigger( 'add-source', controller.media.toJSON() );
-
-                                                       // Restore and reset the default state.
-                                                       controller.setState( controller.options.state );
-                                                       controller.reset();
-                                               }
-                                       }
-                               }
-                       }) );
-               },
-
</del><span class="cx">           renderSelectPosterImageToolbar: function() {
</span><span class="cx">                  this.toolbar.set( new media.view.Toolbar({
</span><span class="cx">                          controller: this,
</span></span></pre>
</div>
</div>

</body>
</html>