Created
November 30, 2013 23:31
-
-
Save montogeek/7725969 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// restfulizer.js | |
/** | |
* Restfulize any hiperlink that contains a data-method attribute by | |
* creating a mini form with the specified method and adding a trigger | |
* within the link. | |
* Requires jQuery! | |
* | |
* Ex: | |
* <a href="post/1" data-method="delete">destroy</a> | |
* // Will trigger the route Route::delete('post/(:id)') | |
* | |
*/ | |
$(function(){ | |
$('[data-method]').append(function(){ | |
return "\n"+ | |
"<form action='"+$(this).attr('href')+"' method='POST' style='display:none'>\n"+ | |
" <input type='hidden' name='_method' value='"+$(this).attr('data-method')+"'>\n"+ | |
"</form>\n" | |
}) | |
.removeAttr('href') | |
.attr('style','cursor:pointer;') | |
.attr('onclick','$(this).find("form").submit();'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment