(function($){
  fetch_sub_items = function(sub_items, category){
    loading_for_button($("#category-loading-"+category)[0]);
    $.ajax({
      url: "/admin/categories/get_children",
      dataType: "html",
      data: {id: category},
      success: function(data, st, ajax){
        $(sub_items).append(data);
        $(".small-loading").remove();
        $("#show-button-"+category).fadeOut(400, function(){
          $("#hide-button-"+category).fadeIn();
        });
        $(sub_items).slideDown();
      },
      error: function(ajax, st, errorThrown) {
        alert('HTTP '+st+': '+errorThrown);
      }
    });
  };

  $(".hide-button").live('click', function(){
    var category = $(this).attr('data-category');
    var sub_items = $('#category-sub-items-'+category);
    $(this).fadeOut(400, function(){
      $("#show-button-"+category).fadeIn();
    });
    $(sub_items).slideUp();
  });

  $(".show-button").live('click', function(){
    var category = $(this).attr('data-category');
    var sub_items = $('#category-sub-items-'+category);
    if(!$(this).attr('data-fetched')){
      fetch_sub_items(sub_items, category);
      $(this).attr('data-fetched', true);
    }
    else{
      $(this).fadeOut(400, function(){
        $("#hide-button-"+category).fadeIn();
      });
      $(sub_items).slideDown();
    }
  });
})(jQuery);


(function($){
  fetch_sub_items = function(sub_items, category){
    loading_for_button($("#category-loading-"+category)[0]);
    $.ajax({
      url: noosfero_root() + "/admin/categories/get_children",
      dataType: "html",
      data: {id: category},
      success: function(data, st, ajax){
        $(sub_items).append(data);
        $(".small-loading").remove();
        $("#show-button-"+category).fadeOut(400, function(){
          $("#hide-button-"+category).fadeIn();
        });
        $(sub_items).slideDown();
      },
      error: function(ajax, st, errorThrown) {
        alert('HTTP '+st+': '+errorThrown);
      }
    });
  };

  $(".hide-button").live('click', function(){
    var category = $(this).attr('data-category');
    var sub_items = $('#category-sub-items-'+category);
    $(this).fadeOut(400, function(){
      $("#show-button-"+category).fadeIn();
    });
    $(sub_items).slideUp();
  });

  $(".show-button").live('click', function(){
    var category = $(this).attr('data-category');
    var sub_items = $('#category-sub-items-'+category);
    if(!$(this).attr('data-fetched')){
      fetch_sub_items(sub_items, category);
      $(this).attr('data-fetched', true);
    }
    else{
      $(this).fadeOut(400, function(){
        $("#hide-button-"+category).fadeIn();
      });
      $(sub_items).slideDown();
    }
  });
})(jQuery);


Fix JS behaviour to show categories when noosfero is in a subdir environment
Fix JS behaviour to show categories when noosfero is in a subdir environment

Signed-off-by: Fabio Teixeira <a90b0aa793b4509973a022e6fee8cf8a263dd84e@gmail.com>
Signed-off-by: Gabriela Navarro <61c2bac069eee966d94f5b4095f9a2d9fa323d86@gmail.com>
