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:
Andrew Ozz 2014-04-04 01:31:15 +00:00
parent be70db8c5f
commit 2d0ce517e8
4 changed files with 24 additions and 23 deletions

View File

@ -13,7 +13,7 @@ window.switchEditors = {
// mode can be 'html', 'tmce', or 'toggle'; 'html' is used for the 'Text' editor tab.
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
id = id || 'content';
@ -32,17 +32,14 @@ window.switchEditors = {
}
function getToolbarHeight() {
var height;
var node = DOM.select( '.mce-toolbar-grp', ed.getContainer() )[0],
height = node && node.clientHeight;
try {
height = DOM.getSize( DOM.select( '.mce-toolbar-grp', ed.getContainer() )[0] );
} catch(e){}
if ( height && height.h && height.h > 10 && height.h < 100 ) {
return height.h;
if ( height && height > 10 && height < 200 ) {
return parseInt( height, 10 );
}
return 0;
return 30;
}
if ( 'tmce' === mode || 'tinymce' === mode ) {
@ -63,8 +60,9 @@ window.switchEditors = {
if ( ed ) {
ed.show();
if ( editorHeight && ( toolbarHeight = getToolbarHeight() ) ) {
editorHeight = editorHeight - toolbarHeight + 11;
if ( editorHeight ) {
toolbarHeight = getToolbarHeight();
editorHeight = editorHeight - toolbarHeight + 14;
// height cannot be under 50 or over 5000
if ( editorHeight > 50 && editorHeight < 5000 ) {
@ -73,9 +71,6 @@ window.switchEditors = {
}
} else {
tinymce.init( tinyMCEPreInit.mceInit[id] );
// ed = tinymce.createEditor( id, tinyMCEPreInit.mceInit[id] );
// ed.render();
}
DOM.removeClass( wrap_id, 'html-active' );
@ -89,11 +84,12 @@ window.switchEditors = {
}
if ( ed ) {
editorHeight = DOM.get( id + '_ifr' );
editorHeight = editorHeight ? parseInt( editorHeight.style.height, 10 ) : 0;
iframe = DOM.get( id + '_ifr' );
editorHeight = iframe ? parseInt( iframe.style.height, 10 ) : 0;
if ( editorHeight && ( toolbarHeight = getToolbarHeight() ) ) {
editorHeight = editorHeight + toolbarHeight - 11;
if ( editorHeight ) {
toolbarHeight = getToolbarHeight();
editorHeight = editorHeight + toolbarHeight - 14;
// height cannot be under 50 or over 5000
if ( editorHeight > 50 && editorHeight < 5000 ) {

File diff suppressed because one or more lines are too long

View File

@ -1014,13 +1014,18 @@ jQuery(document).ready( function($) {
if ( mce ) {
editor.focus();
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;
} else {
$textarea.focus();
height = parseInt( $textarea.css('height'), 10 );
}
$document.off( 'mousemove.wp-editor-resize mouseup.wp-editor-resize' );
$document.off( '.wp-editor-resize' );
// sanity check
if ( height && height > 50 && height < 5000 ) {
@ -1045,10 +1050,10 @@ jQuery(document).ready( function($) {
}
$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();
});
}).on( 'mouseup.wp-editor-resize', endDrag );
})();
if ( typeof tinymce !== 'undefined' ) {

File diff suppressed because one or more lines are too long