Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
focusEditor = () => {
if ( this.props.mode === 'html' ) {
const textNode = this.textInput.current;
// Collapse selection to avoid scrolling to the bottom of the textarea
if ( this.state.selection ) {
this.selectTextInTextArea( this.state.selection );
} else {
textNode.setSelectionRange( 0, 0 );
}
// Browser is not Internet Explorer 11
if ( 11 !== tinymce.Env.ie ) {
textNode.focus();
}
} else if ( this._editor ) {
this._editor.focus();
}
};
} else if ( node.nodeName === 'IMG' || node.nodeName === 'DT' || node.nodeName === 'A' ) {
wrap = dom.getParent( node, 'div.mceTemp' );
}
if ( wrap ) {
dom.events.cancel( event );
removeImage( node );
return false;
}
}
} );
// After undo/redo FF seems to set the image height very slowly when it is set to 'auto' in the CSS.
// This causes image.getBoundingClientRect() to return wrong values and the resize handles are shown in wrong places.
// Collapse the selection to remove the resize handles.
if ( tinymce.Env.gecko ) {
editor.on( 'undo redo', function() {
if ( editor.selection.getNode().nodeName === 'IMG' ) {
editor.selection.collapse();
}
} );
}
editor.wpSetImgCaption = function( content ) {
return parseShortcode( content );
};
editor.wpGetImgCaption = function( content ) {
return getShortcode( content );
};
editor.on( 'BeforeSetContent', function( event ) {
editor.on( 'init', function() {
var env = tinymce.Env,
bodyClass = [ 'mceContentBody' ], // back-compat for themes that use this in editor-style.css...
doc = editor.getDoc(),
dom = editor.dom;
if ( tinymce.Env.iOS ) {
dom.addClass( doc.documentElement, 'ios' );
}
if ( editor.getParam( 'directionality' ) === 'rtl' ) {
bodyClass.push( 'rtl' );
dom.setAttrib( doc.documentElement, 'dir', 'rtl' );
}
if ( env.ie ) {
if ( parseInt( env.ie, 10 ) === 9 ) {
bodyClass.push( 'ie9' );
} else if ( parseInt( env.ie, 10 ) === 8 ) {
bodyClass.push( 'ie8' );
} else if ( env.ie < 8 ) {
bodyClass.push( 'ie7' );
}
parseInt( marginTop, 10 ) +
parseInt( marginBottom, 10 ) +
parseInt( paddingTop, 10 ) +
parseInt( paddingBottom, 10 ) +
parseInt( borderTop, 10 ) +
parseInt( borderBottom, 10 );
// 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
if ( tinymce.Env.ie ) {
myHeight = body.scrollHeight;
} else if ( tinymce.Env.webkit && body.clientHeight === 0 ) {
myHeight = 0;
} else {
myHeight = 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;
parseInt( paddingTop, 10 ) +
parseInt( paddingBottom, 10 ) +
parseInt( borderTop, 10 ) +
parseInt( borderBottom, 10 );
// 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
if ( tinymce.Env.ie ) {
myHeight = body.scrollHeight;
} else if ( tinymce.Env.webkit && body.clientHeight === 0 ) {
myHeight = 0;
} else {
myHeight = 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
editor.on( 'PastePreProcess', function( event ) {
// Remove trailing <br> added by WebKit browsers to the clipboard
event.content = event.content.replace( /<br class="?Apple-interchange-newline">/gi, '' );
// In WebKit this is handled by removeWebKitStyles()
if ( ! tinymce.Env.webkit ) {
// Remove all inline styles
event.content = event.content.replace( /(<[^>]+) style="[^"]*"([^>]*>)/gi, '$1$2' );
// Put back the internal styles
event.content = event.content.replace(
/(<[^>]+) data-mce-style=([^>]+>)/gi,
'$1 style=$2'
);
}
} );
editor.on( 'init', function() {
var env = tinymce.Env,
bodyClass = [ 'mceContentBody' ], // back-compat for themes that use this in editor-style.css...
doc = editor.getDoc(),
dom = editor.dom;
if ( tinymce.Env.iOS ) {
dom.addClass( doc.documentElement, 'ios' );
}
if ( editor.getParam( 'directionality' ) === 'rtl' ) {
bodyClass.push( 'rtl' );
dom.setAttrib( doc.documentElement, 'dir', 'rtl' );
}
if ( env.ie ) {
if ( parseInt( env.ie, 10 ) === 9 ) {
bodyClass.push( 'ie9' );
function wpview( editor ) {
let $ = editor.$,
selected,
Env = tinymce.Env,
VK = tinymce.util.VK,
TreeWalker = tinymce.dom.TreeWalker,
toRemove = false,
firstFocus = true,
isios = /iPad|iPod|iPhone/.test( navigator.userAgent ),
cursorInterval,
lastKeyDownNode,
setViewCursorTries,
focus,
execCommandView,
execCommandBefore,
toolbar;
/**
* Replaces all marker nodes tied to this view instance.
*
editor.on( 'ExecCommand', function( e ) {
if (
tinymce.Env.webkit &&
style &&
( 'InsertUnorderedList' === e.command || 'InsertOrderedList' === e.command )
) {
editor.dom.remove( style );
}
} );
moretext +
'" ' +
'class="wp-more-tag mce-wp-more" title="' +
title +
'" data-mce-resize="false" data-mce-placeholder="1" />'
);
} );
}
if ( event.content.indexOf( '' ) !== -1 ) {
title = translate( 'Page break' );
event.content = event.content.replace(
//g,
'<img data-mce-placeholder="1" data-mce-resize="false" class="wp-more-tag mce-wp-nextpage" data-wp-more="nextpage" src="' +
tinymce.Env.transparentSrc +
'">'
);
}
if ( event.load && event.format !== 'raw' ) {
event.content = wpautop( event.content );
}
}
} );