<!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>[22523] trunk: Media: Backwards compatibility for media_upload_tabs.</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, #logmsg > ol { margin-left: 0; 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/22523">22523</a></dd>
<dt>Author</dt> <dd>koopersmith</dd>
<dt>Date</dt> <dd>2012-11-10 07:51:37 +0000 (Sat, 10 Nov 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Media: Backwards compatibility for media_upload_tabs.

* Adds `createIframeStates()` to the `MediaFrame` view. It creates states and bindings for the `media_upload_tabs` output, and is included on `MediaFrame.Post` by default.
* Hijacks `tb_remove()` when the media modal is open to ensure the modal closes correctly.
* Adds a `chromeless` parameter to thickbox media tab URLs to render the UI without the old row of tabs.

see <a href="http://core.trac.wordpress.org/ticket/22186">#22186</a>, <a href="http://core.trac.wordpress.org/ticket/21390">#21390</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
<li><a href="#trunkwpincludescssmediaviewscss">trunk/wp-includes/css/media-views.css</a></li>
<li><a href="#trunkwpincludesjsmediamodelsjs">trunk/wp-includes/js/media-models.js</a></li>
<li><a href="#trunkwpincludesjsmediaviewsjs">trunk/wp-includes/js/media-views.js</a></li>
<li><a href="#trunkwpincludesmediaphp">trunk/wp-includes/media.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (22522 => 22523)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2012-11-10 07:23:55 UTC (rev 22522)
+++ trunk/wp-admin/includes/media.php        2012-11-10 07:51:37 UTC (rev 22523)
</span><span class="lines">@@ -1275,12 +1275,12 @@
</span><span class="cx">  * @since 2.5.0
</span><span class="cx">  */
</span><span class="cx"> function media_upload_header() {
</span><del>-        ?&gt;
-        &lt;script type=&quot;text/javascript&quot;&gt;post_id = &lt;?php echo intval($_REQUEST['post_id']); ?&gt;;&lt;/script&gt;
-        &lt;div id=&quot;media-upload-header&quot;&gt;
-        &lt;?php the_media_upload_tabs(); ?&gt;
-        &lt;/div&gt;
-        &lt;?php
</del><ins>+        echo '&lt;script type=&quot;text/javascript&quot;&gt;post_id = ' . intval( $_REQUEST['post_id'] ) . &quot;;&lt;/script&gt;\n&quot;;
+        if ( empty( $_GET['chromeless'] ) ) {
+                echo '&lt;div id=&quot;media-upload-header&quot;&gt;';
+                the_media_upload_tabs();
+                echo '&lt;/div&gt;';
+        }
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkwpincludescssmediaviewscss"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/css/media-views.css (22522 => 22523)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/css/media-views.css        2012-11-10 07:23:55 UTC (rev 22522)
+++ trunk/wp-includes/css/media-views.css        2012-11-10 07:51:37 UTC (rev 22523)
</span><span class="lines">@@ -254,6 +254,18 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Iframes
+ */
+.media-frame .media-iframe {
+        overflow: hidden;
+}
+
+.media-iframe iframe {
+        height: 100%;
+        width: 100%;
+}
+
+/**
</ins><span class="cx">  * Search
</span><span class="cx">  */
</span><span class="cx"> .media-frame .search {
</span></span></pre></div>
<a id="trunkwpincludesjsmediamodelsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-models.js (22522 => 22523)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-models.js        2012-11-10 07:23:55 UTC (rev 22522)
+++ trunk/wp-includes/js/media-models.js        2012-11-10 07:51:37 UTC (rev 22523)
</span><span class="lines">@@ -30,6 +30,9 @@
</span><span class="cx">                         frame = new MediaFrame.Post( attributes );
</span><span class="cx"> 
</span><span class="cx">                 delete attributes.frame;
</span><ins>+                // Set the default state.
+                frame.state( frame.options.state );
+                // Render, attach, and open the frame.
</ins><span class="cx">                 return frame.render().attach().open();
</span><span class="cx">         };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/js/media-views.js (22522 => 22523)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/js/media-views.js        2012-11-10 07:23:55 UTC (rev 22522)
+++ trunk/wp-includes/js/media-views.js        2012-11-10 07:51:37 UTC (rev 22523)
</span><span class="lines">@@ -8,6 +8,10 @@
</span><span class="cx">         // Link any localized strings.
</span><span class="cx">         l10n = media.view.l10n = _.isUndefined( _wpMediaViewsL10n ) ? {} : _wpMediaViewsL10n;
</span><span class="cx"> 
</span><ins>+        // Link any settings.
+        media.view.settings = l10n.settings || {};
+        delete l10n.settings;
+
</ins><span class="cx">         // Check if the browser supports CSS 3.0 transitions
</span><span class="cx">         $.support.transition = (function(){
</span><span class="cx">                 var style = document.documentElement.style,
</span><span class="lines">@@ -550,7 +554,9 @@
</span><span class="cx"> 
</span><span class="cx">                 _createStates: function() {
</span><span class="cx">                         // Create the default `states` collection.
</span><del>-                        this.states = new Backbone.Collection();
</del><ins>+                        this.states = new Backbone.Collection( null, {
+                                model: media.controller.State
+                        });
</ins><span class="cx"> 
</span><span class="cx">                         // Ensure states have a reference to the frame.
</span><span class="cx">                         this.states.on( 'add', function( model ) {
</span><span class="lines">@@ -625,12 +631,87 @@
</span><span class="cx">                                 this.uploader.render().$el.appendTo( this.$el );
</span><span class="cx"> 
</span><span class="cx">                         return this;
</span><ins>+                },
+
+                createIframeStates: function( options ) {
+                        var settings = media.view.settings,
+                                tabs = settings.tabs,
+                                tabUrl = settings.tabUrl,
+                                $postId;
+
+                        if ( ! tabs || ! tabUrl )
+                                return;
+
+                        // Add the post ID to the tab URL if it exists.
+                        $postId = $('#post_ID');
+                        if ( $postId.length )
+                                tabUrl += '&amp;post_id=' + $postId.val();
+
+                        // Generate the tab states.
+                        _.each( tabs, function( title, id ) {
+                                var frame = this.get( 'iframe:' + id ).set( _.defaults({
+                                        tab:     id,
+                                        src:     tabUrl + '&amp;tab=' + id,
+                                        title:   title,
+                                        content: 'iframe',
+                                        menu:    'main'
+                                }, options ) );
+                        }, this );
+
+                        this.content.on( 'activate:iframe', this.iframeContent, this );
+                        this.menu.on( 'activate:main', this.iframeMenu, this );
+                        this.on( 'open', this.hijackThickbox, this );
+                        this.on( 'close', this.restoreThickbox, this );
+                },
+
+                iframeContent: function() {
+                        this.$el.addClass('hide-toolbar hide-sidebar');
+                        this.content.view( new media.view.Iframe({
+                                controller: this
+                        }).render() );
+                },
+
+                iframeMenu: function() {
+                        var views = {};
+
+                        _.each( media.view.settings.tabs, function( title, id ) {
+                                views[ 'iframe:' + id ] = {
+                                        text: this.get( 'iframe:' + id ).get('title'),
+                                        priority: 200
+                                };
+                        }, this );
+
+                        this.menu.view().add( views );
+                },
+
+                hijackThickbox: function() {
+                        var frame = this;
+
+                        if ( ! window.tb_remove || this._tb_remove )
+                                return;
+
+                        this._tb_remove = window.tb_remove;
+                        window.tb_remove = function() {
+                                frame.close();
+                                frame.reset();
+                                frame.state( frame.options.state );
+                                frame._tb_remove.call( window );
+                        };
+                },
+
+                restoreThickbox: function() {
+                        if ( ! this._tb_remove )
+                                return;
+
+                        window.tb_remove = this._tb_remove;
+                        delete this._tb_remove;
</ins><span class="cx">                 }
</span><span class="cx">         });
</span><span class="cx"> 
</span><span class="cx">         // Map some of the modal's methods to the frame.
</span><span class="cx">         _.each(['open','close','attach','detach'], function( method ) {
</span><span class="cx">                 media.view.MediaFrame.prototype[ method ] = function( view ) {
</span><ins>+                        this.trigger( method );
</ins><span class="cx">                         if ( this.modal )
</span><span class="cx">                                 this.modal[ method ].apply( this.modal, arguments );
</span><span class="cx">                         return this;
</span><span class="lines">@@ -654,9 +735,6 @@
</span><span class="cx">                         this.createSelection();
</span><span class="cx">                         this.createStates();
</span><span class="cx">                         this.bindHandlers();
</span><del>-
-                        // Set the default state.
-                        this.state( this.options.state );
</del><span class="cx">                 },
</span><span class="cx"> 
</span><span class="cx">                 createSelection: function() {
</span><span class="lines">@@ -809,6 +887,7 @@
</span><span class="cx">                         });
</span><span class="cx"> 
</span><span class="cx">                         media.view.MediaFrame.Select.prototype.initialize.apply( this, arguments );
</span><ins>+                        this.createIframeStates();
</ins><span class="cx">                 },
</span><span class="cx"> 
</span><span class="cx">                 createStates: function() {
</span><span class="lines">@@ -2505,4 +2584,20 @@
</span><span class="cx">                         'change .describe': 'describe'
</span><span class="cx">                 }
</span><span class="cx">         });
</span><ins>+
+        /**
+         * wp.media.view.Iframe
+         */
+        media.view.Iframe = Backbone.View.extend({
+                className: 'media-iframe',
+
+                initialize: function() {
+                        this.controller = this.options.controller;
+                },
+
+                render: function() {
+                        this.$el.html( '&lt;iframe src=&quot;' + this.controller.state().get('src') + '&quot; /&gt;' );
+                        return this;
+                }
+        });
</ins><span class="cx"> }(jQuery));
</span><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (22522 => 22523)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php        2012-11-10 07:23:55 UTC (rev 22522)
+++ trunk/wp-includes/media.php        2012-11-10 07:51:37 UTC (rev 22523)
</span><span class="lines">@@ -1297,7 +1297,30 @@
</span><span class="cx">  * @since 3.5.0
</span><span class="cx">  */
</span><span class="cx"> function wp_enqueue_media() {
</span><ins>+        // We're going to pass the old thickbox media tabs to `media_upload_tabs`
+        // to ensure plugins will work. We will then unset those tabs.
+        $tabs = array(
+                // handler action suffix =&gt; tab text
+                'type'     =&gt; __('From Computer'),
+                'type_url' =&gt; __('From URL'),
+                'gallery'  =&gt; __('Gallery'),
+                'library'  =&gt; __('Media Library'),
+        );
+
+        $tabs = apply_filters( 'media_upload_tabs', $tabs );
+        unset( $tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library'] );
+
+        $settings = array(
+                'tabs'   =&gt; $tabs,
+                'tabUrl' =&gt; add_query_arg( array(
+                        'chromeless' =&gt; true
+                ), admin_url('media-upload.php') ),
+        );
+
</ins><span class="cx">         wp_localize_script( 'media-views', '_wpMediaViewsL10n', array(
</span><ins>+                // Settings
+                'settings' =&gt; $settings,
+
</ins><span class="cx">                 // Generic
</span><span class="cx">                 'insertMedia' =&gt; __( 'Insert Media' ),
</span><span class="cx">                 'search'      =&gt; __( 'Search' ),
</span></span></pre>
</div>
</div>

</body>
</html>