<!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>[27528] trunk/src/wp-includes: Add MCE Views for audio and video.</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/27528">27528</a></dd>
<dt>Author</dt> <dd>wonderboymusic</dd>
<dt>Date</dt> <dd>2014-03-13 23:09:06 +0000 (Thu, 13 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add MCE Views for audio and video. Please clear your browser cache so that you get the latest TinyMCE stylesheet.
* Move TinyMCE shortcode handling from `wpgallery` plugin to `mce-view.js`
* Force `preload="none"` when rendering media in the editor to ensure fast loading (I realize this sounds illogical)
* Move audio and video tag builder logic in `media-template.php` into PHP funcs that can be reused by any code passing `data.model` to an Underscore template
* Pause all players when moving between editor tabs and when moving from the editor to editing in the media modal.
* Rename `wp.media.audio|video.shortcode()` to the more appropriate `wp.media.audio|video.update()` that now returns a `wp.shortcode` object instead of a string.
* Add necessary MediaElement css files to `$mce_css`
* In `wp.mce.View.render()`, support multiple instances of the same shortcode
* When rendering `wp.mce.View`s, fire a ready event that passes the current MCE View root element as context
See <a href="http://core.trac.wordpress.org/ticket/27389">#27389</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesclasswpeditorphp">trunk/src/wp-includes/class-wp-editor.php</a></li>
<li><a href="#trunksrcwpincludesjsmceviewjs">trunk/src/wp-includes/js/mce-view.js</a></li>
<li><a href="#trunksrcwpincludesjsmediaeditorjs">trunk/src/wp-includes/js/media-editor.js</a></li>
<li><a href="#trunksrcwpincludesjsmediamodelsjs">trunk/src/wp-includes/js/media-models.js</a></li>
<li><a href="#trunksrcwpincludesjsmediaviewsjs">trunk/src/wp-includes/js/media-views.js</a></li>
<li><a href="#trunksrcwpincludesjstinymcepluginswpgallerypluginjs">trunk/src/wp-includes/js/tinymce/plugins/wpgallery/plugin.js</a></li>
<li><a href="#trunksrcwpincludesjstinymceskinswordpresswpcontentcss">trunk/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css</a></li>
<li><a href="#trunksrcwpincludesmediatemplatephp">trunk/src/wp-includes/media-template.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesclasswpeditorphp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/class-wp-editor.php (27527 => 27528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/class-wp-editor.php 2014-03-13 21:50:17 UTC (rev 27527)
+++ trunk/src/wp-includes/class-wp-editor.php 2014-03-13 23:09:06 UTC (rev 27528)
</span><span class="lines">@@ -343,9 +343,16 @@
</span><span class="cx"> $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
</span><span class="cx"> $version = 'ver=' . $GLOBALS['wp_version'];
</span><span class="cx"> $dashicons = includes_url( "css/dashicons$suffix.css?$version" );
</span><ins>+ $mediaelement = includes_url( "js/mediaelement/mediaelementplayer.min.css?$version" );
+ $wpmediaelement = includes_url( "js/mediaelement/wp-mediaelement.css?$version" );
</ins><span class="cx">
</span><span class="cx"> // WordPress default stylesheet and dashicons
</span><del>- $mce_css = array( $dashicons, self::$baseurl . '/skins/wordpress/wp-content.css' );
</del><ins>+ $mce_css = array(
+ $dashicons,
+ $mediaelement,
+ $wpmediaelement,
+ self::$baseurl . '/skins/wordpress/wp-content.css'
+ );
</ins><span class="cx">
</span><span class="cx"> // load editor_style.css if the current theme supports it
</span><span class="cx"> if ( ! empty( $GLOBALS['editor_styles'] ) && is_array( $GLOBALS['editor_styles'] ) ) {
</span></span></pre></div>
<a id="trunksrcwpincludesjsmceviewjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/mce-view.js (27527 => 27528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/mce-view.js 2014-03-13 21:50:17 UTC (rev 27527)
+++ trunk/src/wp-includes/js/mce-view.js 2014-03-13 23:09:06 UTC (rev 27528)
</span><span class="lines">@@ -1,4 +1,4 @@
</span><del>-/* global tinymce */
</del><ins>+/* global tinymce, _wpmejsSettings, MediaElementPlayer */
</ins><span class="cx">
</span><span class="cx"> // Ensure the global `wp` object exists.
</span><span class="cx"> window.wp = window.wp || {};
</span><span class="lines">@@ -31,10 +31,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;
</del><ins>+ var doc, self = this;
</ins><span class="cx"> if ( editor.plugins.wpview ) {
</span><span class="cx"> doc = editor.getDoc();
</span><del>- $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).html( html );
</del><ins>+ $( doc ).find( '[data-wpview-text="' + this.encodedText + '"]' ).each(function (i, elem) {
+ var node = $( elem );
+ node.html( html );
+ $( self ).trigger( 'ready', elem );
+ });
</ins><span class="cx"> }
</span><span class="cx"> }, this );
</span><span class="cx"> }
</span><span class="lines">@@ -178,7 +182,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Refresh views after an update is made
</span><del>- *
</del><ins>+ *
</ins><span class="cx"> * @param view {object} being refreshed
</span><span class="cx"> * @param text {string} textual representation of the view
</span><span class="cx"> */
</span><span class="lines">@@ -204,9 +208,9 @@
</span><span class="cx"> return instances[ encodedText ];
</span><span class="cx"> },
</span><span class="cx">
</span><del>- /**
</del><ins>+ /**
</ins><span class="cx"> * render( scope )
</span><del>- *
</del><ins>+ *
</ins><span class="cx"> * Renders any view instances inside a DOM node `scope`.
</span><span class="cx"> *
</span><span class="cx"> * View instances are detected by the presence of wrapper elements.
</span><span class="lines">@@ -302,4 +306,110 @@
</span><span class="cx">
</span><span class="cx"> };
</span><span class="cx"> wp.mce.views.register( 'gallery', wp.mce.gallery );
</span><ins>+
+ wp.mce.media = {
+ toView: function( content ) {
+ var match = wp.shortcode.next( this.shortcode, content );
+
+ if ( ! match ) {
+ return;
+ }
+
+ return {
+ index: match.index,
+ content: match.content,
+ options: {
+ shortcode: match.shortcode
+ }
+ };
+ },
+
+ edit: function( node ) {
+ var p,
+ media = wp.media[ this.shortcode ],
+ self = this,
+ frame, data;
+
+ for (p in window.mejs.players) {
+ window.mejs.players[p].pause();
+ }
+
+ data = window.decodeURIComponent( $( node ).data('wpview-text') );
+ frame = media.edit( data );
+ frame.on( 'close', function () {
+ frame.detach();
+ } );
+ frame.state( self.shortcode + '-details' ).on( 'update', function( selection ) {
+ var shortcode = wp.media[ self.shortcode ].update( selection ).string();
+ $( node ).attr( 'data-wpview-text', window.encodeURIComponent( shortcode ) );
+ wp.mce.views.refreshView( self, shortcode );
+ frame.detach();
+ } );
+ frame.open();
+ }
+ };
+
+ wp.mce.media.ViewMixin = wp.mce.View.extend({
+ initialize: function( options ) {
+ this.shortcode = options.shortcode;
+ _.bindAll( this, 'setPlayer' );
+ $(this).on( 'ready', this.setPlayer );
+ },
+
+ setPlayer: function (e, node) {
+ // if the ready event fires on an empty node
+ if ( ! node ) {
+ return;
+ }
+
+ var id,
+ media,
+ settings = {},
+ className = '.wp-' + this.shortcode.tag + '-shortcode';
+
+ media = $( node ).find( className );
+
+ if ( media.hasClass( 'rendered' ) ) {
+ id = media.closest( className ).attr( 'id' );
+ window.mejs.players[ id ].remove();
+ } else {
+ media.addClass( 'rendered' );
+ }
+
+ media.prop( 'preload', 'none' );
+ media = media.get(0);
+
+ if ( ! _.isUndefined( window._wpmejsSettings ) ) {
+ settings.pluginPath = _wpmejsSettings.pluginPath;
+ }
+
+ media = wp.media.view.MediaDetails.prepareSrc( media );
+ new MediaElementPlayer( media, settings );
+ },
+
+ getHtml: function() {
+ var attrs = this.shortcode.attrs.named;
+ return this.template({ model: attrs });
+ }
+ });
+
+ wp.mce.video = _.extend( {}, wp.mce.media, {
+ shortcode: 'video',
+ View: wp.mce.media.ViewMixin.extend({
+ className: 'editor-video',
+ template: media.template('editor-video')
+ })
+ } );
+
+ wp.mce.views.register( 'video', wp.mce.video );
+
+ wp.mce.audio = _.extend( {}, wp.mce.media, {
+ shortcode: 'audio',
+ View: wp.mce.media.ViewMixin.extend({
+ className: 'editor-audio',
+ template: media.template('editor-audio')
+ })
+ } );
+
+ wp.mce.views.register( 'audio', wp.mce.audio );
</ins><span class="cx"> }(jQuery));
</span></span></pre></div>
<a id="trunksrcwpincludesjsmediaeditorjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/media-editor.js (27527 => 27528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/media-editor.js 2014-03-13 21:50:17 UTC (rev 27527)
+++ trunk/src/wp-includes/js/media-editor.js 2014-03-13 23:09:06 UTC (rev 27528)
</span><span class="lines">@@ -581,20 +581,24 @@
</span><span class="cx"> return frame;
</span><span class="cx"> },
</span><span class="cx">
</span><del>- shortcode : function (shortcode) {
- var self = this;
</del><ins>+ update : function (model) {
+ var self = this, content;
</ins><span class="cx">
</span><del>- _.each( wp.media.audio.defaults, function( value, key ) {
- shortcode[ key ] = self.coerce( shortcode, key );
</del><ins>+ _.each( this.defaults, function( value, key ) {
+ model[ key ] = self.coerce( model, key );
</ins><span class="cx">
</span><del>- if ( value === shortcode[ key ] ) {
- delete shortcode[ key ];
</del><ins>+ if ( value === model[ key ] ) {
+ delete model[ key ];
</ins><span class="cx"> }
</span><span class="cx"> });
</span><span class="cx">
</span><del>- return wp.shortcode.string({
- tag: 'audio',
- attrs: shortcode
</del><ins>+ content = model.content;
+ delete model.content;
+
+ return new wp.shortcode({
+ tag: 'audio',
+ attrs: model,
+ content: content
</ins><span class="cx"> });
</span><span class="cx"> }
</span><span class="cx"> }, wp.media.mixin);
</span><span class="lines">@@ -631,21 +635,23 @@
</span><span class="cx"> return frame;
</span><span class="cx"> },
</span><span class="cx">
</span><del>- shortcode : function (shortcode) {
- var self = this, content = shortcode.content;
- delete shortcode.content;
</del><ins>+ update : function (model) {
+ var self = this, content = '';
</ins><span class="cx">
</span><span class="cx"> _.each( this.defaults, function( value, key ) {
</span><del>- shortcode[ key ] = self.coerce( shortcode, key );
</del><ins>+ model[ key ] = self.coerce( model, key );
</ins><span class="cx">
</span><del>- if ( value === shortcode[ key ] ) {
- delete shortcode[ key ];
</del><ins>+ if ( value === model[ key ] ) {
+ delete model[ key ];
</ins><span class="cx"> }
</span><span class="cx"> });
</span><span class="cx">
</span><del>- return wp.shortcode.string({
- tag: 'video',
- attrs: shortcode,
</del><ins>+ content = model.content;
+ delete model.content;
+
+ return new wp.shortcode({
+ tag: 'video',
+ attrs: model,
</ins><span class="cx"> content: content
</span><span class="cx"> });
</span><span class="cx"> }
</span><span class="lines">@@ -1111,38 +1117,47 @@
</span><span class="cx"> * @global wp.media.view.l10n
</span><span class="cx"> */
</span><span class="cx"> init: function() {
</span><del>- $(document.body).on( 'click', '.insert-media', function( event ) {
- var elem = $( event.currentTarget ),
- editor = elem.data('editor'),
- options = {
- frame: 'post',
- state: 'insert',
- title: wp.media.view.l10n.addMedia,
- multiple: true
- };
</del><ins>+ $(document.body)
+ .on( 'click', '.insert-media', function( event ) {
+ var elem = $( event.currentTarget ),
+ editor = elem.data('editor'),
+ options = {
+ frame: 'post',
+ state: 'insert',
+ title: wp.media.view.l10n.addMedia,
+ multiple: true
+ };
</ins><span class="cx">
</span><del>- event.preventDefault();
</del><ins>+ event.preventDefault();
</ins><span class="cx">
</span><del>- // Remove focus from the `.insert-media` button.
- // Prevents Opera from showing the outline of the button
- // above the modal.
- //
- // See: http://core.trac.wordpress.org/ticket/22445
- elem.blur();
</del><ins>+ // Remove focus from the `.insert-media` button.
+ // Prevents Opera from showing the outline of the button
+ // above the modal.
+ //
+ // See: http://core.trac.wordpress.org/ticket/22445
+ elem.blur();
</ins><span class="cx">
</span><del>- if ( elem.hasClass( 'gallery' ) ) {
- options.state = 'gallery';
- options.title = wp.media.view.l10n.createGalleryTitle;
- } else if ( elem.hasClass( 'playlist' ) ) {
- options.state = 'playlist';
- options.title = wp.media.view.l10n.createPlaylistTitle;
- } else if ( elem.hasClass( 'video-playlist' ) ) {
- options.state = 'video-playlist';
- options.title = wp.media.view.l10n.createVideoPlaylistTitle;
- }
</del><ins>+ if ( elem.hasClass( 'gallery' ) ) {
+ options.state = 'gallery';
+ options.title = wp.media.view.l10n.createGalleryTitle;
+ } else if ( elem.hasClass( 'playlist' ) ) {
+ options.state = 'playlist';
+ options.title = wp.media.view.l10n.createPlaylistTitle;
+ } else if ( elem.hasClass( 'video-playlist' ) ) {
+ options.state = 'video-playlist';
+ options.title = wp.media.view.l10n.createVideoPlaylistTitle;
+ }
</ins><span class="cx">
</span><del>- wp.media.editor.open( editor, options );
- });
</del><ins>+ wp.media.editor.open( editor, options );
+ })
+ .on( 'click', '.wp-switch-editor', function () {
+ var p;
+ if ( window.mejs && window.mejs.players ) {
+ for ( p in window.mejs.players ) {
+ window.mejs.players[p].pause();
+ }
+ }
+ } );
</ins><span class="cx">
</span><span class="cx"> // Initialize and render the Editor drag-and-drop uploader.
</span><span class="cx"> new wp.media.view.EditorUploader().render();
</span></span></pre></div>
<a id="trunksrcwpincludesjsmediamodelsjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/media-models.js (27527 => 27528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/media-models.js 2014-03-13 21:50:17 UTC (rev 27527)
+++ trunk/src/wp-includes/js/media-models.js 2014-03-13 23:09:06 UTC (rev 27528)
</span><span class="lines">@@ -467,6 +467,7 @@
</span><span class="cx"> this.attachment = attachment;
</span><span class="cx"> this.extension = attachment.get('filename' ).split('.').pop();
</span><span class="cx">
</span><ins>+ this.unset( 'src' );
</ins><span class="cx"> if ( _.contains( wp.media.view.settings.embedExts, this.extension ) ) {
</span><span class="cx"> this.set( this.extension, this.attachment.get( 'url' ) );
</span><span class="cx"> } else {
</span></span></pre></div>
<a id="trunksrcwpincludesjsmediaviewsjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/media-views.js (27527 => 27528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/media-views.js 2014-03-13 21:50:17 UTC (rev 27527)
+++ trunk/src/wp-includes/js/media-views.js 2014-03-13 23:09:06 UTC (rev 27528)
</span><span class="lines">@@ -6542,26 +6542,6 @@
</span><span class="cx"> }, this.options );
</span><span class="cx"> },
</span><span class="cx">
</span><del>- /**
- * When multiple players in the DOM contain the same src, things get weird.
- *
- * @param {HTMLElement} media
- * @returns {HTMLElement}
- */
- prepareSrc : function (media) {
- var i = wp.media.view.MediaDetails.instances++;
- _.each( $(media).find('source'), function (source) {
- source.src = [
- source.src,
- source.src.indexOf('?') > -1 ? '&' : '?',
- '_=',
- i
- ].join('');
- });
-
- return media;
- },
-
</del><span class="cx"> removeSetting : function (e) {
</span><span class="cx"> var wrap = $( e.currentTarget ).parent(), setting;
</span><span class="cx">
</span><span class="lines">@@ -6633,9 +6613,10 @@
</span><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> unsetPlayer : function() {
</span><ins>+ var p;
</ins><span class="cx"> if ( this.player ) {
</span><del>- if ( _.isUndefined( this.mejs.pluginType ) ) {
- this.mejs.pause();
</del><ins>+ for ( p in window.mejs.players ) {
+ window.mejs.players[p].pause();
</ins><span class="cx"> }
</span><span class="cx"> this.removePlayer();
</span><span class="cx"> this.player = false;
</span><span class="lines">@@ -6675,7 +6656,30 @@
</span><span class="cx"> this.$( '.embed-media-settings' ).scrollTop( 0 );
</span><span class="cx"> }
</span><span class="cx"> }, {
</span><del>- instances : 0
</del><ins>+ instances : 0,
+
+ /**
+ * When multiple players in the DOM contain the same src, things get weird.
+ *
+ * @param {HTMLElement} media
+ * @returns {HTMLElement}
+ */
+ prepareSrc : function (media) {
+ var i = wp.media.view.MediaDetails.instances++;
+ if ( 0 === i ) {
+ i = (new Date()).getTime();
+ }
+ _.each( $(media).find('source'), function (source) {
+ source.src = [
+ source.src,
+ source.src.indexOf('?') > -1 ? '&' : '?',
+ '_=',
+ i
+ ].join('');
+ });
+
+ return media;
+ }
</ins><span class="cx"> });
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -6694,13 +6698,23 @@
</span><span class="cx"> template: media.template('audio-details'),
</span><span class="cx">
</span><span class="cx"> setMedia: function() {
</span><del>- var audio = this.$('.wp-audio-shortcode');
</del><ins>+ var className = '.wp-audio-shortcode',
+ audio;
</ins><span class="cx">
</span><ins>+ audio = this.$( className );
+
</ins><span class="cx"> if ( audio.find( 'source' ).length ) {
</span><span class="cx"> if ( audio.is(':hidden') ) {
</span><span class="cx"> audio.show();
</span><span class="cx"> }
</span><del>- this.media = this.prepareSrc( audio.get(0) );
</del><ins>+
+ audio = audio.get(0);
+
+ if ( $( className ).length > 0 ) {
+ audio = media.view.MediaDetails.prepareSrc( audio );
+ }
+
+ this.media = audio;
</ins><span class="cx"> } else {
</span><span class="cx"> audio.hide();
</span><span class="cx"> this.media = false;
</span><span class="lines">@@ -6726,18 +6740,25 @@
</span><span class="cx"> template: media.template('video-details'),
</span><span class="cx">
</span><span class="cx"> setMedia: function() {
</span><del>- var video = this.$('.wp-video-shortcode');
</del><ins>+ var className = '.wp-video-shortcode',
+ video,
+ yt;
</ins><span class="cx">
</span><ins>+ video = this.$( className );
+ yt = video.hasClass('youtube-video');
+
</ins><span class="cx"> if ( video.find( 'source' ).length ) {
</span><span class="cx"> if ( video.is(':hidden') ) {
</span><span class="cx"> video.show();
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if ( ! video.hasClass('youtube-video') ) {
- this.media = this.prepareSrc( video.get(0) );
- } else {
- this.media = video.get(0);
</del><ins>+ video = video.get(0);
+
+ if ( ! yt ) {
+ video = media.view.MediaDetails.prepareSrc( video );
</ins><span class="cx"> }
</span><ins>+
+ this.media = video;
</ins><span class="cx"> } else {
</span><span class="cx"> video.hide();
</span><span class="cx"> this.media = false;
</span></span></pre></div>
<a id="trunksrcwpincludesjstinymcepluginswpgallerypluginjs"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/tinymce/plugins/wpgallery/plugin.js (27527 => 27528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/tinymce/plugins/wpgallery/plugin.js 2014-03-13 21:50:17 UTC (rev 27527)
+++ trunk/src/wp-includes/js/tinymce/plugins/wpgallery/plugin.js 2014-03-13 23:09:06 UTC (rev 27528)
</span><span class="lines">@@ -25,8 +25,8 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> function replaceAVShortcodes( content ) {
</span><del>- var testRegex = /\[(video-playlist|audio|video|playlist)[^\]]*\]/,
- replaceRegex = /\[(video-playlist|audio|video|playlist)[^\]]*\]([\s\S]*?\[\/\1\])?/;
</del><ins>+ var testRegex = /\[(video-playlist|playlist)[^\]]*\]/,
+ replaceRegex = /\[(video-playlist|playlist)[^\]]*\]([\s\S]*?\[\/\1\])?/;
</ins><span class="cx">
</span><span class="cx"> while ( testRegex.test( content ) ) {
</span><span class="cx"> content = content.replace( replaceRegex, replaceCallback );
</span><span class="lines">@@ -92,31 +92,6 @@
</span><span class="cx"> editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) );
</span><span class="cx"> frame.detach();
</span><span class="cx"> });
</span><del>- } else if ( editor.dom.hasClass( node, 'wp-video' ) ) {
- frame = wp.media.video.edit( data );
- frame.on( 'close', function () {
- frame.detach();
- } );
- frame.state( 'video-details' ).on(
- 'update replace add-source select-poster-image add-track',
- function ( selection ) {
- var shortcode = wp.media.video.shortcode( selection );
- editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) );
- frame.detach();
- }
- );
- frame.open();
- } else if ( editor.dom.hasClass( node, 'wp-audio' ) ) {
- frame = wp.media.audio.edit( data );
- frame.on( 'close', function () {
- frame.detach();
- } );
- frame.state( 'audio-details' ).on( 'update replace add-source', function ( selection ) {
- var shortcode = wp.media.audio.shortcode( selection );
- editor.dom.setAttrib( node, 'data-wp-media', window.encodeURIComponent( shortcode ) );
- frame.detach();
- } );
- frame.open();
</del><span class="cx"> } else {
</span><span class="cx"> // temp
</span><span class="cx"> window.console && window.console.log( 'Edit AV shortcode ' + data );
</span></span></pre></div>
<a id="trunksrcwpincludesjstinymceskinswordpresswpcontentcss"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css (27527 => 27528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css 2014-03-13 21:50:17 UTC (rev 27527)
+++ trunk/src/wp-includes/js/tinymce/skins/wordpress/wp-content.css 2014-03-13 23:09:06 UTC (rev 27528)
</span><span class="lines">@@ -237,14 +237,32 @@
</span><span class="cx"> /**
</span><span class="cx"> * Gallery preview
</span><span class="cx"> */
</span><del>-.wpview-type-gallery {
</del><ins>+.wpview-type-gallery,
+.wpview-type-audio,
+.wpview-type-video {
</ins><span class="cx"> position: relative;
</span><span class="cx"> padding: 0 0 12px;
</span><span class="cx"> margin-bottom: 16px;
</span><span class="cx"> cursor: pointer;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- .wpview-type-gallery:after {
</del><ins>+.wpview-type-audio {
+ padding: 32px 0 0;
+}
+
+.wpview-type-video {
+ padding: 16px 0 0;
+}
+
+.wpview-type-audio audio,
+.wpview-type-video video {
+ display: inline-block;
+ max-width: 100%;
+}
+
+ .wpview-type-gallery:after,
+ .wpview-type-audio:after,
+ .wpview-type-video:after {
</ins><span class="cx"> content: '';
</span><span class="cx"> display: block;
</span><span class="cx"> height: 0;
</span><span class="lines">@@ -252,11 +270,18 @@
</span><span class="cx"> visibility: hidden;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- .wpview-type-gallery.selected {
</del><ins>+.wpview-type-gallery.selected {
</ins><span class="cx"> background-color: #efefef;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-.wpview-type-gallery .toolbar {
</del><ins>+.wpview-type-audio,
+.wpview-type-video {
+ background-color: #efefef;
+}
+
+.wpview-type-gallery .toolbar,
+.wpview-type-audio .toolbar,
+.wpview-type-video .toolbar {
</ins><span class="cx"> position: absolute;
</span><span class="cx"> top: 0;
</span><span class="cx"> left: 0;
</span><span class="lines">@@ -264,13 +289,21 @@
</span><span class="cx"> color: white;
</span><span class="cx"> padding: 4px;
</span><span class="cx"> display: none;
</span><ins>+ z-index: 100;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+.wpview-type-audio .toolbar,
+.wpview-type-video .toolbar {
+ display: block;
+}
+
</ins><span class="cx"> .wpview-type-gallery.selected .toolbar {
</span><span class="cx"> display: block;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-.wpview-type-gallery .toolbar span {
</del><ins>+.wpview-type-gallery .toolbar span,
+.wpview-type-audio .toolbar span
+.wpview-type-video .toolbar span {
</ins><span class="cx"> cursor: pointer;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunksrcwpincludesmediatemplatephp"></a>
<div class="modfile"><h4>Modified: trunk/src/wp-includes/media-template.php (27527 => 27528)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/src/wp-includes/media-template.php 2014-03-13 21:50:17 UTC (rev 27527)
+++ trunk/src/wp-includes/media-template.php 2014-03-13 23:09:06 UTC (rev 27528)
</span><span class="lines">@@ -8,6 +8,97 @@
</span><span class="cx"> */
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Output the markup for a audio tag to be used in an Underscore template
+ * when data.model is passed.
+ *
+ * @since 3.9.0
+ */
+function wp_underscore_audio_template() {
+ $audio_types = wp_get_audio_extensions();
+?>
+<audio controls
+ class="wp-audio-shortcode"
+ preload="{{ _.isUndefined( data.model.preload ) ? 'none' : data.model.preload }}"
+ <#
+ <?php foreach ( array( 'autoplay', 'loop' ) as $attr ):
+ ?>if ( ! _.isUndefined( data.model.<?php echo $attr ?> ) && data.model.<?php echo $attr ?> ) {
+ #> <?php echo $attr ?><#
+ }
+ <?php endforeach ?>#>
+>
+ <# if ( ! _.isEmpty( data.model.src ) ) { #>
+ <source src="{{ data.model.src }}" type="{{ wp.media.view.settings.embedMimes[ data.model.src.split('.').pop() ] }}" />
+ <# } #>
+
+ <?php foreach ( $audio_types as $type ):
+ ?><# if ( ! _.isEmpty( data.model.<?php echo $type ?> ) ) { #>
+ <source src="{{ data.model.<?php echo $type ?> }}" type="{{ wp.media.view.settings.embedMimes[ '<?php echo $type ?>' ] }}" />
+ <# } #>
+ <?php endforeach;
+?></audio>
+<?php
+}
+
+/**
+ * Output the markup for a video tag to be used in an Underscore template
+ * when data.model is passed.
+ *
+ * @since 3.9.0
+ */
+function wp_underscore_video_template( $onload = false ) {
+ $video_types = wp_get_video_extensions();
+?>
+<#
+var isYouTube = ! _.isEmpty( data.model.src ) && data.model.src.match(/youtube|youtu\.be/);
+ w = ! data.model.width || data.model.width > 640 ? 640 : data.model.width,
+ h = ! data.model.height ? 360 : data.model.height;
+
+if ( data.model.width && w !== data.model.width ) {
+ h = Math.ceil( ( h * w ) / data.model.width );
+}
+#>
+<video controls
+ class="wp-video-shortcode{{ isYouTube ? ' youtube-video' : '' }}"
+ width="{{ w }}"
+ height="{{ h }}"
+ <?php
+ $props = array( 'poster' => '', 'preload' => 'metadata' );
+ foreach ( $props as $key => $value ):
+ if ( empty( $value ) ) {
+ ?><#
+ if ( ! _.isUndefined( data.model.<?php echo $key ?> ) && data.model.<?php echo $key ?> ) {
+ #> <?php echo $key ?>="{{ data.model.<?php echo $key ?> }}"<#
+ } #>
+ <?php } else {
+ echo $key ?>="{{ _.isUndefined( data.model.<?php echo $key ?> ) ? '<?php echo $value ?>' : data.model.<?php echo $key ?> }}"<?php
+ }
+ endforeach;
+ ?><#
+ <?php foreach ( array( 'autoplay', 'loop' ) as $attr ):
+ ?> if ( ! _.isUndefined( data.model.<?php echo $attr ?> ) && data.model.<?php echo $attr ?> ) {
+ #> <?php echo $attr ?><#
+ }
+ <?php endforeach ?>#>
+>
+ <# if ( ! _.isEmpty( data.model.src ) ) {
+ if ( isYouTube ) { #>
+ <source src="{{ data.model.src }}" type="video/youtube" />
+ <# } else { #>
+ <source src="{{ data.model.src }}" type="{{ wp.media.view.settings.embedMimes[ data.model.src.split('.').pop() ] }}" />
+ <# }
+ } #>
+
+ <?php foreach ( $video_types as $type ):
+ ?><# if ( data.model.<?php echo $type ?> ) { #>
+ <source src="{{ data.model.<?php echo $type ?> }}" type="{{ wp.media.view.settings.embedMimes[ '<?php echo $type ?>' ] }}" />
+ <# } #>
+ <?php endforeach; ?>
+ {{{ data.model.content }}}
+</video>
+<?php
+}
+
+/**
</ins><span class="cx"> * Prints the templates used in the media manager.
</span><span class="cx"> *
</span><span class="cx"> * @since 3.5.0
</span><span class="lines">@@ -676,26 +767,7 @@
</span><span class="cx"> <div class="media-embed media-embed-details">
</span><span class="cx"> <div class="embed-media-settings embed-audio-settings">
</span><span class="cx"> <div class="instructions media-instructions">{{{ wp.media.view.l10n.audioDetailsText }}}</div>
</span><del>- <audio controls
- class="wp-audio-shortcode"
- preload="{{ _.isUndefined( data.model.preload ) ? 'none' : data.model.preload }}"
- <#
- <?php foreach ( array( 'autoplay', 'loop' ) as $attr ):
- ?>if ( ! _.isUndefined( data.model.<?php echo $attr ?> ) && data.model.<?php echo $attr ?> ) {
- #> <?php echo $attr ?><#
- }
- <?php endforeach ?>#>
- >
- <# if ( ! _.isEmpty( data.model.src ) ) { #>
- <source src="{{ data.model.src }}" type="{{ wp.media.view.settings.embedMimes[ data.model.src.split('.').pop() ] }}" />
- <# } #>
-
- <?php foreach ( $audio_types as $type ):
- ?><# if ( ! _.isEmpty( data.model.<?php echo $type ?> ) ) { #>
- <source src="{{ data.model.<?php echo $type ?> }}" type="{{ wp.media.view.settings.embedMimes[ '<?php echo $type ?>' ] }}" />
- <# } #>
- <?php endforeach;
- ?></audio>
</del><ins>+ <?php wp_underscore_audio_template() ?>
</ins><span class="cx"> <# if ( ! _.isEmpty( data.model.src ) ) { #>
</span><span class="cx"> <label class="setting">
</span><span class="cx"> <span>SRC</span>
</span><span class="lines">@@ -738,60 +810,21 @@
</span><span class="cx"> </div>
</span><span class="cx"> </script>
</span><span class="cx">
</span><ins>+ <script type="text/html" id="tmpl-editor-audio">
+ <div class="toolbar">
+ <div class="dashicons dashicons-format-audio edit"></div>
+ <div class="dashicons dashicons-no-alt remove"></div>
+ </div>
+ <?php wp_underscore_audio_template() ?>
+ </script>
+
</ins><span class="cx"> <script type="text/html" id="tmpl-video-details">
</span><span class="cx"> <?php $video_types = wp_get_video_extensions(); ?>
</span><span class="cx"> <div class="media-embed media-embed-details">
</span><span class="cx"> <div class="embed-media-settings embed-video-settings">
</span><span class="cx"> <div class="instructions media-instructions">{{{ wp.media.view.l10n.videoDetailsText }}}</div>
</span><span class="cx"> <div class="wp-video-holder">
</span><del>- <#
- var isYouTube = ! _.isEmpty( data.model.src ) && data.model.src.match(/youtube|youtu\.be/);
- w = ! data.model.width || data.model.width > 640 ? 640 : data.model.width,
- h = ! data.model.height ? 360 : data.model.height;
-
- if ( data.model.width && w !== data.model.width ) {
- h = Math.ceil( ( h * w ) / data.model.width );
- }
-
- #>
- <video controls
- class="wp-video-shortcode{{ isYouTube ? ' youtube-video' : '' }}"
- width="{{ w }}"
- height="{{ h }}"
- <?php
- $props = array( 'poster' => '', 'preload' => 'metadata' );
- foreach ( $props as $key => $value ):
- if ( empty( $value ) ) {
- ?><#
- if ( ! _.isUndefined( data.model.<?php echo $key ?> ) && data.model.<?php echo $key ?> ) {
- #> <?php echo $key ?>="{{ data.model.<?php echo $key ?> }}"<#
- } #>
- <?php } else {
- echo $key ?>="{{ _.isUndefined( data.model.<?php echo $key ?> ) ? '<?php echo $value ?>' : data.model.<?php echo $key ?> }}"<?php
- }
- endforeach;
- ?><#
- <?php foreach ( array( 'autoplay', 'loop' ) as $attr ):
- ?> if ( ! _.isUndefined( data.model.<?php echo $attr ?> ) && data.model.<?php echo $attr ?> ) {
- #> <?php echo $attr ?><#
- }
- <?php endforeach ?>#>
- >
- <# if ( ! _.isEmpty( data.model.src ) ) {
- if ( isYouTube ) { #>
- <source src="{{ data.model.src }}" type="video/youtube" />
- <# } else { #>
- <source src="{{ data.model.src }}" type="{{ wp.media.view.settings.embedMimes[ data.model.src.split('.').pop() ] }}" />
- <# }
- } #>
-
- <?php foreach ( $video_types as $type ):
- ?><# if ( data.model.<?php echo $type ?> ) { #>
- <source src="{{ data.model.<?php echo $type ?> }}" type="{{ wp.media.view.settings.embedMimes[ '<?php echo $type ?>' ] }}" />
- <# } #>
- <?php endforeach; ?>
- {{{ data.model.content }}}
- </video>
</del><ins>+ <?php wp_underscore_video_template() ?>
</ins><span class="cx"> <# if ( ! _.isEmpty( data.model.src ) ) { #>
</span><span class="cx"> <label class="setting">
</span><span class="cx"> <span>SRC</span>
</span><span class="lines">@@ -857,6 +890,14 @@
</span><span class="cx"> </div>
</span><span class="cx"> </div>
</span><span class="cx"> </script>
</span><ins>+
+ <script type="text/html" id="tmpl-editor-video">
+ <div class="toolbar">
+ <div class="dashicons dashicons-format-video edit"></div>
+ <div class="dashicons dashicons-no-alt remove"></div>
+ </div>
+ <?php wp_underscore_video_template() ?>
+ </script>
</ins><span class="cx"> <?php
</span><span class="cx">
</span><span class="cx"> //TODO: do we want to deal with the fact that the elements used for gallery items are filterable and can be overriden via shortcode attributes
</span></span></pre>
</div>
</div>
</body>
</html>