diff --git a/tracks/app/views/todo/update_action.rjs b/tracks/app/views/todo/update_action.rjs index af0da8d2..b3ab1507 100644 --- a/tracks/app/views/todo/update_action.rjs +++ b/tracks/app/views/todo/update_action.rjs @@ -2,16 +2,16 @@ if @saved item_container_id = "item-#{@item.id}-container" if @item.context_id == @original_item_context_id page.replace_html item_container_id, :partial => 'todo/item' - page.call "todoItems.makeItemDraggable", item_container_id + page.call "todoItems.prepareForLazyLoadingDraggable", item_container_id page.visual_effect :highlight, item_container_id, :duration => 3 else - page["item-#{@item.id}-container"].remove + page[item_container_id].remove page.call "todoItems.expandNextActionListingByContext", "c#{@item.context_id}items", true page.insert_html :bottom, "c#{@item.context_id}items", :partial => 'todo/item' page.delay(0.5) do page.call "todoItems.ensureContainerHeight", "c#{@original_item_context_id}items" page.call "todoItems.ensureContainerHeight", "c#{@item.context_id}items" - page.call "todoItems.makeItemDraggable", item_container_id + page.call "todoItems.prepareForLazyLoadingDraggable", item_container_id page.visual_effect :highlight, item_container_id, :duration => 3 end end diff --git a/tracks/public/javascripts/todo-items.js b/tracks/public/javascripts/todo-items.js index d3a6e0dc..9338557a 100644 --- a/tracks/public/javascripts/todo-items.js +++ b/tracks/public/javascripts/todo-items.js @@ -155,9 +155,9 @@ var todoItems = { }, addItemDragDrop: function() - { + { $$('.item-container').each(function(containerElem){ - todoItems.makeItemDraggable(containerElem); + todoItems.prepareForLazyLoadingDraggable(containerElem.id); }); $$('.context').each(function(contextElem){ todoItems.makeContextDroppable(contextElem); @@ -169,9 +169,20 @@ var todoItems = { todoItems.makeContextDroppable(contextElem); }); }, + prepareForLazyLoadingDraggable : function(itemContainerElemId) + { + Event.observe($(itemContainerElemId), "mouseover", todoItems.createDraggableListener.bindAsEventListener($(itemContainerElemId))); + }, + createDraggableListener : function() + { + todoItems.makeItemDraggable(this); + //remove this listener once the draggable has been created (no longer needed) + Event.stopObserving(this, "mouseover", this.createDraggableListener); + this.createDraggableListener = null; + }, makeItemDraggable: function(itemContainerElem) { - new Draggable($(itemContainerElem).id, + new Draggable(itemContainerElem.id, { handle:'description', starteffect:todoItems.startDraggingItem, @@ -244,7 +255,6 @@ var todoItems = { evalScripts:true, parameters:"id=" + todoId + "&project_id=" + projectId }) - } -} + }} Event.observe(window, "load", todoItems.addNextActionListingToggles); Event.observe(window, "load", todoItems.addItemDragDrop);