the autoresizer sets overflow-y:hidden on the editor to do its height calculations but never resets it back to overflow-y:auto. Where/How in my tinyMCE init can I specify a callback after the autoresizer is done?
You can reset it after the Tinymce is initialized using the parameter
setup : function(ed) {
ed.onInit.add(function(ed, evt) {
// reset it back here !
});
},
Related
I have a page with multiple textareas that use TinyMCE to be able to display WYSIWYG content. This works fine but I need to set a specific textarea content from a function. I tried this approach...
<script>
function addText() {
var html = "<b>hello world</b>";
tinymce.get('#myFirstTextArea').setContent(html);
}
</script>
But when I do that I get a "Cannot read properties of null (reading 'setContent')" Error. What am I doing wrong here?
I use TinyMCE ver 6
Most likely you have a timing issue in your JavaScript. You cannot make a get() call until after TinyMCE is fully initialized.
TinyMCE has an event that gets called once the editor is fully initialized. You can put this in your TinyMCE init. For example:
tinymce.init({
...
setup: function (editor) {
editor.on('init', function (e) {
editor.setContent('<p>This is the content in TinyMCE!</p>');
});
}
...
});
Is there any openui5 event Handler for orientationchange and window resize ?
onInit: function() {
var data;
this.drawChart(data); // working fine
$( window ).resize(function() {
this.drawChart(data); // not working
});
},
drawChart: function(data) {
//code for draw chart
}
OpenUI5 has built-in functionality for detecting orientation change as well as when there is a responsive size change (desktop->tablet for example).
Take a look at sap.ui.Device.orientation's attachHandler event:
Registers the given event handler to orientation change events of the
document's window.
Here is an example of using sap.ui.Device.orientation.attachHandler:
sap.ui.Device.orientation.attachHandler(function(mParams) {
if (mParams.landscape) {
alert('in landscape mode');
} else {
alert('in portrait mode');
}
});
Also of use is sap.ui.Device.media's attachHandler for detecting when the window is resized to a different range-set.
For directly listening to when the window is resized it looks like you already have a solution for that, just make sure you keep track of the correct scope to use:
var self = this;
$( window ).resize(function() {
self.drawChart(data);
});
I found the solution
this.* will not work inside jquery as this has a different meaning wherever its encapsulated...
in openui5 *.view.js this implies the view object
in *.controller.js this implies the controller object...
in jquery this implies the component in which it is placed or whatever it is referring to in that context...
you cannot simply mix "this" wherever you like
sap.ui.controller("oui5mvc.controllerName").drawChart(data);
There are questions about overriding the physical Android BACK button in Ionic, to provide custom behaviour:
Ionic override all BACK button behaviour for specific controller
Ionic: How to override back button function?
But how do you cancel the override to restore default behaviour?
I have tried changing the priority of the handler, in the hope that a default handler may have a higher priority.
var customBackButton = function() {
console.log("this is custom behaviour");
};
$ionicPlatform.registerBackButtonAction(
customBackButton, 101
);
$scope.$on('$destroy', function() {
$ionicPlatform.registerBackButtonAction(
customBackButton, 0
);
});
This does not work.
Ionic v1 solution (out of date)
According to the Ionic docs for $ionicPlatform, the registerBackButtonAction() returns:
A function that, when called, will deregister this backButtonAction.
This can be seen in the code for registerBackButtonAction():
// return a function to de-register this back button action
return function() {
delete self. [action.id];
};
So the correct way to deregister / cancel the custom behaviour is to call that function when the controller is destroyed:
var customBackButton = function() {
console.log("this is custom behaviour");
};
// registerBackButtonAction() returns a function which can be used to deregister it
var deregisterBackButtonAction = $ionicPlatform.registerBackButtonAction(
customBackButton, 101
);
$scope.$on('$destroy', function() {
deregisterBackButtonAction();
});
A more complete example showing how to override & restore the hard and soft buttons can be found here:
Ionic override all BACK button behaviour for specific controller
In TinyMCE 4, I want to change displayed contents before they are showed on preview popup windows. This change must not affect current contents in editor. Can we do that?
If it can't, I want to catch close event of preview windows. How to do that?
TinyMCE allows us to register callbacks via the property init_instance_callback
By using the BeforeExecCommand event, oddly not in current documentation, you can make changes prior to a command being executed. We can similarly use the ExecCommand event to make changes after the command is executed. The Preview Plugin triggers the mcePreview command. You can view the Editor command Identifiers here.
Putting that together you can add the following when initializing your TinyMCE. This will show "changed content" in the preview without making visible changes to the content within TinyMCE.
var preProssesInnerHtml;
tinymce.init({
//other things...
init_instance_callback: function (editor) {
editor.on('BeforeExecCommand', function (e) {
if (e.command == "mcePreview") {
//store content prior to changing.
preProssesInnerHtml = editor.getContent();
editor.setContent("changed content");
}
});
editor.on("ExecCommand", function (e) {
if (e.command == "mcePreview") {
//Restore initial content.
editor.setContent(preProssesInnerHtml);
}
});
}
}
Is there a way to check if TinyMCE is in fullscreen mode?
I would like to press 'Esc' to exit full screen mode butI also use 'Esc' to cancel editing. Hence I would like a way to first check if the editor is in fullscereen mode.
The fullscreen plugin fires an event, when its state changes:
var tinyOptions = {
plugins: [ 'fullscreen' ],
setup: function(editor) {
editor.on('FullscreenStateChanged', function(e) {
console.log('FullscreenStateChanged event', e);
});
}
};
This way you can track the state yourself.
When TinyMCE is in Fullscreen Mode "mce-fullscreen" class is appended to body tag.
So all you need to do is check for the existence of mce-fullscreen class.
if $('.mce-fullscreen').length{
// Do something here,the editor is in fullscreen mode
}
If you have access to the editor object:
editor.plugins.fullscreen.isFullscreen();
This way is quick and simple.
var catchFulscreen = function() {
if( $('.mce-fullscreen').length > 1){
console.log('Now the editor is on fullscreen mode');
}
}
setInterval(catchFulscreen, 100);
This code was tested on TinyMce 4.1.x
But I had wanted to know to access inited TinyMce Object. If the object can be access, much more better solution for catching fullscreen mode as event!