From afb0b8627bc844e430d90185816ecc55435e540e Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 27 Nov 2012 01:31:51 +0000 Subject: [PATCH] TinyMCE: improve hiding of the image/gallery popup buttons, fix selecting a gallery in IE, don't leave empty paragraph after deleting an image with the popup button, fixes #22463, see #21390 git-svn-id: https://develop.svn.wordpress.org/trunk@22857 602fd350-edb4-49c9-b593-d223f7449a82 --- .../plugins/wordpress/editor_plugin_src.js | 15 +---------- .../plugins/wpeditimage/editor_plugin_src.js | 26 ++++++++++++------- .../plugins/wpgallery/editor_plugin_src.js | 16 ++++++++---- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js b/wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js index dd02ebf56e..6a6d151ea7 100644 --- a/wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js +++ b/wp-includes/js/tinymce/plugins/wordpress/editor_plugin_src.js @@ -6,8 +6,6 @@ var DOM = tinymce.DOM; tinymce.create('tinymce.plugins.WordPress', { - showButtons : 0, - init : function(ed, url) { var t = this, tbId = ed.getParam('wordpress_adv_toolbar', 'toolbar2'), last = 0, moreHTML, nextpageHTML, closeOnClick, mod_key; moreHTML = ''; @@ -374,21 +372,10 @@ 'left' : X+5+'px', 'display' : 'block' }); - - this.showButtons = true; }, _hideButtons : function() { - if ( ! this.showButtons ) - return; - - if ( document.getElementById('wp_editbtns') ) - tinymce.DOM.hide('wp_editbtns'); - - if ( document.getElementById('wp_gallerybtns') ) - tinymce.DOM.hide('wp_gallerybtns'); - - this.showButtons = false; + tinymce.DOM.hide(['wp_editbtns', 'wp_gallerybtns']); }, // Resizes the iframe by a relative height value diff --git a/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js b/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js index c1b9d6bded..17aa30e206 100644 --- a/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js +++ b/wp-includes/js/tinymce/plugins/wpeditimage/editor_plugin_src.js @@ -205,13 +205,14 @@ }, _createButtons : function() { - var t = this, ed = t.editor, DOM = tinymce.DOM, editButton, dellButton, isRetina; + var t = this, ed = tinymce.activeEditor, DOM = tinymce.DOM, editButton, dellButton, isRetina; + + if ( DOM.get('wp_editbtns') ) + return; isRetina = ( window.devicePixelRatio && window.devicePixelRatio > 1 ) || // WebKit, Opera ( window.matchMedia && window.matchMedia('(min-resolution:130dpi)').matches ); // Firefox, IE10, Opera - DOM.remove('wp_editbtns'); - DOM.add(document.body, 'div', { id : 'wp_editbtns', style : 'display:none;' @@ -239,15 +240,20 @@ }); tinymce.dom.Event.add(dellButton, 'mousedown', function(e) { - var el = ed.selection.getNode(), p; + var ed = tinymce.activeEditor, el = ed.selection.getNode(), parent; if ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) { - if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') ) - ed.dom.remove(p); - else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 ) - ed.dom.remove(p); - else + if ( (parent = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(parent, 'mceTemp') ) { + ed.dom.remove(parent); + } else { + if ( el.parentNode.nodeName == 'A' && el.parentNode.childNodes.length == 1 ) + el = el.parentNode; + + if ( el.parentNode.nodeName == 'P' && el.parentNode.childNodes.length == 1 ) + el = el.parentNode; + ed.dom.remove(el); + } ed.execCommand('mceRepaint'); return false; @@ -257,7 +263,7 @@ }, _editImage : function() { - var ed = this.editor, url = this.url, el = ed.selection.getNode(), vp, H, W, cls = el.className; + var ed = tinymce.activeEditor, url = this.url, el = ed.selection.getNode(), vp, H, W, cls = el.className; if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 || el.nodeName != 'IMG' ) return; diff --git a/wp-includes/js/tinymce/plugins/wpgallery/editor_plugin_src.js b/wp-includes/js/tinymce/plugins/wpgallery/editor_plugin_src.js index 819637b5bf..49658d9fff 100644 --- a/wp-includes/js/tinymce/plugins/wpgallery/editor_plugin_src.js +++ b/wp-includes/js/tinymce/plugins/wpgallery/editor_plugin_src.js @@ -11,6 +11,9 @@ // Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...'); ed.addCommand('WP_Gallery', function() { + if ( tinymce.isIE ) + ed.selection.moveToBookmark( ed.wpGalleryBookmark ); + var el = ed.selection.getNode(), gallery = wp.media.gallery, frame; @@ -49,6 +52,7 @@ ed.onMouseDown.add(function(ed, e) { if ( e.target.nodeName == 'IMG' && ed.dom.hasClass(e.target, 'wpGallery') ) { + ed.plugins.wordpress._hideButtons(); ed.plugins.wordpress._showButtons(e.target, 'wp_gallerybtns'); } }); @@ -87,13 +91,14 @@ }, _createButtons : function() { - var t = this, ed = t.editor, DOM = tinymce.DOM, editButton, dellButton, isRetina; + var t = this, ed = tinymce.activeEditor, DOM = tinymce.DOM, editButton, dellButton, isRetina; + + if ( DOM.get('wp_gallerybtns') ) + return; isRetina = ( window.devicePixelRatio && window.devicePixelRatio > 1 ) || // WebKit, Opera ( window.matchMedia && window.matchMedia('(min-resolution:130dpi)').matches ); // Firefox, IE10, Opera - DOM.remove('wp_gallerybtns'); - DOM.add(document.body, 'div', { id : 'wp_gallerybtns', style : 'display:none;' @@ -108,7 +113,8 @@ }); tinymce.dom.Event.add(editButton, 'mousedown', function(e) { - ed.windowManager.bookmark = ed.selection.getBookmark('simple'); + var ed = tinymce.activeEditor; + ed.wpGalleryBookmark = ed.selection.getBookmark('simple'); ed.execCommand("WP_Gallery"); ed.plugins.wordpress._hideButtons(); }); @@ -122,7 +128,7 @@ }); tinymce.dom.Event.add(dellButton, 'mousedown', function(e) { - var el = ed.selection.getNode(); + var ed = tinymce.activeEditor, el = ed.selection.getNode(); if ( el.nodeName == 'IMG' && ed.dom.hasClass(el, 'wpGallery') ) { ed.dom.remove(el);