<!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>[28680] trunk/src/wp-includes/js/mce-view.js: Simplify the creation of MCE views somewhat:</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/28680">28680</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-06-05 17:26:24 +0000 (Thu, 05 Jun 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Simplify the creation of MCE views somewhat:
* Rename the `wp.mce.media` mixin (which was named too ambiguously) to `wp.mce.av`.
* Use the same technique for extending mixins for MCE base classes for views and their base.View property class
* `wp.mce.views.register()` should have default constructor logic if one is not passed.
Props avryl.
See <a href="http://core.trac.wordpress.org/ticket/28458">#28458</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesjsmceviewjs">trunk/src/wp-includes/js/mce-view.js</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesjsmceviewjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/mce-view.js (28679 => 28680)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/mce-view.js 2014-06-05 16:25:01 UTC (rev 28679)
+++ trunk/src/wp-includes/js/mce-view.js 2014-06-05 17:26:24 UTC (rev 28680)
</span><span class="lines">@@ -22,11 +22,13 @@
</span><span class="cx"> *
</span><span class="cx"> * A Backbone-like View constructor intended for use when rendering a TinyMCE View. The main difference is
</span><span class="cx"> * that the TinyMCE View is not tied to a particular DOM node.
</span><ins>+ *
+ * @param {Object} [options={}]
</ins><span class="cx"> */
</span><span class="cx"> wp.mce.View = function( options ) {
</span><del>- options || (options = {});
- _.extend(this, _.pick(options, viewOptions));
- this.initialize.apply(this, arguments);
</del><ins>+ options = options || {};
+ _.extend( this, _.pick( options, viewOptions ) );
+ this.initialize.apply( this, arguments );
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> _.extend( wp.mce.View.prototype, {
</span><span class="lines">@@ -36,15 +38,14 @@
</span><span class="cx"> var html = this.getHtml();
</span><span class="cx"> // Search all tinymce editor instances and update the placeholders
</span><span class="cx"> _.each( tinymce.editors, function( editor ) {
</span><del>- var doc, self = this;
</del><ins>+ var self = this;
</ins><span class="cx"> if ( editor.plugins.wpview ) {
</span><del>- doc = editor.getDoc();
- $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) {
- var node = $( elem );
</del><ins>+ $( editor.getDoc() ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each( function ( i, element ) {
+ var node = $( element );
</ins><span class="cx"> // The <ins> is used to mark the end of the wrapper div. Needed when comparing
</span><span class="cx"> // the content as string for preventing extra undo levels.
</span><span class="cx"> node.html( html ).append( '<ins data-wpview-end="1"></ins>' );
</span><del>- $( self ).trigger( 'ready', elem );
</del><ins>+ $( self ).trigger( 'ready', element );
</ins><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx"> }, this );
</span><span class="lines">@@ -74,6 +75,29 @@
</span><span class="cx"> *
</span><span class="cx"> */
</span><span class="cx"> register: function( type, constructor ) {
</span><ins>+ 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 );
+
</ins><span class="cx"> views[ type ] = constructor;
</span><span class="cx"> },
</span><span class="cx">
</span><span class="lines">@@ -81,6 +105,8 @@
</span><span class="cx"> * wp.mce.views.get( id )
</span><span class="cx"> *
</span><span class="cx"> * Returns a TinyMCE view constructor.
</span><ins>+ *
+ * @param type
</ins><span class="cx"> */
</span><span class="cx"> get: function( type ) {
</span><span class="cx"> return views[ type ];
</span><span class="lines">@@ -90,6 +116,8 @@
</span><span class="cx"> * wp.mce.views.unregister( type )
</span><span class="cx"> *
</span><span class="cx"> * Unregisters a TinyMCE view.
</span><ins>+ *
+ * @param type
</ins><span class="cx"> */
</span><span class="cx"> unregister: function( type ) {
</span><span class="cx"> delete views[ type ];
</span><span class="lines">@@ -112,6 +140,7 @@
</span><span class="cx"> * matches with wrapper elements, and creates a new instance for
</span><span class="cx"> * every match, which triggers the related data to be fetched.
</span><span class="cx"> *
</span><ins>+ * @param content
</ins><span class="cx"> */
</span><span class="cx"> toViews: function( content ) {
</span><span class="cx"> var pieces = [ { content: content } ],
</span><span class="lines">@@ -252,27 +281,10 @@
</span><span class="cx"> }
</span><span class="cx"> };
</span><span class="cx">
</span><del>- wp.mce.gallery = {
- shortcode: 'gallery',
- toView: function( content ) {
- var match = wp.shortcode.next( this.shortcode, content );
</del><ins>+ wp.mce.views.register( 'gallery', {
+ View: {
+ template: media.template( 'editor-gallery' ),
</ins><span class="cx">
</span><del>- if ( ! match ) {
- return;
- }
-
- return {
- index: match.index,
- content: match.content,
- options: {
- shortcode: match.shortcode
- }
- };
- },
- View: wp.mce.View.extend({
- className: 'editor-gallery',
- template: media.template('editor-gallery'),
-
</del><span class="cx"> // The fallback post ID to use as a parent for galleries that don't
</span><span class="cx"> // specify the `ids` or `include` parameters.
</span><span class="cx"> //
</span><span class="lines">@@ -321,7 +333,7 @@
</span><span class="cx"> return this.template( options );
</span><span class="cx">
</span><span class="cx"> }
</span><del>- }),
</del><ins>+ },
</ins><span class="cx">
</span><span class="cx"> edit: function( node ) {
</span><span class="cx"> var gallery = wp.media.gallery,
</span><span class="lines">@@ -338,24 +350,91 @@
</span><span class="cx"> frame.detach();
</span><span class="cx"> });
</span><span class="cx"> }
</span><ins>+ } );
</ins><span class="cx">
</span><del>- };
- wp.mce.views.register( 'gallery', wp.mce.gallery );
-
</del><span class="cx"> /**
</span><del>- * Tiny MCE Views for Audio / Video
</del><ins>+ * These are base methods that are shared by the audio and video shortcode's MCE controller.
</ins><span class="cx"> *
</span><del>- */
-
- /**
- * These are base methods that are shared by each shortcode's MCE controller
- *
</del><span class="cx"> * @mixin
</span><span class="cx"> */
</span><del>- wp.mce.media = {
</del><ins>+ wp.mce.av = {
</ins><span class="cx"> loaded: false,
</span><del>- toView: wp.mce.gallery.toView,
</del><span class="cx">
</span><ins>+ View: _.extend( {}, wp.media.mixin, {
+ initialize: function( options ) {
+ this.players = [];
+ this.shortcode = options.shortcode;
+ _.bindAll( this, 'setPlayer', 'pausePlayers' );
+ $( this ).on( 'ready', this.setPlayer );
+ $( 'body' ).on( 'click', '.wp-switch-editor', this.pausePlayers );
+ $( document ).on( 'media:edit', this.pausePlayers );
+ },
+
+ /**
+ * Creates the player instance for the current node
+ *
+ * @global MediaElementPlayer
+ *
+ * @param {Event} e
+ * @param {HTMLElement} node
+ */
+ setPlayer: function(e, node) {
+ // if the ready event fires on an empty node
+ if ( ! node ) {
+ return;
+ }
+
+ var self = this,
+ media,
+ firefox = this.ua.is( 'ff' ),
+ className = '.wp-' + this.shortcode.tag + '-shortcode';
+
+ media = $( node ).find( className );
+
+ if ( ! this.isCompatible( media ) ) {
+ media.closest( '.wpview-wrap' ).addClass( 'wont-play' );
+ if ( ! media.parent().hasClass( 'wpview-wrap' ) ) {
+ media.parent().replaceWith( media );
+ }
+ media.replaceWith( '<p>' + media.find( 'source' ).eq(0).prop( 'src' ) + '</p>' );
+ return;
+ } else {
+ media.closest( '.wpview-wrap' ).removeClass( 'wont-play' );
+ if ( firefox ) {
+ media.prop( 'preload', 'metadata' );
+ } else {
+ media.prop( 'preload', 'none' );
+ }
+ }
+
+ media = wp.media.view.MediaDetails.prepareSrc( media.get(0) );
+
+ setTimeout( function() {
+ wp.mce.av.loaded = true;
+ self.players.push( new MediaElementPlayer( media, self.mejsSettings ) );
+ }, wp.mce.av.loaded ? 10 : 500 );
+ },
+
+ /**
+ * Pass data to the View's Underscore template and return the compiled output
+ *
+ * @returns {string}
+ */
+ getHtml: function() {
+ var attrs = this.shortcode.attrs.named;
+ attrs.content = this.shortcode.content;
+
+ return this.template({ model: _.defaults(
+ attrs,
+ wp.media[ this.shortcode.tag ].defaults )
+ });
+ },
+
+ unbind: function() {
+ this.unsetPlayers();
+ }
+ } ),
+
</ins><span class="cx"> /**
</span><span class="cx"> * Called when a TinyMCE view is clicked for editing.
</span><span class="cx"> * - Parses the shortcode out of the element's data attribute
</span><span class="lines">@@ -397,294 +476,170 @@
</span><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Base View class for audio and video shortcodes
- *
- * @constructor
- * @augments wp.mce.View
- * @mixes wp.media.mixin
- */
- wp.mce.media.View = wp.mce.View.extend({
- initialize: function( options ) {
- this.players = [];
- this.shortcode = options.shortcode;
- _.bindAll( this, 'setPlayer', 'pausePlayers' );
- $( this ).on( 'ready', this.setPlayer );
- $( 'body' ).on( 'click', '.wp-switch-editor', this.pausePlayers );
- $( document ).on( 'media:edit', this.pausePlayers );
- },
-
- /**
- * Creates the player instance for the current node
- *
- * @global MediaElementPlayer
- * @global _wpmejsSettings
- *
- * @param {Event} e
- * @param {HTMLElement} node
- */
- setPlayer: function(e, node) {
- // if the ready event fires on an empty node
- if ( ! node ) {
- return;
- }
-
- var self = this,
- media,
- firefox = this.ua.is( 'ff' ),
- className = '.wp-' + this.shortcode.tag + '-shortcode';
-
- media = $( node ).find( className );
-
- if ( ! this.isCompatible( media ) ) {
- media.closest( '.wpview-wrap' ).addClass( 'wont-play' );
- if ( ! media.parent().hasClass( 'wpview-wrap' ) ) {
- media.parent().replaceWith( media );
- }
- media.replaceWith( '<p>' + media.find( 'source' ).eq(0).prop( 'src' ) + '</p>' );
- return;
- } else {
- media.closest( '.wpview-wrap' ).removeClass( 'wont-play' );
- if ( firefox ) {
- media.prop( 'preload', 'metadata' );
- } else {
- media.prop( 'preload', 'none' );
- }
- }
-
- media = wp.media.view.MediaDetails.prepareSrc( media.get(0) );
-
- setTimeout( function() {
- wp.mce.media.loaded = true;
- self.players.push( new MediaElementPlayer( media, self.mejsSettings ) );
- }, wp.mce.media.loaded ? 10 : 500 );
- },
-
- /**
- * Pass data to the View's Underscore template and return the compiled output
- *
- * @returns {string}
- */
- getHtml: function() {
- var attrs = this.shortcode.attrs.named;
- attrs.content = this.shortcode.content;
-
- return this.template({ model: _.defaults(
- attrs,
- wp.media[ this.shortcode.tag ].defaults )
- });
- },
-
- unbind: function() {
- this.unsetPlayers();
- }
- });
- _.extend( wp.mce.media.View.prototype, wp.media.mixin );
-
- /**
</del><span class="cx"> * TinyMCE handler for the video shortcode
</span><span class="cx"> *
</span><del>- * @mixes wp.mce.media
</del><ins>+ * @mixes wp.mce.av
</ins><span class="cx"> */
</span><del>- wp.mce.video = _.extend( {}, wp.mce.media, {
</del><ins>+ wp.mce.views.register( 'video', _.extend( {}, wp.mce.av, {
</ins><span class="cx"> shortcode: 'video',
</span><span class="cx"> state: 'video-details',
</span><del>- View: wp.mce.media.View.extend({
- className: 'editor-video',
- template: media.template('editor-video')
- })
- } );
- wp.mce.views.register( 'video', wp.mce.video );
</del><ins>+ View: _.extend( {}, wp.mce.av.View, {
+ template: media.template( 'editor-video' )
+ } )
+ } ) );
</ins><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * TinyMCE handler for the audio shortcode
</span><span class="cx"> *
</span><del>- * @mixes wp.mce.media
</del><ins>+ * @mixes wp.mce.av
</ins><span class="cx"> */
</span><del>- wp.mce.audio = _.extend( {}, wp.mce.media, {
</del><ins>+ wp.mce.views.register( 'audio', _.extend( {}, wp.mce.av, {
</ins><span class="cx"> shortcode: 'audio',
</span><span class="cx"> state: 'audio-details',
</span><del>- View: wp.mce.media.View.extend({
- className: 'editor-audio',
- template: media.template('editor-audio')
- })
- } );
- wp.mce.views.register( 'audio', wp.mce.audio );
</del><ins>+ View: _.extend( {}, wp.mce.av.View, {
+ template: media.template( 'editor-audio' )
+ } )
+ } ) );
</ins><span class="cx">
</span><span class="cx"> /**
</span><del>- * Base View class for playlist shortcodes
</del><ins>+ * TinyMCE handler for the playlist shortcode
</ins><span class="cx"> *
</span><del>- * @constructor
- * @augments wp.mce.View
- * @mixes wp.media.mixin
</del><ins>+ * @mixes wp.mce.av
</ins><span class="cx"> */
</span><del>- wp.mce.media.PlaylistView = wp.mce.View.extend({
- className: 'editor-playlist',
- template: media.template('editor-playlist'),
</del><ins>+ wp.mce.views.register( 'playlist', _.extend( {}, wp.mce.av, {
+ shortcode: 'playlist',
+ state: ['playlist-edit', 'video-playlist-edit'],
+ View: _.extend( {}, wp.media.mixin, {
+ template: media.template( 'editor-playlist' ),
</ins><span class="cx">
</span><del>- initialize: function( options ) {
- this.players = [];
- this.data = {};
- this.attachments = [];
- this.shortcode = options.shortcode;
</del><ins>+ initialize: function( options ) {
+ this.players = [];
+ this.data = {};
+ this.attachments = [];
+ this.shortcode = options.shortcode;
</ins><span class="cx">
</span><del>- $( 'body' ).on( 'click', '.wp-switch-editor', this.pausePlayers );
- $( document ).on( 'media:edit', this.pausePlayers );
</del><ins>+ $( 'body' ).on( 'click', '.wp-switch-editor', this.pausePlayers );
+ $( document ).on( 'media:edit', this.pausePlayers );
</ins><span class="cx">
</span><del>- this.fetch();
- },
</del><ins>+ this.fetch();
</ins><span class="cx">
</span><del>- /**
- * Asynchronously fetch the shortcode's attachments
- */
- fetch: function() {
- this.attachments = wp.media.playlist.attachments( this.shortcode );
- this.dfd = this.attachments.more().done( _.bind( this.render, this ) );
- },
</del><ins>+ $( this ).on( 'ready', this.setPlaylist );
+ },
</ins><span class="cx">
</span><del>- /**
- * Get the HTML for the view (which also set's the data), replace the
- * current HTML, and then invoke the WPPlaylistView instance to render
- * the playlist in the editor
- *
- * @global WPPlaylistView
- * @global tinymce.editors
- */
- render: function() {
- var html = this.getHtml(), self = this;
</del><ins>+ /**
+ * Asynchronously fetch the shortcode's attachments
+ */
+ fetch: function() {
+ this.attachments = wp.media.playlist.attachments( this.shortcode );
+ this.dfd = this.attachments.more().done( _.bind( this.render, this ) );
+ },
</ins><span class="cx">
</span><del>- _.each( tinymce.editors, function( editor ) {
- var doc;
- if ( editor.plugins.wpview ) {
- doc = editor.getDoc();
- $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) {
- var node = $( elem );
</del><ins>+ setPlaylist: function( event, element ) {
+ if ( ! this.data.tracks ) {
+ return;
+ }
</ins><span class="cx">
</span><del>- // The <ins> is used to mark the end of the wrapper div. Needed when comparing
- // the content as string for preventing extra undo levels.
- node.html( html ).append( '<ins data-wpview-end="1"></ins>' );
</del><ins>+ this.players.push( new WPPlaylistView( {
+ el: $( element ).find( '.wp-playlist' ).get( 0 ),
+ metadata: this.data
+ } ).player );
+ },
</ins><span class="cx">
</span><del>- if ( ! self.data.tracks ) {
- return;
- }
</del><ins>+ /**
+ * Set the data that will be used to compile the Underscore template,
+ * compile the template, and then return it.
+ *
+ * @returns {string}
+ */
+ getHtml: function() {
+ var data = this.shortcode.attrs.named,
+ model = wp.media.playlist,
+ options,
+ attachments,
+ tracks = [];
</ins><span class="cx">
</span><del>- self.players.push( new WPPlaylistView({
- el: $( elem ).find( '.wp-playlist' ).get(0),
- metadata: self.data
- }).player );
- });
</del><ins>+ // Don't render errors while still fetching attachments
+ if ( this.dfd && 'pending' === this.dfd.state() && ! this.attachments.length ) {
+ return;
</ins><span class="cx"> }
</span><del>- }, this );
- },
</del><span class="cx">
</span><del>- /**
- * Set the data that will be used to compile the Underscore template,
- * compile the template, and then return it.
- *
- * @returns {string}
- */
- getHtml: function() {
- var data = this.shortcode.attrs.named,
- model = wp.media.playlist,
- options,
- attachments,
- tracks = [];
</del><ins>+ _.each( model.defaults, function( value, key ) {
+ data[ key ] = model.coerce( data, key );
+ });
</ins><span class="cx">
</span><del>- // Don't render errors while still fetching attachments
- if ( this.dfd && 'pending' === this.dfd.state() && ! this.attachments.length ) {
- return;
- }
</del><ins>+ options = {
+ type: data.type,
+ style: data.style,
+ tracklist: data.tracklist,
+ tracknumbers: data.tracknumbers,
+ images: data.images,
+ artists: data.artists
+ };
</ins><span class="cx">
</span><del>- _.each( model.defaults, function( value, key ) {
- data[ key ] = model.coerce( data, key );
- });
</del><ins>+ if ( ! this.attachments.length ) {
+ return this.template( options );
+ }
</ins><span class="cx">
</span><del>- options = {
- type: data.type,
- style: data.style,
- tracklist: data.tracklist,
- tracknumbers: data.tracknumbers,
- images: data.images,
- artists: data.artists
- };
</del><ins>+ attachments = this.attachments.toJSON();
</ins><span class="cx">
</span><del>- if ( ! this.attachments.length ) {
- return this.template( options );
- }
</del><ins>+ _.each( attachments, function( attachment ) {
+ var size = {}, resize = {}, track = {
+ src : attachment.url,
+ type : attachment.mime,
+ title : attachment.title,
+ caption : attachment.caption,
+ description : attachment.description,
+ meta : attachment.meta
+ };
</ins><span class="cx">
</span><del>- attachments = this.attachments.toJSON();
-
- _.each( attachments, function( attachment ) {
- var size = {}, resize = {}, track = {
- src : attachment.url,
- type : attachment.mime,
- title : attachment.title,
- caption : attachment.caption,
- description : attachment.description,
- meta : attachment.meta
- };
-
- if ( 'video' === data.type ) {
- size.width = attachment.width;
- size.height = attachment.height;
- if ( media.view.settings.contentWidth ) {
- resize.width = media.view.settings.contentWidth - 22;
- resize.height = Math.ceil( ( size.height * resize.width ) / size.width );
- if ( ! options.width ) {
- options.width = resize.width;
- options.height = resize.height;
</del><ins>+ if ( 'video' === data.type ) {
+ size.width = attachment.width;
+ size.height = attachment.height;
+ if ( media.view.settings.contentWidth ) {
+ resize.width = media.view.settings.contentWidth - 22;
+ resize.height = Math.ceil( ( size.height * resize.width ) / size.width );
+ if ( ! options.width ) {
+ options.width = resize.width;
+ options.height = resize.height;
+ }
+ } else {
+ if ( ! options.width ) {
+ options.width = attachment.width;
+ options.height = attachment.height;
+ }
</ins><span class="cx"> }
</span><ins>+ track.dimensions = {
+ original : size,
+ resized : _.isEmpty( resize ) ? size : resize
+ };
</ins><span class="cx"> } else {
</span><del>- if ( ! options.width ) {
- options.width = attachment.width;
- options.height = attachment.height;
- }
</del><ins>+ options.width = 400;
</ins><span class="cx"> }
</span><del>- track.dimensions = {
- original : size,
- resized : _.isEmpty( resize ) ? size : resize
- };
- } else {
- options.width = 400;
- }
</del><span class="cx">
</span><del>- track.image = attachment.image;
- track.thumb = attachment.thumb;
</del><ins>+ track.image = attachment.image;
+ track.thumb = attachment.thumb;
</ins><span class="cx">
</span><del>- tracks.push( track );
- } );
</del><ins>+ tracks.push( track );
+ } );
</ins><span class="cx">
</span><del>- options.tracks = tracks;
- this.data = options;
</del><ins>+ options.tracks = tracks;
+ this.data = options;
</ins><span class="cx">
</span><del>- return this.template( options );
- },
</del><ins>+ return this.template( options );
+ },
</ins><span class="cx">
</span><del>- unbind: function() {
- this.unsetPlayers();
- }
- });
- _.extend( wp.mce.media.PlaylistView.prototype, wp.media.mixin );
</del><ins>+ unbind: function() {
+ this.unsetPlayers();
+ }
+ } )
+ } ) );
</ins><span class="cx">
</span><span class="cx"> /**
</span><del>- * TinyMCE handler for the playlist shortcode
- *
- * @mixes wp.mce.media
- */
- wp.mce.playlist = _.extend( {}, wp.mce.media, {
- shortcode: 'playlist',
- state: ['playlist-edit', 'video-playlist-edit'],
- View: wp.mce.media.PlaylistView
- } );
- wp.mce.views.register( 'playlist', wp.mce.playlist );
-
- /**
</del><span class="cx"> * TinyMCE handler for the embed shortcode
</span><span class="cx"> */
</span><del>- wp.mce.embed = {
</del><ins>+ wp.mce.views.register( 'embed', {
</ins><span class="cx"> shortcode: 'embed',
</span><del>- toView: wp.mce.gallery.toView,
- View: wp.mce.View.extend( {
- className: 'editor-embed',
</del><ins>+ View: _.extend( {}, wp.media.mixin, {
</ins><span class="cx"> template: media.template( 'editor-embed' ),
</span><span class="cx"> initialize: function( options ) {
</span><span class="cx"> this.players = [];
</span><span class="lines">@@ -737,10 +692,6 @@
</span><span class="cx"> }
</span><span class="cx"> } ),
</span><span class="cx"> edit: function() {}
</span><del>- };
</del><ins>+ } );
</ins><span class="cx">
</span><del>- _.extend( wp.mce.embed.View.prototype, wp.media.mixin );
-
- wp.mce.views.register( 'embed', wp.mce.embed );
-
</del><span class="cx"> }(jQuery));
</span></span></pre>
</div>
</div>
</body>
</html>