first commit
This commit is contained in:
207
wp-includes/js/tinymce/plugins/wpautoresize/plugin.js
Normal file
207
wp-includes/js/tinymce/plugins/wpautoresize/plugin.js
Normal file
@ -0,0 +1,207 @@
|
||||
/**
|
||||
* plugin.js
|
||||
*
|
||||
* Copyright, Moxiecode Systems AB
|
||||
* Released under LGPL License.
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
// Forked for WordPress so it can be turned on/off after loading.
|
||||
|
||||
/*global tinymce:true */
|
||||
/*eslint no-nested-ternary:0 */
|
||||
|
||||
/**
|
||||
* Auto Resize
|
||||
*
|
||||
* This plugin automatically resizes the content area to fit its content height.
|
||||
* It will retain a minimum height, which is the height of the content area when
|
||||
* it's initialized.
|
||||
*/
|
||||
tinymce.PluginManager.add( 'wpautoresize', function( editor ) {
|
||||
var settings = editor.settings,
|
||||
oldSize = 300,
|
||||
isActive = false;
|
||||
|
||||
if ( editor.settings.inline || tinymce.Env.iOS ) {
|
||||
return;
|
||||
}
|
||||
|
||||
function isFullscreen() {
|
||||
return editor.plugins.fullscreen && editor.plugins.fullscreen.isFullscreen();
|
||||
}
|
||||
|
||||
function getInt( n ) {
|
||||
return parseInt( n, 10 ) || 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets executed each time the editor needs to resize.
|
||||
*/
|
||||
function resize( e ) {
|
||||
var deltaSize, doc, body, docElm, DOM = tinymce.DOM, resizeHeight, myHeight,
|
||||
marginTop, marginBottom, paddingTop, paddingBottom, borderTop, borderBottom;
|
||||
|
||||
if ( ! isActive ) {
|
||||
return;
|
||||
}
|
||||
|
||||
doc = editor.getDoc();
|
||||
if ( ! doc ) {
|
||||
return;
|
||||
}
|
||||
|
||||
e = e || {};
|
||||
body = doc.body;
|
||||
docElm = doc.documentElement;
|
||||
resizeHeight = settings.autoresize_min_height;
|
||||
|
||||
if ( ! body || ( e && e.type === 'setcontent' && e.initial ) || isFullscreen() ) {
|
||||
if ( body && docElm ) {
|
||||
body.style.overflowY = 'auto';
|
||||
docElm.style.overflowY = 'auto'; // Old IE.
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Calculate outer height of the body element using CSS styles.
|
||||
marginTop = editor.dom.getStyle( body, 'margin-top', true );
|
||||
marginBottom = editor.dom.getStyle( body, 'margin-bottom', true );
|
||||
paddingTop = editor.dom.getStyle( body, 'padding-top', true );
|
||||
paddingBottom = editor.dom.getStyle( body, 'padding-bottom', true );
|
||||
borderTop = editor.dom.getStyle( body, 'border-top-width', true );
|
||||
borderBottom = editor.dom.getStyle( body, 'border-bottom-width', true );
|
||||
myHeight = body.offsetHeight + getInt( marginTop ) + getInt( marginBottom ) +
|
||||
getInt( paddingTop ) + getInt( paddingBottom ) +
|
||||
getInt( borderTop ) + getInt( borderBottom );
|
||||
|
||||
// IE < 11, other?
|
||||
if ( myHeight && myHeight < docElm.offsetHeight ) {
|
||||
myHeight = docElm.offsetHeight;
|
||||
}
|
||||
|
||||
// Make sure we have a valid height.
|
||||
if ( isNaN( myHeight ) || myHeight <= 0 ) {
|
||||
// Get height differently depending on the browser used.
|
||||
myHeight = tinymce.Env.ie ? body.scrollHeight : ( tinymce.Env.webkit && body.clientHeight === 0 ? 0 : body.offsetHeight );
|
||||
}
|
||||
|
||||
// Don't make it smaller than the minimum height.
|
||||
if ( myHeight > settings.autoresize_min_height ) {
|
||||
resizeHeight = myHeight;
|
||||
}
|
||||
|
||||
// If a maximum height has been defined don't exceed this height.
|
||||
if ( settings.autoresize_max_height && myHeight > settings.autoresize_max_height ) {
|
||||
resizeHeight = settings.autoresize_max_height;
|
||||
body.style.overflowY = 'auto';
|
||||
docElm.style.overflowY = 'auto'; // Old IE.
|
||||
} else {
|
||||
body.style.overflowY = 'hidden';
|
||||
docElm.style.overflowY = 'hidden'; // Old IE.
|
||||
body.scrollTop = 0;
|
||||
}
|
||||
|
||||
// Resize content element.
|
||||
if (resizeHeight !== oldSize) {
|
||||
deltaSize = resizeHeight - oldSize;
|
||||
DOM.setStyle( editor.iframeElement, 'height', resizeHeight + 'px' );
|
||||
oldSize = resizeHeight;
|
||||
|
||||
// WebKit doesn't decrease the size of the body element until the iframe gets resized.
|
||||
// So we need to continue to resize the iframe down until the size gets fixed.
|
||||
if ( tinymce.isWebKit && deltaSize < 0 ) {
|
||||
resize( e );
|
||||
}
|
||||
|
||||
editor.fire( 'wp-autoresize', { height: resizeHeight, deltaHeight: e.type === 'nodechange' ? deltaSize : null } );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the resize x times in 100ms intervals. We can't wait for load events since
|
||||
* the CSS files might load async.
|
||||
*/
|
||||
function wait( times, interval, callback ) {
|
||||
setTimeout( function() {
|
||||
resize();
|
||||
|
||||
if ( times-- ) {
|
||||
wait( times, interval, callback );
|
||||
} else if ( callback ) {
|
||||
callback();
|
||||
}
|
||||
}, interval );
|
||||
}
|
||||
|
||||
// Define minimum height.
|
||||
settings.autoresize_min_height = parseInt(editor.getParam( 'autoresize_min_height', editor.getElement().offsetHeight), 10 );
|
||||
|
||||
// Define maximum height.
|
||||
settings.autoresize_max_height = parseInt(editor.getParam( 'autoresize_max_height', 0), 10 );
|
||||
|
||||
function on() {
|
||||
if ( ! editor.dom.hasClass( editor.getBody(), 'wp-autoresize' ) ) {
|
||||
isActive = true;
|
||||
editor.dom.addClass( editor.getBody(), 'wp-autoresize' );
|
||||
// Add appropriate listeners for resizing the content area.
|
||||
editor.on( 'nodechange setcontent keyup FullscreenStateChanged', resize );
|
||||
resize();
|
||||
}
|
||||
}
|
||||
|
||||
function off() {
|
||||
var doc;
|
||||
|
||||
// Don't turn off if the setting is 'on'.
|
||||
if ( ! settings.wp_autoresize_on ) {
|
||||
isActive = false;
|
||||
doc = editor.getDoc();
|
||||
editor.dom.removeClass( editor.getBody(), 'wp-autoresize' );
|
||||
editor.off( 'nodechange setcontent keyup FullscreenStateChanged', resize );
|
||||
doc.body.style.overflowY = 'auto';
|
||||
doc.documentElement.style.overflowY = 'auto'; // Old IE.
|
||||
oldSize = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ( settings.wp_autoresize_on ) {
|
||||
// Turn resizing on when the editor loads.
|
||||
isActive = true;
|
||||
|
||||
editor.on( 'init', function() {
|
||||
editor.dom.addClass( editor.getBody(), 'wp-autoresize' );
|
||||
});
|
||||
|
||||
editor.on( 'nodechange keyup FullscreenStateChanged', resize );
|
||||
|
||||
editor.on( 'setcontent', function() {
|
||||
wait( 3, 100 );
|
||||
});
|
||||
|
||||
if ( editor.getParam( 'autoresize_on_init', true ) ) {
|
||||
editor.on( 'init', function() {
|
||||
// Hit it 10 times in 200 ms intervals.
|
||||
wait( 10, 200, function() {
|
||||
// Hit it 5 times in 1 sec intervals.
|
||||
wait( 5, 1000 );
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the stored size.
|
||||
editor.on( 'show', function() {
|
||||
oldSize = 0;
|
||||
});
|
||||
|
||||
// Register the command.
|
||||
editor.addCommand( 'wpAutoResize', resize );
|
||||
|
||||
// On/off.
|
||||
editor.addCommand( 'wpAutoResizeOn', on );
|
||||
editor.addCommand( 'wpAutoResizeOff', off );
|
||||
});
|
1
wp-includes/js/tinymce/plugins/wpautoresize/plugin.min.js
vendored
Normal file
1
wp-includes/js/tinymce/plugins/wpautoresize/plugin.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
tinymce.PluginManager.add("wpautoresize",function(g){var m=g.settings,h=300,c=!1;function f(e){return parseInt(e,10)||0}function y(e){var t,o,n,i,a,s,l,u,r,d=tinymce.DOM;c&&(o=g.getDoc())&&(e=e||{},t=o.body,o=o.documentElement,n=m.autoresize_min_height,!t||e&&"setcontent"===e.type&&e.initial||g.plugins.fullscreen&&g.plugins.fullscreen.isFullscreen()?t&&o&&(t.style.overflowY="auto",o.style.overflowY="auto"):(i=g.dom.getStyle(t,"margin-top",!0),a=g.dom.getStyle(t,"margin-bottom",!0),s=g.dom.getStyle(t,"padding-top",!0),l=g.dom.getStyle(t,"padding-bottom",!0),u=g.dom.getStyle(t,"border-top-width",!0),r=g.dom.getStyle(t,"border-bottom-width",!0),(i=t.offsetHeight+f(i)+f(a)+f(s)+f(l)+f(u)+f(r))&&i<o.offsetHeight&&(i=o.offsetHeight),(i=isNaN(i)||i<=0?tinymce.Env.ie?t.scrollHeight:tinymce.Env.webkit&&0===t.clientHeight?0:t.offsetHeight:i)>m.autoresize_min_height&&(n=i),m.autoresize_max_height&&i>m.autoresize_max_height?(n=m.autoresize_max_height,t.style.overflowY="auto",o.style.overflowY="auto"):(t.style.overflowY="hidden",o.style.overflowY="hidden",t.scrollTop=0),n!==h&&(a=n-h,d.setStyle(g.iframeElement,"height",n+"px"),h=n,tinymce.isWebKit&&a<0&&y(e),g.fire("wp-autoresize",{height:n,deltaHeight:"nodechange"===e.type?a:null}))))}function n(e,t,o){setTimeout(function(){y(),e--?n(e,t,o):o&&o()},t)}g.settings.inline||tinymce.Env.iOS||(m.autoresize_min_height=parseInt(g.getParam("autoresize_min_height",g.getElement().offsetHeight),10),m.autoresize_max_height=parseInt(g.getParam("autoresize_max_height",0),10),m.wp_autoresize_on&&(c=!0,g.on("init",function(){g.dom.addClass(g.getBody(),"wp-autoresize")}),g.on("nodechange keyup FullscreenStateChanged",y),g.on("setcontent",function(){n(3,100)}),g.getParam("autoresize_on_init",!0))&&g.on("init",function(){n(10,200,function(){n(5,1e3)})}),g.on("show",function(){h=0}),g.addCommand("wpAutoResize",y),g.addCommand("wpAutoResizeOn",function(){g.dom.hasClass(g.getBody(),"wp-autoresize")||(c=!0,g.dom.addClass(g.getBody(),"wp-autoresize"),g.on("nodechange setcontent keyup FullscreenStateChanged",y),y())}),g.addCommand("wpAutoResizeOff",function(){var e;m.wp_autoresize_on||(c=!1,e=g.getDoc(),g.dom.removeClass(g.getBody(),"wp-autoresize"),g.off("nodechange setcontent keyup FullscreenStateChanged",y),e.body.style.overflowY="auto",e.documentElement.style.overflowY="auto",h=0)}))});
|
Reference in New Issue
Block a user