diff --git a/app/views/aspects/index.js.erb b/app/views/aspects/index.js.erb new file mode 100644 index 000000000..aa27af5a0 --- /dev/null +++ b/app/views/aspects/index.js.erb @@ -0,0 +1 @@ +$('#main_stream').html("<%= escape_javascript(render('shared/stream', :posts => @post_hashes)) %>"); diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index abd6baa92..dc07b0797 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -44,7 +44,7 @@ #aspect_nav %ul %li{:class => ("selected" if @aspect == :all)} - = link_to t('_home'), root_path + = link_to t('_home'), root_path, :class => 'home_selector' - for aspect in @all_aspects %li{:data=>{:guid=>aspect.id}, :class => ("selected" if current_aspect?(aspect))} diff --git a/public/javascripts/aspect-filters.js b/public/javascripts/aspect-filters.js index b720c67d6..7879e961c 100644 --- a/public/javascripts/aspect-filters.js +++ b/public/javascripts/aspect-filters.js @@ -17,13 +17,18 @@ $(function(){ }); $("#aspect_nav a.aspect_selector").click(function(e){ - e.preventDefault(); + // loading animation + $("#main_stream").fadeTo(100, 0.4); + + + // filtering ////////////////////// var $this = $(this), listElement = $this.parent(), guid = listElement.attr('data-guid'), - baseURL = location.href.split("?")[0]; + baseURL = location.href.split("?")[0], + homeListElement = $("#aspect_nav a.home_selector").parent(); if( listElement.hasClass('selected') ){ // remove filter @@ -31,12 +36,20 @@ $(function(){ if( idx != -1 ){ selectedGUIDS.splice(idx,1); } + listElement.removeClass('selected'); + + if(selectedGUIDS.length == 0){ + homeListElement.addClass('selected'); + } } else { // append filter if(selectedGUIDS.indexOf( guid == 1)){ selectedGUIDS.push( guid ); } + listElement.addClass('selected'); + + homeListElement.removeClass('selected'); } // generate new url @@ -45,7 +58,17 @@ $(function(){ baseURL += 'a_ids[]='+ selectedGUIDS[i] +'&'; } baseURL = baseURL.slice(0,baseURL.length-1); + /////////////////////////////////// + + + //window.location = baseURL; + $.ajax({ + url : baseURL, + dataType : 'script', + success : function(data){ + $("#main_stream").fadeTo(100, 1); + } + }); - window.location = baseURL; }); });