diff --git a/wp-includes/js/tinymce/plugins/wpview/plugin.js b/wp-includes/js/tinymce/plugins/wpview/plugin.js
index 360e418bc9..30179ad777 100644
--- a/wp-includes/js/tinymce/plugins/wpview/plugin.js
+++ b/wp-includes/js/tinymce/plugins/wpview/plugin.js
@@ -12,9 +12,16 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
cursorInterval, lastKeyDownNode, setViewCursorTries, focus;
function getView( node ) {
- return editor.dom.getParent( node, function( node ) {
- return editor.dom.hasClass( node, 'wpview-wrap' );
- });
+ // Doing this directly is about 40% faster
+ while ( node && node.parentNode ) {
+ if ( node.className && (' ' + node.className + ' ').indexOf(' wpview-wrap ') !== -1 ) {
+ return node;
+ }
+
+ node = node.parentNode;
+ }
+
+ return false;
}
/**
@@ -55,6 +62,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
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();
}
@@ -111,6 +119,8 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
dom.bind( clipboard, 'beforedeactivate focusin focusout', _stop );
dom.bind( selected, 'beforedeactivate focusin focusout', _stop );
+ tinymce.DOM.addClass( editor.getContainer(), 'wpview-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.
@@ -274,6 +284,8 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
var view = getView( event.target ),
deselectEventType;
+ firstFocus = false;
+
// Contain clicks inside the view wrapper
if ( view ) {
event.stopPropagation();
@@ -484,33 +496,32 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
if ( keyCode === VK.LEFT ) {
setViewCursor( true, view );
- deselect();
} 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 );
}
- deselect();
+
} else if ( keyCode === VK.RIGHT ) {
setViewCursor( false, view );
- deselect();
} 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 );
}
- deselect();
} else if ( keyCode === VK.ENTER ) {
handleEnter( view );
} else if ( keyCode === VK.DELETE || keyCode === VK.BACKSPACE ) {
@@ -586,38 +597,61 @@ tinymce.PluginManager.add( 'wpview', function( editor ) {
dom.removeClass( views, 'wpview-selection-after' );
dom.removeClass( views, 'wpview-cursor-hide' );
- if ( view && editor.selection.isCollapsed() && focus ) {
- if ( className === 'wpview-selection-before' || className === 'wpview-selection-after' ) {
- setViewCursorTries = 0;
+ if ( ! selected ) {
+ tinymce.DOM.removeClass( editor.getContainer(), 'wpview-selected' );
+ }
- // 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;
- }
+ if ( focus ) {
+ if ( view ) {
+ if ( className === 'wpview-selection-before' || className === 'wpview-selection-after' && editor.selection.isCollapsed() ) {
+ setViewCursorTries = 0;
- dom.addClass( view, className );
+ deselect();
- cursorInterval = setInterval( function() {
- if ( dom.hasClass( view, 'wpview-cursor-hide' ) ) {
- dom.removeClass( view, 'wpview-cursor-hide' );
- } else {
- dom.addClass( view, 'wpview-cursor-hide' );
+ tinymce.DOM.addClass( editor.getContainer(), 'wpview-selected' );
+
+ // 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;
}
- }, 500 );
- // If the cursor happens to be anywhere around the view, then set the cursor properly.
- // Only try this once to prevent a loop. (You never know.)
- } else if ( ! selected && ! setViewCursorTries ) {
- setViewCursorTries++;
- setViewCursor( true, view );
+
+ 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 ( className !== 'wpview-clipboard' && ! setViewCursorTries ) {
+ deselect();
+ setViewCursorTries++;
+ setViewCursor( true, view );
+ }
+ } else {
+ deselect();
}
}
});
+ 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();
+ }
+ });
+
return {
getViewText: getViewText,
setViewText: setViewText
diff --git a/wp-includes/js/tinymce/plugins/wpview/plugin.min.js b/wp-includes/js/tinymce/plugins/wpview/plugin.min.js
index 191ca23acb..24fdaf7b0e 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(b){return a.dom.getParent(b,function(b){return a.dom.hasClass(b,"wpview-wrap")})}function c(c){return(c=b(c))?window.decodeURIComponent(a.dom.getAttrib(c,"data-wpview-text")||""):""}function d(c,d){return c=b(c),c?(a.dom.setAttrib(c,"data-wpview-text",window.encodeURIComponent(d||"")),!0):!1}function e(a){a.stopPropagation()}function f(b,c){var d=b?"before":"after",e=b?0:1;a.selection.setCursorLocation(a.dom.select(".wpview-selection-"+d,c)[0],e),a.nodeChanged()}function g(b,c){var d,e=a.dom;!c&&b.nextSibling&&e.isEmpty(b.nextSibling)&&"P"===b.nextSibling.nodeName?d=b.nextSibling:c&&b.previousSibling&&e.isEmpty(b.previousSibling)&&"P"===b.previousSibling.nodeName?d=b.previousSibling:(d=e.create("p"),p.ie&&p.ie<11||(d.innerHTML='
'),c?b.parentNode.insertBefore(d,b):e.insertAfter(d,b)),i(),a.getBody().focus(),a.selection.setCursorLocation(d,0),a.nodeChanged()}function h(b){var d,f=a.dom;b!==k&&(i(),k=b,f.setAttrib(b,"data-mce-selected",1),d=f.create("div",{"class":"wpview-clipboard",contenteditable:"true"},c(b)),a.dom.select(".wpview-body",b)[0].appendChild(d),f.bind(d,"beforedeactivate focusin focusout",e),f.bind(k,"beforedeactivate focusin focusout",e),a.getBody().focus(),a.selection.select(d,!0),a.nodeChanged())}function i(){var b,c=a.dom;k&&(b=a.dom.select(".wpview-clipboard",k)[0],c.unbind(b),c.remove(b),c.unbind(k,"beforedeactivate focusin focusout click mouseup",e),c.setAttrib(k,"data-mce-selected",null)),k=null}function j(a){return a.replace(/
"+window.decodeURIComponent(b)+"
":""}))}),a.on("keydown",function(c){if(!(c.metaKey||c.ctrlKey||n>=112&&123>=n||k)){var d,e,i,j,l,n=c.keyCode,o=a.dom,p=a.selection,r=p.getNode(),s=b(r);m=r,p.isCollapsed()||(i=p.getRng(),(s=b(i.endContainer))?(j=i.cloneRange(),p.select(s.previousSibling,!0),p.collapse(),l=p.getRng(),j.setEnd(l.endContainer,l.endOffset),p.setRng(j)):(s=b(i.startContainer))&&(j=i.cloneRange(),j.setStart(s.nextSibling,0),p.setRng(j))),s&&((d=o.hasClass(s,"wpview-selection-before"))||(e=o.hasClass(s,"wpview-selection-after")))&&(e&&n===q.UP||d&&n===q.BACKSPACE?(s.previousSibling?b(s.previousSibling)?f(!1,s.previousSibling):o.isEmpty(s.previousSibling)&&n===q.BACKSPACE?o.remove(s.previousSibling):(p.select(s.previousSibling,!0),p.collapse()):f(!0,s),c.preventDefault()):!e||n!==q.DOWN&&n!==q.RIGHT?!d||n!==q.UP&&n!==q.LEFT?d&&n===q.DOWN?(s.nextSibling?b(s.nextSibling)?f(!0,s.nextSibling):p.setCursorLocation(s.nextSibling,0):f(!1,s),c.preventDefault()):e&&n===q.LEFT||d&&n===q.RIGHT?(h(s),c.preventDefault(),c.stopImmediatePropagation()):e&&n===q.BACKSPACE?(o.remove(s),c.preventDefault()):e?g(s):d&&g(s,!0):(s.previousSibling&&(b(s.previousSibling)?f(n===q.UP,s.previousSibling):(p.select(s.previousSibling,!0),p.collapse())),c.preventDefault()):(s.nextSibling&&(b(s.nextSibling)?f(n===q.RIGHT,s.nextSibling):p.setCursorLocation(s.nextSibling,0)),c.preventDefault()),n===q.ENTER&&c.preventDefault())}}),a.on("keydown",function(c){var d,e=a.dom,h=c.keyCode,j=a.selection;if(k){if(c.metaKey||c.ctrlKey||h>=112&&123>=h)return void(!c.metaKey&&!c.ctrlKey||88!==h&&h!==q.BACKSPACE||(88===h?s=k:a.dom.remove(k)));if(d=b(j.getNode()),d!==k)return void i();h===q.LEFT?(f(!0,d),i()):h===q.UP?(d.previousSibling?b(d.previousSibling)?f(!0,d.previousSibling):(j.select(d.previousSibling,!0),j.collapse()):f(!0,d),i()):h===q.RIGHT?(f(!1,d),i()):h===q.DOWN?(d.nextSibling?b(d.nextSibling)?f(!1,d.nextSibling):j.setCursorLocation(d.nextSibling,0):f(!1,d),i()):h===q.ENTER?g(d):(h===q.DELETE||h===q.BACKSPACE)&&e.remove(k),c.preventDefault()}}),a.on("keydown",function(c){var d,e,g,h=a.selection;c.keyCode===q.BACKSPACE&&(d=h.getNode(),a.dom.isEmpty(d)?(g=b(d.previousSibling))&&(f(!1,g),a.dom.remove(d),c.preventDefault()):(e=h.getRng())&&0===e.startOffset&&0===e.endOffset&&(g=b(d.previousSibling))&&(f(!1,g),c.preventDefault()))}),a.on("keyup",function(){s&&(a.dom.remove(s),s=!1)}),a.on("focus",function(){var c;o=!0,a.dom.addClass(a.getBody(),"has-focus"),t&&(c=b(a.getBody().firstChild))&&f(!0,c),t=!1}),a.on("blur",function(){o=!1,a.dom.removeClass(a.getBody(),"has-focus")}),a.on("nodechange",function(c){var d=a.dom,e=a.dom.select(".wpview-wrap"),g=c.element.className,h=b(c.element),i=m;if(m=!1,clearInterval(l),d.removeClass(e,"wpview-selection-before"),d.removeClass(e,"wpview-selection-after"),d.removeClass(e,"wpview-cursor-hide"),h&&a.selection.isCollapsed()&&o)if("wpview-selection-before"===g||"wpview-selection-after"===g){if(n=0,i===h.previousSibling)return void f(!0,h);if(i===h.nextSibling)return void f(!1,h);d.addClass(h,g),l=setInterval(function(){d.hasClass(h,"wpview-cursor-hide")?d.removeClass(h,"wpview-cursor-hide"):d.addClass(h,"wpview-cursor-hide")},500)}else k||n||(n++,f(!0,h))}),{getViewText:c,setViewText:d}}); \ No newline at end of file +tinymce.PluginManager.add("wpview",function(a){function b(a){for(;a&&a.parentNode;){if(a.className&&-1!==(" "+a.className+" ").indexOf(" wpview-wrap "))return a;a=a.parentNode}return!1}function c(c){return(c=b(c))?window.decodeURIComponent(a.dom.getAttrib(c,"data-wpview-text")||""):""}function d(c,d){return c=b(c),c?(a.dom.setAttrib(c,"data-wpview-text",window.encodeURIComponent(d||"")),!0):!1}function e(a){a.stopPropagation()}function f(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 g(b,c){var d,e=a.dom;!c&&b.nextSibling&&e.isEmpty(b.nextSibling)&&"P"===b.nextSibling.nodeName?d=b.nextSibling:c&&b.previousSibling&&e.isEmpty(b.previousSibling)&&"P"===b.previousSibling.nodeName?d=b.previousSibling:(d=e.create("p"),p.ie&&p.ie<11||(d.innerHTML='"+window.decodeURIComponent(b)+"
":""}))}),a.on("keydown",function(c){if(!(c.metaKey||c.ctrlKey||n>=112&&123>=n||k)){var d,e,i,j,l,n=c.keyCode,o=a.dom,p=a.selection,r=p.getNode(),s=b(r);m=r,p.isCollapsed()||(i=p.getRng(),(s=b(i.endContainer))?(j=i.cloneRange(),p.select(s.previousSibling,!0),p.collapse(),l=p.getRng(),j.setEnd(l.endContainer,l.endOffset),p.setRng(j)):(s=b(i.startContainer))&&(j=i.cloneRange(),j.setStart(s.nextSibling,0),p.setRng(j))),s&&((d=o.hasClass(s,"wpview-selection-before"))||(e=o.hasClass(s,"wpview-selection-after")))&&(e&&n===q.UP||d&&n===q.BACKSPACE?(s.previousSibling?b(s.previousSibling)?f(!1,s.previousSibling):o.isEmpty(s.previousSibling)&&n===q.BACKSPACE?o.remove(s.previousSibling):(p.select(s.previousSibling,!0),p.collapse()):f(!0,s),c.preventDefault()):!e||n!==q.DOWN&&n!==q.RIGHT?!d||n!==q.UP&&n!==q.LEFT?d&&n===q.DOWN?(s.nextSibling?b(s.nextSibling)?f(!0,s.nextSibling):p.setCursorLocation(s.nextSibling,0):f(!1,s),c.preventDefault()):e&&n===q.LEFT||d&&n===q.RIGHT?(h(s),c.preventDefault(),c.stopImmediatePropagation()):e&&n===q.BACKSPACE?(o.remove(s),c.preventDefault()):e?g(s):d&&g(s,!0):(s.previousSibling&&(b(s.previousSibling)?f(n===q.UP,s.previousSibling):(p.select(s.previousSibling,!0),p.collapse())),c.preventDefault()):(s.nextSibling&&(b(s.nextSibling)?f(n===q.RIGHT,s.nextSibling):p.setCursorLocation(s.nextSibling,0)),c.preventDefault()),n===q.ENTER&&c.preventDefault())}}),a.on("keydown",function(c){var d,e=a.dom,h=c.keyCode,j=a.selection;if(k){if(c.metaKey||c.ctrlKey||h>=112&&123>=h)return void(!c.metaKey&&!c.ctrlKey||88!==h&&h!==q.BACKSPACE||(88===h?s=k:a.dom.remove(k)));if(d=b(j.getNode()),d!==k)return void i();h===q.LEFT?f(!0,d):h===q.UP?d.previousSibling?b(d.previousSibling)?f(!0,d.previousSibling):(i(),j.select(d.previousSibling,!0),j.collapse()):f(!0,d):h===q.RIGHT?f(!1,d):h===q.DOWN?d.nextSibling?b(d.nextSibling)?f(!1,d.nextSibling):(i(),j.setCursorLocation(d.nextSibling,0)):f(!1,d):h===q.ENTER?g(d):(h===q.DELETE||h===q.BACKSPACE)&&e.remove(k),c.preventDefault()}}),a.on("keydown",function(c){var d,e,g,h=a.selection;c.keyCode===q.BACKSPACE&&(d=h.getNode(),a.dom.isEmpty(d)?(g=b(d.previousSibling))&&(f(!1,g),a.dom.remove(d),c.preventDefault()):(e=h.getRng())&&0===e.startOffset&&0===e.endOffset&&(g=b(d.previousSibling))&&(f(!1,g),c.preventDefault()))}),a.on("keyup",function(){s&&(a.dom.remove(s),s=!1)}),a.on("focus",function(){var c;o=!0,a.dom.addClass(a.getBody(),"has-focus"),t&&(c=b(a.getBody().firstChild))&&f(!0,c),t=!1}),a.on("blur",function(){o=!1,a.dom.removeClass(a.getBody(),"has-focus")}),a.on("nodechange",function(c){var d=a.dom,e=a.dom.select(".wpview-wrap"),g=c.element.className,h=b(c.element),j=m;if(m=!1,clearInterval(l),d.removeClass(e,"wpview-selection-before"),d.removeClass(e,"wpview-selection-after"),d.removeClass(e,"wpview-cursor-hide"),k||tinymce.DOM.removeClass(a.getContainer(),"wpview-selected"),o)if(h)if("wpview-selection-before"===g||"wpview-selection-after"===g&&a.selection.isCollapsed()){if(n=0,i(),tinymce.DOM.addClass(a.getContainer(),"wpview-selected"),j===h.previousSibling)return void f(!0,h);if(j===h.nextSibling)return void f(!1,h);d.addClass(h,g),l=setInterval(function(){d.hasClass(h,"wpview-cursor-hide")?d.removeClass(h,"wpview-cursor-hide"):d.addClass(h,"wpview-cursor-hide")},500)}else"wpview-clipboard"===g||n||(i(),n++,f(!0,h));else i()}),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:c,setViewText:d}}); \ 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 1a5eeea0ef..81f87897b7 100644 Binary files a/wp-includes/js/tinymce/wp-tinymce.js.gz and b/wp-includes/js/tinymce/wp-tinymce.js.gz differ