From ee8813606d5d471a7b8895fa5b512cc91e2febd7 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Fri, 12 Jul 2019 03:25:55 +0000 Subject: [PATCH] TinyMCE: fix adding of too many undo levels for wpviews. The HTML changes several times when a wpview is added. We only want one undo level. Also fixes cases when the cursor is next to an embeddable URL in the Text tab and the user switches to the Visual tab. See #45307. Built from https://develop.svn.wordpress.org/trunk@45631 git-svn-id: http://core.svn.wordpress.org/trunk@45442 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/js/mce-view.js | 15 ++++++---- wp-includes/js/mce-view.min.js | 2 +- .../js/tinymce/plugins/wpview/plugin.js | 28 ++++++++++++++++--- .../js/tinymce/plugins/wpview/plugin.min.js | 2 +- wp-includes/js/tinymce/wp-tinymce.js | 2 +- wp-includes/version.php | 2 +- 6 files changed, 38 insertions(+), 13 deletions(-) diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index e69c748a10..e0439c41c7 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -444,12 +444,16 @@ '
' ); - editor.$( node ).replaceWith( $viewNode ); + editor.undoManager.ignore( function() { + editor.$( node ).replaceWith( $viewNode ); + } ); if ( selected ) { setTimeout( function() { - editor.selection.select( $viewNode[0] ); - editor.selection.collapse(); + editor.undoManager.ignore( function() { + editor.selection.select( $viewNode[0] ); + editor.selection.collapse(); + } ); } ); } } ); @@ -961,8 +965,9 @@ views.register( 'embedURL', _.extend( {}, embed, { match: function( content ) { - var re = /(^|

)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi, - match = re.exec( content ); + // There may be a "bookmark" node next to the URL... + var re = /(^|

(?:]+>\s*<\/span>)?)(https?:\/\/[^\s"]+?)((?:]+>\s*<\/span>)?<\/p>\s*|$)/gi; + var match = re.exec( content ); if ( match ) { return { diff --git a/wp-includes/js/mce-view.min.js b/wp-includes/js/mce-view.min.js index 4188bd6065..86e0166fd1 100644 --- a/wp-includes/js/mce-view.min.js +++ b/wp-includes/js/mce-view.min.js @@ -1 +1 @@ -!function(a,b,c,d){"use strict";var e={},f={};b.mce=b.mce||{},b.mce.views={register:function(a,c){e[a]=b.mce.View.extend(_.extend(c,{type:a}))},unregister:function(a){delete e[a]},get:function(a){return e[a]},unbind:function(){_.each(f,function(a){a.unbind()})},setMarkers:function(a,b){var c,d,f=[{content:a}],g=this;return _.each(e,function(a,e){d=f.slice(),f=[],_.each(d,function(d){var h,i,j=d.content;if(d.processed)return void f.push(d);for(;j&&(h=a.prototype.match(j));)h.index&&f.push({content:j.substring(0,h.index)}),h.options.editor=b,c=g.createInstance(e,h.content,h.options),i=c.loader?".":c.text,f.push({content:c.ignore?i:'

'+i+"

",processed:!0}),j=j.slice(h.index+h.content.length);j&&f.push({content:j})})}),a=_.pluck(f,"content").join(""),a.replace(/

\s*

")},createInstance:function(a,b,c,d){var e,g,h=this.get(a);return b.indexOf("[")!==-1&&b.indexOf("]")!==-1&&(b=b.replace(/\[[^\]]+\]/g,function(a){return a.replace(/[\r\n]/g,"")})),!d&&(g=this.getInstance(b))?g:(e=encodeURIComponent(b),c=_.extend(c||{},{text:b,encodedText:e}),f[e]=new h(c))},getInstance:function(a){return"string"==typeof a?f[encodeURIComponent(a)]:f[d(a).attr("data-wpview-text")]},getText:function(a){return decodeURIComponent(d(a).attr("data-wpview-text")||"")},render:function(a){_.each(f,function(b){b.render(null,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(b).data("rendered",!0),this.bindNode.call(this,a,b)},!!b&&null):this.setLoader())},bindNode:function(){},unbindNode:function(){},unbind:function(){this.getNodes(function(a,b){this.unbindNode.call(this,a,b)},!0)},getEditors:function(a){_.each(tinymce.editors,function(b){b.plugins.wpview&&a.call(this,b)},this)},getNodes:function(a,b){this.getEditors(function(c){var e=this;d(c.getBody()).find('[data-wpview-text="'+e.encodedText+'"]').filter(function(){var a;return null==b||(a=d(this).data("rendered")===!0,b?a:!a)}).each(function(){a.call(e,c,this,this)})})},getMarkers:function(a){this.getEditors(function(b){var c=this;d(b.getBody()).find('[data-wpview-marker="'+this.encodedText+'"]').each(function(){a.call(c,b,this)})})},replaceMarkers:function(){this.getMarkers(function(a,b){var c,e=b===a.selection.getNode();return this.loader||d(b).text()===tinymce.DOM.decode(this.text)?(c=a.$('

'),a.$(b).replaceWith(c),void(e&&setTimeout(function(){a.selection.select(c[0]),a.selection.collapse()}))):void a.dom.setAttrib(b,"data-wpview-marker",null)})},removeMarkers:function(){this.getMarkers(function(a,b){a.dom.setAttrib(b,"data-wpview-marker",null)})},setContent:function(a,b,c){_.isObject(a)&&(a.sandbox||a.head||a.body.indexOf("'),c.undoManager.transact(function(){d.innerHTML="",d.appendChild(_.isString(a)?c.dom.createFragment(a):a),c.dom.add(d,"span",{"class":"wpview-end"})}),b&&b.call(this,c,d)},c)},setIframes:function(c,e,f,g){var h=this;if(e.indexOf("[")!==-1&&e.indexOf("]")!==-1){var i=new RegExp("\\[\\/?(?:"+a.mceViewL10n.shortcodes.join("|")+")[^\\]]*?\\]","g");e=e.replace(i,function(a){return a.replace(//g,">")})}this.getNodes(function(a,g){function i(){var b;r||l.contentWindow&&(b=d(l),h.iframeHeight=d(n.body).height(),b.height()!==h.iframeHeight&&(b.height(h.iframeHeight),a.nodeChanged()))}function j(){a.isHidden()||(d(g).data("rendered",null),setTimeout(function(){b.mce.views.render()}))}function k(){p=new o(_.debounce(i,100)),p.observe(n.body,{attributes:!0,childList:!0,subtree:!0})}var l,m,n,o,p,q,r,s=a.dom,t="",u=a.getBody().className||"",v=a.getDoc().getElementsByTagName("head")[0];if(tinymce.each(s.$('link[rel="stylesheet"]',v),function(a){a.href&&a.href.indexOf("skins/lightgray/content.min.css")===-1&&a.href.indexOf("skins/wordpress/wp-content.css")===-1&&(t+=s.getOuterHTML(a))}),h.iframeHeight&&s.add(g,"span",{"data-mce-bogus":1,style:{display:"block",width:"100%",height:h.iframeHeight}},"\u200b"),a.undoManager.transact(function(){g.innerHTML="",l=s.add(g,"iframe",{src:tinymce.Env.ie?'javascript:""':"",frameBorder:"0",allowTransparency:"true",scrolling:"no","class":"wpview-sandbox",style:{width:"100%",display:"block"},height:h.iframeHeight}),s.add(g,"span",{"class":"mce-shim"}),s.add(g,"span",{"class":"wpview-end"})}),l.contentWindow){if(m=l.contentWindow,n=m.document,n.open(),n.write(''+c+t+''+e+""),n.close(),h.iframeHeight&&(r=!0,setTimeout(function(){r=!1,i()},3e3)),d(m).on("load",i).on("unload",j),o=m.MutationObserver||m.WebKitMutationObserver||m.MozMutationObserver)n.body?k():n.addEventListener("DOMContentLoaded",k,!1);else for(q=1;q<6;q++)setTimeout(i,700*q);f&&f.call(h,a,g)}},g)},setLoader:function(a){this.setContent('
')},setError:function(a,b){this.setContent('

'+a+"

")},match:function(a){var b=c.next(this.type,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}},update:function(a,c,f,g){_.find(e,function(e,h){var i=e.prototype.match(a);if(i)return d(f).data("rendered",!1),c.dom.setAttrib(f,"data-wpview-text",encodeURIComponent(a)),b.mce.views.createInstance(h,a,i.options,g).render(),c.selection.select(f),c.nodeChanged(),c.focus(),!0})},remove:function(a,b){this.unbindNode.call(this,a,b),a.dom.remove(b),a.focus()}})}(window,window.wp,window.wp.shortcode,window.jQuery),function(a,b,c,d){function e(b){var c={};return a.tinymce?!b||b.indexOf("<")===-1&&b.indexOf(">")===-1?b:(j=j||new a.tinymce.html.Schema(c),k=k||new a.tinymce.html.DomParser(c,j),l=l||new a.tinymce.html.Serializer(c,j),l.serialize(k.parse(b,{forced_root_block:!1}))):b.replace(/<[^>]+>/g,"")}var f,g,h,i,j,k,l;f={state:[],edit:function(a,b){var d=this.type,e=c[d].edit(a);this.pausePlayers&&this.pausePlayers(),_.each(this.state,function(a){e.state(a).on("update",function(a){b(c[d].shortcode(a).string(),"gallery"===d)})}),e.on("close",function(){e.detach()}),e.open()}},g=_.extend({},f,{state:["gallery-edit"],template:c.template("editor-gallery"),initialize:function(){var a=c.gallery.attachments(this.shortcode,c.view.settings.post.id),b=this.shortcode.attrs.named,d=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))}),d.render(d.template({verifyHTML:e,attachments:a,columns:b.columns?parseInt(b.columns,10):c.galleryDefaults.columns}))}).fail(function(a,b){d.setError(b)})}}),h=_.extend({},f,{action:"parse-media-shortcode",initialize:function(){var a=this,b=null;this.url&&(this.loader=!1,this.shortcode=c.embed.shortcode({url:this.text})),a.editor&&(b=a.editor.getBody().clientWidth),wp.ajax.post(this.action,{post_ID:c.view.settings.post.id,type:this.shortcode.tag,shortcode:this.shortcode.string(),maxwidth:b}).done(function(b){a.render(b)}).fail(function(b){a.url?(a.ignore=!0,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,c){var e=d("iframe.wpview-sandbox",c).get(0);e&&(e=e.contentWindow)&&e.mejs&&_.each(e.mejs.players,function(a){try{a.pause()}catch(b){}})})}}),i=_.extend({},h,{action:"parse-embed",edit:function(a,b){var d=c.embed.edit(a,this.url),e=this;this.pausePlayers(),d.state("embed").props.on("change:url",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.url:c.embed.shortcode(a).string())}),d.on("close",function(){d.detach()}),d.open()}}),b.register("gallery",_.extend({},g)),b.register("audio",_.extend({},h,{state:["audio-details"]})),b.register("video",_.extend({},h,{state:["video-details"]})),b.register("playlist",_.extend({},h,{state:["playlist-edit","video-playlist-edit"]})),b.register("embed",_.extend({},i)),b.register("embedURL",_.extend({},i,{match:function(a){var b=/(^|

)(https?:\/\/[^\s"]+?)(<\/p>\s*|$)/gi,c=b.exec(a);if(c)return{index:c.index+c[1].length,content:c[2],options:{url:!0}}}}))}(window,window.wp.mce.views,window.wp.media,window.jQuery); \ No newline at end of file +!function(a,b,c,d){"use strict";var e={},f={};b.mce=b.mce||{},b.mce.views={register:function(a,c){e[a]=b.mce.View.extend(_.extend(c,{type:a}))},unregister:function(a){delete e[a]},get:function(a){return e[a]},unbind:function(){_.each(f,function(a){a.unbind()})},setMarkers:function(a,b){var c,d,f=[{content:a}],g=this;return _.each(e,function(a,e){d=f.slice(),f=[],_.each(d,function(d){var h,i,j=d.content;if(d.processed)return void f.push(d);for(;j&&(h=a.prototype.match(j));)h.index&&f.push({content:j.substring(0,h.index)}),h.options.editor=b,c=g.createInstance(e,h.content,h.options),i=c.loader?".":c.text,f.push({content:c.ignore?i:'

'+i+"

",processed:!0}),j=j.slice(h.index+h.content.length);j&&f.push({content:j})})}),a=_.pluck(f,"content").join(""),a.replace(/

\s*

")},createInstance:function(a,b,c,d){var e,g,h=this.get(a);return b.indexOf("[")!==-1&&b.indexOf("]")!==-1&&(b=b.replace(/\[[^\]]+\]/g,function(a){return a.replace(/[\r\n]/g,"")})),!d&&(g=this.getInstance(b))?g:(e=encodeURIComponent(b),c=_.extend(c||{},{text:b,encodedText:e}),f[e]=new h(c))},getInstance:function(a){return"string"==typeof a?f[encodeURIComponent(a)]:f[d(a).attr("data-wpview-text")]},getText:function(a){return decodeURIComponent(d(a).attr("data-wpview-text")||"")},render:function(a){_.each(f,function(b){b.render(null,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(b).data("rendered",!0),this.bindNode.call(this,a,b)},!!b&&null):this.setLoader())},bindNode:function(){},unbindNode:function(){},unbind:function(){this.getNodes(function(a,b){this.unbindNode.call(this,a,b)},!0)},getEditors:function(a){_.each(tinymce.editors,function(b){b.plugins.wpview&&a.call(this,b)},this)},getNodes:function(a,b){this.getEditors(function(c){var e=this;d(c.getBody()).find('[data-wpview-text="'+e.encodedText+'"]').filter(function(){var a;return null==b||(a=d(this).data("rendered")===!0,b?a:!a)}).each(function(){a.call(e,c,this,this)})})},getMarkers:function(a){this.getEditors(function(b){var c=this;d(b.getBody()).find('[data-wpview-marker="'+this.encodedText+'"]').each(function(){a.call(c,b,this)})})},replaceMarkers:function(){this.getMarkers(function(a,b){var c,e=b===a.selection.getNode();return this.loader||d(b).text()===tinymce.DOM.decode(this.text)?(c=a.$('

'),a.undoManager.ignore(function(){a.$(b).replaceWith(c)}),void(e&&setTimeout(function(){a.undoManager.ignore(function(){a.selection.select(c[0]),a.selection.collapse()})}))):void a.dom.setAttrib(b,"data-wpview-marker",null)})},removeMarkers:function(){this.getMarkers(function(a,b){a.dom.setAttrib(b,"data-wpview-marker",null)})},setContent:function(a,b,c){_.isObject(a)&&(a.sandbox||a.head||a.body.indexOf("'),c.undoManager.transact(function(){d.innerHTML="",d.appendChild(_.isString(a)?c.dom.createFragment(a):a),c.dom.add(d,"span",{"class":"wpview-end"})}),b&&b.call(this,c,d)},c)},setIframes:function(c,e,f,g){var h=this;if(e.indexOf("[")!==-1&&e.indexOf("]")!==-1){var i=new RegExp("\\[\\/?(?:"+a.mceViewL10n.shortcodes.join("|")+")[^\\]]*?\\]","g");e=e.replace(i,function(a){return a.replace(//g,">")})}this.getNodes(function(a,g){function i(){var b;r||l.contentWindow&&(b=d(l),h.iframeHeight=d(n.body).height(),b.height()!==h.iframeHeight&&(b.height(h.iframeHeight),a.nodeChanged()))}function j(){a.isHidden()||(d(g).data("rendered",null),setTimeout(function(){b.mce.views.render()}))}function k(){p=new o(_.debounce(i,100)),p.observe(n.body,{attributes:!0,childList:!0,subtree:!0})}var l,m,n,o,p,q,r,s=a.dom,t="",u=a.getBody().className||"",v=a.getDoc().getElementsByTagName("head")[0];if(tinymce.each(s.$('link[rel="stylesheet"]',v),function(a){a.href&&a.href.indexOf("skins/lightgray/content.min.css")===-1&&a.href.indexOf("skins/wordpress/wp-content.css")===-1&&(t+=s.getOuterHTML(a))}),h.iframeHeight&&s.add(g,"span",{"data-mce-bogus":1,style:{display:"block",width:"100%",height:h.iframeHeight}},"\u200b"),a.undoManager.transact(function(){g.innerHTML="",l=s.add(g,"iframe",{src:tinymce.Env.ie?'javascript:""':"",frameBorder:"0",allowTransparency:"true",scrolling:"no","class":"wpview-sandbox",style:{width:"100%",display:"block"},height:h.iframeHeight}),s.add(g,"span",{"class":"mce-shim"}),s.add(g,"span",{"class":"wpview-end"})}),l.contentWindow){if(m=l.contentWindow,n=m.document,n.open(),n.write(''+c+t+''+e+""),n.close(),h.iframeHeight&&(r=!0,setTimeout(function(){r=!1,i()},3e3)),d(m).on("load",i).on("unload",j),o=m.MutationObserver||m.WebKitMutationObserver||m.MozMutationObserver)n.body?k():n.addEventListener("DOMContentLoaded",k,!1);else for(q=1;q<6;q++)setTimeout(i,700*q);f&&f.call(h,a,g)}},g)},setLoader:function(a){this.setContent('
')},setError:function(a,b){this.setContent('

'+a+"

")},match:function(a){var b=c.next(this.type,a);if(b)return{index:b.index,content:b.content,options:{shortcode:b.shortcode}}},update:function(a,c,f,g){_.find(e,function(e,h){var i=e.prototype.match(a);if(i)return d(f).data("rendered",!1),c.dom.setAttrib(f,"data-wpview-text",encodeURIComponent(a)),b.mce.views.createInstance(h,a,i.options,g).render(),c.selection.select(f),c.nodeChanged(),c.focus(),!0})},remove:function(a,b){this.unbindNode.call(this,a,b),a.dom.remove(b),a.focus()}})}(window,window.wp,window.wp.shortcode,window.jQuery),function(a,b,c,d){function e(b){var c={};return a.tinymce?!b||b.indexOf("<")===-1&&b.indexOf(">")===-1?b:(j=j||new a.tinymce.html.Schema(c),k=k||new a.tinymce.html.DomParser(c,j),l=l||new a.tinymce.html.Serializer(c,j),l.serialize(k.parse(b,{forced_root_block:!1}))):b.replace(/<[^>]+>/g,"")}var f,g,h,i,j,k,l;f={state:[],edit:function(a,b){var d=this.type,e=c[d].edit(a);this.pausePlayers&&this.pausePlayers(),_.each(this.state,function(a){e.state(a).on("update",function(a){b(c[d].shortcode(a).string(),"gallery"===d)})}),e.on("close",function(){e.detach()}),e.open()}},g=_.extend({},f,{state:["gallery-edit"],template:c.template("editor-gallery"),initialize:function(){var a=c.gallery.attachments(this.shortcode,c.view.settings.post.id),b=this.shortcode.attrs.named,d=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))}),d.render(d.template({verifyHTML:e,attachments:a,columns:b.columns?parseInt(b.columns,10):c.galleryDefaults.columns}))}).fail(function(a,b){d.setError(b)})}}),h=_.extend({},f,{action:"parse-media-shortcode",initialize:function(){var a=this,b=null;this.url&&(this.loader=!1,this.shortcode=c.embed.shortcode({url:this.text})),a.editor&&(b=a.editor.getBody().clientWidth),wp.ajax.post(this.action,{post_ID:c.view.settings.post.id,type:this.shortcode.tag,shortcode:this.shortcode.string(),maxwidth:b}).done(function(b){a.render(b)}).fail(function(b){a.url?(a.ignore=!0,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,c){var e=d("iframe.wpview-sandbox",c).get(0);e&&(e=e.contentWindow)&&e.mejs&&_.each(e.mejs.players,function(a){try{a.pause()}catch(b){}})})}}),i=_.extend({},h,{action:"parse-embed",edit:function(a,b){var d=c.embed.edit(a,this.url),e=this;this.pausePlayers(),d.state("embed").props.on("change:url",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.url:c.embed.shortcode(a).string())}),d.on("close",function(){d.detach()}),d.open()}}),b.register("gallery",_.extend({},g)),b.register("audio",_.extend({},h,{state:["audio-details"]})),b.register("video",_.extend({},h,{state:["video-details"]})),b.register("playlist",_.extend({},h,{state:["playlist-edit","video-playlist-edit"]})),b.register("embed",_.extend({},i)),b.register("embedURL",_.extend({},i,{match:function(a){var b=/(^|

(?:]+>\s*<\/span>)?)(https?:\/\/[^\s"]+?)((?:]+>\s*<\/span>)?<\/p>\s*|$)/gi,c=b.exec(a);if(c)return{index:c.index+c[1].length,content:c[2],options:{url:!0}}}}))}(window,window.wp.mce.views,window.wp.media,window.jQuery); \ No newline at end of file diff --git a/wp-includes/js/tinymce/plugins/wpview/plugin.js b/wp-includes/js/tinymce/plugins/wpview/plugin.js index 1e3968d2c3..573ecb4167 100644 --- a/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -25,7 +25,7 @@ return '

' + window.decodeURIComponent( $1 ) + '

'; } - if ( ! content ) { + if ( ! content || content.indexOf( ' data-wpview-' ) === -1 ) { return content; } @@ -111,10 +111,30 @@ event.content = resetViews( event.content ); } ); - // Replace views with their text inside undo levels. - // This also prevents that new levels are added when there are changes inside the views. + // Prevent adding of undo levels when replacing wpview markers + // or when there are changes only in the (non-editable) previews. editor.on( 'beforeaddundo', function( event ) { - event.level.content = resetViews( event.level.content ); + var lastContent; + var newContent = event.level.content || ( event.level.fragments && event.level.fragments.join( '' ) ); + + if ( ! event.lastLevel ) { + lastContent = editor.startContent; + } else { + lastContent = event.lastLevel.content || ( event.lastLevel.fragments && event.lastLevel.fragments.join( '' ) ); + } + + if ( + ! newContent || + ! lastContent || + newContent.indexOf( ' data-wpview-' ) === -1 || + lastContent.indexOf( ' data-wpview-' ) === -1 + ) { + return; + } + + if ( resetViews( lastContent ) === resetViews( newContent ) ) { + event.preventDefault(); + } } ); // Make sure views are copied as their text. diff --git a/wp-includes/js/tinymce/plugins/wpview/plugin.min.js b/wp-includes/js/tinymce/plugins/wpview/plugin.min.js index de739675be..a9162a673d 100644 --- a/wp-includes/js/tinymce/plugins/wpview/plugin.min.js +++ b/wp-includes/js/tinymce/plugins/wpview/plugin.min.js @@ -1 +1 @@ -!function(a){a.PluginManager.add("wpview",function(b){function c(){}function d(a){return b.dom.hasClass(a,"wpview")}function e(a){function b(a,b){return"

"+window.decodeURIComponent(b)+"

"}return a?a.replace(/]+data-wpview-text="([^"]+)"[^>]*>(?:\.|[\s\S]+?wpview-end[^>]+>\s*<\/span>\s*)?<\/div>/g,b).replace(/]+data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g,b):a}var f=window.wp;return f&&f.mce&&f.mce.views?(b.on("init",function(){var a=window.MutationObserver||window.WebKitMutationObserver;a&&new a(function(){b.fire("wp-body-class-change")}).observe(b.getBody(),{attributes:!0,attributeFilter:["class"]}),b.on("wp-body-class-change",function(){var a=b.getBody().className;b.$('iframe[class="wpview-sandbox"]').each(function(b,c){if(!c.src||'javascript:""'===c.src)try{c.contentWindow.document.body.className=a}catch(d){}})})}),b.on("beforesetcontent",function(a){var c;if(a.selection||f.mce.views.unbind(),a.content){if(!a.load&&(c=b.selection.getNode(),c&&c!==b.getBody()&&/^\s*https?:\/\/\S+\s*$/i.test(a.content))){if(c=b.dom.getParent(c,"p"),!c||!/^[\s\uFEFF\u00A0]*$/.test(b.$(c).text()||""))return;c.innerHTML=""}a.content=f.mce.views.setMarkers(a.content,b)}}),b.on("setcontent",function(){f.mce.views.render()}),b.on("preprocess hide",function(a){b.$("div[data-wpview-text], p[data-wpview-marker]",a.node).each(function(a,b){b.innerHTML="."})},!0),b.on("postprocess",function(a){a.content=e(a.content)}),b.on("beforeaddundo",function(a){a.level.content=e(a.level.content)}),b.on("drop objectselected",function(a){d(a.targetClone)&&(a.targetClone=b.getDoc().createTextNode(window.decodeURIComponent(b.dom.getAttrib(a.targetClone,"data-wpview-text"))))}),b.on("pastepreprocess",function(b){var c=b.content;c&&(c=a.trim(c.replace(/<[^>]+>/g,"")),/^https?:\/\/\S+$/i.test(c)&&(b.content=c))}),b.on("resolvename",function(a){d(a.target)&&(a.name=b.dom.getAttrib(a.target,"data-wpview-type")||"object")}),b.on("click keyup",function(){var a=b.selection.getNode();d(a)&&b.dom.getAttrib(a,"data-mce-selected")&&a.setAttribute("data-mce-selected","2")}),b.addButton("wp_view_edit",{tooltip:"Edit|button",icon:"dashicon dashicons-edit",onclick:function(){var a=b.selection.getNode();d(a)&&f.mce.views.edit(b,a)}}),b.addButton("wp_view_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",onclick:function(){b.fire("cut")}}),b.once("preinit",function(){var a;b.wp&&b.wp._createToolbar&&(a=b.wp._createToolbar(["wp_view_edit","wp_view_remove"]),b.on("wptoolbar",function(b){!b.collapsed&&d(b.element)&&(b.toolbar=a)}))}),b.wp=b.wp||{},b.wp.getView=c,b.wp.setViewCursor=c,{getView:c}):{getView:c}})}(window.tinymce); \ No newline at end of file +!function(a){a.PluginManager.add("wpview",function(b){function c(){}function d(a){return b.dom.hasClass(a,"wpview")}function e(a){function b(a,b){return"

"+window.decodeURIComponent(b)+"

"}return a&&a.indexOf(" data-wpview-")!==-1?a.replace(/]+data-wpview-text="([^"]+)"[^>]*>(?:\.|[\s\S]+?wpview-end[^>]+>\s*<\/span>\s*)?<\/div>/g,b).replace(/]+data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g,b):a}var f=window.wp;return f&&f.mce&&f.mce.views?(b.on("init",function(){var a=window.MutationObserver||window.WebKitMutationObserver;a&&new a(function(){b.fire("wp-body-class-change")}).observe(b.getBody(),{attributes:!0,attributeFilter:["class"]}),b.on("wp-body-class-change",function(){var a=b.getBody().className;b.$('iframe[class="wpview-sandbox"]').each(function(b,c){if(!c.src||'javascript:""'===c.src)try{c.contentWindow.document.body.className=a}catch(d){}})})}),b.on("beforesetcontent",function(a){var c;if(a.selection||f.mce.views.unbind(),a.content){if(!a.load&&(c=b.selection.getNode(),c&&c!==b.getBody()&&/^\s*https?:\/\/\S+\s*$/i.test(a.content))){if(c=b.dom.getParent(c,"p"),!c||!/^[\s\uFEFF\u00A0]*$/.test(b.$(c).text()||""))return;c.innerHTML=""}a.content=f.mce.views.setMarkers(a.content,b)}}),b.on("setcontent",function(){f.mce.views.render()}),b.on("preprocess hide",function(a){b.$("div[data-wpview-text], p[data-wpview-marker]",a.node).each(function(a,b){b.innerHTML="."})},!0),b.on("postprocess",function(a){a.content=e(a.content)}),b.on("beforeaddundo",function(a){var c,d=a.level.content||a.level.fragments&&a.level.fragments.join("");c=a.lastLevel?a.lastLevel.content||a.lastLevel.fragments&&a.lastLevel.fragments.join(""):b.startContent,d&&c&&d.indexOf(" data-wpview-")!==-1&&c.indexOf(" data-wpview-")!==-1&&e(c)===e(d)&&a.preventDefault()}),b.on("drop objectselected",function(a){d(a.targetClone)&&(a.targetClone=b.getDoc().createTextNode(window.decodeURIComponent(b.dom.getAttrib(a.targetClone,"data-wpview-text"))))}),b.on("pastepreprocess",function(b){var c=b.content;c&&(c=a.trim(c.replace(/<[^>]+>/g,"")),/^https?:\/\/\S+$/i.test(c)&&(b.content=c))}),b.on("resolvename",function(a){d(a.target)&&(a.name=b.dom.getAttrib(a.target,"data-wpview-type")||"object")}),b.on("click keyup",function(){var a=b.selection.getNode();d(a)&&b.dom.getAttrib(a,"data-mce-selected")&&a.setAttribute("data-mce-selected","2")}),b.addButton("wp_view_edit",{tooltip:"Edit|button",icon:"dashicon dashicons-edit",onclick:function(){var a=b.selection.getNode();d(a)&&f.mce.views.edit(b,a)}}),b.addButton("wp_view_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",onclick:function(){b.fire("cut")}}),b.once("preinit",function(){var a;b.wp&&b.wp._createToolbar&&(a=b.wp._createToolbar(["wp_view_edit","wp_view_remove"]),b.on("wptoolbar",function(b){!b.collapsed&&d(b.element)&&(b.toolbar=a)}))}),b.wp=b.wp||{},b.wp.getView=c,b.wp.setViewCursor=c,{getView:c}):{getView:c}})}(window.tinymce); \ No newline at end of file diff --git a/wp-includes/js/tinymce/wp-tinymce.js b/wp-includes/js/tinymce/wp-tinymce.js index 41c3a02e62..a29bae2514 100644 --- a/wp-includes/js/tinymce/wp-tinymce.js +++ b/wp-includes/js/tinymce/wp-tinymce.js @@ -46,4 +46,4 @@ tinymce.PluginManager.add("wpgallery",function(a){function b(a){return a.replace // Source: wp-includes/js/tinymce/plugins/wptextpattern/plugin.min.js !function(a,b){function c(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}a.Env.ie&&a.Env.ie<9||a.PluginManager.add("wptextpattern",function(d){function e(){var e,f,g,h,i,k=d.selection.getRng(),l=k.startContainer,m=k.startOffset;if(l&&3===l.nodeType&&l.data.length&&m){var n=l.data.slice(0,m),p=l.data.charAt(m-1);a.each(o,function(a){if(p===a.delimiter.slice(-1)){var b=c(a.delimiter),d=a.delimiter.charAt(0),h=new RegExp("(.*)"+b+".+"+b+"$"),i=n.match(h);if(i){e=i[1].length,f=m-a.delimiter.length;var j=n.charAt(e-1),k=n.charAt(e+a.delimiter.length);if(!(e&&/\S/.test(j)&&(/\s/.test(k)||j===d)||new RegExp("^[\\s"+c(d)+"]+$").test(n.slice(e,f))))return g=a,!1}}}),g&&(h=d.formatter.get(g.format),h&&h[0].inline&&(d.undoManager.add(),d.undoManager.transact(function(){l.insertData(m,"\ufeff"),l=l.splitText(e),i=l.splitText(m-e),l.deleteData(0,g.delimiter.length),l.deleteData(l.data.length-g.delimiter.length,g.delimiter.length),d.formatter.apply(g.format,{},l),d.selection.setCursorLocation(i,1)}),b(function(){j="space",d.once("selectionchange",function(){var a;i&&(a=i.data.indexOf("\ufeff"),a!==-1&&i.deleteData(a,a+1))})})))}}function f(a){var b,c=d.dom.getParent(a,"p");if(c){for(;(b=c.firstChild)&&3!==b.nodeType;)c=b;if(b)return b.data||(b=b.nextSibling&&3===b.nextSibling.nodeType?b.nextSibling:null),b}}function g(){var c,e,g=d.selection.getRng(),h=g.startContainer;h&&f(h)===h&&(c=h.parentNode,e=h.data,a.each(m,function(a){var f=e.match(a.regExp);if(f&&g.startOffset===f[0].length)return d.undoManager.add(),d.undoManager.transact(function(){h.deleteData(0,f[0].length),c.innerHTML||c.appendChild(document.createElement("br")),d.selection.setCursorLocation(c),d.execCommand(a.cmd)}),b(function(){j="space"}),!1}))}function h(){var c,e,g,h=d.selection.getRng(),k=h.startContainer,l=f(k),m=n.length;if(l){for(c=l.data;m--;)if(n[m].start){if(0===c.indexOf(n[m].start)){e=n[m];break}}else if(n[m].regExp&&n[m].regExp.test(c)){e=n[m];break}e&&(l===k&&a.trim(c)===e.start||d.once("keyup",function(){d.undoManager.add(),d.undoManager.transact(function(){e.format?(d.formatter.apply(e.format,{},l),l.replaceData(0,l.data.length,i(l.data.slice(e.start.length)))):e.element&&(g=l.parentNode&&l.parentNode.parentNode,g&&g.replaceChild(document.createElement(e.element),l.parentNode))}),b(function(){j="enter"})}))}}function i(a){return a?a.replace(/^\s+/,""):""}var j,k=a.util.VK,l=d.settings.wptextpattern||{},m=l.space||[{regExp:/^[*-]\s/,cmd:"InsertUnorderedList"},{regExp:/^1[.)]\s/,cmd:"InsertOrderedList"}],n=l.enter||[{start:"##",format:"h2"},{start:"###",format:"h3"},{start:"####",format:"h4"},{start:"#####",format:"h5"},{start:"######",format:"h6"},{start:">",format:"blockquote"},{regExp:/^(-){3,}$/,element:"hr"}],o=l.inline||[{delimiter:"`",format:"code"}];d.on("selectionchange",function(){j=null}),d.on("keydown",function(a){(j&&27===a.keyCode||"space"===j&&a.keyCode===k.BACKSPACE)&&(d.undoManager.undo(),a.preventDefault(),a.stopImmediatePropagation()),k.metaKeyPressed(a)||(a.keyCode===k.ENTER?h():a.keyCode===k.SPACEBAR?b(g):a.keyCode>47&&!(a.keyCode>=91&&a.keyCode<=93)&&b(e))},!0)})}(window.tinymce,window.setTimeout); // Source: wp-includes/js/tinymce/plugins/wpview/plugin.min.js -!function(a){a.PluginManager.add("wpview",function(b){function c(){}function d(a){return b.dom.hasClass(a,"wpview")}function e(a){function b(a,b){return"

"+window.decodeURIComponent(b)+"

"}return a?a.replace(/]+data-wpview-text="([^"]+)"[^>]*>(?:\.|[\s\S]+?wpview-end[^>]+>\s*<\/span>\s*)?<\/div>/g,b).replace(/]+data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g,b):a}var f=window.wp;return f&&f.mce&&f.mce.views?(b.on("init",function(){var a=window.MutationObserver||window.WebKitMutationObserver;a&&new a(function(){b.fire("wp-body-class-change")}).observe(b.getBody(),{attributes:!0,attributeFilter:["class"]}),b.on("wp-body-class-change",function(){var a=b.getBody().className;b.$('iframe[class="wpview-sandbox"]').each(function(b,c){if(!c.src||'javascript:""'===c.src)try{c.contentWindow.document.body.className=a}catch(d){}})})}),b.on("beforesetcontent",function(a){var c;if(a.selection||f.mce.views.unbind(),a.content){if(!a.load&&(c=b.selection.getNode(),c&&c!==b.getBody()&&/^\s*https?:\/\/\S+\s*$/i.test(a.content))){if(c=b.dom.getParent(c,"p"),!c||!/^[\s\uFEFF\u00A0]*$/.test(b.$(c).text()||""))return;c.innerHTML=""}a.content=f.mce.views.setMarkers(a.content,b)}}),b.on("setcontent",function(){f.mce.views.render()}),b.on("preprocess hide",function(a){b.$("div[data-wpview-text], p[data-wpview-marker]",a.node).each(function(a,b){b.innerHTML="."})},!0),b.on("postprocess",function(a){a.content=e(a.content)}),b.on("beforeaddundo",function(a){a.level.content=e(a.level.content)}),b.on("drop objectselected",function(a){d(a.targetClone)&&(a.targetClone=b.getDoc().createTextNode(window.decodeURIComponent(b.dom.getAttrib(a.targetClone,"data-wpview-text"))))}),b.on("pastepreprocess",function(b){var c=b.content;c&&(c=a.trim(c.replace(/<[^>]+>/g,"")),/^https?:\/\/\S+$/i.test(c)&&(b.content=c))}),b.on("resolvename",function(a){d(a.target)&&(a.name=b.dom.getAttrib(a.target,"data-wpview-type")||"object")}),b.on("click keyup",function(){var a=b.selection.getNode();d(a)&&b.dom.getAttrib(a,"data-mce-selected")&&a.setAttribute("data-mce-selected","2")}),b.addButton("wp_view_edit",{tooltip:"Edit|button",icon:"dashicon dashicons-edit",onclick:function(){var a=b.selection.getNode();d(a)&&f.mce.views.edit(b,a)}}),b.addButton("wp_view_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",onclick:function(){b.fire("cut")}}),b.once("preinit",function(){var a;b.wp&&b.wp._createToolbar&&(a=b.wp._createToolbar(["wp_view_edit","wp_view_remove"]),b.on("wptoolbar",function(b){!b.collapsed&&d(b.element)&&(b.toolbar=a)}))}),b.wp=b.wp||{},b.wp.getView=c,b.wp.setViewCursor=c,{getView:c}):{getView:c}})}(window.tinymce); \ No newline at end of file +!function(a){a.PluginManager.add("wpview",function(b){function c(){}function d(a){return b.dom.hasClass(a,"wpview")}function e(a){function b(a,b){return"

"+window.decodeURIComponent(b)+"

"}return a&&a.indexOf(" data-wpview-")!==-1?a.replace(/]+data-wpview-text="([^"]+)"[^>]*>(?:\.|[\s\S]+?wpview-end[^>]+>\s*<\/span>\s*)?<\/div>/g,b).replace(/]+data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g,b):a}var f=window.wp;return f&&f.mce&&f.mce.views?(b.on("init",function(){var a=window.MutationObserver||window.WebKitMutationObserver;a&&new a(function(){b.fire("wp-body-class-change")}).observe(b.getBody(),{attributes:!0,attributeFilter:["class"]}),b.on("wp-body-class-change",function(){var a=b.getBody().className;b.$('iframe[class="wpview-sandbox"]').each(function(b,c){if(!c.src||'javascript:""'===c.src)try{c.contentWindow.document.body.className=a}catch(d){}})})}),b.on("beforesetcontent",function(a){var c;if(a.selection||f.mce.views.unbind(),a.content){if(!a.load&&(c=b.selection.getNode(),c&&c!==b.getBody()&&/^\s*https?:\/\/\S+\s*$/i.test(a.content))){if(c=b.dom.getParent(c,"p"),!c||!/^[\s\uFEFF\u00A0]*$/.test(b.$(c).text()||""))return;c.innerHTML=""}a.content=f.mce.views.setMarkers(a.content,b)}}),b.on("setcontent",function(){f.mce.views.render()}),b.on("preprocess hide",function(a){b.$("div[data-wpview-text], p[data-wpview-marker]",a.node).each(function(a,b){b.innerHTML="."})},!0),b.on("postprocess",function(a){a.content=e(a.content)}),b.on("beforeaddundo",function(a){var c,d=a.level.content||a.level.fragments&&a.level.fragments.join("");c=a.lastLevel?a.lastLevel.content||a.lastLevel.fragments&&a.lastLevel.fragments.join(""):b.startContent,d&&c&&d.indexOf(" data-wpview-")!==-1&&c.indexOf(" data-wpview-")!==-1&&e(c)===e(d)&&a.preventDefault()}),b.on("drop objectselected",function(a){d(a.targetClone)&&(a.targetClone=b.getDoc().createTextNode(window.decodeURIComponent(b.dom.getAttrib(a.targetClone,"data-wpview-text"))))}),b.on("pastepreprocess",function(b){var c=b.content;c&&(c=a.trim(c.replace(/<[^>]+>/g,"")),/^https?:\/\/\S+$/i.test(c)&&(b.content=c))}),b.on("resolvename",function(a){d(a.target)&&(a.name=b.dom.getAttrib(a.target,"data-wpview-type")||"object")}),b.on("click keyup",function(){var a=b.selection.getNode();d(a)&&b.dom.getAttrib(a,"data-mce-selected")&&a.setAttribute("data-mce-selected","2")}),b.addButton("wp_view_edit",{tooltip:"Edit|button",icon:"dashicon dashicons-edit",onclick:function(){var a=b.selection.getNode();d(a)&&f.mce.views.edit(b,a)}}),b.addButton("wp_view_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",onclick:function(){b.fire("cut")}}),b.once("preinit",function(){var a;b.wp&&b.wp._createToolbar&&(a=b.wp._createToolbar(["wp_view_edit","wp_view_remove"]),b.on("wptoolbar",function(b){!b.collapsed&&d(b.element)&&(b.toolbar=a)}))}),b.wp=b.wp||{},b.wp.getView=c,b.wp.setViewCursor=c,{getView:c}):{getView:c}})}(window.tinymce); \ No newline at end of file diff --git a/wp-includes/version.php b/wp-includes/version.php index 11cf0d2aed..2ffa1ecc58 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-45630'; +$wp_version = '5.3-alpha-45631'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.