TinyMCE: better calculation for editor height when switching Text to Visual and back. Add stopping of editor resizing when the mouse leaves the browser window. See #27279
Built from https://develop.svn.wordpress.org/trunk@27941 git-svn-id: http://core.svn.wordpress.org/trunk@27771 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
be70db8c5f
commit
2d0ce517e8
|
@ -13,7 +13,7 @@ window.switchEditors = {
|
||||||
|
|
||||||
// mode can be 'html', 'tmce', or 'toggle'; 'html' is used for the 'Text' editor tab.
|
// mode can be 'html', 'tmce', or 'toggle'; 'html' is used for the 'Text' editor tab.
|
||||||
go: function( id, mode ) {
|
go: function( id, mode ) {
|
||||||
var t = this, ed, wrap_id, txtarea_el, editorHeight, toolbarHeight,
|
var t = this, ed, wrap_id, txtarea_el, iframe, editorHeight, toolbarHeight,
|
||||||
DOM = tinymce.DOM; //DOMUtils outside the editor iframe
|
DOM = tinymce.DOM; //DOMUtils outside the editor iframe
|
||||||
|
|
||||||
id = id || 'content';
|
id = id || 'content';
|
||||||
|
@ -32,17 +32,14 @@ window.switchEditors = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getToolbarHeight() {
|
function getToolbarHeight() {
|
||||||
var height;
|
var node = DOM.select( '.mce-toolbar-grp', ed.getContainer() )[0],
|
||||||
|
height = node && node.clientHeight;
|
||||||
|
|
||||||
try {
|
if ( height && height > 10 && height < 200 ) {
|
||||||
height = DOM.getSize( DOM.select( '.mce-toolbar-grp', ed.getContainer() )[0] );
|
return parseInt( height, 10 );
|
||||||
} catch(e){}
|
|
||||||
|
|
||||||
if ( height && height.h && height.h > 10 && height.h < 100 ) {
|
|
||||||
return height.h;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 'tmce' === mode || 'tinymce' === mode ) {
|
if ( 'tmce' === mode || 'tinymce' === mode ) {
|
||||||
|
@ -63,8 +60,9 @@ window.switchEditors = {
|
||||||
if ( ed ) {
|
if ( ed ) {
|
||||||
ed.show();
|
ed.show();
|
||||||
|
|
||||||
if ( editorHeight && ( toolbarHeight = getToolbarHeight() ) ) {
|
if ( editorHeight ) {
|
||||||
editorHeight = editorHeight - toolbarHeight + 11;
|
toolbarHeight = getToolbarHeight();
|
||||||
|
editorHeight = editorHeight - toolbarHeight + 14;
|
||||||
|
|
||||||
// height cannot be under 50 or over 5000
|
// height cannot be under 50 or over 5000
|
||||||
if ( editorHeight > 50 && editorHeight < 5000 ) {
|
if ( editorHeight > 50 && editorHeight < 5000 ) {
|
||||||
|
@ -73,9 +71,6 @@ window.switchEditors = {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tinymce.init( tinyMCEPreInit.mceInit[id] );
|
tinymce.init( tinyMCEPreInit.mceInit[id] );
|
||||||
|
|
||||||
// ed = tinymce.createEditor( id, tinyMCEPreInit.mceInit[id] );
|
|
||||||
// ed.render();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DOM.removeClass( wrap_id, 'html-active' );
|
DOM.removeClass( wrap_id, 'html-active' );
|
||||||
|
@ -89,11 +84,12 @@ window.switchEditors = {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ed ) {
|
if ( ed ) {
|
||||||
editorHeight = DOM.get( id + '_ifr' );
|
iframe = DOM.get( id + '_ifr' );
|
||||||
editorHeight = editorHeight ? parseInt( editorHeight.style.height, 10 ) : 0;
|
editorHeight = iframe ? parseInt( iframe.style.height, 10 ) : 0;
|
||||||
|
|
||||||
if ( editorHeight && ( toolbarHeight = getToolbarHeight() ) ) {
|
if ( editorHeight ) {
|
||||||
editorHeight = editorHeight + toolbarHeight - 11;
|
toolbarHeight = getToolbarHeight();
|
||||||
|
editorHeight = editorHeight + toolbarHeight - 14;
|
||||||
|
|
||||||
// height cannot be under 50 or over 5000
|
// height cannot be under 50 or over 5000
|
||||||
if ( editorHeight > 50 && editorHeight < 5000 ) {
|
if ( editorHeight > 50 && editorHeight < 5000 ) {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1014,13 +1014,18 @@ jQuery(document).ready( function($) {
|
||||||
if ( mce ) {
|
if ( mce ) {
|
||||||
editor.focus();
|
editor.focus();
|
||||||
toolbarHeight = $( '#wp-content-editor-container .mce-toolbar-grp' ).height();
|
toolbarHeight = $( '#wp-content-editor-container .mce-toolbar-grp' ).height();
|
||||||
|
|
||||||
|
if ( toolbarHeight < 10 || toolbarHeight > 200 ) {
|
||||||
|
toolbarHeight = 30;
|
||||||
|
}
|
||||||
|
|
||||||
height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28;
|
height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28;
|
||||||
} else {
|
} else {
|
||||||
$textarea.focus();
|
$textarea.focus();
|
||||||
height = parseInt( $textarea.css('height'), 10 );
|
height = parseInt( $textarea.css('height'), 10 );
|
||||||
}
|
}
|
||||||
|
|
||||||
$document.off( 'mousemove.wp-editor-resize mouseup.wp-editor-resize' );
|
$document.off( '.wp-editor-resize' );
|
||||||
|
|
||||||
// sanity check
|
// sanity check
|
||||||
if ( height && height > 50 && height < 5000 ) {
|
if ( height && height > 50 && height < 5000 ) {
|
||||||
|
@ -1045,10 +1050,10 @@ jQuery(document).ready( function($) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$document.on( 'mousemove.wp-editor-resize', dragging )
|
$document.on( 'mousemove.wp-editor-resize', dragging )
|
||||||
.on( 'mouseup.wp-editor-resize', endDrag );
|
.on( 'mouseup.wp-editor-resize mouseleave.wp-editor-resize', endDrag );
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
}).on( 'mouseup.wp-editor-resize', endDrag );
|
||||||
})();
|
})();
|
||||||
|
|
||||||
if ( typeof tinymce !== 'undefined' ) {
|
if ( typeof tinymce !== 'undefined' ) {
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue