javascript - Using Deferred to create custom Jquery UI Modal -


i trying recreate of functions of browser confirm box. need custom 1 our purpose.

my issue if statement on button click returns immediately, instead of after jqconfirm function has received user input , promise returned.

any ideas?

$('#testbutton').click(function () {     if (gjs_confirm('this question, sure want to?????')) {         alert('ok');     }     else {         alert('cancel');     } });   function gjs_confirm(msg) {     $.when(jqconfirm(msg))         .then(function () {              $("#dialog").dialog("close");             return true;         })         .fail(function () {              $("#dialog").dialog("close");             return false;         }); }  function jqconfirm(msg) {      var deferred = $.deferred();      $("#dialog").dialog({             // autoopen:  false,             modal:     true,             resizable: false,             height:    140,             title:     'confirm',             buttons:   {                 ok:     function (e) {                     deferred.resolve();                 },                 cancel: function (e) {                     deferred.reject();                 }             }         }).text(msg);      return deferred.promise(); } 

html

<button id="testbutton" type="button"></button>  <div id="dialog" title="basic dialog"> </div> 


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo