Simple pseudo class that allows you to attach a specific callback to a specific #hash url. Follow this example to understand
####Getting Started: "Hello word"
var Nav = new _Route();
Nav.route("/hello/:name", function(name){
alert("World say Hello, " + name);
});
Nav.listen();
If you load the page with #!/hello/Frogmouth, browser alert this message: "World say Hello, Frogmouth".
Call #!/hello/Frogmouth or #!/hello/Frogmouth*/*** is the same, because "/" is optional (or useless).
You can use also this syntax:
var Nav = new _Route([
["/hello/:name",
function(name){
alert("World say Hello, " + name);
}]
]);
Nav.listen();
_Route accepts one argument, an array that contain arrays with 2 items, first (0 indexed) is the #hash url without #! (ex. "/hello/:name") the second item is the function that was calling like a route callback.
new _Route(array);
Array's structure:
[
[
"/hashPath",
function(){}
],
[
"/hashPath/:id",
function(id){}
],
...
]
#####The two items are mandatory.
- Hash Path not need to specificate #!
- the first character of Hash Path must be "/"
- "/" only, is the default behavior (if is instanced, the callback was trigged if not Hash Path was specified, ex. #!/ or #!)
- to specificate a dynamic element of the path (like id or string) you can append to variable name ":". An example: #!/player/:id match #!/player/1 or #!/player/duncan
- the value of this in the callback is the _Route object.
- the arguments depends to Hash Path (every :element is an argument of the function)
- the name of the arguments aren't necessary the same of the :element, the value of an argument depends of his position, example:
In this Hash Path : /test/:element/:id, the first argument of the callback function is element's value, and the second is id's value.
- if the function return false, the routing past to the next Hash Path in the route set, in the other case the route ended.
Enjoy.
#####Sorry for my english but I have't time to correct my stupid error. :)
This is only a Beta, :)