-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
58 lines (53 loc) · 1.51 KB
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Template.__define__("route", (function() {
var view = this;
var templateName = HashRouter.getRoute(Session.get("route"));
if(Template[templateName]){
return Spacebars.include(view.lookupTemplate(templateName));
}
else{
return Spacebars.include(view.lookupTemplate("home"));
}
}));
HashRouter = {};
HashRouter.go = function(hash){
window.location.hash = hash;
}
HashRouter.routes = {};
HashRouter.add = function(options){
if(!options){
throw new Error("Please send json object with {'hash':}");
}
if(HashRouter.routes[options.route]){
throw new Error("Route already Exists " +options.route);
}
else{
HashRouter.routes[options.route] = options
}
// options.route;
// options.template;
// options.beforeFunction;
// options.afterFunction;
}
HashRouter.getRoute = function(routeName){
if(HashRouter.routes[routeName]){
return HashRouter.routes[routeName].template;
}
else{
console.log("Route Not found " +routeName +". Making 'home' as default route.");
return "home";
}
}
HashRouter.onHashChange = function(){
var hash = window.location.hash;
Session.set("route",hash);
// if(app.routerFunction[hash])
// app.routerFunction[hash]()
// else
// app.routerFunction["#home"]();
}
Session.setDefault("route","#home");
window.onhashchange = HashRouter.onHashChange;
// $(window).on('hashchange',HashRouter.onHashChange);
Meteor.startup(function(){
HashRouter.onHashChange();
});