diff --git a/wp-includes/js/mce-view.js b/wp-includes/js/mce-view.js index b532cb97a5..d2c29f7e88 100644 --- a/wp-includes/js/mce-view.js +++ b/wp-includes/js/mce-view.js @@ -327,9 +327,9 @@ this.replaceMarkers(); if ( content ) { - this.setContent( content, function( editor, node, contentNode ) { + this.setContent( content, function( editor, node ) { $( node ).data( 'rendered', true ); - this.bindNode.call( this, editor, node, contentNode ); + this.bindNode.call( this, editor, node ); }, force ? null : false ); } else { this.setLoader(); @@ -351,8 +351,8 @@ * Runs before their content is removed from the DOM. */ unbind: function() { - this.getNodes( function( editor, node, contentNode ) { - this.unbindNode.call( this, editor, node, contentNode ); + this.getNodes( function( editor, node ) { + this.unbindNode.call( this, editor, node ); $( node ).trigger( 'wp-mce-view-unbind' ); }, true ); }, @@ -394,7 +394,7 @@ return rendered ? data : ! data; } ) .each( function() { - callback.call( self, editor, this, $( this ).find( '.wpview-content' ).get( 0 ) ); + callback.call( self, editor, this ); } ); } ); }, @@ -421,8 +421,7 @@ */ replaceMarkers: function() { this.getMarkers( function( editor, node ) { - var selected = node === editor.selection.getNode(), - $viewNode; + var $viewNode; if ( ! this.loader && $( node ).text() !== this.text ) { editor.dom.setAttrib( node, 'data-wpview-marker', null ); @@ -430,20 +429,10 @@ } $viewNode = editor.$( - '
' + - '

\u00a0

' + - '
' + - '
' + - '
' + - '

\u00a0

' + - '
' + '
' ); editor.$( node ).replaceWith( $viewNode ); - - if ( selected ) { - editor.wp.setViewCursor( false, $viewNode[0] ); - } } ); }, @@ -469,17 +458,20 @@ } else if ( _.isString( content ) && content.indexOf( ''+h+"

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

\s*

")},createInstance:function(a,b,c,d){var e,g,h=this.get(a);return b=tinymce.DOM.decode(b),!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(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,c){d(b).data("rendered",!0),this.bindNode.call(this,a,b,c)},b?null:!1):this.setLoader())},bindNode:function(){},unbindNode:function(){},unbind:function(){this.getNodes(function(a,b,c){this.unbindNode.call(this,a,b,c),d(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(c){var e=this;d(c.getBody()).find('[data-wpview-text="'+e.encodedText+'"]').filter(function(){var a;return null==b?!0:(a=d(this).data("rendered")===!0,b?a:!a)}).each(function(){a.call(e,c,this,d(this).find(".wpview-content").get(0))})})},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()===this.text?(c=a.$('

\xa0

\xa0

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

'+a+"

")},match:function(a){var b=c.next(this.type,a);return b?{index:b.index,content:b.content,options:{shortcode:b.shortcode}}:void 0},update:function(a,c,f,g){_.find(e,function(e,h){var i=e.prototype.match(a);return i?(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.focus(),!0):void 0})},remove:function(a,b){this.unbindNode.call(this,a,b,d(b).find(".wpview-content").get(0)),d(b).trigger("wp-mce-view-unbind"),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||-1===b.indexOf("<")&&-1===b.indexOf(">")?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;this.url&&(this.loader=!1,this.shortcode=c.embed.shortcode({url:this.text})),wp.ajax.post(this.action,{post_ID:c.view.settings.post.id,type:this.shortcode.tag,shortcode:this.shortcode.string()}).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);return c?{index:c.index+c[1].length,content:c[2],options:{url:!0}}:void 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){var b,c,d=[{content:a}],f=this;return _.each(e,function(a,e){c=d.slice(),d=[],_.each(c,function(c){var g,h,i=c.content;if(c.processed)return void d.push(c);for(;i&&(g=a.prototype.match(i));)g.index&&d.push({content:i.substring(0,g.index)}),b=f.createInstance(e,g.content,g.options),h=b.loader?".":b.text,d.push({content:b.ignore?h:'

'+h+"

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

\s*

")},createInstance:function(a,b,c,d){var e,g,h=this.get(a);return b=tinymce.DOM.decode(b),!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(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:!1):this.setLoader())},bindNode:function(){},unbindNode:function(){},unbind:function(){this.getNodes(function(a,b){this.unbindNode.call(this,a,b),d(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(c){var e=this;d(c.getBody()).find('[data-wpview-text="'+e.encodedText+'"]').filter(function(){var a;return null==b?!0:(a=d(this).data("rendered")===!0,b?a:!a)}).each(function(){a.call(e,c,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;return this.loader||d(b).text()===this.text?(c=a.$('

'),void a.$(b).replaceWith(c)):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)&&-1!==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(b,c,e,f){var g=a.MutationObserver||a.WebKitMutationObserver||a.MozMutationObserver,h=this;this.getNodes(function(a,f){var i=a.dom,j="",k=a.getBody().className||"",l=a.getDoc().getElementsByTagName("head")[0];tinymce.each(i.$('link[rel="stylesheet"]',l),function(a){a.href&&-1===a.href.indexOf("skins/lightgray/content.min.css")&&-1===a.href.indexOf("skins/wordpress/wp-content.css")&&(j+=i.getOuterHTML(a))}),h.iframeHeight&&i.add(f,"span",{"data-mce-bogus":1,style:{display:"block",width:"100%",height:h.iframeHeight}},"\u200b"),setTimeout(function(){function l(){var b;r||n.contentWindow&&(b=d(n),h.iframeHeight=d(o.body).height(),b.height()!==h.iframeHeight&&(b.height(h.iframeHeight),a.nodeChanged()))}function m(){o.body.className=a.getBody().className}var n,o,p,q,r;if(a.undoManager.transact(function(){f.innerHTML="",n=i.add(f,"iframe",{src:tinymce.Env.ie?'javascript:""':"",frameBorder:"0",allowTransparency:"true",scrolling:"no","class":"wpview-sandbox",style:{width:"100%",display:"block"},height:h.iframeHeight}),i.add(f,"span",{"class":"mce-shim"}),i.add(f,"span",{"class":"wpview-end"})}),o=n.contentWindow.document,o.open(),o.write(''+b+j+''+c+""),o.close(),h.iframeHeight&&(r=!0,setTimeout(function(){r=!1,l()},3e3)),d(n.contentWindow).on("load",l),g)p=new g(_.debounce(l,100)),p.observe(o.body,{attributes:!0,childList:!0,subtree:!0}),d(f).one("wp-mce-view-unbind",function(){p.disconnect()});else for(q=1;6>q;q++)setTimeout(l,700*q);a.on("wp-body-class-change",m),d(f).one("wp-mce-view-unbind",function(){a.off("wp-body-class-change",m)}),e&&e.call(h,a,f)},50)},f)},setLoader:function(){this.setContent('
')},setError:function(a,b){this.setContent('

'+a+"

")},match:function(a){var b=c.next(this.type,a);return b?{index:b.index,content:b.content,options:{shortcode:b.shortcode}}:void 0},update:function(a,c,f,g){_.find(e,function(e,h){var i=e.prototype.match(a);return i?(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.focus(),!0):void 0})},remove:function(a,b){this.unbindNode.call(this,a,b),d(b).trigger("wp-mce-view-unbind"),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||-1===b.indexOf("<")&&-1===b.indexOf(">")?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;this.url&&(this.loader=!1,this.shortcode=c.embed.shortcode({url:this.text})),wp.ajax.post(this.action,{post_ID:c.view.settings.post.id,type:this.shortcode.tag,shortcode:this.shortcode.string()}).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);return c?{index:c.index+c[1].length,content:c[2],options:{url:!0}}:void 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 61f34bc4b4..4eb1bb497a 100644 --- a/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -1,749 +1,173 @@ -/* global tinymce */ - /** * WordPress View plugin. */ -tinymce.PluginManager.add( 'wpview', function( editor ) { - var $ = editor.$, - selected, - Env = tinymce.Env, - VK = tinymce.util.VK, - TreeWalker = tinymce.dom.TreeWalker, - toRemove = false, - firstFocus = true, - _noop = function() { return false; }, - isios = /iPad|iPod|iPhone/.test( navigator.userAgent ), - cursorInterval, - lastKeyDownNode, - setViewCursorTries, - focus, - execCommandView, - execCommandBefore, - toolbar; +( function( tinymce, wp ) { + tinymce.PluginManager.add( 'wpview', function( editor ) { + function noop () {} - function getView( node ) { - return getParent( node, 'wpview-wrap' ); - } + if ( ! wp || ! wp.mce ) { + return { + getView: noop + }; + } - /** - * Returns the node or a parent of the node that has the passed className. - * Doing this directly is about 40% faster - */ - function getParent( node, className ) { - while ( node && node.parentNode ) { - if ( node.className && ( ' ' + node.className + ' ' ).indexOf( ' ' + className + ' ' ) !== -1 ) { - return node; + // Check if a node is a view or not. + function isView( node ) { + return editor.dom.hasClass( node, 'wpview' ); + } + + // Replace view tags with their text. + function resetViews( content ) { + function callback( match, $1 ) { + return '

' + window.decodeURIComponent( $1 ) + '

'; } - node = node.parentNode; - } - - return false; - } - - function _stop( event ) { - event.stopPropagation(); - } - - function setViewCursor( before, view ) { - var location = before ? 'before' : 'after', - offset = before ? 0 : 1; - deselect(); - editor.selection.setCursorLocation( editor.dom.select( '.wpview-selection-' + location, view )[0], offset ); - editor.nodeChanged(); - } - - function handleEnter( view, before, key ) { - var dom = editor.dom, - padNode = dom.create( 'p' ); - - if ( ! ( Env.ie && Env.ie < 11 ) ) { - padNode.innerHTML = '
'; - } - - if ( before ) { - view.parentNode.insertBefore( padNode, view ); - } else { - dom.insertAfter( padNode, view ); - } - - deselect(); - - if ( before && key === VK.ENTER ) { - setViewCursor( before, view ); - } else { - editor.selection.setCursorLocation( padNode, 0 ); - } - - editor.nodeChanged(); - } - - function removeView( view ) { - editor.undoManager.transact( function() { - handleEnter( view ); - wp.mce.views.remove( editor, view ); - }); - } - - function select( viewNode ) { - var clipboard, - dom = editor.dom; - - if ( ! viewNode ) { - return; - } - - if ( viewNode !== selected ) { - // Make sure that the editor is focused. - // It is possible that the editor is not focused when the mouse event fires - // without focus, the selection will not work properly. - editor.getBody().focus(); - - deselect(); - selected = viewNode; - dom.setAttrib( viewNode, 'data-mce-selected', 1 ); - - clipboard = dom.create( 'div', { - 'class': 'wpview-clipboard', - 'contenteditable': 'true' - }, wp.mce.views.getText( viewNode ) ); - - editor.dom.select( '.wpview-body', viewNode )[0].appendChild( clipboard ); - - // Both of the following are necessary to prevent manipulating the selection/focus - dom.bind( clipboard, 'beforedeactivate focusin focusout', _stop ); - dom.bind( selected, 'beforedeactivate focusin focusout', _stop ); - - // select the hidden div - if ( isios ) { - editor.selection.select( clipboard ); - } else { - editor.selection.select( clipboard, true ); - } - } - - editor.nodeChanged(); - editor.fire( 'wpview-selected', viewNode ); - } - - /** - * Deselect a selected view and remove clipboard - */ - function deselect() { - var clipboard, - dom = editor.dom; - - if ( selected ) { - clipboard = editor.dom.select( '.wpview-clipboard', selected )[0]; - dom.unbind( clipboard ); - dom.remove( clipboard ); - - dom.unbind( selected, 'beforedeactivate focusin focusout click mouseup', _stop ); - dom.setAttrib( selected, 'data-mce-selected', null ); - } - - selected = null; - } - - // Check if the `wp.mce` API exists. - if ( typeof wp === 'undefined' || ! wp.mce ) { - return { - getView: _noop - }; - } - - function resetViewsCallback( match, viewText ) { - return '

' + window.decodeURIComponent( viewText ) + '

'; - } - - // Replace the view tags with the view string - function resetViews( content ) { - return content.replace( /]+data-wpview-text="([^"]+)"[^>]*>(?:[\s\S]+?wpview-selection-after[^>]+>[^<>]*<\/p>\s*|\.)<\/div>/g, resetViewsCallback ) - .replace( /

]*?data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g, resetViewsCallback ); - } - - // Prevent adding undo levels on changes inside a view wrapper - editor.on( 'BeforeAddUndo', function( event ) { - if ( event.level.content ) { - event.level.content = resetViews( event.level.content ); - } - }); - - // When the editor's content changes, scan the new content for - // matching view patterns, and transform the matches into - // view wrappers. - editor.on( 'BeforeSetContent', function( event ) { - var node; - - if ( ! event.selection ) { - wp.mce.views.unbind(); - } - - if ( ! event.content ) { - return; - } - - if ( ! event.load ) { - if ( selected ) { - removeView( selected ); + if ( ! content ) { + return content; } - node = editor.selection.getNode(); + return content + .replace( /]+data-wpview-text="([^"]+)"[^>]*>(?:\.|[\s\S]+?wpview-end[^>]+>\s*<\/span>\s*)?<\/div>/g, callback ) + .replace( /]+data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g, callback ); + } - if ( node && node !== editor.getBody() && /^\s*https?:\/\/\S+\s*$/i.test( event.content ) ) { - // When a url is pasted or inserted, only try to embed it when it is in an empty paragrapgh. - node = editor.dom.getParent( node, 'p' ); + // Scan new content for matching view patterns and replace them with markers. + editor.on( 'beforesetcontent', function( event ) { + var node; - if ( node && /^[\s\uFEFF\u00A0]*$/.test( $( node ).text() || '' ) ) { - // Make sure there are no empty inline elements in the

- node.innerHTML = ''; - } else { - return; - } + if ( ! event.selection ) { + wp.mce.views.unbind(); } - } - event.content = wp.mce.views.setMarkers( event.content ); - }); - - // When pasting strip all tags and check if the string is an URL. - // Then replace the pasted content with the cleaned URL. - editor.on( 'pastePreProcess', function( event ) { - var pastedStr = event.content; - - if ( pastedStr ) { - pastedStr = tinymce.trim( pastedStr.replace( /<[^>]+>/g, '' ) ); - - if ( /^https?:\/\/\S+$/i.test( pastedStr ) ) { - event.content = pastedStr; - } - } - }); - - // When the editor's content has been updated and the DOM has been - // processed, render the views in the document. - editor.on( 'SetContent', function() { - wp.mce.views.render(); - }); - - // Set the cursor before or after a view when clicking next to it. - editor.on( 'click', function( event ) { - var x = event.clientX, - y = event.clientY, - body = editor.getBody(), - bodyRect = body.getBoundingClientRect(), - first = body.firstChild, - last = body.lastChild, - firstRect, lastRect, view; - - if ( ! first || ! last ) { - return; - } - - firstRect = first.getBoundingClientRect(); - lastRect = last.getBoundingClientRect(); - - if ( y < firstRect.top && ( view = getView( first ) ) ) { - setViewCursor( true, view ); - event.preventDefault(); - } else if ( y > lastRect.bottom && ( view = getView( last ) ) ) { - setViewCursor( false, view ); - event.preventDefault(); - } else if ( x < bodyRect.left || x > bodyRect.right ) { - tinymce.each( editor.dom.select( '.wpview-wrap' ), function( view ) { - var rect = view.getBoundingClientRect(); - - if ( y < rect.top ) { - return false; - } - - if ( y >= rect.top && y <= rect.bottom ) { - if ( x < bodyRect.left ) { - setViewCursor( true, view ); - event.preventDefault(); - } else if ( x > bodyRect.right ) { - setViewCursor( false, view ); - event.preventDefault(); - } - - return false; - } - }); - } - }); - - editor.on( 'init', function() { - var scrolled = false, - selection = editor.selection, - MutationObserver = window.MutationObserver || window.WebKitMutationObserver; - - // When a view is selected, ensure content that is being pasted - // or inserted is added to a text node (instead of the view). - editor.on( 'BeforeSetContent', function() { - var walker, target, - view = getView( selection.getNode() ); - - // If the selection is not within a view, bail. - if ( ! view ) { + if ( ! event.content ) { return; } - if ( ! view.nextSibling || getView( view.nextSibling ) ) { - // If there are no additional nodes or the next node is a - // view, create a text node after the current view. - target = editor.getDoc().createTextNode(''); - editor.dom.insertAfter( target, view ); - } else { - // Otherwise, find the next text node. - walker = new TreeWalker( view.nextSibling, view.nextSibling ); - target = walker.next(); - } + if ( ! event.load ) { + node = editor.selection.getNode(); - // Select the `target` text node. - selection.select( target ); - selection.collapse( true ); - }); + if ( node && node !== editor.getBody() && /^\s*https?:\/\/\S+\s*$/i.test( event.content ) ) { + // When a url is pasted or inserted, only try to embed it when it is in an empty paragrapgh. + node = editor.dom.getParent( node, 'p' ); - editor.dom.bind( editor.getDoc(), 'touchmove', function() { - scrolled = true; - }); - - editor.on( 'mousedown mouseup click touchend', function( event ) { - var view = getView( event.target ); - - firstFocus = false; - - // Contain clicks inside the view wrapper - if ( view ) { - event.stopImmediatePropagation(); - event.preventDefault(); - - if ( event.type === 'touchend' && scrolled ) { - scrolled = false; - } else { - select( view ); - } - - // Returning false stops the ugly bars from appearing in IE11 and stops the view being selected as a range in FF. - // Unfortunately, it also inhibits the dragging of views to a new location. - return false; - } else { - if ( event.type === 'touchend' || event.type === 'mousedown' ) { - deselect(); + if ( node && /^[\s\uFEFF\u00A0]*$/.test( editor.$( node ).text() || '' ) ) { + // Make sure there are no empty inline elements in the

+ node.innerHTML = ''; + } else { + return; + } } } - if ( event.type === 'touchend' && scrolled ) { - scrolled = false; - } + event.content = wp.mce.views.setMarkers( event.content ); + } ); + + // Replace any new markers nodes with views. + editor.on( 'setcontent', function() { + wp.mce.views.render(); + } ); + + // Empty view nodes for easier processing. + editor.on( 'preprocess', function( event ) { + editor.$( 'div[data-wpview-text], p[data-wpview-marker]', event.node ).each( function( i, node ) { + node.innerHTML = '.'; + } ); }, true ); - if ( MutationObserver ) { - new MutationObserver( function() { - editor.fire( 'wp-body-class-change' ); - } ) - .observe( editor.getBody(), { - attributes: true, - attributeFilter: ['class'] - } ); - } + // Replace views with their text. + editor.on( 'postprocess', function( event ) { + event.content = resetViews( event.content ); + } ); - if ( tinymce.Env.ie ) { - // Prevent resize handles in newer IE - editor.dom.bind( editor.getBody(), 'controlselect mscontrolselect', function( event ) { - if ( getView( event.target ) ) { - event.preventDefault(); - } - }); - } - }); + // Replace views with their text inside undo levels. + // This also prevents that new levels are added when there are changes inside the views. + editor.on( 'beforeaddundo', function( event ) { + event.level.content = resetViews( event.level.content ); + } ); - // Empty the wpview wrap and marker nodes - function emptyViewNodes( rootNode ) { - $( 'div[data-wpview-text], p[data-wpview-marker]', rootNode ).each( function( i, node ) { - node.innerHTML = '.'; - }); - } - - // Run that before the DOM cleanup - editor.on( 'PreProcess', function( event ) { - emptyViewNodes( event.node ); - }, true ); - - editor.on( 'hide', function() { - wp.mce.views.unbind(); - deselect(); - emptyViewNodes(); - }); - - editor.on( 'PostProcess', function( event ) { - if ( event.content ) { - event.content = event.content.replace( /

]*?data-wpview-text="([^"]+)"[^>]*>[\s\S]*?<\/div>/g, resetViewsCallback ) - .replace( /

]*?data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g, resetViewsCallback ); - } - }); - - // Excludes arrow keys, delete, backspace, enter, space bar. - // Ref: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent.keyCode - function isSpecialKey( key ) { - return ( ( key <= 47 && key !== VK.SPACEBAR && key !== VK.ENTER && key !== VK.DELETE && key !== VK.BACKSPACE && ( key < 37 || key > 40 ) ) || - key >= 224 || // OEM or non-printable - ( key >= 144 && key <= 150 ) || // Num Lock, Scroll Lock, OEM - ( key >= 91 && key <= 93 ) || // Windows keys - ( key >= 112 && key <= 135 ) ); // F keys - } - - // (De)select views when arrow keys are used to navigate the content of the editor. - editor.on( 'keydown', function( event ) { - var key = event.keyCode, - dom = editor.dom, - selection = editor.selection, - node, view, cursorBefore, cursorAfter, - range, clonedRange, tempRange; - - if ( selected ) { - // Ignore key presses that involve the command or control key, but continue when in combination with backspace or v. - // Also ignore the F# keys. - if ( ( ( event.metaKey || event.ctrlKey ) && key !== VK.BACKSPACE && key !== 86 ) || ( key >= 112 && key <= 123 ) ) { - // Remove the view when pressing cmd/ctrl+x on keyup, otherwise the browser can't copy the content. - if ( ( event.metaKey || event.ctrlKey ) && key === 88 ) { - toRemove = selected; - } - return; + // Make sure views are copied as their text. + editor.on( 'drop objectselected', function( event ) { + if ( isView( event.targetClone ) ) { + event.targetClone = editor.getDoc().createTextNode( + window.decodeURIComponent( editor.dom.getAttrib( event.targetClone, 'data-wpview-text' ) ) + ); } + } ); - view = getView( selection.getNode() ); + // Clean up URLs for easier processing. + editor.on( 'pastepreprocess', function( event ) { + var content = event.content; - // If the caret is not within the selected view, deselect the view and bail. - if ( view !== selected ) { - deselect(); - return; + if ( content ) { + content = tinymce.trim( content.replace( /<[^>]+>/g, '' ) ); + + if ( /^https?:\/\/\S+$/i.test( content ) ) { + event.content = content; + } } + } ); - if ( key === VK.LEFT ) { - setViewCursor( true, view ); - event.preventDefault(); - } else if ( key === VK.UP ) { - if ( view.previousSibling ) { - if ( getView( view.previousSibling ) ) { - setViewCursor( true, view.previousSibling ); - } else { - deselect(); - selection.select( view.previousSibling, true ); - selection.collapse(); + // Show the view type in the element path. + editor.on( 'resolvename', function( event ) { + if ( isView( event.target ) ) { + event.name = editor.dom.getAttrib( event.target, 'data-wpview-type' ) || 'object'; + } + } ); + + // See `media` plugin. + editor.on( 'click keyup', function() { + var node = editor.selection.getNode(); + + if ( isView( node ) ) { + if ( editor.dom.getAttrib( node, 'data-mce-selected' ) ) { + node.setAttribute( 'data-mce-selected', '2' ); + } + } + } ); + + editor.addButton( 'wp_view_edit', { + tooltip: 'Edit ', // trailing space is needed, used for context + icon: 'dashicon dashicons-edit', + onclick: function() { + var node = editor.selection.getNode(); + + if ( isView( node ) ) { + wp.mce.views.edit( editor, node ); + } + } + } ); + + editor.addButton( 'wp_view_remove', { + tooltip: 'Remove', + icon: 'dashicon dashicons-no', + onclick: function() { + editor.fire( 'cut' ); + } + } ); + + editor.once( 'preinit', function() { + var toolbar; + + if ( editor.wp && editor.wp._createToolbar ) { + toolbar = editor.wp._createToolbar( [ + 'wp_view_edit', + 'wp_view_remove' + ] ); + + editor.on( 'wptoolbar', function( event ) { + if ( isView( event.element ) ) { + event.toolbar = toolbar; } - } else { - setViewCursor( true, view ); - } - event.preventDefault(); - } else if ( key === VK.RIGHT ) { - setViewCursor( false, view ); - event.preventDefault(); - } else if ( key === VK.DOWN ) { - if ( view.nextSibling ) { - if ( getView( view.nextSibling ) ) { - setViewCursor( false, view.nextSibling ); - } else { - deselect(); - selection.setCursorLocation( view.nextSibling, 0 ); - } - } else { - setViewCursor( false, view ); - } - - event.preventDefault(); - // Ignore keys that don't insert anything. - } else if ( ! isSpecialKey( key ) ) { - removeView( selected ); - - if ( key === VK.ENTER || key === VK.DELETE || key === VK.BACKSPACE ) { - event.preventDefault(); - } - } - } else { - if ( event.metaKey || event.ctrlKey || ( key >= 112 && key <= 123 ) ) { - return; + } ); } + } ); - node = selection.getNode(); - lastKeyDownNode = node; - view = getView( node ); + editor.wp = editor.wp || {}; + editor.wp.getView = noop; + editor.wp.setViewCursor = noop; - // Make sure we don't delete part of a view. - // If the range ends or starts with the view, we'll need to trim it. - if ( ! selection.isCollapsed() ) { - range = selection.getRng(); - - if ( view = getView( range.endContainer ) ) { - clonedRange = range.cloneRange(); - selection.select( view.previousSibling, true ); - selection.collapse(); - tempRange = selection.getRng(); - clonedRange.setEnd( tempRange.endContainer, tempRange.endOffset ); - selection.setRng( clonedRange ); - } else if ( view = getView( range.startContainer ) ) { - clonedRange = range.cloneRange(); - clonedRange.setStart( view.nextSibling, 0 ); - selection.setRng( clonedRange ); - } - } - - if ( ! view ) { - // Make sure we don't eat any content. - if ( event.keyCode === VK.BACKSPACE ) { - if ( editor.dom.isEmpty( node ) ) { - if ( view = getView( node.previousSibling ) ) { - setViewCursor( false, view ); - editor.dom.remove( node ); - event.preventDefault(); - } - } else if ( ( range = selection.getRng() ) && - range.startOffset === 0 && - range.endOffset === 0 && - ( view = getView( node.previousSibling ) ) ) { - setViewCursor( false, view ); - event.preventDefault(); - } - } - return; - } - - if ( ! ( ( cursorBefore = dom.hasClass( view, 'wpview-selection-before' ) ) || - ( cursorAfter = dom.hasClass( view, 'wpview-selection-after' ) ) ) ) { - return; - } - - if ( isSpecialKey( key ) ) { - // ignore - return; - } - - if ( ( cursorAfter && key === VK.UP ) || ( cursorBefore && key === VK.BACKSPACE ) ) { - if ( view.previousSibling ) { - if ( getView( view.previousSibling ) ) { - setViewCursor( false, view.previousSibling ); - } else { - if ( dom.isEmpty( view.previousSibling ) && key === VK.BACKSPACE ) { - dom.remove( view.previousSibling ); - } else { - selection.select( view.previousSibling, true ); - selection.collapse(); - } - } - } else { - setViewCursor( true, view ); - } - event.preventDefault(); - } else if ( cursorAfter && ( key === VK.DOWN || key === VK.RIGHT ) ) { - if ( view.nextSibling ) { - if ( getView( view.nextSibling ) ) { - setViewCursor( key === VK.RIGHT, view.nextSibling ); - } else { - selection.setCursorLocation( view.nextSibling, 0 ); - } - } - event.preventDefault(); - } else if ( cursorBefore && ( key === VK.UP || key === VK.LEFT ) ) { - if ( view.previousSibling ) { - if ( getView( view.previousSibling ) ) { - setViewCursor( key === VK.UP, view.previousSibling ); - } else { - selection.select( view.previousSibling, true ); - selection.collapse(); - } - } - event.preventDefault(); - } else if ( cursorBefore && key === VK.DOWN ) { - if ( view.nextSibling ) { - if ( getView( view.nextSibling ) ) { - setViewCursor( true, view.nextSibling ); - } else { - selection.setCursorLocation( view.nextSibling, 0 ); - } - } else { - setViewCursor( false, view ); - } - event.preventDefault(); - } else if ( ( cursorAfter && key === VK.LEFT ) || ( cursorBefore && key === VK.RIGHT ) ) { - select( view ); - event.preventDefault(); - } else if ( cursorAfter && key === VK.BACKSPACE ) { - removeView( view ); - event.preventDefault(); - } else if ( cursorAfter ) { - handleEnter( view ); - } else if ( cursorBefore ) { - handleEnter( view , true, key ); - } - - if ( key === VK.ENTER ) { - event.preventDefault(); - } - } - }); - - editor.on( 'keyup', function() { - if ( toRemove ) { - removeView( toRemove ); - toRemove = false; - } - }); - - editor.on( 'focus', function() { - var view; - - focus = true; - editor.dom.addClass( editor.getBody(), 'has-focus' ); - - // Edge case: show the fake caret when the editor is focused for the first time - // and the first element is a view. - if ( firstFocus && ( view = getView( editor.getBody().firstChild ) ) ) { - setViewCursor( true, view ); - } - - firstFocus = false; + return { + getView: noop + }; } ); - - editor.on( 'blur', function() { - focus = false; - editor.dom.removeClass( editor.getBody(), 'has-focus' ); - } ); - - editor.on( 'NodeChange', function( event ) { - var dom = editor.dom, - views = editor.dom.select( '.wpview-wrap' ), - className = event.element.className, - view = getView( event.element ), - lKDN = lastKeyDownNode; - - lastKeyDownNode = false; - - clearInterval( cursorInterval ); - - // This runs a lot and is faster than replacing each class separately - tinymce.each( views, function ( view ) { - if ( view.className ) { - view.className = view.className.replace( / ?\bwpview-(?:selection-before|selection-after|cursor-hide)\b/g, '' ); - } - }); - - if ( focus && view ) { - if ( ( className === 'wpview-selection-before' || className === 'wpview-selection-after' ) && - editor.selection.isCollapsed() ) { - - setViewCursorTries = 0; - - deselect(); - - // Make sure the cursor arrived in the right node. - // This is necessary for Firefox. - if ( lKDN === view.previousSibling ) { - setViewCursor( true, view ); - return; - } else if ( lKDN === view.nextSibling ) { - setViewCursor( false, view ); - return; - } - - dom.addClass( view, className ); - - cursorInterval = setInterval( function() { - if ( dom.hasClass( view, 'wpview-cursor-hide' ) ) { - dom.removeClass( view, 'wpview-cursor-hide' ); - } else { - dom.addClass( view, 'wpview-cursor-hide' ); - } - }, 500 ); - // If the cursor lands anywhere else in the view, set the cursor before it. - // Only try this once to prevent a loop. (You never know.) - } else if ( ! getParent( event.element, 'wpview-clipboard' ) && ! setViewCursorTries ) { - deselect(); - setViewCursorTries++; - setViewCursor( true, view ); - } - } - }); - - editor.on( 'BeforeExecCommand', function() { - var node = editor.selection.getNode(), - view; - - if ( node && ( ( execCommandBefore = node.className === 'wpview-selection-before' ) || node.className === 'wpview-selection-after' ) && ( view = getView( node ) ) ) { - handleEnter( view, execCommandBefore ); - execCommandView = view; - } - }); - - editor.on( 'ExecCommand', function() { - var toSelect, node; - - if ( selected ) { - toSelect = selected; - deselect(); - select( toSelect ); - } - - if ( execCommandView ) { - node = execCommandView[ execCommandBefore ? 'previousSibling' : 'nextSibling' ]; - - if ( node && node.nodeName === 'P' && editor.dom.isEmpty( node ) ) { - editor.dom.remove( node ); - setViewCursor( execCommandBefore, execCommandView ); - } - - execCommandView = false; - } - }); - - editor.on( 'ResolveName', function( event ) { - if ( editor.dom.hasClass( event.target, 'wpview-wrap' ) ) { - event.name = editor.dom.getAttrib( event.target, 'data-wpview-type' ) || 'wpview'; - event.stopPropagation(); - } else if ( getView( event.target ) ) { - event.preventDefault(); - event.stopPropagation(); - } - }); - - editor.addButton( 'wp_view_edit', { - tooltip: 'Edit ', // trailing space is needed, used for context - icon: 'dashicon dashicons-edit', - onclick: function() { - selected && wp.mce.views.edit( editor, selected ); - } - } ); - - editor.addButton( 'wp_view_remove', { - tooltip: 'Remove', - icon: 'dashicon dashicons-no', - onclick: function() { - selected && removeView( selected ); - } - } ); - - editor.once( 'preinit', function() { - if ( editor.wp && editor.wp._createToolbar ) { - toolbar = editor.wp._createToolbar( [ - 'wp_view_edit', - 'wp_view_remove' - ] ); - } - } ); - - editor.on( 'wptoolbar', function( event ) { - if ( selected ) { - event.element = selected; - event.toolbar = toolbar; - } - } ); - - // Add to editor.wp - editor.wp = editor.wp || {}; - editor.wp.getView = getView; - editor.wp.setViewCursor = setViewCursor; - - // Keep for back-compat. - return { - getView: getView - }; -}); +} )( window.tinymce, window.wp ); diff --git a/wp-includes/js/tinymce/plugins/wpview/plugin.min.js b/wp-includes/js/tinymce/plugins/wpview/plugin.min.js index 9a2846e807..d67199a1a8 100644 --- a/wp-includes/js/tinymce/plugins/wpview/plugin.min.js +++ b/wp-includes/js/tinymce/plugins/wpview/plugin.min.js @@ -1 +1 @@ -tinymce.PluginManager.add("wpview",function(a){function b(a){return c(a,"wpview-wrap")}function c(a,b){for(;a&&a.parentNode;){if(a.className&&-1!==(" "+a.className+" ").indexOf(" "+b+" "))return a;a=a.parentNode}return!1}function d(a){a.stopPropagation()}function e(b,c){var d=b?"before":"after",e=b?0:1;i(),a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function f(b,c,d){var f=a.dom,g=f.create("p");w.ie&&w.ie<11||(g.innerHTML='
'),c?b.parentNode.insertBefore(g,b):f.insertAfter(g,b),i(),c&&d===x.ENTER?e(c,b):a.selection.setCursorLocation(g,0),a.nodeChanged()}function g(b){a.undoManager.transact(function(){f(b),wp.mce.views.remove(a,b)})}function h(b){var c,e=a.dom;b&&(b!==n&&(a.getBody().focus(),i(),n=b,e.setAttrib(b,"data-mce-selected",1),c=e.create("div",{"class":"wpview-clipboard",contenteditable:"true"},wp.mce.views.getText(b)),a.dom.select(".wpview-body",b)[0].appendChild(c),e.bind(c,"beforedeactivate focusin focusout",d),e.bind(n,"beforedeactivate focusin focusout",d),C?a.selection.select(c):a.selection.select(c,!0)),a.nodeChanged(),a.fire("wpview-selected",b))}function i(){var b,c=a.dom;n&&(b=a.dom.select(".wpview-clipboard",n)[0],c.unbind(b),c.remove(b),c.unbind(n,"beforedeactivate focusin focusout click mouseup",d),c.setAttrib(n,"data-mce-selected",null)),n=null}function j(a,b){return"

