A general way to do this is as follows:
foo.dialog({ // ... buttons: (function() { function CloseHandler() { // close ... }; function DownloadHandler() { // download ... }; return condition ? { "Download": DownloadHandler, "Close": CloseHandler } : { "Close": CloseHandler }; })(), // ... });
The idea is that you create a function in which you can make decisions, and then return the result that you decide.
source share