Created
July 5, 2010 02:26
-
-
Save fujimura/463939 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Set passed background-image to form type=submit just before ajax request was submitted. | |
// reset with ajax:complete. | |
// options: | |
// loadingImage: background-image | |
// loadingText: text | |
jQuery.fn.swapBackgroundToLoading = function(options){ | |
$(this).live('ajax:before', function(){ | |
var submit = $(this).find('input[type=submit]') | |
var text = submit.val(); | |
var backgroundImage = submit.css('background-image'); | |
// set loading | |
submit.val(options.loadingText || ''); | |
submit.css('background-image', 'url(' + loadingImagePath + ')'); | |
$(this).one('ajax:complete', function(){ | |
// reset | |
submit.css('background-image', backgroundImage); | |
submit.val(text); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment