diff --git a/src/toolbar/dialog.js b/src/toolbar/dialog.js index e655948a..ffe85c6f 100644 --- a/src/toolbar/dialog.js +++ b/src/toolbar/dialog.js @@ -163,8 +163,13 @@ * Show the dialog element */ show: function(elementToChange) { - if (dom.hasClass(this.link, CLASS_NAME_OPENED)) { - return; + if (this.opened) { + if (this.elementToChange == elementToChange) { + return; + } + else { + this.hide(); + } } var that = this, @@ -176,6 +181,7 @@ this.interval = setInterval(function() { that._interpolate(true); }, 500); } dom.addClass(this.link, CLASS_NAME_OPENED); + this.opened = true; this.container.style.display = ""; this.fire("show"); if (firstField && !elementToChange) { @@ -189,9 +195,14 @@ * Hide the dialog element */ hide: function() { + if (!this.opened) { + return; + } + clearInterval(this.interval); this.elementToChange = null; dom.removeClass(this.link, CLASS_NAME_OPENED); + this.opened = false; this.container.style.display = "none"; this.fire("hide"); } diff --git a/src/toolbar/toolbar.js b/src/toolbar/toolbar.js index fcfd125e..8a097603 100644 --- a/src/toolbar/toolbar.js +++ b/src/toolbar/toolbar.js @@ -85,6 +85,10 @@ that.editor.fire("show:dialog", { command: command, dialogContainer: dialogElement, commandLink: link }); }); + dialog.on("hide", function() { + that.editor.fire("hide:dialog", { command: command, dialogContainer: dialogElement, commandLink: link }); + }); + dialog.on("save", function(attributes) { if (caretBookmark) { that.composer.selection.setBookmark(caretBookmark);