jQuery(document).ready(function()
{
var mec_fes_form_ajax = false;
jQuery("#mec_fes_form").on("submit", function(event)
{
event.preventDefault();
var $form = jQuery("#mec_fes_form");
// Hide the message
jQuery("#mec_fes_form_message").removeClass("mec-success").removeClass("mec-success").html("").hide();
// Add loading Class to the form
$form.addClass("mec-fes-loading");
jQuery(".mec-fes-form-cntt").hide();
jQuery(".mec-fes-form-sdbr").hide();
jQuery(".mec-fes-submit-wide").hide();
// Fix WordPress editor issue
jQuery("#mec_fes_content-html").click();
jQuery("#mec_fes_content-tmce").click();
// Abort previous request
if(mec_fes_form_ajax) mec_fes_form_ajax.abort();
var data = $form.serialize();
mec_fes_form_ajax = jQuery.ajax(
{
type: "POST",
url: "'.admin_url('admin-ajax.php', NULL).'",
data: data,
dataType: "JSON",
success: function(response)
{
// Remove the loading Class from the form
jQuery("#mec_fes_form").removeClass("mec-fes-loading");
jQuery(".mec-fes-form-cntt").show();
jQuery(".mec-fes-form-sdbr").show();
jQuery(".mec-fes-submit-wide").show();
if(response.success == "1")
{
// Show the message
jQuery("#mec_fes_form_message").removeClass("mec-success").addClass("mec-success").html(response.message).css("display","inline-block");
// Set the event id
jQuery(".mec-fes-post-id").val(response.data.post_id);
// Redirect Currnet Page
if(response.data.redirect_to !== "")
{
setTimeout(function()
{
window.location.href = response.data.redirect_to;
},' . ((isset($this->settings['fes_thankyou_page_time']) and trim($this->settings['fes_thankyou_page_time']) != '') ? (int) $this->settings['fes_thankyou_page_time'] : 2000) . ');
}
}
else
{
// Show the message
jQuery("#mec_fes_form_message").removeClass("mec-error").addClass("mec-error").html(response.message).css("display","inline-block");
}
},
error: function(jqXHR, textStatus, errorThrown)
{
// Remove the loading Class from the form
jQuery("#mec_fes_form").removeClass("loading");
}
});
});
});
function mec_fes_upload_featured_image()
{
var fd = new FormData();
fd.append("action", "mec_fes_upload_featured_image");
fd.append("_wpnonce", "'.wp_create_nonce('mec_fes_upload_featured_image').'");
fd.append("file", jQuery("#mec_featured_image_file").prop("files")[0]);
jQuery("#mec_fes_thumbnail_error").html("").addClass("mec-util-hidden");
jQuery.ajax(
{
url: "'.admin_url('admin-ajax.php', NULL).'",
type: "POST",
data: fd,
dataType: "json",
processData: false,
contentType: false
})
.done(function(data)
{
if(data.success)
{
jQuery("#mec_fes_thumbnail").val(data.data.url);
jQuery("#mec_featured_image_file").val("");
jQuery("#mec_fes_thumbnail_img").html("");
jQuery("#mec_fes_remove_image_button").removeClass("mec-util-hidden");
}
else
{
jQuery("#mec_fes_thumbnail_error").html(data.message).removeClass("mec-util-hidden");
}
});
return false;
}
function mec_fes_upload_location_thumbnail()
{
var fd = new FormData();
fd.append("action", "mec_fes_upload_featured_image");
fd.append("_wpnonce", "'.wp_create_nonce('mec_fes_upload_featured_image').'");
fd.append("file", jQuery("#mec_fes_location_thumbnail_file").prop("files")[0]);
jQuery.ajax(
{
url: "'.admin_url('admin-ajax.php', NULL).'",
type: "POST",
data: fd,
dataType: "json",
processData: false,
contentType: false
})
.done(function(data)
{
jQuery("#mec_fes_location_thumbnail").val(data.data.url);
jQuery("#mec_fes_location_thumbnail_file").val("");
jQuery("#mec_fes_location_thumbnail_img").html("
");
jQuery("#mec_fes_location_remove_image_button").removeClass("mec-util-hidden");
});
return false;
}
function mec_fes_upload_organizer_thumbnail()
{
var fd = new FormData();
fd.append("action", "mec_fes_upload_featured_image");
fd.append("_wpnonce", "'.wp_create_nonce('mec_fes_upload_featured_image').'");
fd.append("file", jQuery("#mec_fes_organizer_thumbnail_file").prop("files")[0]);
jQuery.ajax(
{
url: "'.admin_url('admin-ajax.php', NULL).'",
type: "POST",
data: fd,
dataType: "json",
processData: false,
contentType: false
})
.done(function(data)
{
jQuery("#mec_fes_organizer_thumbnail").val(data.data.url);
jQuery("#mec_fes_organizer_thumbnail_file").val("");
jQuery("#mec_fes_organizer_thumbnail_img").html("
");
jQuery("#mec_fes_organizer_remove_image_button").removeClass("mec-util-hidden");
});
return false;
}
';
// Include javascript code into the footer
$this->factory->params('footer', $javascript);
?>