For Bootstrap 3.3.4 and earlier, for the hide.bs.modal
and hidden.bs.modal
events, the event
object passed to the handlers contains no information about the original source of the event.
There is an issue for this on bootstrap project page: #15408: Get cause of hidden.bs.modal event which has been rolled into a more generic ticket (Bootstrap issue #15393) for forwarding the original trigger event down the queue (for the 4.0 milestone).
As a side note, I have used the following workaround(using a variable to store the original event trigger):
var eventTrigger='';
$("#myModal").submit(function(evt){
eventTrigger=evt.type;
// Do submit stuff
});
$('#myModal').on('hidden.bs.modal', function (evt) {
switch(eventTrigger) {
case "submit": // Submit. Do something
...
break:
default: // No submit (Esc key, close button, programmatic 'hide'
};
eventTrigger='';
});
In your case, you'll have to add the following event handlers:
$('#taketour').on( 'click', function () { eventTrigger='taketour'; } );
$('#register').on( 'click', function () { eventTrigger='register'; } );
$('#login').on( 'click', function () { eventTrigger='login'; } );
Please note that as your buttons have the data-dismiss="modal"
attribute, the modal will be hidden when you click the buttons. However, the click
handlers will kick in and set eventTrigger
before the modal
is hidden, that is, before the hidden.bs.modal
event, so your handler for the event can be a simple switch
:
$('#welcomeModal').on('hidden.bs.modal', function (e) {
switch(eventTrigger) {
case 'taketour':
$(window).location=e.href;
break; // this may be redundant, but I'm unsure.
case 'login':
$('#welomeModal').remote='element-login';
break;
case 'register':
// do register magic
break;
default:
// handle unexpected user behaviour
}
});