--- /dev/null +++ b/static/css/mouchak.css @@ -1 +1,7 @@ +.title { + text-align: center; + margin: 0 auto; + padding: 3px; + font-size: 1.5em; +} --- a/static/js/editor.js +++ b/static/js/editor.js @@ -107,7 +107,7 @@ this.render(); }, nameChanged: function(page) { - M.pagelistview.render(); + //M.pagelistview.render(); console.log('name changed', page); }, render: function() { @@ -209,6 +209,9 @@ console.log('saved', model, response); model.set(response.page); model.id = response.page.id; + //console.log(model); + //console.log(M.pages.models); + M.pagelistview.render(); }, error: function(model, xhr) { console.log('failed', model, xhr); --- a/static/js/mouchak.js +++ b/static/js/mouchak.js @@ -14,8 +14,9 @@ }, render: function() { var menu = new M.types.model.menu(M.site_content.menu); - var navview = new NavigationView({model: menu}); - navview.render(); + var navView = new NavigationView({model: menu}); + navView.render(); + this.navView = navView; }, updateBreadcrumbs: function(event) { //TODO: write code to use bootstrap's breadcrumbs to render a @@ -26,11 +27,13 @@ var NavigationView = Backbone.View.extend({ el: '#navigation', events: { - 'click .nav li a' : 'navClicked' + 'click .nav li a' : 'navClicked', + 'navclicked': 'navClicked' }, initialize: function() { _.bindAll(this); this.template = _.template($('#nav-bar-template').html()); + this.bind('navclicked', this.navClicked); }, render: function() { // if custom menu is not defined, render a default menu @@ -46,6 +49,12 @@ console.log('rendering custom menu..'); this.$el.append(this.model.get('html')); } + var fragment = location.hash.split('/')[1]; + var pos = _.indexOf(M.pages.models, M.pages.where({'name': fragment})[0]); + if(!fragment) { + pos = 0; + } + $(this.$links[pos]).addClass('active'); }, populate: function() { var item_template = _.template($('#nav-item-template').html()); @@ -57,26 +66,27 @@ })); }, this); this.$links = $('.nav li'); - //console.log(this.$links[0]); - $(this.$links[0]).addClass('active'); }, navClicked: function(event) { - console.log('navClicked'); this.$links.removeClass('active'); - $(event.currentTarget).parent().addClass('active'); + if(!event) { + var fragment = location.hash.split('/')[1]; + var pos = _.indexOf(M.pages.models, M.pages.where({'name': fragment})[0]); + if(!fragment) { + pos = 0; + } + $(this.$links[pos]).addClass('active'); + } + else { + $(event.currentTarget).parent().addClass('active'); + } } }); var AppRouter = Backbone.Router.extend({ routes : { - //'index' : 'index', ':page' : 'showPage' }, - /*index: function() { - $('.pageview').hide(); - var id = nameIdMap['index']; - $('#'+id).show(); - },*/ showPage: function(page) { $('.pageview').hide(); //news pages are rendered on the fly, @@ -97,6 +107,7 @@ else { $('#navigation').show(); } + M.appView.navView.trigger('navclicked'); }, render404: function() { $('.pageview').hide(); @@ -153,8 +164,8 @@ var app_router = new AppRouter(); Backbone.history.start(); - var startpage = M.pages.models[0].get('name'); - app_router.navigate(startpage, {trigger: true}); + //var startpage = M.pages.models[0].get('name'); + //app_router.navigate(startpage, {trigger: true}); //M.simHeir(); }; --- a/static/js/views.js +++ b/static/js/views.js @@ -122,7 +122,7 @@ render: function() { $('#content-container').append(this.el); //this.appendNavTemplate(); - $(this.el).append('

'+this.model.get('title')+'

'); + $(this.el).append('
'+this.model.get('title')+'
'); var self = this; _.each(this.model.get('content'), function(item) { var view = M.types.view[item.get('type')]; --- a/templates/index.html +++ b/templates/index.html @@ -14,6 +14,7 @@ +