"+window.decodeURIComponent(b)+"

"}function k(a){return a.replace(/]+data-wpview-text="([^"]+)"[^>]*>(?:[\s\S]+?wpview-selection-after[^>]+>[^<>]*<\/p>\s*|\.)<\/div>/g,j).replace(/

]*?data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g,j)}function l(a){v("div[data-wpview-text], p[data-wpview-marker]",a).each(function(a,b){b.innerHTML="."})}function m(a){return 47>=a&&a!==x.SPACEBAR&&a!==x.ENTER&&a!==x.DELETE&&a!==x.BACKSPACE&&(37>a||a>40)||a>=224||a>=144&&150>=a||a>=91&&93>=a||a>=112&&135>=a}var n,o,p,q,r,s,t,u,v=a.$,w=tinymce.Env,x=tinymce.util.VK,y=tinymce.dom.TreeWalker,z=!1,A=!0,B=function(){return!1},C=/iPad|iPod|iPhone/.test(navigator.userAgent);return"undefined"!=typeof wp&&wp.mce?(a.on("BeforeAddUndo",function(a){a.level.content&&(a.level.content=k(a.level.content))}),a.on("BeforeSetContent",function(b){var c;if(b.selection||wp.mce.views.unbind(),b.content){if(!b.load&&(n&&g(n),c=a.selection.getNode(),c&&c!==a.getBody()&&/^\s*https?:\/\/\S+\s*$/i.test(b.content))){if(c=a.dom.getParent(c,"p"),!c||!/^[\s\uFEFF\u00A0]*$/.test(v(c).text()||""))return;c.innerHTML=""}b.content=wp.mce.views.setMarkers(b.content)}}),a.on("pastePreProcess",function(a){var b=a.content;b&&(b=tinymce.trim(b.replace(/<[^>]+>/g,"")),/^https?:\/\/\S+$/i.test(b)&&(a.content=b))}),a.on("SetContent",function(){wp.mce.views.render()}),a.on("click",function(c){var d,f,g,h=c.clientX,i=c.clientY,j=a.getBody(),k=j.getBoundingClientRect(),l=j.firstChild,m=j.lastChild;l&&m&&(d=l.getBoundingClientRect(),f=m.getBoundingClientRect(),if.bottom&&(g=b(m))?(e(!1,g),c.preventDefault()):(hk.right)&&tinymce.each(a.dom.select(".wpview-wrap"),function(a){var b=a.getBoundingClientRect();return i=b.top&&i<=b.bottom?(hk.right&&(e(!1,a),c.preventDefault()),!1):void 0}))}),a.on("init",function(){var c=!1,d=a.selection,e=window.MutationObserver||window.WebKitMutationObserver;a.on("BeforeSetContent",function(){var c,e,f=b(d.getNode());f&&(!f.nextSibling||b(f.nextSibling)?(e=a.getDoc().createTextNode(""),a.dom.insertAfter(e,f)):(c=new y(f.nextSibling,f.nextSibling),e=c.next()),d.select(e),d.collapse(!0))}),a.dom.bind(a.getDoc(),"touchmove",function(){c=!0}),a.on("mousedown mouseup click touchend",function(a){var d=b(a.target);return A=!1,d?(a.stopImmediatePropagation(),a.preventDefault(),"touchend"===a.type&&c?c=!1:h(d),!1):("touchend"!==a.type&&"mousedown"!==a.type||i(),void("touchend"===a.type&&c&&(c=!1)))},!0),e&&new e(function(){a.fire("wp-body-class-change")}).observe(a.getBody(),{attributes:!0,attributeFilter:["class"]}),tinymce.Env.ie&&a.dom.bind(a.getBody(),"controlselect mscontrolselect",function(a){b(a.target)&&a.preventDefault()})}),a.on("PreProcess",function(a){l(a.node)},!0),a.on("hide",function(){wp.mce.views.unbind(),i(),l()}),a.on("PostProcess",function(a){a.content&&(a.content=a.content.replace(/

]*?data-wpview-text="([^"]+)"[^>]*>[\s\S]*?<\/div>/g,j).replace(/

]*?data-wpview-marker="([^"]+)"[^>]*>[\s\S]*?<\/p>/g,j))}),a.on("keydown",function(c){var d,j,k,l,o,q,r,s=c.keyCode,t=a.dom,u=a.selection;if(n){if((c.metaKey||c.ctrlKey)&&s!==x.BACKSPACE&&86!==s||s>=112&&123>=s)return void((c.metaKey||c.ctrlKey)&&88===s&&(z=n));if(j=b(u.getNode()),j!==n)return void i();s===x.LEFT?(e(!0,j),c.preventDefault()):s===x.UP?(j.previousSibling?b(j.previousSibling)?e(!0,j.previousSibling):(i(),u.select(j.previousSibling,!0),u.collapse()):e(!0,j),c.preventDefault()):s===x.RIGHT?(e(!1,j),c.preventDefault()):s===x.DOWN?(j.nextSibling?b(j.nextSibling)?e(!1,j.nextSibling):(i(),u.setCursorLocation(j.nextSibling,0)):e(!1,j),c.preventDefault()):m(s)||(g(n),s!==x.ENTER&&s!==x.DELETE&&s!==x.BACKSPACE||c.preventDefault())}else{if(c.metaKey||c.ctrlKey||s>=112&&123>=s)return;if(d=u.getNode(),p=d,j=b(d),u.isCollapsed()||(o=u.getRng(),(j=b(o.endContainer))?(q=o.cloneRange(),u.select(j.previousSibling,!0),u.collapse(),r=u.getRng(),q.setEnd(r.endContainer,r.endOffset),u.setRng(q)):(j=b(o.startContainer))&&(q=o.cloneRange(),q.setStart(j.nextSibling,0),u.setRng(q))),!j)return void(c.keyCode===x.BACKSPACE&&(a.dom.isEmpty(d)?(j=b(d.previousSibling))&&(e(!1,j),a.dom.remove(d),c.preventDefault()):(o=u.getRng())&&0===o.startOffset&&0===o.endOffset&&(j=b(d.previousSibling))&&(e(!1,j),c.preventDefault())));if(!(k=t.hasClass(j,"wpview-selection-before"))&&!(l=t.hasClass(j,"wpview-selection-after")))return;if(m(s))return;l&&s===x.UP||k&&s===x.BACKSPACE?(j.previousSibling?b(j.previousSibling)?e(!1,j.previousSibling):t.isEmpty(j.previousSibling)&&s===x.BACKSPACE?t.remove(j.previousSibling):(u.select(j.previousSibling,!0),u.collapse()):e(!0,j),c.preventDefault()):!l||s!==x.DOWN&&s!==x.RIGHT?!k||s!==x.UP&&s!==x.LEFT?k&&s===x.DOWN?(j.nextSibling?b(j.nextSibling)?e(!0,j.nextSibling):u.setCursorLocation(j.nextSibling,0):e(!1,j),c.preventDefault()):l&&s===x.LEFT||k&&s===x.RIGHT?(h(j),c.preventDefault()):l&&s===x.BACKSPACE?(g(j),c.preventDefault()):l?f(j):k&&f(j,!0,s):(j.previousSibling&&(b(j.previousSibling)?e(s===x.UP,j.previousSibling):(u.select(j.previousSibling,!0),u.collapse())),c.preventDefault()):(j.nextSibling&&(b(j.nextSibling)?e(s===x.RIGHT,j.nextSibling):u.setCursorLocation(j.nextSibling,0)),c.preventDefault()),s===x.ENTER&&c.preventDefault()}}),a.on("keyup",function(){z&&(g(z),z=!1)}),a.on("focus",function(){var c;r=!0,a.dom.addClass(a.getBody(),"has-focus"),A&&(c=b(a.getBody().firstChild))&&e(!0,c),A=!1}),a.on("blur",function(){r=!1,a.dom.removeClass(a.getBody(),"has-focus")}),a.on("NodeChange",function(d){var f=a.dom,g=a.dom.select(".wpview-wrap"),h=d.element.className,j=b(d.element),k=p;if(p=!1,clearInterval(o),tinymce.each(g,function(a){a.className&&(a.className=a.className.replace(/ ?\bwpview-(?:selection-before|selection-after|cursor-hide)\b/g,""))}),r&&j)if("wpview-selection-before"!==h&&"wpview-selection-after"!==h||!a.selection.isCollapsed())c(d.element,"wpview-clipboard")||q||(i(),q++,e(!0,j));else{if(q=0,i(),k===j.previousSibling)return void e(!0,j);if(k===j.nextSibling)return void e(!1,j);f.addClass(j,h),o=setInterval(function(){f.hasClass(j,"wpview-cursor-hide")?f.removeClass(j,"wpview-cursor-hide"):f.addClass(j,"wpview-cursor-hide")},500)}}),a.on("BeforeExecCommand",function(){var c,d=a.selection.getNode();d&&((t="wpview-selection-before"===d.className)||"wpview-selection-after"===d.className)&&(c=b(d))&&(f(c,t),s=c)}),a.on("ExecCommand",function(){var b,c;n&&(b=n,i(),h(b)),s&&(c=s[t?"previousSibling":"nextSibling"],c&&"P"===c.nodeName&&a.dom.isEmpty(c)&&(a.dom.remove(c),e(t,s)),s=!1)}),a.on("ResolveName",function(c){a.dom.hasClass(c.target,"wpview-wrap")?(c.name=a.dom.getAttrib(c.target,"data-wpview-type")||"wpview",c.stopPropagation()):b(c.target)&&(c.preventDefault(),c.stopPropagation())}),a.addButton("wp_view_edit",{tooltip:"Edit ",icon:"dashicon dashicons-edit",onclick:function(){n&&wp.mce.views.edit(a,n)}}),a.addButton("wp_view_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",onclick:function(){n&&g(n)}}),a.once("preinit",function(){a.wp&&a.wp._createToolbar&&(u=a.wp._createToolbar(["wp_view_edit","wp_view_remove"]))}),a.on("wptoolbar",function(a){n&&(a.element=n,a.toolbar=u)}),a.wp=a.wp||{},a.wp.getView=b,a.wp.setViewCursor=e,{getView:b}):{getView:B}}); \ No newline at end of file +!function(a,b){a.PluginManager.add("wpview",function(c){function d(){}function e(a){return c.dom.hasClass(a,"wpview")}function f(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}return b&&b.mce?(c.on("beforesetcontent",function(a){var d;if(a.selection||b.mce.views.unbind(),a.content){if(!a.load&&(d=c.selection.getNode(),d&&d!==c.getBody()&&/^\s*https?:\/\/\S+\s*$/i.test(a.content))){if(d=c.dom.getParent(d,"p"),!d||!/^[\s\uFEFF\u00A0]*$/.test(c.$(d).text()||""))return;d.innerHTML=""}a.content=b.mce.views.setMarkers(a.content)}}),c.on("setcontent",function(){b.mce.views.render()}),c.on("preprocess",function(a){c.$("div[data-wpview-text], p[data-wpview-marker]",a.node).each(function(a,b){b.innerHTML="."})},!0),c.on("postprocess",function(a){a.content=f(a.content)}),c.on("beforeaddundo",function(a){a.level.content=f(a.level.content)}),c.on("drop objectselected",function(a){e(a.targetClone)&&(a.targetClone=c.getDoc().createTextNode(window.decodeURIComponent(c.dom.getAttrib(a.targetClone,"data-wpview-text"))))}),c.on("pastepreprocess",function(b){var c=b.content;c&&(c=a.trim(c.replace(/<[^>]+>/g,"")),/^https?:\/\/\S+$/i.test(c)&&(b.content=c))}),c.on("resolvename",function(a){e(a.target)&&(a.name=c.dom.getAttrib(a.target,"data-wpview-type")||"object")}),c.on("click keyup",function(){var a=c.selection.getNode();e(a)&&c.dom.getAttrib(a,"data-mce-selected")&&a.setAttribute("data-mce-selected","2")}),c.addButton("wp_view_edit",{tooltip:"Edit ",icon:"dashicon dashicons-edit",onclick:function(){var a=c.selection.getNode();e(a)&&b.mce.views.edit(c,a)}}),c.addButton("wp_view_remove",{tooltip:"Remove",icon:"dashicon dashicons-no",onclick:function(){c.fire("cut")}}),c.once("preinit",function(){var a;c.wp&&c.wp._createToolbar&&(a=c.wp._createToolbar(["wp_view_edit","wp_view_remove"]),c.on("wptoolbar",function(b){e(b.element)&&(b.toolbar=a)}))}),c.wp=c.wp||{},c.wp.getView=d,c.wp.setViewCursor=d,{getView:d}):{getView:d}})}(window.tinymce,window.wp); \ No newline at end of file diff --git a/wp-includes/js/tinymce/skins/wordpress/wp-content.css b/wp-includes/js/tinymce/skins/wordpress/wp-content.css index 80510aca8a..eeb9aa1446 100644 --- a/wp-includes/js/tinymce/skins/wordpress/wp-content.css +++ b/wp-includes/js/tinymce/skins/wordpress/wp-content.css @@ -209,98 +209,15 @@ audio { * WP Views */ -.wpview-wrap { +.wpview { width: 99.99%; /* All IE need hasLayout, incl. 11 (ugh, not again!!) */ position: relative; clear: both; -} - -/* delegate the handling of the selection to the wpview tinymce plugin */ -.wpview-wrap, -.wpview-wrap * { - -moz-user-select: none; - -webkit-user-select: none; - -ms-user-select: none; - user-select: none; -} - -/* hide the shortcode content, but allow the content to still be selected */ -.wpview-wrap .wpview-clipboard, -.wpview-wrap > p { - position: absolute; - top: 0; - left: 0; - z-index: -1; - clip: rect(1px 1px 1px 1px); /* IE7 */ - clip: rect(1px, 1px, 1px, 1px); - overflow: hidden; - outline: 0; - padding: 0; - border: 0; - width: 1px; - height: 1px; -} - -/* An ugly box will appear when this is focussed in IE, so we'll move it outside the window. */ -.wpview-wrap.wpview-selection-before > p, -.wpview-wrap.wpview-selection-after > p { - left: -10000px; -} - -.wpview-wrap .wpview-clipboard, -.wpview-wrap .wpview-clipboard *, -.wpview-wrap > p { - -moz-user-select: text; - -webkit-user-select: text; - -ms-user-select: text; - user-select: text; -} - -.has-focus .wpview-wrap.wpview-selection-before:before, -.has-focus .wpview-wrap.wpview-selection-after:before { - content: ''; - margin: 0; - padding: 0; - position: absolute; - top: -2px; - left: -3px; - bottom: -2px; - width: 1px; - background-color: black; - background-color: currentcolor; - opacity: 1; -} - -.has-focus .wpview-wrap.wpview-selection-after:before { - left: auto; - right: -3px; -} - -.has-focus .wpview-wrap.wpview-cursor-hide:before { - opacity: 0; -} - -/** - * Media previews - */ -.wpview-wrap { - position: relative; - margin-bottom: 16px; + margin-bottom: 16px; border: 1px solid transparent; } -.wpview-wrap[data-mce-selected] { - background-color: rgba(0,0,0,0.1); - border-color: rgba(0,0,0,0.3); -} - -.ie8 .wpview-wrap[data-mce-selected], -.ie7 .wpview-wrap[data-mce-selected] { - background-color: #e5e5e5; - border-color: #72777c; -} - -.wpview-overlay { +.mce-shim { position: absolute; top: 0; right: 0; @@ -308,21 +225,21 @@ audio { left: 0; } -.wpview-wrap[data-mce-selected] .wpview-overlay { +.wpview[data-mce-selected="2"] .mce-shim { display: none; } -.wpview-wrap .loading-placeholder { +.wpview .loading-placeholder { border: 1px dashed #ccc; padding: 10px; } -.wpview-wrap[data-mce-selected] .loading-placeholder { +.wpview[data-mce-selected] .loading-placeholder { border-color: transparent; } /* A little "loading" animation, not showing in IE < 10 */ -.wpview-wrap .wpview-loading { +.wpview .wpview-loading { width: 60px; height: 5px; overflow: hidden; @@ -330,7 +247,7 @@ audio { margin: 10px auto 0; } -.wpview-wrap .wpview-loading ins { +.wpview .wpview-loading ins { background-color: #333; margin: 0 0 0 -60px; width: 36px; @@ -358,7 +275,7 @@ audio { } } -.wpview-wrap .wpview-content > iframe { +.wpview .wpview-content > iframe { max-width: 100%; background: transparent; } @@ -370,7 +287,7 @@ audio { word-wrap: break-word; } -.wpview-wrap[data-mce-selected] .wpview-error { +.wpview[data-mce-selected] .wpview-error { border-color: transparent; } diff --git a/wp-includes/js/tinymce/wp-tinymce.js.gz b/wp-includes/js/tinymce/wp-tinymce.js.gz index d0996f7fe3..9a54f1c581 100644 Binary files a/wp-includes/js/tinymce/wp-tinymce.js.gz and b/wp-includes/js/tinymce/wp-tinymce.js.gz differ diff --git a/wp-includes/version.php b/wp-includes/version.php index 18c0e17e00..f5ae0fec4c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-alpha-37444'; +$wp_version = '4.6-alpha-37446'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.