I'm currently trying to invoke a callback based on a triggered "click" event. This approach is a hack to log out, which is only available after a click on a button.
When I do the trigger command in the console, the keyup event handler works as expected after the trigger.
Trying to automate this process with code using the following does not work however:
let editorSwitchTmce = jQuery( ".wp-editor-tabs .switch-tmce" ),
editorCallback = function() {
tinyMCE.activeEditor.on( "keyup", function () {
console.log( tinyMCE.activeEditor.getContent() );
});
};
editorSwitchTmce.bind("click", function () {
editorCallback();
});
editorSwitchTmce.trigger( "click" );
The problem is, that the activeEditor is null until this click. So why is this not working? I mean I'm triggering the click and expecting that the activeEditor is set like when I do it with manually in the console of the browser?
editorCallback()when a "real click" happens? ie, to ensure that other code has time to assign theactiveEditor?editorSwitchTmce.bind( "mouseup", .. )editorSwitchTmce.bind( "click", function () { setTimeout(function() { editorCallback(); }, 100); } );