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: http://core.svn.wordpress.org/trunk@22857 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
cef5227d7f
commit
3fd9321c91
|
@ -6,8 +6,6 @@
|
||||||
var DOM = tinymce.DOM;
|
var DOM = tinymce.DOM;
|
||||||
|
|
||||||
tinymce.create('tinymce.plugins.WordPress', {
|
tinymce.create('tinymce.plugins.WordPress', {
|
||||||
showButtons : 0,
|
|
||||||
|
|
||||||
init : function(ed, url) {
|
init : function(ed, url) {
|
||||||
var t = this, tbId = ed.getParam('wordpress_adv_toolbar', 'toolbar2'), last = 0, moreHTML, nextpageHTML, closeOnClick, mod_key;
|
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')+'" />';
|
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',
|
'left' : X+5+'px',
|
||||||
'display' : 'block'
|
'display' : 'block'
|
||||||
});
|
});
|
||||||
|
|
||||||
this.showButtons = true;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_hideButtons : function() {
|
_hideButtons : function() {
|
||||||
if ( ! this.showButtons )
|
tinymce.DOM.hide(['wp_editbtns', 'wp_gallerybtns']);
|
||||||
return;
|
|
||||||
|
|
||||||
if ( document.getElementById('wp_editbtns') )
|
|
||||||
tinymce.DOM.hide('wp_editbtns');
|
|
||||||
|
|
||||||
if ( document.getElementById('wp_gallerybtns') )
|
|
||||||
tinymce.DOM.hide('wp_gallerybtns');
|
|
||||||
|
|
||||||
this.showButtons = false;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Resizes the iframe by a relative height value
|
// Resizes the iframe by a relative height value
|
||||||
|
|
|
@ -205,13 +205,14 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
_createButtons : function() {
|
_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
|
isRetina = ( window.devicePixelRatio && window.devicePixelRatio > 1 ) || // WebKit, Opera
|
||||||
( window.matchMedia && window.matchMedia('(min-resolution:130dpi)').matches ); // Firefox, IE10, Opera
|
( window.matchMedia && window.matchMedia('(min-resolution:130dpi)').matches ); // Firefox, IE10, Opera
|
||||||
|
|
||||||
DOM.remove('wp_editbtns');
|
|
||||||
|
|
||||||
DOM.add(document.body, 'div', {
|
DOM.add(document.body, 'div', {
|
||||||
id : 'wp_editbtns',
|
id : 'wp_editbtns',
|
||||||
style : 'display:none;'
|
style : 'display:none;'
|
||||||
|
@ -239,15 +240,20 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
tinymce.dom.Event.add(dellButton, 'mousedown', function(e) {
|
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 ( el.nodeName == 'IMG' && ed.dom.getAttrib(el, 'class').indexOf('mceItem') == -1 ) {
|
||||||
if ( (p = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(p, 'mceTemp') )
|
if ( (parent = ed.dom.getParent(el, 'div')) && ed.dom.hasClass(parent, 'mceTemp') ) {
|
||||||
ed.dom.remove(p);
|
ed.dom.remove(parent);
|
||||||
else if ( (p = ed.dom.getParent(el, 'A')) && p.childNodes.length == 1 )
|
} else {
|
||||||
ed.dom.remove(p);
|
if ( el.parentNode.nodeName == 'A' && el.parentNode.childNodes.length == 1 )
|
||||||
else
|
el = el.parentNode;
|
||||||
|
|
||||||
|
if ( el.parentNode.nodeName == 'P' && el.parentNode.childNodes.length == 1 )
|
||||||
|
el = el.parentNode;
|
||||||
|
|
||||||
ed.dom.remove(el);
|
ed.dom.remove(el);
|
||||||
|
}
|
||||||
|
|
||||||
ed.execCommand('mceRepaint');
|
ed.execCommand('mceRepaint');
|
||||||
return false;
|
return false;
|
||||||
|
@ -257,7 +263,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
_editImage : function() {
|
_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' )
|
if ( cls.indexOf('mceItem') != -1 || cls.indexOf('wpGallery') != -1 || el.nodeName != 'IMG' )
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
|
|
||||||
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
|
// Register the command so that it can be invoked by using tinyMCE.activeEditor.execCommand('...');
|
||||||
ed.addCommand('WP_Gallery', function() {
|
ed.addCommand('WP_Gallery', function() {
|
||||||
|
if ( tinymce.isIE )
|
||||||
|
ed.selection.moveToBookmark( ed.wpGalleryBookmark );
|
||||||
|
|
||||||
var el = ed.selection.getNode(),
|
var el = ed.selection.getNode(),
|
||||||
gallery = wp.media.gallery,
|
gallery = wp.media.gallery,
|
||||||
frame;
|
frame;
|
||||||
|
@ -49,6 +52,7 @@
|
||||||
|
|
||||||
ed.onMouseDown.add(function(ed, e) {
|
ed.onMouseDown.add(function(ed, e) {
|
||||||
if ( e.target.nodeName == 'IMG' && ed.dom.hasClass(e.target, 'wpGallery') ) {
|
if ( e.target.nodeName == 'IMG' && ed.dom.hasClass(e.target, 'wpGallery') ) {
|
||||||
|
ed.plugins.wordpress._hideButtons();
|
||||||
ed.plugins.wordpress._showButtons(e.target, 'wp_gallerybtns');
|
ed.plugins.wordpress._showButtons(e.target, 'wp_gallerybtns');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -87,13 +91,14 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
_createButtons : function() {
|
_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
|
isRetina = ( window.devicePixelRatio && window.devicePixelRatio > 1 ) || // WebKit, Opera
|
||||||
( window.matchMedia && window.matchMedia('(min-resolution:130dpi)').matches ); // Firefox, IE10, Opera
|
( window.matchMedia && window.matchMedia('(min-resolution:130dpi)').matches ); // Firefox, IE10, Opera
|
||||||
|
|
||||||
DOM.remove('wp_gallerybtns');
|
|
||||||
|
|
||||||
DOM.add(document.body, 'div', {
|
DOM.add(document.body, 'div', {
|
||||||
id : 'wp_gallerybtns',
|
id : 'wp_gallerybtns',
|
||||||
style : 'display:none;'
|
style : 'display:none;'
|
||||||
|
@ -108,7 +113,8 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
tinymce.dom.Event.add(editButton, 'mousedown', function(e) {
|
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.execCommand("WP_Gallery");
|
||||||
ed.plugins.wordpress._hideButtons();
|
ed.plugins.wordpress._hideButtons();
|
||||||
});
|
});
|
||||||
|
@ -122,7 +128,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
tinymce.dom.Event.add(dellButton, 'mousedown', function(e) {
|
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') ) {
|
if ( el.nodeName == 'IMG' && ed.dom.hasClass(el, 'wpGallery') ) {
|
||||||
ed.dom.remove(el);
|
ed.dom.remove(el);
|
||||||
|
|
Loading…
Reference in New Issue