jquerybpopup

How to call a function on beforeclose event in bpopup?


I want to call a function before closing the bpopup. I have used following code:

$('#casepromptPopup').bPopup({
    escClose: false,
    closeClass: 'b-close',
    modalClose: false,
    onClose: function() {                         
        confirm("Are you sure you wish to quit and grade your performance?");

I want to show the confirm message before popup close. But onClose method fires after the popup close.


Solution

  • While I'm not a fan of plugin modifications, it seems that there's no other way to achieve this.

    Modify the bpopup.js:

    Now you can add confirmation into your bpopup options:

    $('#casepromptPopup').bPopup({
        escClose     : false,
        closeClass   : 'b-close',
        confirmClose : function(){                         
            return confirm("Are you sure you wish to quit and grade your performance?");
        }
    });
    

    JSFiddle