So I''m making an element draggable on the fly with a mousedown event handler. I''ve run into a bit of a problem (perhaps a race condition) where if you double click on one of the items quickly enough the onEnd function doesn''t fire and I''m using that to remove the cloned node that was being dragged. When I get it in this state if I look at the Draggables object it will show there is indeed an element in the drags array. Does anyone have suggestions on how to fix this? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, Here''s what I''m using: var draggable = new Draggable(clone, { onEnd: function(drag) { drag.destroy(); drag.element.remove(); } }); draggable.initDrag(event); draggable.startDrag(event); Works perfectly in FF and Safari, not yet tested in IE. Let me know whow thigns go. Best, Tobie emullet wrote:> So I''m making an element draggable on the fly with a mousedown event > handler. I''ve run into a bit of a problem (perhaps a race condition) > where if you double click on one of the items quickly enough the onEnd > function doesn''t fire and I''m using that to remove the cloned node > that was being dragged. > > When I get it in this state if I look at the Draggables object it will > show there is indeed an element in the drags array. > > Does anyone have suggestions on how to fix this?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for your reply Tobie. I had slightly different code than you. I was using updateDrag instead of startDrag to jump start the drag. I also was defining an observer object with an onEnd event handler. I changed those 2 things to be like your code and I''m still having the issue, although the element appears opaque now (like it does with the ghosting effect). Currently I have the mousedown handler watching a parent of the element I want to clone. Which element is your mousedown handler attached to? Here is a code snippet Event.observe(''root'',''mousedown'',function(event) { var e = Event.element(event); if(e.className == ''field'') { var dupe = e.cloneNode(true); Position.absolutize(dupe); $(''gray1Header'').appendChild(dupe); Position.clone(e,dupe); dupe.innerHTML = '' some fun html''; dupe.className = null; var d = new Draggable(dupe,{ onEnd: function(drag) { drag.destroy(); drag.element.remove(); } }); d.initDrag(event); d.startDrag(event); } }); On Dec 13, 2:04 am, Tobie Langel <tobie.lan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > Here''s what I''m using: > > var draggable = new Draggable(clone, { > onEnd: function(drag) { > drag.destroy(); > drag.element.remove(); > } > }); > draggable.initDrag(event); > draggable.startDrag(event); > > Works perfectly in FF and Safari,notyet tested in IE. > > Let me know whow thigns go. > > Best, > > Tobie > > emullet wrote: > > So I''m making an element draggable on the fly with a mousedown event > > handler. I''ve run into a bit of a problem (perhaps a race condition) > > where if you double click on one of the items quickly enough theonEnd > > function doesn''t fire and I''m using that to remove the cloned node > > that was being dragged. > > > When I get it in this state if I look at the Draggables object it will > > show there is indeed an element in the drags array. > > > Does anyone have suggestions on how to fix this?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, Took me quite a while to figure out what the issue was, hence the delay in responding. You were right, and I was experiencing the same problem (simply hadn''t tried double-clicking). There is indeed a race condition and it''s caused by the Draggable._dragging[element] being set to false only after the end effect finishes (which never triggers since by then, you''ve already removed the draggable element on which the effect is supposed to occur). Solving it it is actually pretty simple, just specify the following start and end effects in your options hash: starteffect: function(element) { new Effect.Opacity(element, { duration:0.2, from: element.getOpacity(), to:0.7 }); }, endeffect: Prototype.emptyFunction You''ll have the same visual look and feel as before without the double- click issue. Best regards, Tobie On Dec 13, 5:49 pm, emullet <nathan.p...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Thanks for your reply Tobie. I had slightly different code than you. I > was using updateDrag instead of startDrag to jump start the drag. I > also was defining an observer object with an onEnd event handler. I > changed those 2 things to be like your code and I''m still having the > issue, although the element appears opaque now (like it does with the > ghosting effect). > > Currently I have the mousedown handler watching a parent of the > element I want to clone. Which element is your mousedown handler > attached to? > > Here is a code snippet > Event.observe(''root'',''mousedown'',function(event) { > var e = Event.element(event); > if(e.className == ''field'') { > var dupe = e.cloneNode(true); > Position.absolutize(dupe); > $(''gray1Header'').appendChild(dupe); > Position.clone(e,dupe); > dupe.innerHTML = '' some fun html''; > dupe.className = null; > var d = new Draggable(dupe,{ > onEnd: function(drag) { > drag.destroy(); > drag.element.remove(); > } > }); > d.initDrag(event); > d.startDrag(event); > } > }); > > On Dec 13, 2:04 am, Tobie Langel <tobie.lan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > Here''s what I''m using: > > > var draggable = new Draggable(clone, { > > onEnd: function(drag) { > > drag.destroy(); > > drag.element.remove(); > > } > > }); > > draggable.initDrag(event); > > draggable.startDrag(event); > > > Works perfectly in FF and Safari,notyet tested in IE. > > > Let me know whow thigns go. > > > Best, > > > Tobie > > > emullet wrote: > > > So I''m making an element draggable on the fly with a mousedown event > > > handler. I''ve run into a bit of a problem (perhaps a race condition) > > > where if you double click on one of the items quickly enough theonEnd > > > function doesn''t fire and I''m using that to remove the cloned node > > > that was being dragged. > > > > When I get it in this state if I look at the Draggables object it will > > > show there is indeed an element in the drags array. > > > > Does anyone have suggestions on how to fix this?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Tobie, Thank you so much for your help. I added the null endEffect and it worked perfectly. Cheers, Nathan On Dec 16, 8:14 am, Tobie Langel <tobie.lan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > Took me quite a while to figure out what the issue was, hence the > delay in responding. > > You were right, and I was experiencing the same problem (simply hadn''t > tried double-clicking). > > There is indeed a race condition and it''s caused by the > Draggable._dragging[element] being set to false only after the end > effect finishes (which never triggers since by then, you''ve already > removed the draggable element on which the effect is supposed to > occur). > > Solving it it is actually pretty simple, just specify the following > start and end effects in your options hash: > > starteffect: function(element) { > new Effect.Opacity(element, { duration:0.2, from: > element.getOpacity(), to:0.7 }); > }, > endeffect: Prototype.emptyFunction > > You''ll have the same visual look and feel as before without the double- > click issue. > > Best regards, > > Tobie > > On Dec 13, 5:49 pm, emullet <nathan.p...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Thanks for your reply Tobie. I had slightly different code than you. I > > was using updateDrag instead of startDrag to jump start the drag. I > > also was defining an observer object with an onEnd event handler. I > > changed those 2 things to be like your code and I''m still having the > > issue, although the element appears opaque now (like it does with the > > ghosting effect). > > > Currently I have the mousedown handler watching a parent of the > > element I want to clone. Which element is your mousedown handler > > attached to? > > > Here is a code snippet > > Event.observe(''root'',''mousedown'',function(event) { > > var e = Event.element(event); > > if(e.className == ''field'') { > > var dupe = e.cloneNode(true); > > Position.absolutize(dupe); > > $(''gray1Header'').appendChild(dupe); > > Position.clone(e,dupe); > > dupe.innerHTML = '' some fun html''; > > dupe.className = null; > > var d = new Draggable(dupe,{ > > onEnd: function(drag) { > > drag.destroy(); > > drag.element.remove(); > > } > > }); > > d.initDrag(event); > > d.startDrag(event); > > } > > }); > > > On Dec 13, 2:04 am, Tobie Langel <tobie.lan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi, > > > > Here''s what I''m using: > > > > var draggable = new Draggable(clone, { > > > onEnd: function(drag) { > > > drag.destroy(); > > > drag.element.remove(); > > > } > > > }); > > > draggable.initDrag(event); > > > draggable.startDrag(event); > > > > Works perfectly in FF and Safari,notyet tested in IE. > > > > Let me know whow thigns go. > > > > Best, > > > > Tobie > > > > emullet wrote: > > > > So I''m making an element draggable on the fly with a mousedown event > > > > handler. I''ve run into a bit of a problem (perhaps a race condition) > > > > where if you double click on one of the items quickly enough theonEnd > > > > function doesn''t fire and I''m using that to remove the cloned node > > > > that was being dragged. > > > > > When I get it in this state if I look at the Draggables object it will > > > > show there is indeed an element in the drags array. > > > > > Does anyone have suggestions on how to fix this?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---