Created
July 12, 2009 02:24
-
-
Save CodeOfficer/145492 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
jQuery.fn.restForm = function(type, options) { | |
var defaults = { | |
method: 'post', | |
action: this.attr('href'), | |
confirm: false, | |
confirm_message: 'Are you sure?', | |
trigger_on: 'click' | |
}; | |
var opts = $.extend(defaults, options); | |
this.bind(opts.trigger_on, function() { | |
var $form = $('<form></form>').attr({ | |
method: opts.method, | |
action: opts.action | |
}).append('<input type="hidden" name="_method" value="' + type + '" />'); | |
if (opts.confirm && !confirm(opts.confirm_message)) { | |
return false; | |
} | |
this.after($form); | |
$form.submit(); | |
return false; | |
}); | |
}; | |
$(function() { | |
$('.put').restForm('PUT'); | |
$('.delete').restForm('DELETE', {confirm: true}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment