From 1d637d85e0d8d5eb53e147f8c4809793272a1c49 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sat, 19 Jul 2014 00:34:15 +0000 Subject: [PATCH] TinyMCE wpView: - Typing something replaces a selected view. - Pressing backspace deletes the selection. - Pressing enter also deletes the selection. - Pasting something replaces the selection. - Also merge the different 'keydown' handlers. Props avryl, fixes #28913. Built from https://develop.svn.wordpress.org/trunk@29236 git-svn-id: http://core.svn.wordpress.org/trunk@29020 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../js/tinymce/plugins/wpview/plugin.js | 373 +++++++++--------- .../js/tinymce/plugins/wpview/plugin.min.js | 2 +- wp-includes/js/tinymce/wp-tinymce.js.gz | Bin 133247 -> 133257 bytes 3 files changed, 184 insertions(+), 191 deletions(-) diff --git a/wp-includes/js/tinymce/plugins/wpview/plugin.js b/wp-includes/js/tinymce/plugins/wpview/plugin.js index e706df4746..fe08e8b228 100644 --- a/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -76,7 +76,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { editor.nodeChanged(); } - function handleEnter( view, before, keyCode ) { + function handleEnter( view, before, key ) { var dom = editor.dom, padNode = dom.create( 'p' ); @@ -92,7 +92,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { deselect(); - if ( before && keyCode === VK.ENTER ) { + if ( before && key === VK.ENTER ) { setViewCursor( before, view ); } else { editor.selection.setCursorLocation( padNode, 0 ); @@ -336,207 +336,197 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { // (De)select views when arrow keys are used to navigate the content of the editor. editor.on( 'keydown', function( event ) { - if ( event.metaKey || event.ctrlKey || ( keyCode >= 112 && keyCode <= 123 ) ) { - return; - } - - if ( selected ) { - return; - } - - var keyCode = event.keyCode, + var key = event.keyCode, dom = editor.dom, selection = editor.selection, - node = selection.getNode(), - view = getView( node ), - cursorBefore, cursorAfter, - range, clonedRange, tempRange; + node, view, cursorBefore, cursorAfter, + range, clonedRange, tempRange, remove; - lastKeyDownNode = node; - - // 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 ( selected ) { + // Let key presses that involve the command or control keys through. + // Also, let any of the F# keys through. + if ( event.metaKey || event.ctrlKey || ( key >= 112 && key <= 123 ) ) { + // But remove the view when cmd/ctrl + x/backspace are pressed. + if ( ( event.metaKey || event.ctrlKey ) && ( key === 88 || key === VK.BACKSPACE ) ) { + // We'll remove a cut view on keyup, otherwise the browser can't copy the content. + if ( key === 88 ) { + toRemove = selected; + } else { + editor.dom.remove( selected ); + } + } + return; } - } - if ( ! view ) { - return; - } + view = getView( selection.getNode() ); - if ( ! ( ( cursorBefore = dom.hasClass( view, 'wpview-selection-before' ) ) || - ( cursorAfter = dom.hasClass( view, 'wpview-selection-after' ) ) ) ) { - return; - } + // If the caret is not within the selected view, deselect the view and bail. + if ( view !== selected ) { + deselect(); + return; + } - if ( ( cursorAfter && keyCode === VK.UP ) || ( cursorBefore && keyCode === VK.BACKSPACE ) ) { - if ( view.previousSibling ) { - if ( getView( view.previousSibling ) ) { - setViewCursor( false, view.previousSibling ); + 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(); + } } else { - if ( dom.isEmpty( view.previousSibling ) && keyCode === VK.BACKSPACE ) { - dom.remove( view.previousSibling ); + 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 ( ( key > 47 || VK.SPACEBAR || key === VK.ENTER || key === VK.DELETE || key === VK.BACKSPACE ) && key !== 144 && key !== 145 ) { + editor.undoManager.transact( function() { + remove = selected; + handleEnter( selected ); + dom.remove( remove ); + }); + + 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 ); + + // 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 ); + } + } + + // 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(); + return; + } + } else if ( ( range = selection.getRng() ) && + range.startOffset === 0 && + range.endOffset === 0 && + ( view = getView( node.previousSibling ) ) ) { + setViewCursor( false, view ); + event.preventDefault(); + return; + } + } + + if ( ! view ) { + return; + } + + if ( ! ( ( cursorBefore = dom.hasClass( view, 'wpview-selection-before' ) ) || + ( cursorAfter = dom.hasClass( view, 'wpview-selection-after' ) ) ) ) { + 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(); } } - } else { - setViewCursor( true, view ); - } - event.preventDefault(); - } else if ( cursorAfter && ( keyCode === VK.DOWN || keyCode === VK.RIGHT ) ) { - if ( view.nextSibling ) { - if ( getView( view.nextSibling ) ) { - setViewCursor( keyCode === VK.RIGHT, view.nextSibling ); + 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 { - selection.setCursorLocation( view.nextSibling, 0 ); - } - } - event.preventDefault(); - } else if ( cursorBefore && ( keyCode === VK.UP || keyCode === VK.LEFT ) ) { - if ( view.previousSibling ) { - if ( getView( view.previousSibling ) ) { - setViewCursor( keyCode === VK.UP, view.previousSibling ); - } else { - selection.select( view.previousSibling, true ); - selection.collapse(); - } - } - event.preventDefault(); - } else if ( cursorBefore && keyCode === 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 && keyCode === VK.LEFT ) || ( cursorBefore && keyCode === VK.RIGHT ) ) { - select( view ); - event.preventDefault(); - event.stopImmediatePropagation(); - } else if ( cursorAfter && keyCode === VK.BACKSPACE ) { - dom.remove( view ); - event.preventDefault(); - } else if ( cursorAfter ) { - handleEnter( view ); - } else if ( cursorBefore ) { - handleEnter( view , true, keyCode ); - } - - if ( keyCode === VK.ENTER ) { - event.preventDefault(); - } - }); - - // Handle key presses for selected views. - editor.on( 'keydown', function( event ) { - var dom = editor.dom, - keyCode = event.keyCode, - selection = editor.selection, - view; - - // If a view isn't selected, let the event go on its merry way. - if ( ! selected ) { - return; - } - - // Let key presses that involve the command or control keys through. - // Also, let any of the F# keys through. - if ( event.metaKey || event.ctrlKey || ( keyCode >= 112 && keyCode <= 123 ) ) { - // But remove the view when cmd/ctrl + x/backspace are pressed. - if ( ( event.metaKey || event.ctrlKey ) && ( keyCode === 88 || keyCode === VK.BACKSPACE ) ) { - // We'll remove a cut view on keyup, otherwise the browser can't copy the content. - if ( keyCode === 88 ) { - toRemove = selected; - } else { - editor.dom.remove( selected ); - } - } - return; - } - - view = getView( selection.getNode() ); - - // If the caret is not within the selected view, deselect the view and bail. - if ( view !== selected ) { - deselect(); - return; - } - - if ( keyCode === VK.LEFT ) { - setViewCursor( true, view ); - } else if ( keyCode === VK.UP ) { - if ( view.previousSibling ) { - if ( getView( view.previousSibling ) ) { - setViewCursor( true, view.previousSibling ); - } else { - deselect(); - selection.select( view.previousSibling, true ); - selection.collapse(); - } - } else { - setViewCursor( true, view ); - } - - } else if ( keyCode === VK.RIGHT ) { - setViewCursor( false, view ); - } else if ( keyCode === VK.DOWN ) { - if ( view.nextSibling ) { - if ( getView( view.nextSibling ) ) { - setViewCursor( false, view.nextSibling ); - } else { - deselect(); - selection.setCursorLocation( view.nextSibling, 0 ); - } - } else { - setViewCursor( false, view ); - } - } else if ( keyCode === VK.ENTER ) { - handleEnter( view ); - } else if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) { - dom.remove( selected ); - } - - event.preventDefault(); - }); - - // Make sure we don't eat any content. - editor.on( 'keydown', function( event ) { - var selection = editor.selection, - node, range, view; - - if ( event.keyCode === VK.BACKSPACE ) { - node = selection.getNode(); - - 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(); + } else if ( ( cursorAfter && key === VK.LEFT ) || ( cursorBefore && key === VK.RIGHT ) ) { + select( view ); + event.preventDefault(); + } else if ( cursorAfter && key === VK.BACKSPACE ) { + editor.undoManager.transact( function() { + handleEnter( view ); + dom.remove( view ); + }); + event.preventDefault(); + } else if ( cursorAfter ) { + handleEnter( view ); + } else if ( cursorBefore ) { + handleEnter( view , true, key ); + } + + if ( key === VK.ENTER ) { event.preventDefault(); } } @@ -580,9 +570,12 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { clearInterval( cursorInterval ); - dom.removeClass( views, 'wpview-selection-before' ); - dom.removeClass( views, 'wpview-selection-after' ); - dom.removeClass( views, 'wpview-cursor-hide' ); + // 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 ) { if ( view ) { diff --git a/wp-includes/js/tinymce/plugins/wpview/plugin.min.js b/wp-includes/js/tinymce/plugins/wpview/plugin.min.js index c60c0d3c91..b22bf87bda 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(c){return(c=b(c))?window.decodeURIComponent(a.dom.getAttrib(c,"data-wpview-text")||""):""}function e(c,d){return c=b(c),c?(a.dom.setAttrib(c,"data-wpview-text",window.encodeURIComponent(d||"")),!0):!1}function f(a){a.stopPropagation()}function g(b,c){var d=b?"before":"after",e=b?0:1;j(),a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function h(b,c,d){var e=a.dom,f=e.create("p");r.ie&&r.ie<11||(f.innerHTML='
'),c?b.parentNode.insertBefore(f,b):e.insertAfter(f,b),j(),c&&d===s.ENTER?g(c,b):a.selection.setCursorLocation(f,0),a.nodeChanged()}function i(b){var c,e=a.dom;b!==l&&(j(),l=b,e.setAttrib(b,"data-mce-selected",1),c=e.create("div",{"class":"wpview-clipboard",contenteditable:"true"},d(b)),a.dom.select(".wpview-body",b)[0].appendChild(c),e.bind(c,"beforedeactivate focusin focusout",f),e.bind(l,"beforedeactivate focusin focusout",f),a.getBody().focus(),a.selection.select(c,!0),a.nodeChanged())}function j(){var b,c=a.dom;l&&(b=a.dom.select(".wpview-clipboard",l)[0],c.unbind(b),c.remove(b),c.unbind(l,"beforedeactivate focusin focusout click mouseup",f),c.setAttrib(l,"data-mce-selected",null)),l=null}function k(a){return a.replace(/]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?: |\u00a0)*<\/p><\/div>/g,"$1")}var l,m,n,o,p,q,r=tinymce.Env,s=tinymce.util.VK,t=tinymce.dom.TreeWalker,u=!1,v=!0,w=function(){return!1};return"undefined"!=typeof wp&&wp.mce?(a.on("BeforeAddUndo",function(a){a.lastLevel&&k(a.level.content)===k(a.lastLevel.content)&&a.preventDefault()}),a.on("BeforeSetContent",function(b){var c;b.content&&(b.initial||wp.mce.views.unbind(a),c=a.selection.getNode(),(!b.content.match(/^\s*(https?:\/\/[^\s"]+)\s*$/i)||"P"===c.nodeName&&c.parentNode===a.getBody()&&a.dom.isEmpty(c))&&(b.content=wp.mce.views.toViews(b.content)))}),a.on("SetContent",function(){wp.mce.views.render()}),a.on("click",function(c){var d,e=c.clientX,f=c.clientY,h=a.getBody(),i=h.getBoundingClientRect(),j=h.firstChild,k=j.getBoundingClientRect(),l=h.lastChild,m=l.getBoundingClientRect();fm.bottom&&(d=b(l))?(g(!1,d),c.preventDefault()):tinymce.each(a.dom.select(".wpview-wrap"),function(a){var b=a.getBoundingClientRect();return f>=b.top&&f<=b.bottom?void(ei.right&&(g(!1,a),c.preventDefault())):void 0})}),a.on("init",function(){var c=a.selection;a.on("BeforeSetContent",function(){var d,e,f=b(c.getNode());f&&(!f.nextSibling||b(f.nextSibling)?(e=a.getDoc().createTextNode(""),a.dom.insertAfter(e,f)):(d=new t(f.nextSibling,f.nextSibling),e=d.next()),c.select(e),c.collapse(!0))}),a.dom.bind(a.getBody().parentNode,"mousedown mouseup click",function(c){var d,e=b(c.target);return v=!1,e?(c.stopPropagation(),r.ie<=10&&j(),i(e),"click"!==c.type||c.metaKey||c.ctrlKey||(a.dom.hasClass(c.target,"edit")?wp.mce.views.edit(e):a.dom.hasClass(c.target,"remove")&&a.dom.remove(e)),!1):(d=r.ie&&r.ie<=8?"mouseup":"mousedown",void(c.type===d&&j()))})}),a.on("PreProcess",function(b){tinymce.each(a.dom.select("div[data-wpview-text]",b.node),function(a){a.textContent=a.innerText=" "})}),a.on("PostProcess",function(a){a.content&&(a.content=a.content.replace(/
]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g,function(a,b){return b?"

"+window.decodeURIComponent(b)+"

":""}))}),a.on("keydown",function(c){if(!(c.metaKey||c.ctrlKey||m>=112&&123>=m||l)){var d,e,f,j,k,m=c.keyCode,o=a.dom,p=a.selection,q=p.getNode(),r=b(q);n=q,p.isCollapsed()||(f=p.getRng(),(r=b(f.endContainer))?(j=f.cloneRange(),p.select(r.previousSibling,!0),p.collapse(),k=p.getRng(),j.setEnd(k.endContainer,k.endOffset),p.setRng(j)):(r=b(f.startContainer))&&(j=f.cloneRange(),j.setStart(r.nextSibling,0),p.setRng(j))),r&&((d=o.hasClass(r,"wpview-selection-before"))||(e=o.hasClass(r,"wpview-selection-after")))&&(e&&m===s.UP||d&&m===s.BACKSPACE?(r.previousSibling?b(r.previousSibling)?g(!1,r.previousSibling):o.isEmpty(r.previousSibling)&&m===s.BACKSPACE?o.remove(r.previousSibling):(p.select(r.previousSibling,!0),p.collapse()):g(!0,r),c.preventDefault()):!e||m!==s.DOWN&&m!==s.RIGHT?!d||m!==s.UP&&m!==s.LEFT?d&&m===s.DOWN?(r.nextSibling?b(r.nextSibling)?g(!0,r.nextSibling):p.setCursorLocation(r.nextSibling,0):g(!1,r),c.preventDefault()):e&&m===s.LEFT||d&&m===s.RIGHT?(i(r),c.preventDefault(),c.stopImmediatePropagation()):e&&m===s.BACKSPACE?(o.remove(r),c.preventDefault()):e?h(r):d&&h(r,!0,m):(r.previousSibling&&(b(r.previousSibling)?g(m===s.UP,r.previousSibling):(p.select(r.previousSibling,!0),p.collapse())),c.preventDefault()):(r.nextSibling&&(b(r.nextSibling)?g(m===s.RIGHT,r.nextSibling):p.setCursorLocation(r.nextSibling,0)),c.preventDefault()),m===s.ENTER&&c.preventDefault())}}),a.on("keydown",function(c){var d,e=a.dom,f=c.keyCode,i=a.selection;if(l){if(c.metaKey||c.ctrlKey||f>=112&&123>=f)return void(!c.metaKey&&!c.ctrlKey||88!==f&&f!==s.BACKSPACE||(88===f?u=l:a.dom.remove(l)));if(d=b(i.getNode()),d!==l)return void j();f===s.LEFT?g(!0,d):f===s.UP?d.previousSibling?b(d.previousSibling)?g(!0,d.previousSibling):(j(),i.select(d.previousSibling,!0),i.collapse()):g(!0,d):f===s.RIGHT?g(!1,d):f===s.DOWN?d.nextSibling?b(d.nextSibling)?g(!1,d.nextSibling):(j(),i.setCursorLocation(d.nextSibling,0)):g(!1,d):f===s.ENTER?h(d):(f===s.DELETE||f===s.BACKSPACE)&&e.remove(l),c.preventDefault()}}),a.on("keydown",function(c){var d,e,f,h=a.selection;c.keyCode===s.BACKSPACE&&(d=h.getNode(),a.dom.isEmpty(d)?(f=b(d.previousSibling))&&(g(!1,f),a.dom.remove(d),c.preventDefault()):(e=h.getRng())&&0===e.startOffset&&0===e.endOffset&&(f=b(d.previousSibling))&&(g(!1,f),c.preventDefault()))}),a.on("keyup",function(){u&&(a.dom.remove(u),u=!1)}),a.on("focus",function(){var c;p=!0,a.dom.addClass(a.getBody(),"has-focus"),v&&(c=b(a.getBody().firstChild))&&g(!0,c),v=!1}),a.on("blur",function(){p=!1,a.dom.removeClass(a.getBody(),"has-focus")}),a.on("NodeChange",function(d){var e=a.dom,f=a.dom.select(".wpview-wrap"),h=d.element.className,i=b(d.element),k=n;if(n=!1,clearInterval(m),e.removeClass(f,"wpview-selection-before"),e.removeClass(f,"wpview-selection-after"),e.removeClass(f,"wpview-cursor-hide"),p)if(i)if("wpview-selection-before"!==h&&"wpview-selection-after"!==h||!a.selection.isCollapsed())c(d.element,"wpview-clipboard")||o||(j(),o++,g(!0,i));else{if(o=0,j(),k===i.previousSibling)return void g(!0,i);if(k===i.nextSibling)return void g(!1,i);e.addClass(i,h),m=setInterval(function(){e.hasClass(i,"wpview-cursor-hide")?e.removeClass(i,"wpview-cursor-hide"):e.addClass(i,"wpview-cursor-hide")},500)}else j()}),a.on("BeforeExecCommand",function(){var c,d=a.selection.getNode();d&&("wpview-selection-before"===d.className||"wpview-selection-after"===d.className)&&(c=b(d))&&(h(c),q=c)}),a.on("ExecCommand",function(){var b,c;l&&(b=l,j(),i(b)),q&&(c=q.nextSibling,c&&"P"===c.nodeName&&a.dom.isEmpty(c)&&(a.dom.remove(c),g(!1,q)),q=!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())}),{getViewText:d,setViewText:e,getView:b}):{getViewText:w,setViewText:w,getView:w}}); \ No newline at end of file +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(c){return(c=b(c))?window.decodeURIComponent(a.dom.getAttrib(c,"data-wpview-text")||""):""}function e(c,d){return c=b(c),c?(a.dom.setAttrib(c,"data-wpview-text",window.encodeURIComponent(d||"")),!0):!1}function f(a){a.stopPropagation()}function g(b,c){var d=b?"before":"after",e=b?0:1;j(),a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function h(b,c,d){var e=a.dom,f=e.create("p");r.ie&&r.ie<11||(f.innerHTML='
'),c?b.parentNode.insertBefore(f,b):e.insertAfter(f,b),j(),c&&d===s.ENTER?g(c,b):a.selection.setCursorLocation(f,0),a.nodeChanged()}function i(b){var c,e=a.dom;b!==l&&(j(),l=b,e.setAttrib(b,"data-mce-selected",1),c=e.create("div",{"class":"wpview-clipboard",contenteditable:"true"},d(b)),a.dom.select(".wpview-body",b)[0].appendChild(c),e.bind(c,"beforedeactivate focusin focusout",f),e.bind(l,"beforedeactivate focusin focusout",f),a.getBody().focus(),a.selection.select(c,!0),a.nodeChanged())}function j(){var b,c=a.dom;l&&(b=a.dom.select(".wpview-clipboard",l)[0],c.unbind(b),c.remove(b),c.unbind(l,"beforedeactivate focusin focusout click mouseup",f),c.setAttrib(l,"data-mce-selected",null)),l=null}function k(a){return a.replace(/]+data-wpview-text=\"([^"]+)"[^>]*>[\s\S]+?wpview-selection-after[^>]+>(?: |\u00a0)*<\/p><\/div>/g,"$1")}var l,m,n,o,p,q,r=tinymce.Env,s=tinymce.util.VK,t=tinymce.dom.TreeWalker,u=!1,v=!0,w=function(){return!1};return"undefined"!=typeof wp&&wp.mce?(a.on("BeforeAddUndo",function(a){a.lastLevel&&k(a.level.content)===k(a.lastLevel.content)&&a.preventDefault()}),a.on("BeforeSetContent",function(b){var c;b.content&&(b.initial||wp.mce.views.unbind(a),c=a.selection.getNode(),(!b.content.match(/^\s*(https?:\/\/[^\s"]+)\s*$/i)||"P"===c.nodeName&&c.parentNode===a.getBody()&&a.dom.isEmpty(c))&&(b.content=wp.mce.views.toViews(b.content)))}),a.on("SetContent",function(){wp.mce.views.render()}),a.on("click",function(c){var d,e=c.clientX,f=c.clientY,h=a.getBody(),i=h.getBoundingClientRect(),j=h.firstChild,k=j.getBoundingClientRect(),l=h.lastChild,m=l.getBoundingClientRect();fm.bottom&&(d=b(l))?(g(!1,d),c.preventDefault()):tinymce.each(a.dom.select(".wpview-wrap"),function(a){var b=a.getBoundingClientRect();return f>=b.top&&f<=b.bottom?void(ei.right&&(g(!1,a),c.preventDefault())):void 0})}),a.on("init",function(){var c=a.selection;a.on("BeforeSetContent",function(){var d,e,f=b(c.getNode());f&&(!f.nextSibling||b(f.nextSibling)?(e=a.getDoc().createTextNode(""),a.dom.insertAfter(e,f)):(d=new t(f.nextSibling,f.nextSibling),e=d.next()),c.select(e),c.collapse(!0))}),a.dom.bind(a.getBody().parentNode,"mousedown mouseup click",function(c){var d,e=b(c.target);return v=!1,e?(c.stopPropagation(),r.ie<=10&&j(),i(e),"click"!==c.type||c.metaKey||c.ctrlKey||(a.dom.hasClass(c.target,"edit")?wp.mce.views.edit(e):a.dom.hasClass(c.target,"remove")&&a.dom.remove(e)),!1):(d=r.ie&&r.ie<=8?"mouseup":"mousedown",void(c.type===d&&j()))})}),a.on("PreProcess",function(b){tinymce.each(a.dom.select("div[data-wpview-text]",b.node),function(a){a.textContent=a.innerText=" "})}),a.on("PostProcess",function(a){a.content&&(a.content=a.content.replace(/
]*?data-wpview-text="([^"]*)"[^>]*>[\s\S]*?<\/div>/g,function(a,b){return b?"

"+window.decodeURIComponent(b)+"

":""}))}),a.on("keydown",function(c){var d,e,f,k,m,o,p,q,r=c.keyCode,t=a.dom,v=a.selection;if(l){if(c.metaKey||c.ctrlKey||r>=112&&123>=r)return void(!c.metaKey&&!c.ctrlKey||88!==r&&r!==s.BACKSPACE||(88===r?u=l:a.dom.remove(l)));if(e=b(v.getNode()),e!==l)return void j();r===s.LEFT?(g(!0,e),c.preventDefault()):r===s.UP?(e.previousSibling?b(e.previousSibling)?g(!0,e.previousSibling):(j(),v.select(e.previousSibling,!0),v.collapse()):g(!0,e),c.preventDefault()):r===s.RIGHT?(g(!1,e),c.preventDefault()):r===s.DOWN?(e.nextSibling?b(e.nextSibling)?g(!1,e.nextSibling):(j(),v.setCursorLocation(e.nextSibling,0)):g(!1,e),c.preventDefault()):(r>47||s.SPACEBAR||r===s.ENTER||r===s.DELETE||r===s.BACKSPACE)&&144!==r&&145!==r&&(a.undoManager.transact(function(){q=l,h(l),t.remove(q)}),(r===s.ENTER||r===s.DELETE||r===s.BACKSPACE)&&c.preventDefault())}else{if(c.metaKey||c.ctrlKey||r>=112&&123>=r)return;if(d=v.getNode(),n=d,e=b(d),v.isCollapsed()||(m=v.getRng(),(e=b(m.endContainer))?(o=m.cloneRange(),v.select(e.previousSibling,!0),v.collapse(),p=v.getRng(),o.setEnd(p.endContainer,p.endOffset),v.setRng(o)):(e=b(m.startContainer))&&(o=m.cloneRange(),o.setStart(e.nextSibling,0),v.setRng(o))),c.keyCode===s.BACKSPACE)if(a.dom.isEmpty(d)){if(e=b(d.previousSibling))return g(!1,e),a.dom.remove(d),void c.preventDefault()}else if((m=v.getRng())&&0===m.startOffset&&0===m.endOffset&&(e=b(d.previousSibling)))return g(!1,e),void c.preventDefault();if(!e)return;if(!(f=t.hasClass(e,"wpview-selection-before"))&&!(k=t.hasClass(e,"wpview-selection-after")))return;k&&r===s.UP||f&&r===s.BACKSPACE?(e.previousSibling?b(e.previousSibling)?g(!1,e.previousSibling):t.isEmpty(e.previousSibling)&&r===s.BACKSPACE?t.remove(e.previousSibling):(v.select(e.previousSibling,!0),v.collapse()):g(!0,e),c.preventDefault()):!k||r!==s.DOWN&&r!==s.RIGHT?!f||r!==s.UP&&r!==s.LEFT?f&&r===s.DOWN?(e.nextSibling?b(e.nextSibling)?g(!0,e.nextSibling):v.setCursorLocation(e.nextSibling,0):g(!1,e),c.preventDefault()):k&&r===s.LEFT||f&&r===s.RIGHT?(i(e),c.preventDefault()):k&&r===s.BACKSPACE?(a.undoManager.transact(function(){h(e),t.remove(e)}),c.preventDefault()):k?h(e):f&&h(e,!0,r):(e.previousSibling&&(b(e.previousSibling)?g(r===s.UP,e.previousSibling):(v.select(e.previousSibling,!0),v.collapse())),c.preventDefault()):(e.nextSibling&&(b(e.nextSibling)?g(r===s.RIGHT,e.nextSibling):v.setCursorLocation(e.nextSibling,0)),c.preventDefault()),r===s.ENTER&&c.preventDefault()}}),a.on("keyup",function(){u&&(a.dom.remove(u),u=!1)}),a.on("focus",function(){var c;p=!0,a.dom.addClass(a.getBody(),"has-focus"),v&&(c=b(a.getBody().firstChild))&&g(!0,c),v=!1}),a.on("blur",function(){p=!1,a.dom.removeClass(a.getBody(),"has-focus")}),a.on("NodeChange",function(d){var e=a.dom,f=a.dom.select(".wpview-wrap"),h=d.element.className,i=b(d.element),k=n;if(n=!1,clearInterval(m),tinymce.each(f,function(a){a.className&&(a.className=a.className.replace(/ ?\bwpview-(?:selection-before|selection-after|cursor-hide)\b/g,""))}),p)if(i)if("wpview-selection-before"!==h&&"wpview-selection-after"!==h||!a.selection.isCollapsed())c(d.element,"wpview-clipboard")||o||(j(),o++,g(!0,i));else{if(o=0,j(),k===i.previousSibling)return void g(!0,i);if(k===i.nextSibling)return void g(!1,i);e.addClass(i,h),m=setInterval(function(){e.hasClass(i,"wpview-cursor-hide")?e.removeClass(i,"wpview-cursor-hide"):e.addClass(i,"wpview-cursor-hide")},500)}else j()}),a.on("BeforeExecCommand",function(){var c,d=a.selection.getNode();d&&("wpview-selection-before"===d.className||"wpview-selection-after"===d.className)&&(c=b(d))&&(h(c),q=c)}),a.on("ExecCommand",function(){var b,c;l&&(b=l,j(),i(b)),q&&(c=q.nextSibling,c&&"P"===c.nodeName&&a.dom.isEmpty(c)&&(a.dom.remove(c),g(!1,q)),q=!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())}),{getViewText:d,setViewText:e,getView:b}):{getViewText:w,setViewText:w,getView:w}}); \ No newline at end of file diff --git a/wp-includes/js/tinymce/wp-tinymce.js.gz b/wp-includes/js/tinymce/wp-tinymce.js.gz index 6993c1b13e65e4e10cfa437d8ee17042177382ef..2907710964414d15e40960bf93245989ec2ac78c 100644 GIT binary patch delta 1249 zcmV<71RneUkO+y92!MnEv;w~af46pRJ8c6&^j9zsk*ykpDODq*#cEaBB2|DQP+#Z+ zb`lYikPAsrCG#)+mVQ}xW^c0>=hF72)Xv&F-km+WJ9}nEO(A=0hKeDc>8@S@ymEZ3 z{FPvet0)E}zDIOv5kABNicS&dkxxtKspOsKjS1^@J>10E(2OG?-?!5W~+;;pdDOSV` zM&f0#{olX#U$-*WY?~4TxWYK67v7|=BUI5jA5WBnVZ)SZTUv3{)^HO{qrfy zD{06V32KQ@X%^5zF7H>?f5_LwjIh$p&sdfnw_4fp+cP$|!lOp|iB>BjkF?udmFHY> zB3Q(0A`4gGHl&i77fUv>oliM3V+2Rf#JdL!qff3*caU46fVFQ87t zrG1T(LtGkq&q(btlPn}X65=*W5zo&~-q-c>A@<_O4;`))W_zYC6qiX{(L4v)$%)X1 z?Bt#JPrR82J7c5tf$K%OP&zUL?T>e=Iq)?|f80^qK{LCI=w@Tf7$9`6*6ICh>`l#>%b0bH|0vFv;vGcf6gbfsZ~jemsc1n z)o-`g>KB|FblYr;phqr(ZUdfcu~YXI2t;~Ig8v}i^c?Bd&7k=JuQMGYVtfQ%UO>T| z3&a2Nj)1sMe|`_aPBg4GO8e4(?ed2C#%f_HhSOD~75}Esf)%G^ZVAmD7884EC%j(b zq(;DMnV^xytk}>tUC0BXGe7<4&gQE=S9` zRrPcYn=DYTe$k~i`jOXp#^bd+=Lfz~Q!&I%NXP+Vf3P~?Nrw!f6iIK@sCPfV0Oy0% z{U{zg9P_@rmM1>jQM+JWG@LZv!@1Wn0ZX}FA2nB@lWPb1We zBr#3c4!_oQ)Ob{yRHkuK-_pz%9TN!H3={U7Hz}&XKvK_PuAQ(Ww5ty>Z;v}<>Ec>G z3T-b6f76lW6wII?Ni917_r@{fgHLys6|i2n+tD_5EToml!8NAd&u`s=(Q}U7uQMW%b`oSdfB!;7Noag%PiLLd| zDJCJ($DRR$N|F-;j7aP3x>bgr0t&LEFo3ln@21b>s+THyL;0HIR>2pm;EOK!0<`5n L6iIHC&=>{)k#S$W delta 1239 zcmV;|1StE7kqG~g2!MnEv;w~af0uSFJ8i_kUuif*YhfxvFVRNJUP@b}3J?PI)C1Yg ziiB*lNfo$+f9bdM%jy}wW^8Xr+Y6A5y&gQ{d3hdIguL5xRD9r>L-jMTSH&NzSQC_} zMHLXlx4@KE1*18LSPTKUETlKNi}A`|muG>u&PTCnA6vfc{ZUR~XZgAt^za?l;SF)AMH0XxH4;#qVP_BN5w4Jz13agk=ka`)# z(eGbJuLn764sD46vBD_R%ShT4X z7zldkE%LT;c!5vjK_-5p#tK7e^G*BCSz#R)s)*}$rJk( ztH}*9Wt|`x)OcJ1Pm*ZnF>i1X z=+k2qc=HU;cpV(^Iy&NN1}7Z{OB75U(ofD8)IO<4>^p5hFj1ThKb*8_+cHIkhtZf4 z&#W`}#L*gGf6j!edjZW&%UVDtTMAvmniEY>BBIAg%4T{Ql)XZC1DR=2s%5QxynlqEwqXv;fHZ&6z#&~62KHT)cO2E|s-r0WafvUxO0BA@8VLO$#2naolk&Ac%b zasWB+;7u91wWrJNhArLg3ExVr>t1x_ylmukk+*iQf2sPYEF)XA+t*;6BSP$ziqfZ$ zSz(k}wVXX{E+N|g`C*y0;7Oz~H+z(t1BM!vrgvn8$MFQZAgNKEfY539(YvVbztXo5 ze7oBXdT${`<+nk`PF$s>t)LdN!q4jXSR%6LCaN3w`l>iZm-Q32#0lw}@>Vkyc3BUm z>?jyGe}aLeYwH{`2irm&C5IMP3*PCF^Yk{Be6xE-M$Q%Dxsp-sDN9CSK! z4l)UPk&BT5m9KNxhh{#`)V$5`fMytlzNXzJ_W?SUmGM|F<-!!5Qq%E`YbF~ioA6pi z6^Fb-FJw~+6h!bEUds4YI&z|l`t{I^I&#jzN!x&t57A9om=>q4R%Nf_g_*rkO!z89 zPJA1>V{%$!<+C8V*F*<^A)eRrC;2p!HgaJ4DsndPg$;ah179E__z!-sf59sl1^`dd BVQByW