From 76c3055aece5127879db8651c6021d798f8d4572 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Wed, 16 Jul 2014 00:09:58 +0000 Subject: [PATCH] TinyMCE wpView: - Cast off commands targeted to a view except undo, redo, RemoveFormat and mceToggleFormat (bold, italic, etc.). - Disable the link and unlink buttons when a view is selected. Props avryl, see #28595 git-svn-id: https://develop.svn.wordpress.org/trunk@29183 602fd350-edb4-49c9-b593-d223f7449a82 --- .../js/tinymce/plugins/wplink/plugin.js | 5 +++-- .../js/tinymce/plugins/wpview/plugin.js | 20 ++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/js/tinymce/plugins/wplink/plugin.js b/src/wp-includes/js/tinymce/plugins/wplink/plugin.js index d992360b86..8c055857fb 100644 --- a/src/wp-includes/js/tinymce/plugins/wplink/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wplink/plugin.js @@ -15,9 +15,10 @@ tinymce.PluginManager.add( 'wplink', function( editor ) { editor.addShortcut( 'ctrl+k', '', 'WP_Link' ); function setState( button, node ) { - var parent = editor.dom.getParent( node, 'a' ); + var parent = editor.dom.getParent( node, 'a' ), + getView = editor.plugins.wpview ? editor.plugins.wpview.getView : function() { return false; }; - button.disabled( ( editor.selection.isCollapsed() && ! parent ) || ( parent && ! parent.href ) ); + button.disabled( ( editor.selection.isCollapsed() && ! parent ) || ( parent && ! parent.href ) || getView( node ) ); button.active( parent && parent.href ); } diff --git a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js index d9ca259117..b74debcddd 100644 --- a/src/wp-includes/js/tinymce/plugins/wpview/plugin.js +++ b/src/wp-includes/js/tinymce/plugins/wpview/plugin.js @@ -1,4 +1,5 @@ /* global tinymce */ + /** * WordPress View plugin. */ @@ -21,7 +22,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { */ function getParent( node, className ) { while ( node && node.parentNode ) { - if ( node.className && (' ' + node.className + ' ').indexOf(' ' + className + ' ') !== -1 ) { + if ( node.className && ( ' ' + node.className + ' ' ).indexOf( ' ' + className + ' ' ) !== -1 ) { return node; } @@ -563,7 +564,7 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { editor.dom.removeClass( editor.getBody(), 'has-focus' ); } ); - editor.on( 'nodechange', function( event ) { + editor.on( 'NodeChange', function( event ) { var dom = editor.dom, views = editor.dom.select( '.wpview-wrap' ), className = event.element.className, @@ -617,7 +618,20 @@ tinymce.PluginManager.add( 'wpview', function( editor ) { } }); - editor.on( 'resolvename', function( event ) { + editor.on( 'BeforeExecCommand', function( event ) { + var cmd = event.command, + view; + + if ( cmd === 'undo' || cmd === 'redo' || cmd === 'RemoveFormat' || cmd === 'mceToggleFormat' ) { + return; + } + + if ( view = getView( editor.selection.getNode() ) ) { + handleEnter( view ); + } + }); + + 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();