Browse Source

Improve modal callback data

pull/3795/head
Artur Arseniev 4 years ago
parent
commit
3c6a9e98e9
  1. 10
      docs/modules/Modal.md
  2. 11
      src/modal_dialog/index.js
  3. 2
      src/utils/dom.js

10
docs/modules/Modal.md

@ -107,11 +107,11 @@ const editor = grapesjs.init({
editor.on('modal', props => {
// The `props` will contain all the information you need in order to update your custom modal.
// props.open - Indicates if the modal should be open
// props.title - Modal title
// props.content - Modal content
// props.attributes - Modal custom attributes (eg. class)
// props.close - A callback to use when you want to close the modal programmatically
// props.open (boolean) - Indicates if the modal should be open
// props.title (Node) - Modal title
// props.content (Node) - Modal content
// props.attributes (Object) - Modal custom attributes (eg. class)
// props.close (Function) - A callback to use when you want to close the modal programmatically
// Here you would put the logic to control your modal.
})

11
src/modal_dialog/index.js

@ -33,7 +33,8 @@
* @module Modal
*/
import { debounce } from 'underscore';
import { debounce, isString } from 'underscore';
import { createText } from '../utils/dom';
import defaults from './config/config';
import ModalM from './model/Modal';
import ModalView from './view/ModalView';
@ -87,8 +88,14 @@ export default () => {
},
_evData() {
const titl = this.getTitle();
const cnt = this.getContent();
const { open, attributes } = model.attributes;
return {
...model.attributes,
open,
attributes,
title: isString(titl) ? createText(titl) : titl,
content: isString(cnt) ? createText(cnt) : cnt.get ? cnt.get(0) : cnt,
close: () => this.close()
};
},

2
src/utils/dom.js

@ -68,6 +68,8 @@ export const createEl = (tag, attrs = '', child) => {
return el;
};
export const createText = str => document.createTextNode(str);
// Unfortunately just creating `KeyboardEvent(e.type, e)` is not enough,
// the keyCode/which will be always `0`. Even if it's an old/deprecated
// property keymaster (and many others) still use it... using `defineProperty`

Loading…
Cancel
Save