diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index acb1e682d8..36b9470267 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -91,6 +91,7 @@ window.wp = window.wp || {}; setMarkers: function( content ) { var pieces = [ { content: content } ], self = this, + instance, current; _.each( views, function( view, type ) { @@ -115,11 +116,11 @@ window.wp = window.wp || {}; pieces.push( { content: remaining.substring( 0, result.index ) } ); } - self.createInstance( type, result.content, result.options ); + instance = self.createInstance( type, result.content, result.options ); // Add the processed piece for the match. pieces.push( { - content: '
' + result.content + '
', + content: '' + instance.text + '
', processed: true } ); @@ -149,8 +150,12 @@ window.wp = window.wp || {}; */ createInstance: function( type, text, options ) { var View = this.get( type ), - encodedText = encodeURIComponent( text ), - instance = this.getInstance( encodedText ); + encodedText, + instance; + + text = tinymce.DOM.decode( text ), + encodedText = encodeURIComponent( text ), + instance = this.getInstance( encodedText ); if ( instance ) { return instance; @@ -754,7 +759,7 @@ window.wp = window.wp || {}; if ( this.url ) { this.loader = false; this.shortcode = wp.media.embed.shortcode( { - url: this.url + url: this.text } ); } @@ -804,7 +809,7 @@ window.wp = window.wp || {}; edit: function( text, update ) { var media = wp.media.embed, - frame = media.edit( text, !! this.url ), + frame = media.edit( text, this.url ), self = this, events = 'change:url change:width change:height'; @@ -819,13 +824,7 @@ window.wp = window.wp || {}; frame.state( 'embed' ).on( 'select', function() { var data = frame.state( 'embed' ).metadata; - if ( data.width ) { - delete self.url; - } else { - self.url = data.url; - } - - if ( self.url ) { + if ( self.url && ! data.width ) { update( data.url ); } else { update( media.shortcode( data ).string() ); @@ -866,7 +865,7 @@ window.wp = window.wp || {}; index: match.index + match[1].length, content: match[2], options: { - url: match[2] + url: true } }; } diff --git a/wp-includes/js/mce-view.min.js b/wp-includes/js/mce-view.min.js index 70c314dfac..892b78d93d 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=[{content:a}],e=this;return _.each(d,function(a,d){b=c.slice(),c=[],_.each(b,function(b){var f,g=b.content;if(b.processed)return void c.push(b);for(;g&&(f=a.prototype.match(g));)f.index&&c.push({content:g.substring(0,f.index)}),e.createInstance(d,f.content,f.options),c.push({content:''+f.content+"
",processed:!0}),g=g.slice(f.index+f.content.length);g&&c.push({content:g})})}),_.pluck(c,"content").join("")},createInstance:function(a,b,c){var d=this.get(a),f=encodeURIComponent(b),g=this.getInstance(f);return g?g:(c=_.extend(c||{},{text:b,encodedText:f}),e[f]=new d(c))},getInstance:function(a){return"string"==typeof a?e[encodeURIComponent(a)]:e[c(a).data("wpview-text")]},getText:function(a){return decodeURIComponent(c(a).data("wpview-text")||"")},render:function(a){_.each(e,function(b){b.render(a)})},update:function(a,b,c){var d=this.getInstance(c);d&&d.update(a,b,c)},edit:function(a,b){var c=this.getInstance(b);c&&c.edit&&c.edit(c.text,function(d){c.update(d,a,b)})},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){(this.loader||this.getContent())&&(a&&this.unbind(),this.replaceMarkers(),this.getContent()?this.setContent(this.getContent(),function(a,b){c(b).data("rendered",!0).trigger("wp-mce-view-bind")},a?null:!1):this.setLoader())},unbind:function(){this.getNodes(function(a,b){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 c(b).text()!==this.text?void a.dom.setAttrib(b,"data-wpview-marker",null):void a.dom.replace(a.dom.createFragment('