From fc67370ef4c2e7eb747706a5a4ce08396545bfcf Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Wed, 12 Jun 2013 17:57:10 +0530 Subject: [PATCH] Fix few bugs - After new page was created in the editor, its view was dangling - it could not be reached. Fix that. - When page was refreshed, framework was taking it to home page irrespective of the URL hash. Fixed. --- static/css/mouchak.css | 6 ++++++ static/js/editor.js | 5 ++++- static/js/mouchak.js | 41 ++++++++++++++++++++++++++--------------- static/js/views.js | 2 +- templates/index.html | 1 + 5 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 static/css/mouchak.css diff --git a/static/css/mouchak.css b/static/css/mouchak.css new file mode 100644 index 0000000..6e92460 --- /dev/null +++ b/static/css/mouchak.css @@ -0,0 +1,6 @@ +.title { + text-align: center; + margin: 0 auto; + padding: 3px; + font-size: 1.5em; +} diff --git a/static/js/editor.js b/static/js/editor.js index 8e0860b..dfc04a1 100644 --- 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); diff --git a/static/js/mouchak.js b/static/js/mouchak.js index 108faee..f4abf72 100644 --- a/static/js/mouchak.js +++ b/static/js/mouchak.js @@ -14,8 +14,9 @@ var AppView = Backbone.View.extend({ }, 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 AppView = Backbone.View.extend({ 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 @@ var NavigationView = Backbone.View.extend({ 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 @@ var NavigationView = Backbone.View.extend({ })); }, 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 @@ var AppRouter = Backbone.Router.extend({ else { $('#navigation').show(); } + M.appView.navView.trigger('navclicked'); }, render404: function() { $('.pageview').hide(); @@ -153,8 +164,8 @@ M.init = function() { 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(); }; diff --git a/static/js/views.js b/static/js/views.js index 912996f..1e1dd99 100644 --- 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')]; diff --git a/templates/index.html b/templates/index.html index ed3695f..f8bec27 100644 --- a/templates/index.html +++ b/templates/index.html @@ -14,6 +14,7 @@ + -- 1.7.10.4