Skip to content

Commit

Permalink
Added modal:open and modal:close events in the Modal module. Closes
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Jan 13, 2019
1 parent 919c0cc commit 414a0ae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@
* ### RTE
* * `rte:enable` - RTE enabled. The view, on which RTE is enabled, is passed as an argument
* * `rte:disable` - RTE disabled. The view, on which RTE is disabled, is passed as an argument
* ### Modal
* * `modal:open` - Modal is opened
* * `modal:close` - Modal is closed
* ### Commands
* * `run:{commandName}` - Triggered when some command is called to run (eg. editor.runCommand('preview'))
* * `stop:{commandName}` - Triggered when some command is called to stop (eg. editor.stopCommand('preview'))
Expand Down
22 changes: 17 additions & 5 deletions src/modal_dialog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,22 @@ module.exports = () => {
*/
name: 'Modal',

getConfig() {
return c;
},

/**
* Initialize module. Automatically called with a new instance of the editor
* @param {Object} config Configurations
* @private
*/
init(config) {
c = config || {};
for (var name in defaults) {
if (!(name in c)) c[name] = defaults[name];
}
init(config = {}) {
c = {
...defaults,
...config
};

this.em = c.em;
var ppfx = c.pStylePrefix;
if (ppfx) c.stylePrefix = ppfx + c.stylePrefix;

Expand All @@ -68,6 +73,11 @@ module.exports = () => {
this.render().appendTo(el);
},

triggerEvent(event) {
const { em } = this;
em && em.trigger(`modal:${event}`);
},

/**
* Open the modal window
* @param {Object} [opts={}] Options
Expand All @@ -79,6 +89,7 @@ module.exports = () => {
opts.title && this.setTitle(opts.title);
opts.content && this.setContent(opts.content);
modal.show();
this.triggerEvent('open');
return this;
},

Expand All @@ -88,6 +99,7 @@ module.exports = () => {
*/
close() {
modal.hide();
this.triggerEvent('close');
return this;
},

Expand Down

0 comments on commit 414a0ae

Please sign in to comment.