diff --git a/addon/dialog/dialog.js b/addon/dialog/dialog.js index 14ab7248495adb3f17b6ab627c5e2608c7218b0c..ced394d3fca9b535eee8e4278757da31e93e6579 100644 --- a/addon/dialog/dialog.js +++ b/addon/dialog/dialog.js @@ -14,7 +14,14 @@ return dialog; } + function closeNotification(cm, newVal) { + if (cm.state.currentNotificationClose) + cm.state.currentNotificationClose(); + cm.state.currentNotificationClose = newVal; + } + CodeMirror.defineExtension("openDialog", function(template, callback, options) { + closeNotification(this, null); var dialog = dialogDiv(this, template, options && options.bottom); var closed = false, me = this; function close() { @@ -51,6 +58,7 @@ }); CodeMirror.defineExtension("openConfirm", function(template, callbacks, options) { + closeNotification(this, null); var dialog = dialogDiv(this, template, options && options.bottom); var buttons = dialog.getElementsByTagName("button"); var closed = false, me = this, blurring = 1; @@ -86,30 +94,24 @@ * If a notification is opened while another is opened, it will close the * currently opened one and open the new one immediately. */ - var currentNotificationClose; - CodeMirror.defineExtension("openNotification", function(template, callback, options) { + CodeMirror.defineExtension("openNotification", function(template, options) { + closeNotification(this, close); var dialog = dialogDiv(this, template, options && options.bottom); var duration = options && (options.duration === undefined ? 5000 : options.duration); - var closed = false, me = this, doneTimer; + var closed = false, doneTimer; function close() { if (closed) return; closed = true; clearTimeout(doneTimer); - doneTimer = null; - if (callback) callback(me); dialog.parentNode.removeChild(dialog); } - if (currentNotificationClose) currentNotificationClose(); - currentNotificationClose = close; - CodeMirror.on(dialog, 'click', function(e) { CodeMirror.e_preventDefault(e); close(); }); - if (duration) { + if (duration) doneTimer = setTimeout(close, options.duration); - } }); })(); diff --git a/doc/manual.html b/doc/manual.html index d79265fd6b00cdccabd4a09d38271ea9fdb9fc7a..80de6d950f29d4dd7529438a8debcf347ebe7686 100644 --- a/doc/manual.html +++ b/doc/manual.html @@ -1708,11 +1708,14 @@ <dl> <dt id="addon_dialog"><a href="../addon/dialog/dialog.js"><code>dialog/dialog.js</code></a></dt> <dd>Provides a very simple way to query users for text input. - Adds an <code>openDialog</code> method to CodeMirror instances, - which can be called with an HTML fragment that provides the - prompt (should include an <code>input</code> tag), and a - callback function that is called when text has been entered. - Depends on <code>addon/dialog/dialog.css</code>.</dd> + Adds an <strong><code>openDialog</code></strong> method to + CodeMirror instances, which can be called with an HTML fragment + that provides the prompt (should include an <code>input</code> + tag), and a callback function that is called when text has been + entered. Also adds + an <strong><code>openNotification</code></strong> function that + simply shows an HTML fragment as a notification. Depends + on <code>addon/dialog/dialog.css</code>.</dd> <dt id="addon_searchcursor"><a href="../addon/search/searchcursor.js"><code>search/searchcursor.js</code></a></dt> <dd>Adds the <code>getSearchCursor(query, start, caseFold) →