I have a function whinch performs something and it works great. Now i want to add a bootstrap modal and execute the same code when modal closes. But my problem is that i have to check for user status. Is there a way how to execute this code and not to copy everything twice?
if(USERTYPE == 0) {
$("#fastRegisterModal").modal('show');
$("#fastRegisterModal").on('hidden', function() {
//Code for registration and upload code
}
} else {
//upload code
}
I want to include this into multiple jquery function (mostly .live functions) and i don't want to move "upload code" into normal js function (I got the .js file writen as it is and i don't want to change 70% of the file)
Is this even possible in this or any other way?
EDITED
Here is some more code:
$('.someAction').live('click', function(event) {
// Init section
var data1 = $(".getData1").val();
var data2 = $(".getData2").val();
// I want to add this modal check before exsisting code
if(USERTYPE == 0) {
$("#fastRegisterModal").modal('show').on('hidden', function() {
var email = $(".getModalEmail").val();
var pass = $(".getModalPass").val();
$.ajax({
url: "actions/fastRegister",
type: 'POST',
data: {email: email, pass: pass},
success: function(data) {
if (data.success == 1) {
// continue with existing block of code
}
}
});
});
}
// Existing block of code
$.ajax({
url: "actions/someAction",
type: 'POST',
data: {data1: data1, data2: data2},
success: function(data) {
if (data != '') {
// show success
}
}
});
});
I hope this explaings my situation bether :)