summaryrefslogtreecommitdiffstats
path: root/web/js/labitrack.d/40-router.js
blob: c8952aeeb2b0a1401536ab2751dbe0bb53285cc3 (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
59
60
61
62
(function(){
	var r = λ.r = new Backbone.Router();

	function handle_click(event) {
		if (!Modernizr.history) return true;
		var href = $(event.target).attr('href');
		var curpath = window.location.pathname;
		if (href !== undef && href[0] === '/') {
			event.preventDefault();
			if (curpath === href) {
				console.log('ignoring click event for', href);
				return;
			}
			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;
}());