latest updates
[namibia] / public / js / app / controller.js
1 ;(function(){
2
3   _App.Controller = function( args )
4   {
5       this.initialize( args );
6   };
7
8   _App.Controller.prototype =
9   {
10
11       initialize : function( args )
12       {
13           for( var key in args )
14           {
15               this[key] = args[key];
16           }
17
18           this.getElems();
19           this.setupScrollListener();
20       },
21
22       getElems : function()
23       {
24           this.$_head           = $('head');
25           this.$_body           = $('body');
26           this.$_htmlBody       = $('html, body');
27           this.$_navAnchors     = $('#Header .nav a').map( function(i, a){ return $(a); });
28       },
29
30       changePage : function( pageName )
31       {
32           App.Event.trigger('Controller.LoadingTemplate:' + pageName, {"pageName": pageName});
33           var prevPage = this.currentPage;
34           this.currentPage = pageName || '';
35           this.$_el.addClass('loading');
36           //this.$_body.attr('id', this.currentPage.capitalize() + 'Page' );
37           this.$_navAnchors.each(function(i, $_a)
38                 {
39                   if ( $_a.attr('href') == window.location.hash )
40                   {
41                       $_a.addClass('active');
42                   }
43                   else
44                   {
45                       $_a.removeClass('active');
46                   }
47           });
48           $('div.hero-nav').remove();
49           App.activePage = false;
50           if (_t[prevPage])
51           {
52                   App.Event.trigger('Controller.RemovingPage:' + prevPage, {"pageName": prevPage});
53                   _t[prevPage].remove();
54                   $('#PageContent').removeClass(prevPage);
55           }
56                   App.Template.register(
57                                   pageName, "page", pageName, 'PageContent', {},
58                                   $.proxy( this.renderPage, this )
59                                   );
60       },
61
62       renderPage : function( id, pageName )
63       {
64                   _t[pageName].publish();
65           App.Event.trigger(
66                           'Controller.Published:' + pageName,
67                           {"id": "page", "pageName": pageName}
68                           );
69           this.$_el.removeClass('loading');
70           this.$_htmlBody.animate({
71             'scrollTop' : 0
72           }, 250);
73           $('#PageContent').addClass(pageName);
74           App.activePage = pageName;
75       },
76
77       setupScrollListener : function()
78       {
79           $(window).on('scroll', function() {
80             if ( $(window).scrollTop() > 50 )
81             {
82                 $('#Header').addClass('compressed');
83             }
84             else
85             {
86                 $('#Header').removeClass('compressed');
87             }
88         });
89       }
90
91   };
92
93 })();