<!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>[31546] trunk/src/wp-includes: TinyMCE: wpView improvements:</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" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/31546">31546</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/31546","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>azaozz</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-02-25 23:12:08 +0000 (Wed, 25 Feb 2015)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>TinyMCE: wpView improvements:
- Better structure, simpler "view" registration, better extensibility.
- Better inline documentation.
- Don't show a placeholder for pasted link until we know the link is "embeddable'.
And many more improvements. Props iseulde. See <a href="https://core.trac.wordpress.org/ticket/31412">#31412</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesjsmceviewjs">trunk/src/wp-includes/js/mce-view.js</a></li>
<li><a href="#trunksrcwpincludesjstinymcepluginswpviewpluginjs">trunk/src/wp-includes/js/tinymce/plugins/wpview/plugin.js</a></li>
<li><a href="#trunksrcwpincludesmediatemplatephp">trunk/src/wp-includes/media-template.php</a></li>
<li><a href="#trunksrcwpincludesversionphp">trunk/src/wp-includes/version.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesjsmceviewjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/js/mce-view.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/js/mce-view.js      2015-02-25 20:15:46 UTC (rev 31545)
+++ trunk/src/wp-includes/js/mce-view.js        2015-02-25 23:12:08 UTC (rev 31546)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1,279 +1,38 @@
</span><span class="cx" style="display: block; padding: 0 10px"> /* global tinymce */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/**
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+window.wp = window.wp || {};
+
+/*
+ * The TinyMCE view API.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px">  * Note: this API is "experimental" meaning that it will probably change
</span><span class="cx" style="display: block; padding: 0 10px">  * in the next few releases based on feedback from 3.9.0.
</span><span class="cx" style="display: block; padding: 0 10px">  * If you decide to use it, please follow the development closely.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *
+ * Diagram
+ *
+ * |- registered view constructor (type)
+ * |  |- view instance (unique text)
+ * |  |  |- editor 1
+ * |  |  |  |- view node
+ * |  |  |  |- view node
+ * |  |  |  |- ...
+ * |  |  |- editor 2
+ * |  |  |  |- ...
+ * |  |- view instance
+ * |  |  |- ...
+ * |- registered view
+ * |  |- ...
</ins><span class="cx" style="display: block; padding: 0 10px">  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-// Ensure the global `wp` object exists.
-window.wp = window.wp || {};
-
-( function( $ ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+( function( window, wp, $ ) {
</ins><span class="cx" style="display: block; padding: 0 10px">         'use strict';
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        var views = {},
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                instances = {},
-               media = wp.media,
-               mediaWindows = [],
-               windowIdx = 0,
-               waitInterval = 50,
-               viewOptions = ['encodedText'];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         instances = {};
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        // Create the `wp.mce` object if necessary.
</del><span class="cx" style="display: block; padding: 0 10px">         wp.mce = wp.mce || {};
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * wp.mce.View
-        *
-        * A Backbone-like View constructor intended for use when rendering a TinyMCE View. The main difference is
-        * that the TinyMCE View is not tied to a particular DOM node.
-        *
-        * @param {Object} [options={}]
-        */
-       wp.mce.View = function( options ) {
-               options = options || {};
-               this.type = options.type;
-               _.extend( this, _.pick( options, viewOptions ) );
-               this.initialize.apply( this, arguments );
-       };
-
-       _.extend( wp.mce.View.prototype, {
-               initialize: function() {},
-               getHtml: function() {
-                       return '';
-               },
-               loadingPlaceholder: function() {
-                       return '' +
-                               '<div class="loading-placeholder">' +
-                                       '<div class="dashicons dashicons-admin-media"></div>' +
-                                       '<div class="wpview-loading"><ins></ins></div>' +
-                               '</div>';
-               },
-               render: function( force ) {
-                       if ( force || ! this.rendered() ) {
-                               this.unbind();
-
-                               this.setContent(
-                                       '<p class="wpview-selection-before">\u00a0</p>' +
-                                       '<div class="wpview-body" contenteditable="false">' +
-                                               '<div class="toolbar mce-arrow-down">' +
-                                                       ( _.isFunction( views[ this.type ].edit ) ? '<div class="dashicons dashicons-edit edit"></div>' : '' ) +
-                                                       '<div class="dashicons dashicons-no remove"></div>' +
-                                               '</div>' +
-                                               '<div class="wpview-content wpview-type-' + this.type + '">' +
-                                                       ( this.getHtml() || this.loadingPlaceholder() ) +
-                                               '</div>' +
-                                               ( this.overlay ? '<div class="wpview-overlay"></div>' : '' ) +
-                                       '</div>' +
-                                       '<p class="wpview-selection-after">\u00a0</p>',
-                                       'wrap'
-                               );
-
-                               $( this ).trigger( 'ready' );
-
-                               this.rendered( true );
-                       }
-               },
-               unbind: function() {},
-               getEditors: function( callback ) {
-                       var editors = [];
-
-                       _.each( tinymce.editors, function( editor ) {
-                               if ( editor.plugins.wpview ) {
-                                       if ( callback ) {
-                                               callback( editor );
-                                       }
-
-                                       editors.push( editor );
-                               }
-                       }, this );
-
-                       return editors;
-               },
-               getNodes: function( callback ) {
-                       var nodes = [],
-                               self = this;
-
-                       this.getEditors( function( editor ) {
-                               $( editor.getBody() )
-                               .find( '[data-wpview-text="' + self.encodedText + '"]' )
-                               .each( function ( i, node ) {
-                                       if ( callback ) {
-                                               callback( editor, node, $( node ).find( '.wpview-content' ).get( 0 ) );
-                                       }
-
-                                       nodes.push( node );
-                               } );
-                       } );
-
-                       return nodes;
-               },
-               setContent: function( html, option ) {
-                       this.getNodes( function ( editor, node, content ) {
-                               var el = ( option === 'wrap' || option === 'replace' ) ? node : content,
-                                       insert = html;
-
-                               if ( _.isString( insert ) ) {
-                                       insert = editor.dom.createFragment( insert );
-                               }
-
-                               if ( option === 'replace' ) {
-                                       editor.dom.replace( insert, el );
-                               } else {
-                                       el.innerHTML = '';
-                                       el.appendChild( insert );
-                               }
-                       } );
-               },
-               /* jshint scripturl: true */
-               setIframes: function ( head, body ) {
-                       var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver,
-                               importStyles = this.type === 'video' || this.type === 'audio' || this.type === 'playlist';
-
-                       if ( head || body.indexOf( '<script' ) !== -1 ) {
-                               this.getNodes( function ( editor, node, content ) {
-                                       var dom = editor.dom,
-                                               styles = '',
-                                               bodyClasses = editor.getBody().className || '',
-                                               iframe, iframeDoc, i, resize;
-
-                                       content.innerHTML = '';
-                                       head = head || '';
-
-                                       if ( importStyles ) {
-                                               if ( ! wp.mce.views.sandboxStyles ) {
-                                                       tinymce.each( dom.$( 'link[rel="stylesheet"]', editor.getDoc().head ), function( link ) {
-                                                               if ( link.href && link.href.indexOf( 'skins/lightgray/content.min.css' ) === -1 &&
-                                                                       link.href.indexOf( 'skins/wordpress/wp-content.css' ) === -1 ) {
-
-                                                                       styles += dom.getOuterHTML( link ) + '\n';
-                                                               }
-                                                       });
-
-                                                       wp.mce.views.sandboxStyles = styles;
-                                               } else {
-                                                       styles = wp.mce.views.sandboxStyles;
-                                               }
-                                       }
-
-                                       // Seems Firefox needs a bit of time to insert/set the view nodes, or the iframe will fail
-                                       // especially when switching Text => Visual.
-                                       setTimeout( function() {
-                                               iframe = dom.add( content, 'iframe', {
-                                                       src: tinymce.Env.ie ? 'javascript:""' : '',
-                                                       frameBorder: '0',
-                                                       allowTransparency: 'true',
-                                                       scrolling: 'no',
-                                                       'class': 'wpview-sandbox',
-                                                       style: {
-                                                               width: '100%',
-                                                               display: 'block'
-                                                       }
-                                               } );
-
-                                               iframeDoc = iframe.contentWindow.document;
-
-                                               iframeDoc.open();
-                                               iframeDoc.write(
-                                                       '<!DOCTYPE html>' +
-                                                       '<html>' +
-                                                               '<head>' +
-                                                                       '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +
-                                                                       head +
-                                                                       styles +
-                                                                       '<style>' +
-                                                                               'html {' +
-                                                                                       'background: transparent;' +
-                                                                                       'padding: 0;' +
-                                                                                       'margin: 0;' +
-                                                                               '}' +
-                                                                               'body#wpview-iframe-sandbox {' +
-                                                                                       'background: transparent;' +
-                                                                                       'padding: 1px 0 !important;' +
-                                                                                       'margin: -1px 0 0 !important;' +
-                                                                               '}' +
-                                                                               'body#wpview-iframe-sandbox:before,' +
-                                                                               'body#wpview-iframe-sandbox:after {' +
-                                                                                       'display: none;' +
-                                                                                       'content: "";' +
-                                                                               '}' +
-                                                                       '</style>' +
-                                                               '</head>' +
-                                                               '<body id="wpview-iframe-sandbox" class="' + bodyClasses + '">' +
-                                                                       body +
-                                                               '</body>' +
-                                                       '</html>'
-                                               );
-                                               iframeDoc.close();
-
-                                               resize = function() {
-                                                       var $iframe, iframeDocHeight;
-
-                                                       // Make sure the iframe still exists.
-                                                       if ( iframe.contentWindow ) {
-                                                               $iframe = $( iframe );
-                                                               iframeDocHeight = $( iframeDoc.body ).height();
-
-                                                               if ( $iframe.height() !== iframeDocHeight ) {
-                                                                       $iframe.height( iframeDocHeight );
-                                                                       editor.nodeChanged();
-                                                               }
-                                                       }
-                                               };
-
-                                               if ( MutationObserver ) {
-                                                       new MutationObserver( _.debounce( function() {
-                                                               resize();
-                                                       }, 100 ) )
-                                                       .observe( iframeDoc.body, {
-                                                               attributes: true,
-                                                               childList: true,
-                                                               subtree: true
-                                                       } );
-                                               } else {
-                                                       for ( i = 1; i < 6; i++ ) {
-                                                               setTimeout( resize, i * 700 );
-                                                       }
-                                               }
-
-                                               if ( importStyles ) {
-                                                       editor.on( 'wp-body-class-change', function() {
-                                                               iframeDoc.body.className = editor.getBody().className;
-                                                       });
-                                               }
-                                       }, waitInterval );
-                               });
-                       } else {
-                               this.setContent( body );
-                       }
-               },
-               setError: function( message, dashicon ) {
-                       this.setContent(
-                               '<div class="wpview-error">' +
-                                       '<div class="dashicons dashicons-' + ( dashicon ? dashicon : 'no' ) + '"></div>' +
-                                       '<p>' + message + '</p>' +
-                               '</div>'
-                       );
-               },
-               rendered: function( value ) {
-                       var notRendered;
-
-                       this.getNodes( function( editor, node ) {
-                               if ( value != null ) {
-                                       $( node ).data( 'rendered', value === true );
-                               } else {
-                                       notRendered = notRendered || ! $( node ).data( 'rendered' );
-                               }
-                       } );
-
-                       return ! notRendered;
-               }
-       } );
-
-       // take advantage of the Backbone extend method
-       wp.mce.View.extend = Backbone.View.extend;
-
-       /**
</del><span class="cx" style="display: block; padding: 0 10px">          * wp.mce.views
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * A set of utilities that simplifies adding custom UI within a TinyMCE editor.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -283,67 +42,36 @@
</span><span class="cx" style="display: block; padding: 0 10px">        wp.mce.views = {
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * wp.mce.views.register( type, view )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * Registers a new view type.
</ins><span class="cx" style="display: block; padding: 0 10px">                  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * Registers a new TinyMCE view.
-                *
-                * @param type
-                * @param constructor
-                *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param {String} type   The view type.
+                * @param {Object} extend An object to extend wp.mce.View.prototype with.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                register: function( type, constructor ) {
-                       var defaultConstructor = {
-                                       type: type,
-                                       View: {},
-                                       toView: function( content ) {
-                                               var match = wp.shortcode.next( this.type, content );
-
-                                               if ( ! match ) {
-                                                       return;
-                                               }
-
-                                               return {
-                                                       index: match.index,
-                                                       content: match.content,
-                                                       options: {
-                                                               shortcode: match.shortcode
-                                                       }
-                                               };
-                                       }
-                               };
-
-                       constructor = _.defaults( constructor, defaultConstructor );
-                       constructor.View = wp.mce.View.extend( constructor.View );
-
-                       views[ type ] = constructor;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         register: function( type, extend ) {
+                       views[ type ] = wp.mce.View.extend( _.extend( extend, { type: type } ) );
</ins><span class="cx" style="display: block; padding: 0 10px">                 },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * wp.mce.views.get( id )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * Unregisters a view type.
</ins><span class="cx" style="display: block; padding: 0 10px">                  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * Returns a TinyMCE view constructor.
-                *
-                * @param type
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param {String} type The view type.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                get: function( type ) {
-                       return views[ type ];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         unregister: function( type ) {
+                       delete views[ type ];
</ins><span class="cx" style="display: block; padding: 0 10px">                 },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * wp.mce.views.unregister( type )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * Returns the settings of a view type.
</ins><span class="cx" style="display: block; padding: 0 10px">                  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * Unregisters a TinyMCE view.
-                *
-                * @param type
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param {String} type The view type.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                unregister: function( type ) {
-                       delete views[ type ];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         get: function( type ) {
+                       return views[ type ];
</ins><span class="cx" style="display: block; padding: 0 10px">                 },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * wp.mce.views.unbind( editor )
-                *
-                * The editor DOM is being rebuilt, run cleanup.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * Unbinds all view nodes.
+                * Runs before removing all view nodes from the DOM.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><span class="cx" style="display: block; padding: 0 10px">                unbind: function() {
</span><span class="cx" style="display: block; padding: 0 10px">                        _.each( instances, function( instance ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -352,18 +80,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * toViews( content )
-                * Scans a `content` string for each view's pattern, replacing any
-                * matches with wrapper elements, and creates a new instance for
-                * every match, which triggers the related data to be fetched.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * Scans a given string for each view's pattern,
+                * replacing any matches with markers,
+                * and creates a new instance for every match.
</ins><span class="cx" style="display: block; padding: 0 10px">                  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * @param content
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param {String} content The string to scan.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                toViews: function( content ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         setMarkers: function( content ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         var pieces = [ { content: content } ],
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                self = this,
</ins><span class="cx" style="display: block; padding: 0 10px">                                 current;
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        _.each( views, function( view, viewType ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 _.each( views, function( view, type ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 current = pieces.slice();
</span><span class="cx" style="display: block; padding: 0 10px">                                pieces  = [];
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -379,110 +107,72 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                        // Iterate through the string progressively matching views
</span><span class="cx" style="display: block; padding: 0 10px">                                        // and slicing the string as we go.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        while ( remaining && (result = view.toView( remaining )) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 while ( remaining && ( result = view.prototype.match( remaining ) ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 // Any text before the match becomes an unprocessed piece.
</span><span class="cx" style="display: block; padding: 0 10px">                                                if ( result.index ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                        pieces.push({ content: remaining.substring( 0, result.index ) });
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                 pieces.push( { content: remaining.substring( 0, result.index ) } );
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                self.createInstance( type, result.content, result.options );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 // Add the processed piece for the match.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                pieces.push({
-                                                       content: wp.mce.views.toView( viewType, result.content, result.options ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         pieces.push( {
+                                                       content: '<p data-wpview-marker="' + encodeURIComponent( result.content ) + '">' + result.content + '</p>',
</ins><span class="cx" style="display: block; padding: 0 10px">                                                         processed: true
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                });
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         } );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                                                // Update the remaining content.
</span><span class="cx" style="display: block; padding: 0 10px">                                                remaining = remaining.slice( result.index + result.content.length );
</span><span class="cx" style="display: block; padding: 0 10px">                                        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        // There are no additional matches. If any content remains,
-                                       // add it as an unprocessed piece.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 // There are no additional matches.
+                                       // If any content remains, add it as an unprocessed piece.
</ins><span class="cx" style="display: block; padding: 0 10px">                                         if ( remaining ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                pieces.push({ content: remaining });
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         pieces.push( { content: remaining } );
</ins><span class="cx" style="display: block; padding: 0 10px">                                         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                });
-                       });
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         } );
+                       } );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return _.pluck( pieces, 'content' ).join('');
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return _.pluck( pieces, 'content' ).join( '' );
</ins><span class="cx" style="display: block; padding: 0 10px">                 },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * Create a placeholder for a particular view type
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * Create a view instance.
</ins><span class="cx" style="display: block; padding: 0 10px">                  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * @param viewType
-                * @param text
-                * @param options
-                *
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param {String} type    The view type.
+                * @param {String} text    The textual representation of the view.
+                * @param {Object} options Options.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                toView: function( viewType, text, options ) {
-                       var view = wp.mce.views.get( viewType ),
-                               encodedText = window.encodeURIComponent( text ),
-                               instance, viewOptions;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         createInstance: function( type, text, options ) {
+                       var View = this.get( type ),
+                               encodedText = encodeURIComponent( text ),
+                               instance = this.getInstance( encodedText );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                       if ( ! view ) {
-                               return text;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( instance ) {
+                               return instance;
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( ! wp.mce.views.getInstance( encodedText ) ) {
-                               viewOptions = options;
-                               viewOptions.type = viewType;
-                               viewOptions.encodedText = encodedText;
-                               instance = new view.View( viewOptions );
-                               instances[ encodedText ] = instance;
-                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 options = _.extend( options || {}, {
+                               text: text,
+                               encodedText: encodedText
+                       } );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return wp.html.string({
-                               tag: 'div',
-
-                               attrs: {
-                                       'class': 'wpview-wrap',
-                                       'data-wpview-text': encodedText,
-                                       'data-wpview-type': viewType
-                               },
-
-                               content: '\u00a0'
-                       });
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return instances[ encodedText ] = new View( options );
</ins><span class="cx" style="display: block; padding: 0 10px">                 },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * Refresh views after an update is made
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * Get a view instance.
</ins><span class="cx" style="display: block; padding: 0 10px">                  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * @param view {object} being refreshed
-                * @param text {string} textual representation of the view
-                * @param force {Boolean} whether to force rendering
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param {String} text The textual representation of the view.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                refreshView: function( view, text, force ) {
-                       var encodedText = window.encodeURIComponent( text ),
-                               viewOptions,
-                               result, instance;
-
-                       instance = wp.mce.views.getInstance( encodedText );
-
-                       if ( ! instance ) {
-                               result = view.toView( text );
-                               viewOptions = result.options;
-                               viewOptions.type = view.type;
-                               viewOptions.encodedText = encodedText;
-                               instance = new view.View( viewOptions );
-                               instances[ encodedText ] = instance;
-                       }
-
-                       instance.render( force );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         getInstance: function( text ) {
+                       return instances[ encodeURIComponent( text ) ];
</ins><span class="cx" style="display: block; padding: 0 10px">                 },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                getInstance: function( encodedText ) {
-                       return instances[ encodedText ];
-               },
-
</del><span class="cx" style="display: block; padding: 0 10px">                 /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * render( scope )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * Renders all view nodes that are not yet rendered.
</ins><span class="cx" style="display: block; padding: 0 10px">                  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * Renders any view instances inside a DOM node `scope`.
-                *
-                * View instances are detected by the presence of wrapper elements.
-                * To generate wrapper elements, pass your content through
-                * `wp.mce.view.toViews( content )`.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param {Boolean} force Rerender all view nodes.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><span class="cx" style="display: block; padding: 0 10px">                render: function( force ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        _.each( instances, function( instance ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -490,408 +180,645 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        } );
</span><span class="cx" style="display: block; padding: 0 10px">                },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                edit: function( node ) {
-                       var viewType = $( node ).data('wpview-type'),
-                               view = wp.mce.views.get( viewType );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Update the text of a given view node.
+                *
+                * @param {String}         text   The new text.
+                * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in.
+                * @param {HTMLElement}    node   The view node to update.
+                */
+               update: function( text, editor, node ) {
+                       var oldText = decodeURIComponent( $( node ).data( 'wpview-text' ) ),
+                               instance = this.getInstance( oldText );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( view ) {
-                               view.edit( node );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( instance ) {
+                               instance.update( text, editor, node );
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                },
+
+               /**
+                * Renders any editing interface based on the view type.
+                *
+                * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in.
+                * @param {HTMLElement}    node   The view node to edit.
+                */
+               edit: function( editor, node ) {
+                       var text = decodeURIComponent( $( node ).data( 'wpview-text' ) ),
+                               instance = this.getInstance( text );
+
+                       if ( instance && instance.edit ) {
+                               instance.edit( text, function( text ) {
+                                       instance.update( text, editor, node );
+                               } );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        };
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        wp.mce.views.register( 'gallery', {
-               View: {
-                       template: media.template( 'editor-gallery' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+        * A Backbone-like View constructor intended for use when rendering a TinyMCE View.
+        * The main difference is that the TinyMCE View is not tied to a particular DOM node.
+        *
+        * @param {Object} Options.
+        */
+       wp.mce.View = function( options ) {
+               _.extend( this, options );
+               this.initialize();
+       };
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        // The fallback post ID to use as a parent for galleries that don't
-                       // specify the `ids` or `include` parameters.
-                       //
-                       // Uses the hidden input on the edit posts page by default.
-                       postID: $('#post_ID').val(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp.mce.View.extend = Backbone.View.extend;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        initialize: function( options ) {
-                               this.shortcode = options.shortcode;
-                               this.fetch();
-                       },
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ _.extend( wp.mce.View.prototype, {
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        fetch: function() {
-                               var self = this;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * The content.
+                *
+                * @type {*}
+                */
+               content: null,
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                this.attachments = wp.media.gallery.attachments( this.shortcode, this.postID );
-                               this.dfd = this.attachments.more().done( function() {
-                                       self.render( true );
-                               } );
-                       },
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Whether or not to display a loader.
+                *
+                * @type {Boolean}
+                */
+               loader: true,
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        getHtml: function() {
-                               var attrs = this.shortcode.attrs.named,
-                                       attachments = false,
-                                       options;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Runs after the view instance is created.
+                */
+               initialize: function() {},
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                // Don't render errors while still fetching attachments
-                               if ( this.dfd && 'pending' === this.dfd.state() && ! this.attachments.length ) {
-                                       return '';
-                               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Retuns the content to render in the view node.
+                *
+                * @return {*}
+                */
+               getContent: function() {
+                       return this.content;
+               },
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( this.attachments.length ) {
-                                       attachments = this.attachments.toJSON();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Renders all view nodes tied to this view instance that are not yet rendered.
+                *
+                * @param {Boolean} force Rerender all view nodes tied to this view instance.
+                */
+               render: function( force ) {
+                       // If there's nothing to render an no loader needs to be shown, stop.
+                       if ( ! this.loader && ! this.getContent() ) {
+                               return;
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        _.each( attachments, function( attachment ) {
-                                               if ( attachment.sizes ) {
-                                                       if ( attrs.size && attachment.sizes[ attrs.size ] ) {
-                                                               attachment.thumbnail = attachment.sizes[ attrs.size ];
-                                                       } else if ( attachment.sizes.thumbnail ) {
-                                                               attachment.thumbnail = attachment.sizes.thumbnail;
-                                                       } else if ( attachment.sizes.full ) {
-                                                               attachment.thumbnail = attachment.sizes.full;
-                                                       }
-                                               }
-                                       } );
-                               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // We're about to rerender all views of this instance, so unbind rendered views.
+                       force && this.unbind();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                options = {
-                                       attachments: attachments,
-                                       columns: attrs.columns ? parseInt( attrs.columns, 10 ) : wp.media.galleryDefaults.columns
-                               };
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 // Replace any left over markers.
+                       this.replaceMarkers();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                return this.template( options );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( this.getContent() ) {
+                               this.setContent( this.getContent(), function( editor, node ) {
+                                       $( node ).data( 'rendered', true );
+                                       this.bindNodes.apply( this, arguments );
+                               }, force ? null : false );
+                       } else {
+                               this.setLoader();
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                edit: function( node ) {
-                       var gallery = wp.media.gallery,
-                               self = this,
-                               frame, data;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Binds a given rendered view node.
+                * Runs after a view node's content is added to the DOM.
+                *
+                * @param {tinymce.Editor} editor      The TinyMCE editor instance the view node is in.
+                * @param {HTMLElement}    node        The view node.
+                * @param {HTMLElement}    contentNode The view's content node.
+                */
+               bindNodes: function( /* editor, node, contentNode */ ) {},
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        data = window.decodeURIComponent( $( node ).attr('data-wpview-text') );
-                       frame = gallery.edit( data );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Unbinds all view nodes tied to this view instance.
+                * Runs before their content is removed from the DOM.
+                */
+               unbind: function() {
+                       this.getNodes( function() {
+                               this.unbindNodes.apply( this, arguments );
+                       }, true );
+               },
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        frame.state('gallery-edit').on( 'update', function( selection ) {
-                               var shortcode = gallery.shortcode( selection ).string();
-                               $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) );
-                               wp.mce.views.refreshView( self, shortcode, true );
-                       });
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Unbinds a given view node.
+                * Runs before the view node's content is removed from the DOM.
+                *
+                * @param {tinymce.Editor} editor      The TinyMCE editor instance the view node is in.
+                * @param {HTMLElement}    node        The view node.
+                * @param {HTMLElement}    contentNode The view's content node.
+                */
+               unbindNodes: function( /* editor, node, contentNode */ ) {},
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        frame.on( 'close', function() {
-                               frame.detach();
-                       });
-               }
-       } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Gets all the TinyMCE editor instances that support views.
+                *
+                * @param {Function} callback A callback.
+                */
+               getEditors: function( callback ) {
+                       _.each( tinymce.editors, function( editor ) {
+                               if ( editor.plugins.wpview ) {
+                                       callback.call( this, editor );
+                               }
+                       }, this );
+               },
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        /**
-        * These are base methods that are shared by the audio and video shortcode's MCE controller.
-        *
-        * @mixin
-        */
-       wp.mce.av = {
-               View: {
-                       overlay: true,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Gets all view nodes tied to this view instance.
+                *
+                * @param {Function} callback A callback.
+                * @param {Boolean}  rendered Get (un)rendered view nodes. Optional.
+                */
+               getNodes: function( callback, rendered ) {
+                       this.getEditors( function( editor ) {
+                               var self = this;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        action: 'parse-media-shortcode',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $( editor.getBody() )
+                                       .find( '[data-wpview-text="' + self.encodedText + '"]' )
+                                       .filter( function() {
+                                               var data;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        initialize: function( options ) {
-                               var self = this;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         if ( rendered == null ) {
+                                                       return true;
+                                               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                this.shortcode = options.shortcode;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         data = $( this ).data( 'rendered' ) === true;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                _.bindAll( this, 'setIframes', 'setNodes', 'fetch', 'stopPlayers' );
-                               $( this ).on( 'ready', this.setNodes );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         return rendered ? data : ! data;
+                                       } )
+                                       .each( function() {
+                                               callback.call( self, editor, this, $( this ).find( '.wpview-content' ).get( 0 ) );
+                                       } );
+                       } );
+               },
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $( document ).on( 'media:edit', this.stopPlayers );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Gets all marker nodes tied to this view instance.
+                *
+                * @param {Function} callback A callback.
+                */
+               getMarkers: function( callback ) {
+                       this.getEditors( function( editor ) {
+                               var self = this;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                this.fetch();
-
-                               this.getEditors( function( editor ) {
-                                       editor.on( 'hide', function () {
-                                               mediaWindows = [];
-                                               windowIdx = 0;
-                                               self.stopPlayers();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $( editor.getBody() )
+                                       .find( '[data-wpview-marker="' + this.encodedText + '"]' )
+                                       .each( function() {
+                                               callback.call( self, editor, this );
</ins><span class="cx" style="display: block; padding: 0 10px">                                         } );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                });
-                       },
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 } );
+               },
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        pauseOtherWindows: function ( win ) {
-                               _.each( mediaWindows, function ( mediaWindow ) {
-                                       if ( mediaWindow.sandboxId !== win.sandboxId ) {
-                                               _.each( mediaWindow.mejs.players, function ( player ) {
-                                                       player.pause();
-                                               } );
-                                       }
-                               } );
-                       },
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Replaces all marker nodes tied to this view instance.
+                */
+               replaceMarkers: function() {
+                       this.getMarkers( function( editor, node ) {
+                               if ( $( node ).text() !== this.text ) {
+                                       editor.dom.setAttrib( node, 'data-wpview-marker', null );
+                                       return;
+                               }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        iframeLoaded: function (win) {
-                               return _.bind( function () {
-                                       var callback;
-                                       if ( ! win.mejs || _.isEmpty( win.mejs.players ) ) {
-                                               return;
-                                       }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         editor.dom.replace(
+                                       editor.dom.createFragment(
+                                               '<div class="wpview-wrap" data-wpview-text="' + this.encodedText + '" data-wpview-type="' + this.type + '">' +
+                                                       '<p class="wpview-selection-before">\u00a0</p>' +
+                                                       '<div class="wpview-body" contenteditable="false">' +
+                                                               '<div class="toolbar mce-arrow-down">' +
+                                                                       ( this.edit ? '<div class="dashicons dashicons-edit edit"></div>' : '' ) +
+                                                                       '<div class="dashicons dashicons-no remove"></div>' +
+                                                               '</div>' +
+                                                               '<div class="wpview-content wpview-type-' + this.type + '"></div>' +
+                                                       '</div>' +
+                                                       '<p class="wpview-selection-after">\u00a0</p>' +
+                                               '</div>'
+                                       ),
+                                       node
+                               );
+                       } );
+               },
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        win.sandboxId = windowIdx;
-                                       windowIdx++;
-                                       mediaWindows.push( win );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Removes all marker nodes tied to this view instance.
+                */
+               removeMarkers: function() {
+                       this.getMarkers( function( editor, node ) {
+                               editor.dom.setAttrib( node, 'data-wpview-marker', null );
+                       } );
+               },
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        callback = _.bind( function () {
-                                               this.pauseOtherWindows( win );
-                                       }, this );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Sets the content for all view nodes tied to this view instance.
+                *
+                * @param {*}        content  The content to set.
+                * @param {Function} callback A callback. Optional.
+                * @param {Boolean}  rendered Only set for (un)rendered nodes. Optional.
+                */
+               setContent: function( content, callback, rendered ) {
+                       if ( _.isObject( content ) && content.body.indexOf( '<script' ) !== -1 ) {
+                               this.setIframes( content.head, content.body, callback, rendered );
+                       } else if ( _.isString( content ) && content.indexOf( '<script' ) !== -1 ) {
+                               this.setIframes( null, content, callback, rendered );
+                       } else {
+                               this.getNodes( function( editor, node, contentNode ) {
+                                       content = content.body || content;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        if ( ! _.isEmpty( win.mejs.MediaPluginBridge.pluginMediaElements ) ) {
-                                               _.each( win.mejs.MediaPluginBridge.pluginMediaElements, function ( mediaElement ) {
-                                                       mediaElement.addEventListener( 'play', callback );
-                                               } );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 if ( content.indexOf( '<iframe' ) !== -1 ) {
+                                               content += '<div class="wpview-overlay"></div>';
</ins><span class="cx" style="display: block; padding: 0 10px">                                         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        _.each( win.mejs.players, function ( player ) {
-                                               $( player.node ).on( 'play', callback );
-                                       }, this );
-                               }, this );
-                       },
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 contentNode.innerHTML = '';
+                                       contentNode.appendChild( _.isString( content ) ? editor.dom.createFragment( content ) : content );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        listenToSandboxes: function () {
-                               _.each( this.getNodes(), function ( node ) {
-                                       var win, iframe = $( '.wpview-sandbox', node ).get( 0 );
-                                       if ( iframe && ( win = iframe.contentWindow ) ) {
-                                               $( win ).load( _.bind( this.iframeLoaded( win ), this ) );
-                                       }
-                               }, this );
-                       },
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 callback && callback.apply( this, arguments );
+                               }, rendered );
+                       }
+               },
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        deferredListen: function () {
-                               window.setTimeout( _.bind( this.listenToSandboxes, this ), this.getNodes().length * waitInterval );
-                       },
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Sets the content in an iframe for all view nodes tied to this view instance.
+                *
+                * @param {String}   head     HTML string to be added to the head of the document.
+                * @param {String}   body     HTML string to be added to the body of the document.
+                * @param {Function} callback A callback. Optional.
+                * @param {Boolean}  rendered Only set for (un)rendered nodes. Optional.
+                */
+               setIframes: function( head, body, callback, rendered ) {
+                       var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver,
+                               importStyles = this.type === 'video' || this.type === 'audio' || this.type === 'playlist';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        setNodes: function () {
-                               if ( this.parsed ) {
-                                       this.setIframes( this.parsed.head, this.parsed.body );
-                                       this.deferredListen();
-                               } else {
-                                       this.fail();
-                               }
-                       },
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 this.getNodes( function( editor, node, content ) {
+                               var dom = editor.dom,
+                                       styles = '',
+                                       bodyClasses = editor.getBody().className || '',
+                                       iframe, iframeDoc, i, resize;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        fetch: function () {
-                               var self = this;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         content.innerHTML = '';
+                               head = head || '';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                wp.ajax.send( this.action, {
-                                       data: {
-                                               post_ID: $( '#post_ID' ).val() || 0,
-                                               type: this.shortcode.tag,
-                                               shortcode: this.shortcode.string()
-                                       }
-                               } )
-                               .done( function( response ) {
-                                       if ( response ) {
-                                               self.parsed = response;
-                                               self.setIframes( response.head, response.body );
-                                               self.deferredListen();
-                                       } else {
-                                               self.fail( true );
-                                       }
-                               } )
-                               .fail( function( response ) {
-                                       self.fail( response || true );
-                               } );
-                       },
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         if ( importStyles ) {
+                                       if ( ! wp.mce.views.sandboxStyles ) {
+                                               tinymce.each( dom.$( 'link[rel="stylesheet"]', editor.getDoc().head ), function( link ) {
+                                                       if ( link.href && link.href.indexOf( 'skins/lightgray/content.min.css' ) === -1 &&
+                                                               link.href.indexOf( 'skins/wordpress/wp-content.css' ) === -1 ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        fail: function( error ) {
-                               if ( ! this.error ) {
-                                       if ( error ) {
-                                               this.error = error;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                                         styles += dom.getOuterHTML( link ) + '\n';
+                                                       }
+                                               });
+
+                                               wp.mce.views.sandboxStyles = styles;
</ins><span class="cx" style="display: block; padding: 0 10px">                                         } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                return;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         styles = wp.mce.views.sandboxStyles;
</ins><span class="cx" style="display: block; padding: 0 10px">                                         }
</span><span class="cx" style="display: block; padding: 0 10px">                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( this.error.message ) {
-                                       if ( ( this.error.type === 'not-embeddable' && this.type === 'embed' ) || this.error.type === 'not-ssl' ||
-                                               this.error.type === 'no-items' ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         // Seems Firefox needs a bit of time to insert/set the view nodes,
+                               // or the iframe will fail especially when switching Text => Visual.
+                               setTimeout( function() {
+                                       iframe = dom.add( content, 'iframe', {
+                                               /* jshint scripturl: true */
+                                               src: tinymce.Env.ie ? 'javascript:""' : '',
+                                               frameBorder: '0',
+                                               allowTransparency: 'true',
+                                               scrolling: 'no',
+                                               'class': 'wpview-sandbox',
+                                               style: {
+                                                       width: '100%',
+                                                       display: 'block'
+                                               }
+                                       } );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                this.setError( this.error.message, 'admin-media' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 dom.add( content, 'div', { 'class': 'wpview-overlay' } );
+
+                                       iframeDoc = iframe.contentWindow.document;
+
+                                       iframeDoc.open();
+
+                                       iframeDoc.write(
+                                               '<!DOCTYPE html>' +
+                                               '<html>' +
+                                                       '<head>' +
+                                                               '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' +
+                                                               head +
+                                                               styles +
+                                                               '<style>' +
+                                                                       'html {' +
+                                                                               'background: transparent;' +
+                                                                               'padding: 0;' +
+                                                                               'margin: 0;' +
+                                                                       '}' +
+                                                                       'body#wpview-iframe-sandbox {' +
+                                                                               'background: transparent;' +
+                                                                               'padding: 1px 0 !important;' +
+                                                                               'margin: -1px 0 0 !important;' +
+                                                                       '}' +
+                                                                       'body#wpview-iframe-sandbox:before,' +
+                                                                       'body#wpview-iframe-sandbox:after {' +
+                                                                               'display: none;' +
+                                                                               'content: "";' +
+                                                                       '}' +
+                                                               '</style>' +
+                                                       '</head>' +
+                                                       '<body id="wpview-iframe-sandbox" class="' + bodyClasses + '">' +
+                                                               body +
+                                                       '</body>' +
+                                               '</html>'
+                                       );
+
+                                       iframeDoc.close();
+
+                                       resize = function() {
+                                               var $iframe, iframeDocHeight;
+
+                                               // Make sure the iframe still exists.
+                                               if ( iframe.contentWindow ) {
+                                                       $iframe = $( iframe );
+                                                       iframeDocHeight = $( iframeDoc.body ).height();
+
+                                                       if ( $iframe.height() !== iframeDocHeight ) {
+                                                               $iframe.height( iframeDocHeight );
+                                                               editor.nodeChanged();
+                                                       }
+                                               }
+                                       };
+
+                                       if ( MutationObserver ) {
+                                               new MutationObserver( _.debounce( function() {
+                                                       resize();
+                                               }, 100 ) )
+                                               .observe( iframeDoc.body, {
+                                                       attributes: true,
+                                                       childList: true,
+                                                       subtree: true
+                                               } );
</ins><span class="cx" style="display: block; padding: 0 10px">                                         } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                this.setContent( '<p>' + this.original + '</p>', 'replace' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         for ( i = 1; i < 6; i++ ) {
+                                                       setTimeout( resize, i * 700 );
+                                               }
</ins><span class="cx" style="display: block; padding: 0 10px">                                         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                } else if ( this.error.statusText ) {
-                                       this.setError( this.error.statusText, 'admin-media' );
-                               } else if ( this.original ) {
-                                       this.setContent( '<p>' + this.original + '</p>', 'replace' );
-                               }
-                       },
</del><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        stopPlayers: function( remove ) {
-                               var rem = remove === 'remove';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 if ( importStyles ) {
+                                               editor.on( 'wp-body-class-change', function() {
+                                                       iframeDoc.body.className = editor.getBody().className;
+                                               } );
+                                       }
+                               }, 50 );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                this.getNodes( function( editor, node, content ) {
-                                       var p, win,
-                                               iframe = $( 'iframe.wpview-sandbox', content ).get(0);
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         callback && callback.apply( this, arguments );
+                       }, rendered );
+               },
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        if ( iframe && ( win = iframe.contentWindow ) && win.mejs ) {
-                                               // Sometimes ME.js may show a "Download File" placeholder and player.remove() doesn't exist there.
-                                               try {
-                                                       for ( p in win.mejs.players ) {
-                                                               win.mejs.players[p].pause();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Sets a loader for all view nodes tied to this view instance.
+                */
+               setLoader: function() {
+                       this.setContent(
+                               '<div class="loading-placeholder">' +
+                                       '<div class="dashicons dashicons-admin-media"></div>' +
+                                       '<div class="wpview-loading"><ins></ins></div>' +
+                               '</div>'
+                       );
+               },
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                                if ( rem ) {
-                                                                       win.mejs.players[p].remove();
-                                                               }
-                                                       }
-                                               } catch( er ) {}
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         /**
+                * Sets an error for all view nodes tied to this view instance.
+                *
+                * @param {String} message  The error message to set.
+                * @param {String} dashicon A dashicon ID (optional). {@link https://developer.wordpress.org/resource/dashicons/}
+                */
+               setError: function( message, dashicon ) {
+                       this.setContent(
+                               '<div class="wpview-error">' +
+                                       '<div class="dashicons dashicons-' + ( dashicon || 'no' ) + '"></div>' +
+                                       '<p>' + message + '</p>' +
+                               '</div>'
+                       );
+               },
+
+               /**
+                * Tries to find a text match in a given string.
+                *
+                * @param {String} content The string to scan.
+                *
+                * @return {Object}
+                */
+               match: function( content ) {
+                       var match = wp.shortcode.next( this.type, content );
+
+                       if ( match ) {
+                               return {
+                                       index: match.index,
+                                       content: match.content,
+                                       options: {
+                                               shortcode: match.shortcode
</ins><span class="cx" style="display: block; padding: 0 10px">                                         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                });
-                       },
-
-                       unbind: function() {
-                               this.stopPlayers( 'remove' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         };
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><span class="cx" style="display: block; padding: 0 10px">                },
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * Called when a TinyMCE view is clicked for editing.
-                * - Parses the shortcode out of the element's data attribute
-                * - Calls the `edit` method on the shortcode model
-                * - Launches the model window
-                * - Bind's an `update` callback which updates the element's data attribute
-                *   re-renders the view
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * Update the text of a given view node.
</ins><span class="cx" style="display: block; padding: 0 10px">                  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                 * @param {HTMLElement} node
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+          * @param {String}         text   The new text.
+                * @param {tinymce.Editor} editor The TinyMCE editor instance the view node is in.
+                * @param {HTMLElement}    node   The view node to update.
</ins><span class="cx" style="display: block; padding: 0 10px">                  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                edit: function( node ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         update: function( text, editor, node ) {
+                       $( node ).data( 'rendered', false );
+                       editor.dom.setAttrib( node, 'data-wpview-text', encodeURIComponent( text ) );
+                       wp.mce.views.createInstance( this.type, text, this.match( text ).options ).render();
+               }
+       } );
+} )( window, window.wp, window.jQuery );
+
+/*
+ * The WordPress core TinyMCE views.
+ * Views for the gallery, audio, video, playlist and embed shortcodes,
+ * and a view for embeddable URLs.
+ */
+( function( window, views, $ ) {
+       var postID = $( '#post_ID' ).val() || 0,
+               media, gallery, av, embed;
+
+       media = {
+               state: [],
+
+               edit: function( text, update ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         var media = wp.media[ this.type ],
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                self = this,
-                               frame, data, callback;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         frame = media.edit( text );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $( document ).trigger( 'media:edit' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 this.stopPlayers && this.stopPlayers();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        data = window.decodeURIComponent( $( node ).attr('data-wpview-text') );
-                       frame = media.edit( data );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 _.each( this.state, function( state ) {
+                               frame.state( state ).on( 'update', function( selection ) {
+                                       update( media.shortcode( selection ).string() );
+                               } );
+                       } );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         frame.on( 'close', function() {
</span><span class="cx" style="display: block; padding: 0 10px">                                frame.detach();
</span><span class="cx" style="display: block; padding: 0 10px">                        } );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                }
+       };
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        callback = function( selection ) {
-                               var shortcode = wp.media[ self.type ].shortcode( selection ).string();
-                               $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) );
-                               wp.mce.views.refreshView( self, shortcode );
-                               frame.detach();
-                       };
-                       if ( _.isArray( self.state ) ) {
-                               _.each( self.state, function (state) {
-                                       frame.state( state ).on( 'update', callback );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ gallery = _.extend( {}, media, {
+               state: [ 'gallery-edit' ],
+               template: wp.media.template( 'editor-gallery' ),
+
+               initialize: function() {
+                       var attachments = wp.media.gallery.attachments( this.shortcode, postID ),
+                               attrs = this.shortcode.attrs.named,
+                               self = this;
+
+                       attachments.more()
+                       .done( function() {
+                               attachments = attachments.toJSON();
+
+                               _.each( attachments, function( attachment ) {
+                                       if ( attachment.sizes ) {
+                                               if ( attrs.size && attachment.sizes[ attrs.size ] ) {
+                                                       attachment.thumbnail = attachment.sizes[ attrs.size ];
+                                               } else if ( attachment.sizes.thumbnail ) {
+                                                       attachment.thumbnail = attachment.sizes.thumbnail;
+                                               } else if ( attachment.sizes.full ) {
+                                                       attachment.thumbnail = attachment.sizes.full;
+                                               }
+                                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                                 } );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        } else {
-                               frame.state( self.state ).on( 'update', callback );
-                       }
-                       frame.open();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                               self.content = self.template( {
+                                       attachments: attachments,
+                                       columns: attrs.columns ? parseInt( attrs.columns, 10 ) : wp.media.galleryDefaults.columns
+                               } );
+
+                               self.render();
+                       } )
+                       .fail( function( jqXHR, textStatus ) {
+                               self.setError( textStatus );
+                       } );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        };
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        /**
-        * TinyMCE handler for the video shortcode
-        *
-        * @mixes wp.mce.av
-        */
-       wp.mce.views.register( 'video', _.extend( {}, wp.mce.av, {
-               state: 'video-details'
-       } ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ av = _.extend( {}, media, {
+               action: 'parse-media-shortcode',
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        /**
-        * TinyMCE handler for the audio shortcode
-        *
-        * @mixes wp.mce.av
-        */
-       wp.mce.views.register( 'audio', _.extend( {}, wp.mce.av, {
-               state: 'audio-details'
-       } ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         initialize: function() {
+                       var self = this;
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        /**
-        * TinyMCE handler for the playlist shortcode
-        *
-        * @mixes wp.mce.av
-        */
-       wp.mce.views.register( 'playlist', _.extend( {}, wp.mce.av, {
-               state: [ 'playlist-edit', 'video-playlist-edit' ]
-       } ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( this.url ) {
+                               this.loader = false;
+                               this.shortcode = wp.media.embed.shortcode( {
+                                       url: this.url
+                               } );
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        /**
-        * TinyMCE handler for the embed shortcode
-        */
-       wp.mce.embedMixin = {
-               View: _.extend( {}, wp.mce.av.View, {
-                       overlay: true,
-                       action: 'parse-embed',
-                       initialize: function( options ) {
-                               this.content = options.content;
-                               this.original = options.url || options.shortcode.string();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 wp.ajax.send( this.action, {
+                               data: {
+                                       post_ID: postID,
+                                       type: this.shortcode.tag,
+                                       shortcode: this.shortcode.string()
+                               }
+                       } )
+                       .done( function( response ) {
+                               self.content = response;
+                               self.render();
+                       } )
+                       .fail( function( response ) {
+                               if ( self.type === 'embedURL' ) {
+                                       self.removeMarkers();
+                               } else {
+                                       self.setError( response.message || response.statusText, 'admin-media' );
+                               }
+                       } );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                if ( options.url ) {
-                                       this.shortcode = media.embed.shortcode( {
-                                               url: options.url
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 this.getEditors( function( editor ) {
+                               editor.on( 'wpview-selected', function() {
+                                       self.stopPlayers();
+                               } );
+                       } );
+               },
+
+               stopPlayers: function( remove ) {
+                       this.getNodes( function( editor, node, content ) {
+                               var win = $( 'iframe.wpview-sandbox', content ).get( 0 );
+
+                               if ( win && ( win = win.contentWindow ) && win.mejs ) {
+                                       _.each( win.mejs.players, function( player ) {
+                                               try {
+                                                       player[ remove ? 'remove' : 'pause' ]();
+                                               } catch ( e ) {}
</ins><span class="cx" style="display: block; padding: 0 10px">                                         } );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                } else {
-                                       this.shortcode = options.shortcode;
</del><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        } );
+               }
+       } );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                _.bindAll( this, 'setIframes', 'setNodes', 'fetch' );
-                               $( this ).on( 'ready', this.setNodes );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ embed = _.extend( {}, av, {
+               action: 'parse-embed',
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                this.fetch();
-                       }
-               } ),
-               edit: function( node ) {
-                       var embed = media.embed,
-                               self = this,
-                               frame,
-                               data,
-                               isURL = 'embedURL' === this.type;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         edit: function( text, update ) {
+                       var media = wp.media.embed,
+                               isURL = 'embedURL' === this.type,
+                               frame = media.edit( text, isURL );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        $( document ).trigger( 'media:edit' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 this.stopPlayers();
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        data = window.decodeURIComponent( $( node ).attr('data-wpview-text') );
-                       frame = embed.edit( data, isURL );
-                       frame.on( 'close', function() {
-                               frame.detach();
-                       } );
-                       frame.state( 'embed' ).props.on( 'change:url', function (model, url) {
-                               if ( ! url ) {
-                                       return;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 frame.state( 'embed' ).props.on( 'change:url', function( model, url ) {
+                               if ( url ) {
+                                       frame.state( 'embed' ).metadata = model.toJSON();
</ins><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                frame.state( 'embed' ).metadata = model.toJSON();
</del><span class="cx" style="display: block; padding: 0 10px">                         } );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                         frame.state( 'embed' ).on( 'select', function() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                var shortcode;
-
</del><span class="cx" style="display: block; padding: 0 10px">                                 if ( isURL ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        shortcode = frame.state( 'embed' ).metadata.url;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 update( frame.state( 'embed' ).metadata.url );
</ins><span class="cx" style="display: block; padding: 0 10px">                                 } else {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        shortcode = embed.shortcode( frame.state( 'embed' ).metadata ).string();
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 update( media.shortcode( frame.state( 'embed' ).metadata ).string() );
</ins><span class="cx" style="display: block; padding: 0 10px">                                 }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) );
-                               wp.mce.views.refreshView( self, shortcode );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 } );
+
+                       frame.on( 'close', function() {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 frame.detach();
</span><span class="cx" style="display: block; padding: 0 10px">                        } );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                         frame.open();
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        };
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        wp.mce.views.register( 'embed', _.extend( {}, wp.mce.embedMixin ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ views.register( 'gallery', _.extend( {}, gallery ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        wp.mce.views.register( 'embedURL', _.extend( {}, wp.mce.embedMixin, {
-               toView: function( content ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ views.register( 'audio', _.extend( {}, av, {
+               state: [ 'audio-details' ]
+       } ) );
+
+       views.register( 'video', _.extend( {}, av, {
+               state: [ 'video-details' ]
+       } ) );
+
+       views.register( 'playlist', _.extend( {}, av, {
+               state: [ 'playlist-edit', 'video-playlist-edit' ]
+       } ) );
+
+       views.register( 'embed', _.extend( {}, embed ) );
+
+       views.register( 'embedURL', _.extend( {}, embed, {
+               match: function( content ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         var re = /(^|<p>)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi,
</span><span class="cx" style="display: block; padding: 0 10px">                                match = re.exec( tinymce.trim( content ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( ! match ) {
-                               return;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( match ) {
+                               return {
+                                       index: match.index + match[1].length,
+                                       content: match[2],
+                                       options: {
+                                               url: match[2]
+                                       }
+                               };
</ins><span class="cx" style="display: block; padding: 0 10px">                         }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-                       return {
-                               index: match.index + match[1].length,
-                               content: match[2],
-                               options: {
-                                       url: match[2]
-                               }
-                       };
</del><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        } ) );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
-}(jQuery));
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+} )( window, window.wp.mce.views, window.jQuery );
</ins></span></pre></div>
<a id="trunksrcwpincludesjstinymcepluginswpviewpluginjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/js/tinymce/plugins/wpview/plugin.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/js/tinymce/plugins/wpview/plugin.js 2015-02-25 20:15:46 UTC (rev 31545)
+++ trunk/src/wp-includes/js/tinymce/plugins/wpview/plugin.js   2015-02-25 23:12:08 UTC (rev 31546)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -237,7 +237,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                event.content = wp.mce.views.toViews( event.content );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         event.content = wp.mce.views.setMarkers( event.content );
</ins><span class="cx" style="display: block; padding: 0 10px">         });
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // When the editor's content has been updated and the DOM has been
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -341,7 +341,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                        editor.focus();
</span><span class="cx" style="display: block; padding: 0 10px">                                                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                                wp.mce.views.edit( view );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                         wp.mce.views.edit( editor, view );
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 return false;
</span><span class="cx" style="display: block; padding: 0 10px">                                        } else if ( editor.dom.hasClass( event.target, 'remove' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                                removeView( view );
</span></span></pre></div>
<a id="trunksrcwpincludesmediatemplatephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/media-template.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/media-template.php  2015-02-25 20:15:46 UTC (rev 31545)
+++ trunk/src/wp-includes/media-template.php    2015-02-25 23:12:08 UTC (rev 31546)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1205,7 +1205,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        </script>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        <script type="text/html" id="tmpl-editor-gallery">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                <# if ( data.attachments ) { #>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         <# if ( data.attachments.length ) { #>
</ins><span class="cx" style="display: block; padding: 0 10px">                         <div class="gallery gallery-columns-{{ data.columns }}">
</span><span class="cx" style="display: block; padding: 0 10px">                                <# _.each( data.attachments, function( attachment, index ) { #>
</span><span class="cx" style="display: block; padding: 0 10px">                                        <dl class="gallery-item">
</span></span></pre></div>
<a id="trunksrcwpincludesversionphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/version.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/version.php 2015-02-25 20:15:46 UTC (rev 31545)
+++ trunk/src/wp-includes/version.php   2015-02-25 23:12:08 UTC (rev 31546)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -18,7 +18,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @global string $tinymce_version
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-$tinymce_version = '4107-20141130';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+$tinymce_version = '4107-20150225';
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px">  * Holds the required PHP version
</span></span></pre>
</div>
</div>

</body>
</html>