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); | |
}); | |
}); | |
}; |
No comments:
Post a Comment