Workaround to closing dialogs so you can quickly open another
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Closes the currently open dialog asynchronously. | |
* This has an ugly workaround which is to try to set a new | |
* event handler on the dialog until it fails. When it failed | |
* we know the original dialog object was destroyed and we | |
* can then proceed. The issue we are working around is that | |
* if you call two dialogs back to back, the second one will | |
* likely not open at all. | |
* @param {Office.context.ui.dialog} dialog The dialog to be closed | |
* @param {function()} asyncResult The callback when close is complete | |
*/ | |
function dialogCloseAsync(dialog, asyncResult){ | |
// issue the close | |
dialog.close(); | |
// and then try to add a handler | |
// when that fails it is closed | |
setTimeout(function() { | |
try{ | |
dialog.addEventHandler(Office.EventType.DialogMessageReceived, function() {}); | |
dialogCloseAsync(dialog, asyncResult); | |
} catch(e) { | |
asyncResult(); // done - closed | |
} | |
}, 0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment