Skip to content

Instantly share code, notes, and snippets.

@johnantoni
Created January 31, 2012 15:11
Show Gist options
  • Select an option

  • Save johnantoni/1710985 to your computer and use it in GitHub Desktop.

Select an option

Save johnantoni/1710985 to your computer and use it in GitHub Desktop.
ajaxForm_with_fancybox - pulled from a project for dissection
$.fn.ajaxForm_with_fancybox = function(options) {
$("<input>").attr("type", "hidden").attr("name", "lightbox").val("1").appendTo(this);
var url = jQuery(this).attr("action");
this.ajaxForm({
url: url + ".json",
beforeSend: function(request){
$.fancybox.showLoading();
},
error: function(request, textStatus, errorThrown){
$.fancybox.hideLoading();
},
success: function(data, textStatus, request){
var location = data.location;
if (location !== null && location !== "" && location !== undefined) {
window.location = location; // redirect to page
} else {
// check if main site content, if yes, close and redirect to naked site
if ($(data).find(".logged-in").length > 0) {
$.fancybox.close(true);
window.location = "/";
}
else {
$.fancybox({
'content' : data
});
}
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment