Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/oroce/jquery.urlfor
url_for jQuery
https://github.com/oroce/jquery.urlfor
Last synced: about 1 month ago
JSON representation
url_for jQuery
- Host: GitHub
- URL: https://github.com/oroce/jquery.urlfor
- Owner: oroce
- Created: 2011-06-23T21:28:15.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-06-29T20:42:31.000Z (over 13 years ago)
- Last Synced: 2024-04-14T14:45:47.542Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 93.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
jQuery.urlFor
This small jQ plugin tries to simulate - in MVC's world - well-know url_for function.
Idea is mostly based on perl MVC framework ( Catalyst MVC uri_for and Mojolicious url_for ), as far as i know there is something like that in Ruby and Symfony.
You can use this plugin with the following parameters:
$.urlFor( "url" ) which generates "url"
$.urlFor( "/list","of","the","parameters" ) which generates "/list/of/the/parameters"
$.urlFor( "/action/:param1/:param2", { param1: "foo", param2: "bar" }) or
$.urlFor( "/action/:param1/:param2", [ "foo", "bar" ]) which generate "/action/foo/bar"An example, how to use this plugin:
window.MYNAMESPACE: {
URLS:{
editContact: "/contant/:id"
}
};$.ajax({
url: $.urlFor( MYNAMESPACE.URLS.editContact, { id: $( "#elem" ).data( "id" ) } ),
....
});Using with Sammy.js
Sammy.Application.prototype.setLocation = function( url, params ){
return this._location_proxy.setLocation( jQuery.urlFor( url, params ) );
}Ideas, issues, patches are welcome.
Fork and have fun. :)