TinyMCE: views: use media setting to get post ID

Also fix dependency declarations and confusing variable names.

Props rhurling.
Fixes #33096.


git-svn-id: https://develop.svn.wordpress.org/trunk@33426 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ella Iseulde Van Dorpe 2015-07-26 10:10:31 +00:00
parent 16cc16da9e
commit 079d7eb56e
2 changed files with 19 additions and 24 deletions

View File

@ -1,7 +1,5 @@
/* global tinymce */ /* global tinymce */
window.wp = window.wp || {};
/* /*
* The TinyMCE view API. * The TinyMCE view API.
* *
@ -24,7 +22,7 @@ window.wp = window.wp || {};
* |- registered view * |- registered view
* | |- ... * | |- ...
*/ */
( function( window, wp, $ ) { ( function( window, wp, shortcode, $ ) {
'use strict'; 'use strict';
var views = {}, var views = {},
@ -671,7 +669,7 @@ window.wp = window.wp || {};
* @return {Object} * @return {Object}
*/ */
match: function( content ) { match: function( content ) {
var match = wp.shortcode.next( this.type, content ); var match = shortcode.next( this.type, content );
if ( match ) { if ( match ) {
return { return {
@ -720,30 +718,28 @@ window.wp = window.wp || {};
editor.focus(); editor.focus();
} }
} ); } );
} )( window, window.wp, window.jQuery ); } )( window, window.wp, window.wp.shortcode, window.jQuery );
/* /*
* The WordPress core TinyMCE views. * The WordPress core TinyMCE views.
* Views for the gallery, audio, video, playlist and embed shortcodes, * Views for the gallery, audio, video, playlist and embed shortcodes,
* and a view for embeddable URLs. * and a view for embeddable URLs.
*/ */
( function( window, views, $ ) { ( function( window, views, media ) {
var postID = $( '#post_ID' ).val() || 0, var base, gallery, av, embed;
media, gallery, av, embed;
media = { base = {
state: [], state: [],
edit: function( text, update ) { edit: function( text, update ) {
var type = this.type, var type = this.type,
media = wp.media[ type ], frame = media[ type ].edit( text );
frame = media.edit( text );
this.pausePlayers && this.pausePlayers(); this.pausePlayers && this.pausePlayers();
_.each( this.state, function( state ) { _.each( this.state, function( state ) {
frame.state( state ).on( 'update', function( selection ) { frame.state( state ).on( 'update', function( selection ) {
update( media.shortcode( selection ).string(), type === 'gallery' ); update( media[ type ].shortcode( selection ).string(), type === 'gallery' );
} ); } );
} ); } );
@ -755,12 +751,12 @@ window.wp = window.wp || {};
} }
}; };
gallery = _.extend( {}, media, { gallery = _.extend( {}, base, {
state: [ 'gallery-edit' ], state: [ 'gallery-edit' ],
template: wp.media.template( 'editor-gallery' ), template: media.template( 'editor-gallery' ),
initialize: function() { initialize: function() {
var attachments = wp.media.gallery.attachments( this.shortcode, postID ), var attachments = media.gallery.attachments( this.shortcode, media.view.settings.post.id ),
attrs = this.shortcode.attrs.named, attrs = this.shortcode.attrs.named,
self = this; self = this;
@ -782,7 +778,7 @@ window.wp = window.wp || {};
self.render( self.template( { self.render( self.template( {
attachments: attachments, attachments: attachments,
columns: attrs.columns ? parseInt( attrs.columns, 10 ) : wp.media.galleryDefaults.columns columns: attrs.columns ? parseInt( attrs.columns, 10 ) : media.galleryDefaults.columns
} ) ); } ) );
} ) } )
.fail( function( jqXHR, textStatus ) { .fail( function( jqXHR, textStatus ) {
@ -791,7 +787,7 @@ window.wp = window.wp || {};
} }
} ); } );
av = _.extend( {}, media, { av = _.extend( {}, base, {
action: 'parse-media-shortcode', action: 'parse-media-shortcode',
initialize: function() { initialize: function() {
@ -799,13 +795,13 @@ window.wp = window.wp || {};
if ( this.url ) { if ( this.url ) {
this.loader = false; this.loader = false;
this.shortcode = wp.media.embed.shortcode( { this.shortcode = media.embed.shortcode( {
url: this.text url: this.text
} ); } );
} }
wp.ajax.post( this.action, { wp.ajax.post( this.action, {
post_ID: postID, post_ID: media.view.settings.post.id,
type: this.shortcode.tag, type: this.shortcode.tag,
shortcode: this.shortcode.string() shortcode: this.shortcode.string()
} ) } )
@ -846,8 +842,7 @@ window.wp = window.wp || {};
action: 'parse-embed', action: 'parse-embed',
edit: function( text, update ) { edit: function( text, update ) {
var media = wp.media.embed, var frame = media.embed.edit( text, this.url ),
frame = media.edit( text, this.url ),
self = this; self = this;
this.pausePlayers(); this.pausePlayers();
@ -864,7 +859,7 @@ window.wp = window.wp || {};
if ( self.url ) { if ( self.url ) {
update( data.url ); update( data.url );
} else { } else {
update( media.shortcode( data ).string() ); update( media.embed.shortcode( data ).string() );
} }
} ); } );
@ -908,4 +903,4 @@ window.wp = window.wp || {};
} }
} }
} ) ); } ) );
} )( window, window.wp.mce.views, window.jQuery ); } )( window, window.wp.mce.views, window.wp.media );

View File

@ -456,7 +456,7 @@ function wp_default_scripts( &$scripts ) {
$scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement' ), false, 1 ); $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement' ), false, 1 );
$scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 ); $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 );
$scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor' ), false, 1 ); $scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor' ), false, 1 );
$scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'media-models', 'media-audiovideo', 'wp-playlist' ), false, 1 ); $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'jquery', 'media-views', 'media-audiovideo' ), false, 1 );
if ( is_admin() ) { if ( is_admin() ) {
$scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array( 'jquery', 'wp-ajax-response' ), false, 1 ); $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array( 'jquery', 'wp-ajax-response' ), false, 1 );