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
This commit is contained in:
Andrew Ozz 2012-11-27 01:31:51 +00:00
parent 0c434b7cc7
commit afb0b8627b
3 changed files with 28 additions and 29 deletions

View File

@ -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 = '<img src="' + url + '/img/trans.gif" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
@ -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

View File

@ -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;

View File

@ -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);