HTMLGuyLLC / jAlert

jQuery alert/modal/lightbox plugin
https://htmlguyllc.github.io/jAlert/
MIT License
76 stars 35 forks source link

confirm implementation #5

Closed mandricmihai closed 9 years ago

mandricmihai commented 9 years ago

this is my actual confirm using build in browser

function lol(){
                        var r = confirm ("Do you want to add this?");
                         if (r == true){
                             return true;
                         } else {
                             return false;
                         }

                    }

and then I do if (confirm() == true) how to make this with jAlert?

HTMLGuyLLC commented 9 years ago

That's the downside to custom confirms. They don't work the same as the built-in one javascript supplies. You have the use the onConfirm and onDeny callbacks. The best way if you want a custom question is:

$.fn.jAlert.defaults.confirmQuestion = 'Do you want to add this?';

confirm(
  function(e, btn){ //onConfirm
    e.preventDefault();
    //do something here
    btn.parents('.jAlert').closeAlert();
    return false;
  }, function(e,btn){ //onDeny
    e.preventDefault();
    //do something here
    btn.parents('.jAlert').closeAlert();
    return false;
  }
);

or

$.jAlert({
  'type': confirm',
  'confirmQuestion': 'Do you want to add this?',
  'onConfirm': function(e, btn){
    e.preventDefault();
    //do something here
    btn.parents('.jAlert').closeAlert();
    return false;
  },
  'onDeny': function(e, btn){
    e.preventDefault();
    //do something here
    btn.parents('.jAlert').closeAlert();
    return false;
  }
);
mandricmihai commented 9 years ago

oh thanks know its working as intended great plugin :+1:

HTMLGuyLLC commented 9 years ago

thank you!