manage-categories.js
1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(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);