aboutsummaryrefslogtreecommitdiffstats
path: root/www/js/router.js
blob: 2217c9ba01dcf52172d0fb44e2c185fb6704dba7 (plain)
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
;(function (FMS, Backbone, _, $) {
    _.extend(FMS, {
        appRouter: Backbone.Router.extend({
            currentView: null,

            routes: {
                '': 'home',
                'home': 'home',
                'around': 'around'
            },

            initialize: function() {
            },

            back: function() {
                if (this.currentView && this.currentView.prev) {
                    this.currentView.onClickButtonPrev();
                }
            },

            around: function(){
                var aroundView = new FMS.AroundView();
                this.changeView(aroundView);
            },

            home: function(){
                var homeView = new FMS.HomeView();
                this.changeView(homeView);
            },

            changeView: function(view) {
                $(view.el).attr('data-role', 'page');
                view.render();
                $('body').append($(view.el));
                $.mobile.changePage($(view.el), { changeHash: false });
                if(!_.isNull(this.currentView)) {
                    var oldView = this.currentView;
                    oldView.destroy();
                }
                view.afterDisplay();
                this.currentView = view;
            }
        })
    });
})(FMS, Backbone, _, $);