summaryrefslogtreecommitdiff
path: root/static/js/cats.js
blob: e65cc282ad669dd6cced30b91057de82e176b3c3 (plain)
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
var counter = 0;

$(document).ready(function(){
        $("li > span").click(function(){
                var span = $(this);
                var img = $("img#add").copy().attr('src', function() { return this.src.replace("add", "undo"); });

                img.click(function(){
                    var input = $(this).prev();

                    $(this).remove();
                    input.fadeOut("slow", 
                        function() { 
                            span.toggle(); 
                            });
                    
                    input.val(span.text());
                });

                span.toggle();
                $(this).next().fadeIn("slow", function() {$(this).after(img); });
        });

        $("img#add").click(function(){
            var input = $("input#new").copy();
            var img = $(this).copy().attr('src', function() { return this.src.replace("add", "minus"); });
            img.click(function() { $(this).parent().fadeOut("slow", function() { $(this).remove(); }) });

            input.attr('name', function() { return this.name + counter; })
                 .removeAttr('style')
                 .insertBefore($(this).parent())
                 .wrap("<li />");
            
            input.parent().append(img)
                          .hide().fadeIn("slow", function (){ input.focus(); });
            
            counter = counter + 1;
        });
})