From 079d7eb56e083fa9c2e4038d310ad746493ab91f Mon Sep 17 00:00:00 2001 From: Ella Iseulde Van Dorpe Date: Sun, 26 Jul 2015 10:10:31 +0000 Subject: [PATCH] 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 --- src/wp-includes/js/mce-view.js | 41 ++++++++++++++----------------- src/wp-includes/script-loader.php | 2 +- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/wp-includes/js/mce-view.js b/src/wp-includes/js/mce-view.js index dbd11ab298..3863924f07 100644 --- a/src/wp-includes/js/mce-view.js +++ b/src/wp-includes/js/mce-view.js @@ -1,7 +1,5 @@ /* global tinymce */ -window.wp = window.wp || {}; - /* * The TinyMCE view API. * @@ -24,7 +22,7 @@ window.wp = window.wp || {}; * |- registered view * | |- ... */ -( function( window, wp, $ ) { +( function( window, wp, shortcode, $ ) { 'use strict'; var views = {}, @@ -671,7 +669,7 @@ window.wp = window.wp || {}; * @return {Object} */ match: function( content ) { - var match = wp.shortcode.next( this.type, content ); + var match = shortcode.next( this.type, content ); if ( match ) { return { @@ -720,30 +718,28 @@ window.wp = window.wp || {}; editor.focus(); } } ); -} )( window, window.wp, window.jQuery ); +} )( window, window.wp, window.wp.shortcode, 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; +( function( window, views, media ) { + var base, gallery, av, embed; - media = { + base = { state: [], edit: function( text, update ) { var type = this.type, - media = wp.media[ type ], - frame = media.edit( text ); + frame = media[ type ].edit( text ); this.pausePlayers && this.pausePlayers(); _.each( this.state, function( state ) { 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' ], - template: wp.media.template( 'editor-gallery' ), + template: media.template( 'editor-gallery' ), 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, self = this; @@ -782,7 +778,7 @@ window.wp = window.wp || {}; self.render( self.template( { 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 ) { @@ -791,7 +787,7 @@ window.wp = window.wp || {}; } } ); - av = _.extend( {}, media, { + av = _.extend( {}, base, { action: 'parse-media-shortcode', initialize: function() { @@ -799,13 +795,13 @@ window.wp = window.wp || {}; if ( this.url ) { this.loader = false; - this.shortcode = wp.media.embed.shortcode( { + this.shortcode = media.embed.shortcode( { url: this.text } ); } wp.ajax.post( this.action, { - post_ID: postID, + post_ID: media.view.settings.post.id, type: this.shortcode.tag, shortcode: this.shortcode.string() } ) @@ -846,8 +842,7 @@ window.wp = window.wp || {}; action: 'parse-embed', edit: function( text, update ) { - var media = wp.media.embed, - frame = media.edit( text, this.url ), + var frame = media.embed.edit( text, this.url ), self = this; this.pausePlayers(); @@ -864,7 +859,7 @@ window.wp = window.wp || {}; if ( self.url ) { update( data.url ); } 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 ); diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 5a6230b440..8862b764e6 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -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-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( '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() ) { $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array( 'jquery', 'wp-ajax-response' ), false, 1 );