diff options
Diffstat (limited to '')
-rw-r--r-- | static/js/cats.js | 39 | ||||
-rw-r--r-- | static/js/lib.js | 6 |
2 files changed, 45 insertions, 0 deletions
diff --git a/static/js/cats.js b/static/js/cats.js new file mode 100644 index 0000000..e65cc28 --- /dev/null +++ b/static/js/cats.js @@ -0,0 +1,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; + }); +}) diff --git a/static/js/lib.js b/static/js/lib.js new file mode 100644 index 0000000..43b0dc8 --- /dev/null +++ b/static/js/lib.js @@ -0,0 +1,6 @@ +jQuery.fn.extend({ + // copies an object and removes 'id' and 'class' values + copy: function() { + return this.clone().removeAttr("id").removeAttr("class"); + } +}); |