From fa43409d3e8abf41a440637d2fba23172bbf0bf2 Mon Sep 17 00:00:00 2001 From: Anon Ray Date: Tue, 25 Mar 2014 00:48:42 +0530 Subject: [PATCH] Add class .active to nav --- mouchak/static/js/mouchak.js | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/mouchak/static/js/mouchak.js b/mouchak/static/js/mouchak.js index ac61f21..6533a2a 100644 --- a/mouchak/static/js/mouchak.js +++ b/mouchak/static/js/mouchak.js @@ -67,8 +67,8 @@ var NavigationView = Backbone.View.extend({ } $(this.$links[pos]).addClass('active'); - $(this.$links[pos]).find('a p.nav-item-icon').addClass('active'); - this.updateNavIcon(); + //$(this.$links[pos]).find('a p.navicon').addClass('active'); + //this.updateNavIcon(); }, populate: function() { var item_template = _.template($('#nav-item-template').html()); @@ -90,7 +90,7 @@ var NavigationView = Backbone.View.extend({ //Fix it always receive the click event. navClicked: function(event) { this.$links.removeClass('active'); - $('.nav>li>a>p.nav-item-icon').removeClass('active'); + $('#navpos > li > a').find('p.navicon').removeClass('active'); if(this.model.get('customMenu') === false) { if(!event) { @@ -101,25 +101,36 @@ var NavigationView = Backbone.View.extend({ pos = 0; } $(this.$links[pos]).addClass('active'); - $(this.$links[pos]).find('p.nav-item-icon').addClass('active'); + $(this.$links[pos]).find('p.navicon').addClass('active'); } else { $(event.currentTarget).parent().addClass('active'); // for maraa custom HTML nav - $(event.currentTarget).find('p.nav-item-icon').addClass('active'); + $(event.currentTarget).find('p.navicon').addClass('active'); } } else if(this.model.get('customMenu') === true) { - // get the URL fragment - var fragment = location.hash.split('/')[1]; - // find out where it is in the nav menu - var link = $('.nav').find('a[href="#/'+ fragment +'"]')[0]; - // find its
  • parent all the way up in the main ul.nav - $(link).closest('ul.nav > li').addClass('active'); - // custom nav for maraa - $(link).closest('ul.nav > li > a').find('p.nav-item-icon').addClass('active'); + if(event) { + // TODO: FIX: BAD HACK!! + // Hunt down the bug and fix it! + // Bug is: the following statement doesn't get executed in its normal + // flow; async does!! + setTimeout(function() { + $(event.currentTarget).find('p.navicon').addClass('active'); + }, 100); + } + else { + // get the URL fragment + var fragment = location.hash.split('/')[1]; + // find out where it is in the nav menu + var link = $('.nav').find('a[href="#/'+ fragment +'"]')[0]; + // find its
  • parent all the way up in the main ul.nav + $(link).closest('ul.nav > li').addClass('active'); + // custom nav for maraa + $(link).find('p.navicon').addClass('active'); + } } - this.updateNavIcon(); + //this.updateNavIcon(); }, navIconPos: { 'home': '-8px', -- 1.7.10.4