From d44c684599852ff07413cde489c254e4e3d1dcd4 Mon Sep 17 00:00:00 2001 From: Ella Iseulde Van Dorpe <*@iseulde.com> Date: Sun, 26 Jul 2015 10:11:24 +0000 Subject: [PATCH] TinyMCE: views: use media setting to get post ID Also fix dependency declarations and confusing variable names. Props rhurling. Fixes #33096. Built from https://develop.svn.wordpress.org/trunk@33426 git-svn-id: http://core.svn.wordpress.org/trunk@33393 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/mce-view.js | 41 +++++++++++++++------------------- wp-includes/js/mce-view.min.js | 2 +- wp-includes/script-loader.php | 2 +- wp-includes/version.php | 2 +- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index dbd11ab298..3863924f07 100644 --- a/wp-includes/js/mce-view.js +++ b/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/wp-includes/js/mce-view.min.js b/wp-includes/js/mce-view.min.js index e2a4c8350d..014b7c74c8 100644 --- a/wp-includes/js/mce-view.min.js +++ b/wp-includes/js/mce-view.min.js @@ -1 +1 @@ -window.wp=window.wp||{},function(a,b,c){"use strict";var d={},e={};b.mce=b.mce||{},b.mce.views={register:function(a,c){d[a]=b.mce.View.extend(_.extend(c,{type:a}))},unregister:function(a){delete d[a]},get:function(a){return d[a]},unbind:function(){_.each(e,function(a){a.unbind()})},setMarkers:function(a){var b,c,e=[{content:a}],f=this;return _.each(d,function(a,d){c=e.slice(),e=[],_.each(c,function(c){var g,h,i=c.content;if(c.processed)return void e.push(c);for(;i&&(g=a.prototype.match(i));)g.index&&e.push({content:i.substring(0,g.index)}),b=f.createInstance(d,g.content,g.options),h=b.loader?".":b.text,e.push({content:'
'+h+"
",processed:!0}),i=i.slice(g.index+g.content.length);i&&e.push({content:i})})}),a=_.pluck(e,"content").join(""),a.replace(/\s*
")},createInstance:function(a,b,c,d){var f,g,h=this.get(a);return b=tinymce.DOM.decode(b),!d&&(g=this.getInstance(b))?g:(f=encodeURIComponent(b),c=_.extend(c||{},{text:b,encodedText:f}),e[f]=new h(c))},getInstance:function(a){return"string"==typeof a?e[encodeURIComponent(a)]:e[c(a).attr("data-wpview-text")]},getText:function(a){return decodeURIComponent(c(a).attr("data-wpview-text")||"")},render:function(a){_.each(e,function(b){b.render(a)})},update:function(a,b,c,d){var e=this.getInstance(c);e&&e.update(a,b,c,d)},edit:function(a,b){var c=this.getInstance(b);c&&c.edit&&c.edit(c.text,function(d,e){c.update(d,a,b,e)})},remove:function(a,b){var c=this.getInstance(b);c&&c.remove(a,b)}},b.mce.View=function(a){_.extend(this,a),this.initialize()},b.mce.View.extend=Backbone.View.extend,_.extend(b.mce.View.prototype,{content:null,loader:!0,initialize:function(){},getContent:function(){return this.content},render:function(a,b){null!=a&&(this.content=a),a=this.getContent(),(this.loader||a)&&(b&&this.unbind(),this.replaceMarkers(),a?this.setContent(a,function(a,b,d){c(b).data("rendered",!0),this.bindNode.call(this,a,b,d)},b?null:!1):this.setLoader())},bindNode:function(){},unbindNode:function(){},unbind:function(){this.getNodes(function(a,b,d){this.unbindNode.call(this,a,b,d),c(b).trigger("wp-mce-view-unbind")},!0)},getEditors:function(a){_.each(tinymce.editors,function(b){b.plugins.wpview&&a.call(this,b)},this)},getNodes:function(a,b){this.getEditors(function(d){var e=this;c(d.getBody()).find('[data-wpview-text="'+e.encodedText+'"]').filter(function(){var a;return null==b?!0:(a=c(this).data("rendered")===!0,b?a:!a)}).each(function(){a.call(e,d,this,c(this).find(".wpview-content").get(0))})})},getMarkers:function(a){this.getEditors(function(b){var d=this;c(b.getBody()).find('[data-wpview-marker="'+this.encodedText+'"]').each(function(){a.call(d,b,this)})})},replaceMarkers:function(){this.getMarkers(function(a,b){return this.loader||c(b).text()===this.text?void a.dom.replace(a.dom.createFragment('
\xa0
\xa0