Skip to content
Newer
Older
100644 88 lines (61 sloc) 3.93 KB
a3296ef removed jQuery and started the readme.
Robert Hurst authored
1 OriginJS
2 ========
3bf6a3e Update readme.md
Robert Hurst authored
3 Every route begins with an origin.
a3296ef removed jQuery and started the readme.
Robert Hurst authored
4
a47c81a Wow, its works on IE 5.5!
Robert Hurst authored
5 Introduction
6 ============
d7aadf0 - Removed the examples from the readme and better fleshed out the doc…
Robert Hurst authored
7 OriginJS is am awesome clent slide router. It's lightweight, easy to use, and has a lot of very powerful features.
8 If your building a single page application, and javascript game, or anything else heavy in javascript, OriginJS will
9 make your application more accessable and might even help you code in a more organized way.
a47c81a Wow, its works on IE 5.5!
Robert Hurst authored
10
99f1dc2 Updated the readme with docs
Robert Hurst authored
11
12 Documentation
13 =============
14
23b3dec Update readme.md
Robert Hurst authored
15 Bind
16 ----
99f1dc2 Updated the readme with docs
Robert Hurst authored
17
d7aadf0 - Removed the examples from the readme and better fleshed out the doc…
Robert Hurst authored
18 OriginJS.bind(route, setupCallback(urisArray, previousUrisArray)[, tearDownCallback(urisArray, previousUrisArray)]);
99f1dc2 Updated the readme with docs
Robert Hurst authored
19
d7aadf0 - Removed the examples from the readme and better fleshed out the doc…
Robert Hurst authored
20 This method is the corner stone of this library. It binds your route logic to the routes of your application. To bind a
21 route you simply call `OriginJS.bind()` passing it a route (like /home, /about, etc...), and a setup callback that will
22 load the content of your route. You can optionally pass a teardown callback aswell if you wish to cleanup your loaded
23 content when a different route is followed. You can think of `setupCallback()` and `tearDownCallback()` as parellels to the
24 DOM's `onload` and `onunload` events.
99f1dc2 Updated the readme with docs
Robert Hurst authored
25
23b3dec Update readme.md
Robert Hurst authored
26 ### Arguments
99f1dc2 Updated the readme with docs
Robert Hurst authored
27
d7aadf0 - Removed the examples from the readme and better fleshed out the doc…
Robert Hurst authored
28 - `route`: A route string or an array of route strings. The route can contain dynamic uris such as `*`, `+`, or `:someIdHere`.
29 - `setupCallback`: A function or array of functions that will be called when the route is followed.
30 - `tearDownCallback`: Optional. A function or array of functions that will be called when the navigating way from the route.
31
32 Both the `setupCallback()` and the `tearDownCallback()` are passed two arguments; A uris array for the current route,
33 and a uris array from the route followed prior to the current.
34
35 ### Uris Arrays
36 Uris arrays contain each uri from the triggering hash url. So if your route is binded to `/home/*` and someone navigated
37 to `/home/cake` the uri array would be `['home', 'cake']`.
38
39 ### Special Route Uris
99f1dc2 Updated the readme with docs
Robert Hurst authored
40
d7aadf0 - Removed the examples from the readme and better fleshed out the doc…
Robert Hurst authored
41 - `*`: Wildcard uris will match any uri.
42 - `:[name]`: Dynamic uris are a colon followed by a key name. Examples `:key`, `:user`, `:cake`. Dynaimc uris will capture
43 the value of the uri they match and attach it the the uris array as a keyed value. `:key` becomes `urisArray.key`,
44 `:user` becomes `urisArray.user`, `:cake` becomes `urisArray.cake`.
45 - `+`: Catchall uris will match any uri and anything that follows it. It can be used to setup things like 404 pages and
46 other types of catchall pages.
99f1dc2 Updated the readme with docs
Robert Hurst authored
47
23b3dec Update readme.md
Robert Hurst authored
48 Go
49 --
99f1dc2 Updated the readme with docs
Robert Hurst authored
50
a47c81a Wow, its works on IE 5.5!
Robert Hurst authored
51 OriginJS.go(url);
99f1dc2 Updated the readme with docs
Robert Hurst authored
52
d7aadf0 - Removed the examples from the readme and better fleshed out the doc…
Robert Hurst authored
53 At some point you may want to trigger routes or open other pages programatically. This is what `OriginJS.go()` is for.
54 If `OriginJS.bind()` is ying, `OriginJS.go()` is yang.
99f1dc2 Updated the readme with docs
Robert Hurst authored
55
23b3dec Update readme.md
Robert Hurst authored
56 ### Arguments
99f1dc2 Updated the readme with docs
Robert Hurst authored
57
d7aadf0 - Removed the examples from the readme and better fleshed out the doc…
Robert Hurst authored
58 - `url`: Any url you wish to follow. If the url is pointing to a binded route the router will load that route. No need to
99f1dc2 Updated the readme with docs
Robert Hurst authored
59 prefix with `/#`. If the url is not pointing to a binded route it will redirect to the url. If the url contains a domain
60 it will open the url in a new tab (or window).
61
23b3dec Update readme.md
Robert Hurst authored
62 Update
63 ------
99f1dc2 Updated the readme with docs
Robert Hurst authored
64
a47c81a Wow, its works on IE 5.5!
Robert Hurst authored
65 OriginJS.update();
99f1dc2 Updated the readme with docs
Robert Hurst authored
66
d7aadf0 - Removed the examples from the readme and better fleshed out the doc…
Robert Hurst authored
67 The `OriginJS.update()` method is used to trigger force Origin to match the current hash url routes are defined. You should
f9e6879 Clarified the purpose of `Origin.update`.
Robert Hurst authored
68 call this after your routes are binded in your appication. You should only need to to call this function once.
ce2a8e4 Added the disclaimer
Robert Hurst authored
69
d7aadf0 - Removed the examples from the readme and better fleshed out the doc…
Robert Hurst authored
70 Point
71 -----
72
73 OriginJS.point(route[, ...]).to(route)
74 OriginJS.point(route[, ...]).at(route)
75
76 At some point you may want to setup aliases or redirects. `OriginJS.point()` creates aliases and redrects with ease. It
77 takes any number route strings. and returns an object with two functions. These functions are `at()` and `to()`.
78
79 - `at(route)`: Creates an alias from the routes passed to `point()` and points them to a `route` passed.
80 - `to(route)`: Creates a redirect from the routes passed to `point()` and forwards them to a `route` passed.
81
b6f8930 Update readme.md
Robert Hurst authored
82 Credits
ea3437e Update readme.md
Robert Hurst authored
83 =======
ce2a8e4 Added the disclaimer
Robert Hurst authored
84
85 I (Robert Hurst) made this to enable me to build more robust applications without wasting time creating a half baked
86 router. I'd like to share it with fellow devs. Feel free to fork this project and make your own changes.
87
88 [![endorse](http://api.coderwall.com/robertwhurst/endorsecount.png)](http://coderwall.com/robertwhurst)
Something went wrong with that request. Please try again.