From 04494a6c32b78b8f3d72c43c2d3b34f12cdaa644 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Thu, 12 Mar 2015 01:05:54 +0000 Subject: [PATCH] TinyMCE wpViews: always import the non-default editor styles in the sandbox iframe in views. Props iseulde, mattheu. Fixes #31464. Built from https://develop.svn.wordpress.org/trunk@31742 git-svn-id: http://core.svn.wordpress.org/trunk@31723 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/mce-view.js | 38 ++++++++++++++-------------------- wp-includes/js/mce-view.min.js | 2 +- wp-includes/version.php | 2 +- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index c2db6cef88..4a7b96b1c6 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -461,8 +461,7 @@ window.wp = window.wp || {}; * @param {Boolean} rendered Only set for (un)rendered nodes. Optional. */ setIframes: function( head, body, callback, rendered ) { - var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver, - importStyles = this.type === 'video' || this.type === 'audio' || this.type === 'playlist'; + var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver; this.getNodes( function( editor, node, content ) { // Seems Firefox needs a bit of time to insert/set the view nodes, @@ -473,21 +472,18 @@ window.wp = window.wp || {}; bodyClasses = editor.getBody().className || '', iframe, iframeDoc, observer, i; - if ( importStyles ) { - if ( ! wp.mce.views.sandboxStyles ) { - tinymce.each( dom.$( 'link[rel="stylesheet"]', editor.getDoc().head ), function( link ) { - if ( link.href && link.href.indexOf( 'skins/lightgray/content.min.css' ) === -1 && - link.href.indexOf( 'skins/wordpress/wp-content.css' ) === -1 ) { - - styles += dom.getOuterHTML( link ) + '\n'; - } - }); - - wp.mce.views.sandboxStyles = styles; - } else { - styles = wp.mce.views.sandboxStyles; + tinymce.each( dom.$( + 'link[rel="stylesheet"]', + editor.getDoc().getElementsByTagName( 'head' )[0] + ), function( link ) { + if ( + link.href && + link.href.indexOf( 'skins/lightgray/content.min.css' ) >= 0 && + link.href.indexOf( 'skins/wordpress/wp-content.css' ) >= 0 + ) { + styles += dom.getOuterHTML( link ); } - } + } ); content.innerHTML = ''; @@ -580,13 +576,11 @@ window.wp = window.wp || {}; iframeDoc.body.className = editor.getBody().className; } - if ( importStyles ) { - editor.on( 'wp-body-class-change', classChange ); + editor.on( 'wp-body-class-change', classChange ); - $( node ).one( 'wp-mce-view-unbind', function() { - editor.off( 'wp-body-class-change', classChange ); - } ); - } + $( node ).one( 'wp-mce-view-unbind', function() { + editor.off( 'wp-body-class-change', classChange ); + } ); callback && callback.apply( this, arguments ); }, 50 ); diff --git a/wp-includes/js/mce-view.min.js b/wp-includes/js/mce-view.min.js index 79d1c51dc8..a8afa9ae53 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=c.content;if(c.processed)return void e.push(c);for(;h&&(g=a.prototype.match(h));)g.index&&e.push({content:h.substring(0,g.index)}),b=f.createInstance(d,g.content,g.options),e.push({content:'

'+b.text+"

",processed:!0}),h=h.slice(g.index+g.content.length);h&&e.push({content:h})})}),_.pluck(e,"content").join("")},createInstance:function(a,b,c){var d,f,g=this.get(a);return b=tinymce.DOM.decode(b),d=encodeURIComponent(b),(f=this.getInstance(d))?f:(c=_.extend(c||{},{text:b,encodedText:d}),e[d]=new g(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){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('

 

 

'),b)})},removeMarkers:function(){this.getMarkers(function(a,b){a.dom.setAttrib(b,"data-wpview-marker",null)})},setContent:function(a,b,c){_.isObject(a)&&-1!==a.body.indexOf("'),e.innerHTML="",e.appendChild(_.isString(a)?c.dom.createFragment(a):a),b&&b.apply(this,arguments)},c)},setIframes:function(d,e,f,g){var h=a.MutationObserver||a.WebKitMutationObserver||a.MozMutationObserver,i="video"===this.type||"audio"===this.type||"playlist"===this.type;this.getNodes(function(a,g,j){setTimeout(function(){function k(){var b,d;m.contentWindow&&(b=c(m),d=c(n.body).height(),b.height()!==d&&(b.height(d),a.nodeChanged()))}function l(){n.body.className=a.getBody().className}var m,n,o,p,q=a.dom,r="",s=a.getBody().className||"";if(i&&(b.mce.views.sandboxStyles?r=b.mce.views.sandboxStyles:(tinymce.each(q.$('link[rel="stylesheet"]',a.getDoc().head),function(a){a.href&&-1===a.href.indexOf("skins/lightgray/content.min.css")&&-1===a.href.indexOf("skins/wordpress/wp-content.css")&&(r+=q.getOuterHTML(a)+"\n")}),b.mce.views.sandboxStyles=r)),j.innerHTML="",m=q.add(j,"iframe",{src:tinymce.Env.ie?'javascript:""':"",frameBorder:"0",allowTransparency:"true",scrolling:"no","class":"wpview-sandbox",style:{width:"100%",display:"block"}}),q.add(j,"div",{"class":"wpview-overlay"}),n=m.contentWindow.document,n.open(),n.write(''+d+r+''+e+""),n.close(),h)o=new h(_.debounce(k,100)),o.observe(n.body,{attributes:!0,childList:!0,subtree:!0}),c(g).one("wp-mce-view-unbind",function(){o.disconnect()});else for(p=1;6>p;p++)setTimeout(k,700*p);i&&(a.on("wp-body-class-change",l),c(g).one("wp-mce-view-unbind",function(){a.off("wp-body-class-change",l)})),f&&f.apply(this,arguments)},50)},g)},setLoader:function(){this.setContent('
')},setError:function(a,b){this.setContent('

'+a+"

")},match:function(a){var c=b.shortcode.next(this.type,a);return c?{index:c.index,content:c.content,options:{shortcode:c.shortcode}}:void 0},update:function(a,e,f){_.find(d,function(d,g){var h=d.prototype.match(a);return h?(c(f).data("rendered",!1),e.dom.setAttrib(f,"data-wpview-text",encodeURIComponent(a)),b.mce.views.createInstance(g,a,h.options).render(),!0):void 0})},remove:function(a,b){c(b).trigger("wp-mce-view-unbind"),a.dom.remove(b)}})}(window,window.wp,window.jQuery),function(a,b,c){var d,e,f,g,h=c("#post_ID").val()||0;d={state:[],edit:function(a,b){var c=wp.media[this.type],d=c.edit(a);this.pausePlayers&&this.pausePlayers(),_.each(this.state,function(a){d.state(a).on("update",function(a){b(c.shortcode(a).string())})}),d.on("close",function(){d.detach()}),d.open()}},e=_.extend({},d,{state:["gallery-edit"],template:wp.media.template("editor-gallery"),initialize:function(){var a=wp.media.gallery.attachments(this.shortcode,h),b=this.shortcode.attrs.named,c=this;a.more().done(function(){a=a.toJSON(),_.each(a,function(a){a.sizes&&(b.size&&a.sizes[b.size]?a.thumbnail=a.sizes[b.size]:a.sizes.thumbnail?a.thumbnail=a.sizes.thumbnail:a.sizes.full&&(a.thumbnail=a.sizes.full))}),c.content=c.template({attachments:a,columns:b.columns?parseInt(b.columns,10):wp.media.galleryDefaults.columns}),c.render()}).fail(function(a,b){c.setError(b)})}}),f=_.extend({},d,{action:"parse-media-shortcode",initialize:function(){var a=this;this.url&&(this.loader=!1,this.shortcode=wp.media.embed.shortcode({url:this.text})),wp.ajax.send(this.action,{data:{post_ID:h,type:this.shortcode.tag,shortcode:this.shortcode.string()}}).done(function(b){a.content=b,a.render()}).fail(function(b){a.url?a.removeMarkers():a.setError(b.message||b.statusText,"admin-media")}),this.getEditors(function(b){b.on("wpview-selected",function(){a.pausePlayers()})})},pausePlayers:function(){this.getNodes(function(a,b,d){var e=c("iframe.wpview-sandbox",d).get(0);e&&(e=e.contentWindow)&&e.mejs&&_.each(e.mejs.players,function(a){try{a.pause()}catch(b){}})})}}),g=_.extend({},f,{action:"parse-embed",edit:function(a,b){var c=wp.media.embed,d=c.edit(a,this.url),e=this,f="change:url change:width change:height";this.pausePlayers(),d.state("embed").props.on(f,function(a,b){b&&a.get("url")&&(d.state("embed").metadata=a.toJSON())}),d.state("embed").on("select",function(){var a=d.state("embed").metadata;b(e.url&&!a.width?a.url:c.shortcode(a).string())}),d.on("close",function(){d.detach()}),d.open()}}),b.register("gallery",_.extend({},e)),b.register("audio",_.extend({},f,{state:["audio-details"]})),b.register("video",_.extend({},f,{state:["video-details"]})),b.register("playlist",_.extend({},f,{state:["playlist-edit","video-playlist-edit"]})),b.register("embed",_.extend({},g)),b.register("embedURL",_.extend({},g,{match:function(a){var b=/(^|

)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi,c=b.exec(a);return c?{index:c.index+c[1].length,content:c[2],options:{url:!0}}:void 0}}))}(window,window.wp.mce.views,window.jQuery); \ No newline at end of file +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=c.content;if(c.processed)return void e.push(c);for(;h&&(g=a.prototype.match(h));)g.index&&e.push({content:h.substring(0,g.index)}),b=f.createInstance(d,g.content,g.options),e.push({content:'

'+b.text+"

",processed:!0}),h=h.slice(g.index+g.content.length);h&&e.push({content:h})})}),_.pluck(e,"content").join("")},createInstance:function(a,b,c){var d,f,g=this.get(a);return b=tinymce.DOM.decode(b),d=encodeURIComponent(b),(f=this.getInstance(d))?f:(c=_.extend(c||{},{text:b,encodedText:d}),e[d]=new g(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){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('

 

 

'),b)})},removeMarkers:function(){this.getMarkers(function(a,b){a.dom.setAttrib(b,"data-wpview-marker",null)})},setContent:function(a,b,c){_.isObject(a)&&-1!==a.body.indexOf("'),e.innerHTML="",e.appendChild(_.isString(a)?c.dom.createFragment(a):a),b&&b.apply(this,arguments)},c)},setIframes:function(b,d,e,f){var g=a.MutationObserver||a.WebKitMutationObserver||a.MozMutationObserver;this.getNodes(function(a,f,h){setTimeout(function(){function i(){var b,d;k.contentWindow&&(b=c(k),d=c(l.body).height(),b.height()!==d&&(b.height(d),a.nodeChanged()))}function j(){l.body.className=a.getBody().className}var k,l,m,n,o=a.dom,p="",q=a.getBody().className||"";if(tinymce.each(o.$('link[rel="stylesheet"]',a.getDoc().getElementsByTagName("head")[0]),function(a){a.href&&a.href.indexOf("skins/lightgray/content.min.css")>=0&&a.href.indexOf("skins/wordpress/wp-content.css")>=0&&(p+=o.getOuterHTML(a))}),h.innerHTML="",k=o.add(h,"iframe",{src:tinymce.Env.ie?'javascript:""':"",frameBorder:"0",allowTransparency:"true",scrolling:"no","class":"wpview-sandbox",style:{width:"100%",display:"block"}}),o.add(h,"div",{"class":"wpview-overlay"}),l=k.contentWindow.document,l.open(),l.write(''+b+p+''+d+""),l.close(),g)m=new g(_.debounce(i,100)),m.observe(l.body,{attributes:!0,childList:!0,subtree:!0}),c(f).one("wp-mce-view-unbind",function(){m.disconnect()});else for(n=1;6>n;n++)setTimeout(i,700*n);a.on("wp-body-class-change",j),c(f).one("wp-mce-view-unbind",function(){a.off("wp-body-class-change",j)}),e&&e.apply(this,arguments)},50)},f)},setLoader:function(){this.setContent('
')},setError:function(a,b){this.setContent('

'+a+"

")},match:function(a){var c=b.shortcode.next(this.type,a);return c?{index:c.index,content:c.content,options:{shortcode:c.shortcode}}:void 0},update:function(a,e,f){_.find(d,function(d,g){var h=d.prototype.match(a);return h?(c(f).data("rendered",!1),e.dom.setAttrib(f,"data-wpview-text",encodeURIComponent(a)),b.mce.views.createInstance(g,a,h.options).render(),!0):void 0})},remove:function(a,b){c(b).trigger("wp-mce-view-unbind"),a.dom.remove(b)}})}(window,window.wp,window.jQuery),function(a,b,c){var d,e,f,g,h=c("#post_ID").val()||0;d={state:[],edit:function(a,b){var c=wp.media[this.type],d=c.edit(a);this.pausePlayers&&this.pausePlayers(),_.each(this.state,function(a){d.state(a).on("update",function(a){b(c.shortcode(a).string())})}),d.on("close",function(){d.detach()}),d.open()}},e=_.extend({},d,{state:["gallery-edit"],template:wp.media.template("editor-gallery"),initialize:function(){var a=wp.media.gallery.attachments(this.shortcode,h),b=this.shortcode.attrs.named,c=this;a.more().done(function(){a=a.toJSON(),_.each(a,function(a){a.sizes&&(b.size&&a.sizes[b.size]?a.thumbnail=a.sizes[b.size]:a.sizes.thumbnail?a.thumbnail=a.sizes.thumbnail:a.sizes.full&&(a.thumbnail=a.sizes.full))}),c.content=c.template({attachments:a,columns:b.columns?parseInt(b.columns,10):wp.media.galleryDefaults.columns}),c.render()}).fail(function(a,b){c.setError(b)})}}),f=_.extend({},d,{action:"parse-media-shortcode",initialize:function(){var a=this;this.url&&(this.loader=!1,this.shortcode=wp.media.embed.shortcode({url:this.text})),wp.ajax.send(this.action,{data:{post_ID:h,type:this.shortcode.tag,shortcode:this.shortcode.string()}}).done(function(b){a.content=b,a.render()}).fail(function(b){a.url?a.removeMarkers():a.setError(b.message||b.statusText,"admin-media")}),this.getEditors(function(b){b.on("wpview-selected",function(){a.pausePlayers()})})},pausePlayers:function(){this.getNodes(function(a,b,d){var e=c("iframe.wpview-sandbox",d).get(0);e&&(e=e.contentWindow)&&e.mejs&&_.each(e.mejs.players,function(a){try{a.pause()}catch(b){}})})}}),g=_.extend({},f,{action:"parse-embed",edit:function(a,b){var c=wp.media.embed,d=c.edit(a,this.url),e=this,f="change:url change:width change:height";this.pausePlayers(),d.state("embed").props.on(f,function(a,b){b&&a.get("url")&&(d.state("embed").metadata=a.toJSON())}),d.state("embed").on("select",function(){var a=d.state("embed").metadata;b(e.url&&!a.width?a.url:c.shortcode(a).string())}),d.on("close",function(){d.detach()}),d.open()}}),b.register("gallery",_.extend({},e)),b.register("audio",_.extend({},f,{state:["audio-details"]})),b.register("video",_.extend({},f,{state:["video-details"]})),b.register("playlist",_.extend({},f,{state:["playlist-edit","video-playlist-edit"]})),b.register("embed",_.extend({},g)),b.register("embedURL",_.extend({},g,{match:function(a){var b=/(^|

)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi,c=b.exec(a);return c?{index:c.index+c[1].length,content:c[2],options:{url:!0}}:void 0}}))}(window,window.wp.mce.views,window.jQuery); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index 0a964df9ea..10f5088bc3 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31741'; +$wp_version = '4.2-alpha-31742'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.