Skip to content
This repository has been archived by the owner on Nov 16, 2021. It is now read-only.

added ability to register custom buttons (issue 29) #48

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

iaK
Copy link

@iaK iaK commented Nov 23, 2019

This PR adds ability to register custom buttons, as discussed in issue 29

This is a quite tricky problem to solve, and this implementation is not that great. Using eval always feels dirty, and having to make the js file publicly available and fetching it with ajax also feels kinda gross, butt hopefully it will get the ball rolling and at least we have a starting point.

To register custom buttons. create a js file containing a function that receives a froala editor instance as its first parameter and make it publicly available on the server.

example:

// /public/js/alert.js
(FroalaEditor) => {
    FroalaEditor.DefineIcon('alert', { NAME: 'info', SVG_KEY: 'help' });
    FroalaEditor.RegisterCommand('alert', {
        title: 'Hello',
        focus: false,
        undo: false,
        refreshAfterCallback: false,
        callback: function() {
            alert('Hello!');
        }
    });
}

Then, in your froala config file, add the following:

'customToolbarButtons' => [
    'alert' => '/js/alert.js',
],

And finally - add the button to your toolbarButtons array like any other button

That's all.

What do you think?

@iaK
Copy link
Author

iaK commented Dec 6, 2019

@slavarazum any response? :)

@slavarazum
Copy link
Collaborator

Hi,
Thanks for the implementation. Agreed with you that it's not enough clean as I'd want, but it may help to make new thoughts about solving this issue.

@slavarazum slavarazum added good first issue Good for newcomers help wanted Extra attention is needed labels Dec 9, 2019
@iaK
Copy link
Author

iaK commented Dec 9, 2019

So what's the alternativs?

We can't get them in at build time, so they have to be picked up runtime.

Using imports would be optimal, but i guess we cant rely on all the browsers to support that. Or can we? https://caniuse.com/#feat=es6-module-dynamic-import
IE and edge would not be supported then.

We could also output the button-logic into the dom to be picked up by plugin.

@slavarazum
Copy link
Collaborator

For now dynamic imports are using to include Froala plugins, maybe we can use it for custom buttons.

@iaK
Copy link
Author

iaK commented Dec 13, 2019

Alright. I'll look into that

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants