Documentation / API Reference

Modal

create #

Arguments
name String
params Object

Here is an example of creating a modal with a form.


Redactor.add('plugin', 'myplugin', {
    modals: {
        edit: {
            width: '100%',
            title: 'My plugin',
            form: {
                'id': { type: 'input' }
            },
            footer: {
                save: { title: '', command: 'myplugin.save', type: 'primary' },
                cancel: { title: '', command: 'modal.close' }
            }
        }
    },
    start() {
        let button = {
            title: 'My plugin',
            icon: '<svg...>',
            command: 'blockid.popup'
        };

        this.app.toolbar.add('myplugin', button);
    },
    popup(e, button) {
        let instance = this.app.block.get();
        let id = instance.getId();

        // create
        let stack = this.app.create('stack');
        stack.create('myplugin', this.modals.edit);
        stack.setData({ id: id });

        // open
        this.app.modal.open({ name: 'myplugin', stack: stack, focus: 'id', button: button });
    },
    save(stack) {
        this.app.modal.close();

        let id = stack.getData('id');
        let instance = this.app.block.get();
        instance.setId(id);
    }
});

close #

Closes the opened modal.


this.app.modal.close();

isOpen #

Checks if a modal is opened.


if (this.app.modal.isOpen()) {
    ...
}

getName #

Returns a name of the opened modal.


let name = this.app.modal.getName();