summaryrefslogtreecommitdiffstats
path: root/web/js/labitrack.d/40-router.js
blob: 153e0b1206e4a1fb881e2185a227b2616af82c7a (plain) (blame)
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
(function(){
	var r = λ.r = new Backbone.Router();

	function handle_click(event) {
		console.log('click');
		if (!Modernizr.history) return true;
		event.preventDefault();
		var href = $(event.target).attr('href');
		if (href !== undef && href[0] === '/') {
			Backbone.history.navigate(href, true);
		}
	}

	var mainview = Backbone.View.extend({
		events: {
			'click a': 'handleClick'
		},
		handleClick: handle_click,
		initialize: function(){
			_(this).bindAll('handleClick', 'render');
		}
	});
	$(function(){
		new mainview({el: document.body});
	});

	var view = Backbone.View.extend({
		el: '#tmplcontent',
		events: {
			'click a': 'handleClick'
		},
		handleClick: handle_click,
		initialize: function(){
			_(this).bindAll('handleClick', 'render');
		}
	});

	function route_handler()
	{
		var t = this;
		if (t.instance === undef) {
			t.instance = new t();
		}
		t.instance.render.apply(t.instance, arguments);
	};

	view.route = function(route, name)
	{
		name || (name = route);
		var t = this;
		λ.r.route(route, name, function(){
			λ.topbar.update();
			route_handler.apply(t, arguments);
		});
	};

	λ.routableview = view;
}());