mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-31 13:15:17 +01:00
Improve page load performance with by lazy loading Draggables. Thanks to Ryan Gahl for his mailing list post on the subject at http://lists.rubyonrails.org/pipermail/rails-spinoffs/2006-February/002459.html.
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@278 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
1b5215ed0e
commit
b4891224ec
2 changed files with 18 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue