I’m having a little issue with an application I’m making. I have a page where the user edits a document via dragging modules into the page or “canvas” area.
http://thinktankdesign.ca/temp_img.jpg
When the page is loaded, javascript haves the modules collapsible (like above). However after the user drags in a new module the effect is applied again some new modules can collapse as well. here is the problem. each time a module loads the same effect gets applied to the modules that already can collapse. It ends up breaking their animations.
heres the code that gets executed on page load.
//make colapsible $("h1.handle").click(function() { var object = $(this); v$(this).next().toggle("fast", colapsible_class(object)); vreturn false; }).addClass("open");
and heres the code that gets executed in the creation of a module via ajax
function get_module(id){ var template = $('input[name=template]').val(); $.post(window.location.href, { template: template, module: id, mode: 'create' }, function(data){ $(data).insertBefore(".target_wrapper"); //enable deletion of module $(".js_no_modules").slideUp("slow"); $(enable_module_deletion()); //show delete button $("button[name=delete]").show(); //make colapsible $("h1.handle").click(function() { var object = $(this); $(this).next().toggle("fast", colapsible_class(object)); return false; }).addClass("open"); } ); }
I need a solid way of preventing the toggle effect to be applied to the same module twice
Use jQuery 1.3 live events instead.
and then eliminate the click declaration in the second block of code, changing it to
$("h1.handle").addClass("open");Live events bind all current and future matching elements with an event.