Edit File by line
/home/barbar84/www/wp-inclu.../js/tinymce/plugins/wpautore...
File: plugin.js
/**
[0] Fix | Delete
* plugin.js
[1] Fix | Delete
*
[2] Fix | Delete
* Copyright, Moxiecode Systems AB
[3] Fix | Delete
* Released under LGPL License.
[4] Fix | Delete
*
[5] Fix | Delete
* License: http://www.tinymce.com/license
[6] Fix | Delete
* Contributing: http://www.tinymce.com/contributing
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
// Forked for WordPress so it can be turned on/off after loading.
[10] Fix | Delete
[11] Fix | Delete
/*global tinymce:true */
[12] Fix | Delete
/*eslint no-nested-ternary:0 */
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Auto Resize
[16] Fix | Delete
*
[17] Fix | Delete
* This plugin automatically resizes the content area to fit its content height.
[18] Fix | Delete
* It will retain a minimum height, which is the height of the content area when
[19] Fix | Delete
* it's initialized.
[20] Fix | Delete
*/
[21] Fix | Delete
tinymce.PluginManager.add( 'wpautoresize', function( editor ) {
[22] Fix | Delete
var settings = editor.settings,
[23] Fix | Delete
oldSize = 300,
[24] Fix | Delete
isActive = false;
[25] Fix | Delete
[26] Fix | Delete
if ( editor.settings.inline || tinymce.Env.iOS ) {
[27] Fix | Delete
return;
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
function isFullscreen() {
[31] Fix | Delete
return editor.plugins.fullscreen && editor.plugins.fullscreen.isFullscreen();
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
function getInt( n ) {
[35] Fix | Delete
return parseInt( n, 10 ) || 0;
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* This method gets executed each time the editor needs to resize.
[40] Fix | Delete
*/
[41] Fix | Delete
function resize( e ) {
[42] Fix | Delete
var deltaSize, doc, body, docElm, DOM = tinymce.DOM, resizeHeight, myHeight,
[43] Fix | Delete
marginTop, marginBottom, paddingTop, paddingBottom, borderTop, borderBottom;
[44] Fix | Delete
[45] Fix | Delete
if ( ! isActive ) {
[46] Fix | Delete
return;
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
doc = editor.getDoc();
[50] Fix | Delete
if ( ! doc ) {
[51] Fix | Delete
return;
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
e = e || {};
[55] Fix | Delete
body = doc.body;
[56] Fix | Delete
docElm = doc.documentElement;
[57] Fix | Delete
resizeHeight = settings.autoresize_min_height;
[58] Fix | Delete
[59] Fix | Delete
if ( ! body || ( e && e.type === 'setcontent' && e.initial ) || isFullscreen() ) {
[60] Fix | Delete
if ( body && docElm ) {
[61] Fix | Delete
body.style.overflowY = 'auto';
[62] Fix | Delete
docElm.style.overflowY = 'auto'; // Old IE.
[63] Fix | Delete
}
[64] Fix | Delete
[65] Fix | Delete
return;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
// Calculate outer height of the body element using CSS styles.
[69] Fix | Delete
marginTop = editor.dom.getStyle( body, 'margin-top', true );
[70] Fix | Delete
marginBottom = editor.dom.getStyle( body, 'margin-bottom', true );
[71] Fix | Delete
paddingTop = editor.dom.getStyle( body, 'padding-top', true );
[72] Fix | Delete
paddingBottom = editor.dom.getStyle( body, 'padding-bottom', true );
[73] Fix | Delete
borderTop = editor.dom.getStyle( body, 'border-top-width', true );
[74] Fix | Delete
borderBottom = editor.dom.getStyle( body, 'border-bottom-width', true );
[75] Fix | Delete
myHeight = body.offsetHeight + getInt( marginTop ) + getInt( marginBottom ) +
[76] Fix | Delete
getInt( paddingTop ) + getInt( paddingBottom ) +
[77] Fix | Delete
getInt( borderTop ) + getInt( borderBottom );
[78] Fix | Delete
[79] Fix | Delete
// IE < 11, other?
[80] Fix | Delete
if ( myHeight && myHeight < docElm.offsetHeight ) {
[81] Fix | Delete
myHeight = docElm.offsetHeight;
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
// Make sure we have a valid height.
[85] Fix | Delete
if ( isNaN( myHeight ) || myHeight <= 0 ) {
[86] Fix | Delete
// Get height differently depending on the browser used.
[87] Fix | Delete
myHeight = tinymce.Env.ie ? body.scrollHeight : ( tinymce.Env.webkit && body.clientHeight === 0 ? 0 : body.offsetHeight );
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
// Don't make it smaller than the minimum height.
[91] Fix | Delete
if ( myHeight > settings.autoresize_min_height ) {
[92] Fix | Delete
resizeHeight = myHeight;
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
// If a maximum height has been defined don't exceed this height.
[96] Fix | Delete
if ( settings.autoresize_max_height && myHeight > settings.autoresize_max_height ) {
[97] Fix | Delete
resizeHeight = settings.autoresize_max_height;
[98] Fix | Delete
body.style.overflowY = 'auto';
[99] Fix | Delete
docElm.style.overflowY = 'auto'; // Old IE.
[100] Fix | Delete
} else {
[101] Fix | Delete
body.style.overflowY = 'hidden';
[102] Fix | Delete
docElm.style.overflowY = 'hidden'; // Old IE.
[103] Fix | Delete
body.scrollTop = 0;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
// Resize content element.
[107] Fix | Delete
if (resizeHeight !== oldSize) {
[108] Fix | Delete
deltaSize = resizeHeight - oldSize;
[109] Fix | Delete
DOM.setStyle( editor.iframeElement, 'height', resizeHeight + 'px' );
[110] Fix | Delete
oldSize = resizeHeight;
[111] Fix | Delete
[112] Fix | Delete
// WebKit doesn't decrease the size of the body element until the iframe gets resized.
[113] Fix | Delete
// So we need to continue to resize the iframe down until the size gets fixed.
[114] Fix | Delete
if ( tinymce.isWebKit && deltaSize < 0 ) {
[115] Fix | Delete
resize( e );
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
editor.fire( 'wp-autoresize', { height: resizeHeight, deltaHeight: e.type === 'nodechange' ? deltaSize : null } );
[119] Fix | Delete
}
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/**
[123] Fix | Delete
* Calls the resize x times in 100ms intervals. We can't wait for load events since
[124] Fix | Delete
* the CSS files might load async.
[125] Fix | Delete
*/
[126] Fix | Delete
function wait( times, interval, callback ) {
[127] Fix | Delete
setTimeout( function() {
[128] Fix | Delete
resize();
[129] Fix | Delete
[130] Fix | Delete
if ( times-- ) {
[131] Fix | Delete
wait( times, interval, callback );
[132] Fix | Delete
} else if ( callback ) {
[133] Fix | Delete
callback();
[134] Fix | Delete
}
[135] Fix | Delete
}, interval );
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
// Define minimum height.
[139] Fix | Delete
settings.autoresize_min_height = parseInt(editor.getParam( 'autoresize_min_height', editor.getElement().offsetHeight), 10 );
[140] Fix | Delete
[141] Fix | Delete
// Define maximum height.
[142] Fix | Delete
settings.autoresize_max_height = parseInt(editor.getParam( 'autoresize_max_height', 0), 10 );
[143] Fix | Delete
[144] Fix | Delete
function on() {
[145] Fix | Delete
if ( ! editor.dom.hasClass( editor.getBody(), 'wp-autoresize' ) ) {
[146] Fix | Delete
isActive = true;
[147] Fix | Delete
editor.dom.addClass( editor.getBody(), 'wp-autoresize' );
[148] Fix | Delete
// Add appropriate listeners for resizing the content area.
[149] Fix | Delete
editor.on( 'nodechange setcontent keyup FullscreenStateChanged', resize );
[150] Fix | Delete
resize();
[151] Fix | Delete
}
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
function off() {
[155] Fix | Delete
var doc;
[156] Fix | Delete
[157] Fix | Delete
// Don't turn off if the setting is 'on'.
[158] Fix | Delete
if ( ! settings.wp_autoresize_on ) {
[159] Fix | Delete
isActive = false;
[160] Fix | Delete
doc = editor.getDoc();
[161] Fix | Delete
editor.dom.removeClass( editor.getBody(), 'wp-autoresize' );
[162] Fix | Delete
editor.off( 'nodechange setcontent keyup FullscreenStateChanged', resize );
[163] Fix | Delete
doc.body.style.overflowY = 'auto';
[164] Fix | Delete
doc.documentElement.style.overflowY = 'auto'; // Old IE.
[165] Fix | Delete
oldSize = 0;
[166] Fix | Delete
}
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
if ( settings.wp_autoresize_on ) {
[170] Fix | Delete
// Turn resizing on when the editor loads.
[171] Fix | Delete
isActive = true;
[172] Fix | Delete
[173] Fix | Delete
editor.on( 'init', function() {
[174] Fix | Delete
editor.dom.addClass( editor.getBody(), 'wp-autoresize' );
[175] Fix | Delete
});
[176] Fix | Delete
[177] Fix | Delete
editor.on( 'nodechange keyup FullscreenStateChanged', resize );
[178] Fix | Delete
[179] Fix | Delete
editor.on( 'setcontent', function() {
[180] Fix | Delete
wait( 3, 100 );
[181] Fix | Delete
});
[182] Fix | Delete
[183] Fix | Delete
if ( editor.getParam( 'autoresize_on_init', true ) ) {
[184] Fix | Delete
editor.on( 'init', function() {
[185] Fix | Delete
// Hit it 10 times in 200 ms intervals.
[186] Fix | Delete
wait( 10, 200, function() {
[187] Fix | Delete
// Hit it 5 times in 1 sec intervals.
[188] Fix | Delete
wait( 5, 1000 );
[189] Fix | Delete
});
[190] Fix | Delete
});
[191] Fix | Delete
}
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
// Reset the stored size.
[195] Fix | Delete
editor.on( 'show', function() {
[196] Fix | Delete
oldSize = 0;
[197] Fix | Delete
});
[198] Fix | Delete
[199] Fix | Delete
// Register the command.
[200] Fix | Delete
editor.addCommand( 'wpAutoResize', resize );
[201] Fix | Delete
[202] Fix | Delete
// On/off.
[203] Fix | Delete
editor.addCommand( 'wpAutoResizeOn', on );
[204] Fix | Delete
editor.addCommand( 'wpAutoResizeOff', off );
[205] Fix | Delete
});
[206] Fix | Delete
[207] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function