I want to add a custom class to a custom button in TinyMCE 6, however it doesn't seem to be possible anymore.
const setup = (editor: Editor, url: string): void => {
editor.ui.registry.addButton('blue-box', {
icon: 'table-cell-select-all',
class: 'MyCoolBtn',
tooltip: "Blue Box",
onAction: () => {
editor.setContent('<p>content added from blue-box</p>');
}
});
};
In this example, I tried to add class: MyCoolBtn, however, I received an error because there's no class instance on the addButton method.
Is there any possibility to add a class or add a custom design to specific buttons in TinyMce 6?
Looking through the Tiny 6 and Tiny 5 docs, I couldn't find a reference to the addButton API allowing a class value (sounds like a function from Tiny 4 or earlier?).
Anyway, I tested out the custom button, in Tiny 6 on a fiddle with your example button, and again in a local file, I while I didn't get any errors about a class instance not found for the addButton method, I did find that adding a class to the button was not carried through the rendered rich text editor. When Tiny runs, it adds classes to each element based on the CSS content specified by the default skin configured.
It is possible to override the .tox classes that the Tiny skin places for each element (as seen in the screen cap), but it's not recommended.
One solution, if you want to change the style of the specific, custom buttons added to the toolbar, is to make a custom skin with the specific style element needed set up and targeting that .tox-tbtn class.
Related
I am using Prestashop. I have made several templates. Is it possible to prepare a button that will insert the selected template?
For example, I have 4 templates and I want to make 4 buttons.
the first button inserts the first template.
the second button inserts the second template and so on.
I tried to use this code in the file \js\admin\tinymce.inc.js but my new button is not displaying :(
toolbar2: 'customInsertButton',
setup: function (editor) {
editor.ui.registry.addButton('customInsertButton', {
text: 'My Button',
onAction: function (_) {
editor.insertContent('My button works!');
}
});
},
Perhaps Prestashop has some limited version of this editor?
I ask because for example it is possible to add templates. but I would like to be able to insert them faster, with one button...
TinyMCE itself already has a template plugin:
https://www.tiny.cloud/docs/plugins/opensource/template/
Have you considered using that functionality?
I have already found a solution. It is possible by adding a custom plugin.
Everything is beautifully described on the TinyMCE website :
https://www.tiny.cloud/docs/advanced/creating-a-plugin/
then we modify tinymce.inc.js and add plugin support and a defined button in the toolbar.
I have a page with multiple TinyMCE editors (org.vaadin.tinymce.TinyMce), and I want to know which the user is 'in'. One approach would be to use the focus/blur events, but I've tried adding a class like this:
public class MyTinyMce extends TinyMce implements Focusable<TinyMce> { ... }
and then associating event handlers like this:
myTinyMce.addFocusListener(e -> {
System.out.println("focus!!");
});
myTinyMce.addBlurListener(e -> {
System.out.println("blurred!!");
});
but the events don't fire reliably. If I do the exact same thing with a Text component, it works as expected.
I say not "reliably" because they do fire if I click on the empty space in the TinyMCE toolbar (to the right of 'Tools' in the screenshot), but not if I click on the TinyMCE menu or into the editable body.
screenshot
Am I doing something wrong, or does the TinyMCE component simply not support this use-case? Is there another way to keep track of the user switching between different editors?
I am adding menu buttons to a tinymce editor. In this interface there are multiple tinymce editors loaded on the page at once. The menu buttons I am adding all do some custom styling either using the formatter or by applying custom css classes to selected elements. As part of one of the items I need to also "remove all formatting" from the selection as well as add some text around the selection. There is already a built-in plugin that does this, so I would like to just call that function from my plugin.
I got this working by using jQuery to click the "remove all formatting" button, however since there are multiple editors on the page, this makes the page scroll from where the user is at, depending on which button actually gets clicked by jQuery.
I would rather not use this approach because i feel like it would be much cleaner and provide a better result to execute the remove formatting code from my plugin, but I am unsure how to access the function I need to call.
{
type: 'menuitem',
text: 'Sample Answer',
onAction: function() {
$('button[title|="Clear formatting"]').click(); //I would like to call this function here instead of jQuery clicking a button.
editor.formatter.apply('sample_answer');
}
},
So after some more digging, it appears that a certain amount of tinymce commands can be executed using editor.execCommand RemoveFormat is one of the commands you can use, so they made it easy on me for what I need to do.
It would still be nice to know if there was a way to execute other functions if I wanted to, but the execCommand function definitely solves this issue.
{
type: 'menuitem',
text: 'Sample Answer',
onAction: function() {
editor.execCommand('RemoveFormat');
editor.formatter.apply('sample_answer');
}
},
anyone know if sapui5 provide solution/function to change button style in select dialog? I've checked the SAPUI5 sdk but there is none for this solution.
If you are OK with using "private" properties then you can use _oOkButton property of SelectDialog or else you can use _getOkButton function which also is kind of "private" and returns ok button instance.
Just use the instance of the Select Dialog and get all buttons using the following methods. Select Dialog is a dialog only, you can use the methods of sap.m.Dialog
Let say you have the instance of the dialog as oSlectDialog then
oSlectDialog.getButtons() - will return all the Buttons in the footer. You can use loop them and give custom class accordingly.
var oBtns = oSlectDialog.getButtons()
for(var b in oBtns) {
var oBtn = oBtns[b];//You can check for button instance, if you want to add custom class differently.
oBtn.addStyleClass("YourCustomClass");
}
You can also use the sap.m.Dialog methods like oSlectDialog.getBeginButton(), oSlectDialog.getEndButton().
Since UI5 1.62.0, the primary action OK (later renamed to Select) is automatically emphasized if the theme is sap_fiori_3.
https://openui5.hana.ondemand.com/#/entity/sap.m.SelectDialog/sample/sap.m.sample.SelectDialog
If it's not urgent, I'd suggest to avoid relying on private methods/ properties, but update to the latest UI5 version and themes.
Update: and since 1.70 (commit:1f421b0), the button is automatically emphasized in other supported themes too, such as sap_belize, sap_belize_plus
Related Github issue: https://github.com/SAP/openui5/issues/2254
My requirement is to remove the title icons for all views but it seems impossible.
First i removed the references to the icons from extension point="org.eclipse.ui.views" in my plugin.xml file.
There is a similar question to this one where it is suggested to override getTitleImage() in the view that extends ViewPart so i did just that and i tryed 2 versions.
#Override
public Image getTitleImage() {
return null;
}
#Override
public Image getTitleImage() {
return new Image(getSite().getShell().getDisplay(), new Rectangle(0, 0, 1, 1));
}
The result no matter which method i used is that some views don't display the icon and some do. For example the first view is always opened without the icon but the following views get the default icon. Also if i have save and restore enabled and restart the application while leaving some views open, the one that is selected doesn't have the icon while the rest do.
This is so frustrating, i just don't get why something so simple has to be so complicated to implement.
I think the problem is views that have not yet been created (so getTitleImage has not been called). In that case the workbench part reference code uses the default image if there is nothing defined in the view definition.
If the above is correct creating an empty image icon file and defining that as the icon in the org.eclipse.ui.views extension in your plugin.xml should work.