X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/ceb5a929e00123b4e224977c6b5a149f6431b250..41578db67d72562346e4dbb2a14889b23d522813:/wp-admin/js/editor.js diff --git a/wp-admin/js/editor.js b/wp-admin/js/editor.js index fff8b61b..e7187163 100644 --- a/wp-admin/js/editor.js +++ b/wp-admin/js/editor.js @@ -13,15 +13,15 @@ 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, - dom = tinymce.DOM; + var t = this, ed, wrap_id, txtarea_el, iframe, editorHeight, toolbarHeight, + DOM = tinymce.DOM; //DOMUtils outside the editor iframe id = id || 'content'; mode = mode || 'toggle'; ed = tinymce.get( id ); wrap_id = 'wp-' + id + '-wrap'; - txtarea_el = dom.get( id ); + txtarea_el = DOM.get( id ); if ( 'toggle' === mode ) { if ( ed && ! ed.isHidden() ) { @@ -31,6 +31,17 @@ window.switchEditors = { } } + function getToolbarHeight() { + var node = DOM.select( '.mce-toolbar-grp', ed.getContainer() )[0], + height = node && node.clientHeight; + + if ( height && height > 10 && height < 200 ) { + return parseInt( height, 10 ); + } + + return 30; + } + if ( 'tmce' === mode || 'tinymce' === mode ) { if ( ed && ! ed.isHidden() ) { return false; @@ -40,19 +51,30 @@ window.switchEditors = { QTags.closeAllTags( id ); } + editorHeight = txtarea_el ? parseInt( txtarea_el.style.height, 10 ) : 0; + if ( tinyMCEPreInit.mceInit[ id ] && tinyMCEPreInit.mceInit[ id ].wpautop ) { txtarea_el.value = t.wpautop( txtarea_el.value ); } if ( ed ) { ed.show(); + + if ( editorHeight ) { + toolbarHeight = getToolbarHeight(); + editorHeight = editorHeight - toolbarHeight + 14; + + // height cannot be under 50 or over 5000 + if ( editorHeight > 50 && editorHeight < 5000 ) { + ed.theme.resizeTo( null, editorHeight ); + } + } } else { - ed = new tinymce.Editor( id, tinyMCEPreInit.mceInit[ id ] ); - ed.render(); + tinymce.init( tinyMCEPreInit.mceInit[id] ); } - dom.removeClass( wrap_id, 'html-active' ); - dom.addClass( wrap_id, 'tmce-active' ); + DOM.removeClass( wrap_id, 'html-active' ); + DOM.addClass( wrap_id, 'tmce-active' ); setUserSetting( 'editor', 'tinymce' ); } else if ( 'html' === mode ) { @@ -62,6 +84,19 @@ window.switchEditors = { } if ( ed ) { + iframe = DOM.get( id + '_ifr' ); + editorHeight = iframe ? parseInt( iframe.style.height, 10 ) : 0; + + if ( editorHeight ) { + toolbarHeight = getToolbarHeight(); + editorHeight = editorHeight + toolbarHeight - 14; + + // height cannot be under 50 or over 5000 + if ( editorHeight > 50 && editorHeight < 5000 ) { + txtarea_el.style.height = editorHeight + 'px'; + } + } + ed.hide(); } else { // The TinyMCE instance doesn't exist, run the content through 'pre_wpautop()' and show the textarea @@ -69,11 +104,11 @@ window.switchEditors = { txtarea_el.value = t.pre_wpautop( txtarea_el.value ); } - dom.setStyles( txtarea_el, {'display': '', 'visibility': ''} ); + DOM.setStyles( txtarea_el, {'display': '', 'visibility': ''} ); } - dom.removeClass( wrap_id, 'tmce-active' ); - dom.addClass( wrap_id, 'html-active' ); + DOM.removeClass( wrap_id, 'tmce-active' ); + DOM.addClass( wrap_id, 'html-active' ); setUserSetting( 'editor', 'html' ); } return false; @@ -88,8 +123,9 @@ window.switchEditors = { if ( content.indexOf( ']*>[\s\S]+?<\/\1>/g, function( a ) { - a = a.replace( /
(\r\n|\n)?/g, '' ); - return a.replace( /<\/?p( [^>]*)?>(\r\n|\n)?/g, '' ); + a = a.replace( /
(\r\n|\n)?/g, '' ); + a = a.replace( /<\/?p( [^>]*)?>(\r\n|\n)?/g, '' ); + return a.replace( /\r?\n/g, '' ); }); } @@ -149,7 +185,7 @@ window.switchEditors = { // put back the line breaks in pre|script if ( preserve_linebreaks ) { - content = content.replace( //g, '\n' ); + content = content.replace( //g, '\n' ); } // and the
tags in captions @@ -163,9 +199,9 @@ window.switchEditors = { _wp_Autop: function(pee) { var preserve_linebreaks = false, preserve_br = false, - blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select' + - '|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section' + - '|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary'; + blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre' + + '|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section' + + '|article|aside|hgroup|header|footer|nav|figure|details|menu|summary'; if ( pee.indexOf( '/g, function( a ) { @@ -181,7 +217,7 @@ window.switchEditors = { if ( pee.indexOf( ']*>[\s\S]+?<\/\1>/g, function( a ) { - return a.replace( /(\r\n|\n)/g, '' ); + return a.replace( /(\r\n|\n)/g, '' ); }); } @@ -230,7 +266,7 @@ window.switchEditors = { // put back the line breaks in pre|script if ( preserve_linebreaks ) { - pee = pee.replace( //g, '\n' ); + pee = pee.replace( //g, '\n' ); } if ( preserve_br ) {