bigyellow
2007-Apr-05 14:18 UTC
Trying to get drag and drop to revert when I want and stay at other times
Here''s the deal. I''m making an ajax-based chess game. It''s done but there''s something I''d like changed. Right now, to move pieces, you click on the piece you want and you click where you want the piece to go. People expect that, but they also expect the ability to simply drag and drop the piece. So I''ve been using the draggables and droppables, but I can''t quite get the affect I want. I want it so that when the draggable (the piece) is dropped on a droppable (a square) my code is run to see if the move is legal. If it''s not, it snaps back to where it was. However, if it''s legal, it should stay where the user put it. That should be nothing more than messing with the "revert" attribute, right? Btw, I haven''t been able to figure out how to dynamically change that property, so I don''t even know how to do that. However, I don''t quite want that. Why? Because when a move is good, I don''t want the piece to just stay where the player put it. I want it to re-center itself on the new square that the user placed it at. So here''s what I tried. I created the draggables with a revert of true. Like I said, I don''t know how to modify this property on the fly. I''m sure it''s easy, but I couldn''t figure it out. Then, if the move is illegal, it just snaps back. If it''s legal, what I was trying to do is clear out the div that holds the piece (in it''s old location) and re-write the div inside the new square with the draggable object. Visually it looks fine until I try and drag the piece again. At the point, I lose the ability to drag it again. It''s as if the piece never had a draggable property attached to it. I''m a little stuck here. Am I going about this wrong? Any advice would be greatly appreciated. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Fabian Lange
2007-Apr-05 14:40 UTC
Re: Trying to get drag and drop to revert when I want and stay at other times
Hi, you most likely are not updating the div with evalScripts = true, so the new draggable javascript coming in for that dropped piece is not executed .: Fabian -----Original Message----- From: grbounce-_Pkz0AUAAAB9-VKt0-RY8LHUELm10l3Y=fabian.lange=web.de@googlegroups.c om [mailto:grbounce-_Pkz0AUAAAB9-VKt0-RY8LHUELm10l3Y=fabian.lange=web.de@google groups.com] On Behalf Of bigyellow Sent: Donnerstag, 5. April 2007 16:19 To: Ruby on Rails: Spinoffs Subject: [Rails-spinoffs] Trying to get drag and drop to revert when I want and stay at other times Here''s the deal. I''m making an ajax-based chess game. It''s done but there''s something I''d like changed. Right now, to move pieces, you click on the piece you want and you click where you want the piece to go. People expect that, but they also expect the ability to simply drag and drop the piece. So I''ve been using the draggables and droppables, but I can''t quite get the affect I want. I want it so that when the draggable (the piece) is dropped on a droppable (a square) my code is run to see if the move is legal. If it''s not, it snaps back to where it was. However, if it''s legal, it should stay where the user put it. That should be nothing more than messing with the "revert" attribute, right? Btw, I haven''t been able to figure out how to dynamically change that property, so I don''t even know how to do that. However, I don''t quite want that. Why? Because when a move is good, I don''t want the piece to just stay where the player put it. I want it to re-center itself on the new square that the user placed it at. So here''s what I tried. I created the draggables with a revert of true. Like I said, I don''t know how to modify this property on the fly. I''m sure it''s easy, but I couldn''t figure it out. Then, if the move is illegal, it just snaps back. If it''s legal, what I was trying to do is clear out the div that holds the piece (in it''s old location) and re-write the div inside the new square with the draggable object. Visually it looks fine until I try and drag the piece again. At the point, I lose the ability to drag it again. It''s as if the piece never had a draggable property attached to it. I''m a little stuck here. Am I going about this wrong? Any advice would be greatly appreciated. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Red
2007-Apr-05 15:14 UTC
Re: Trying to get drag and drop to revert when I want and stay at other times
Ah, didn''t even know evalScripts existed. Thanks Fabian. I''ll try this as soon as I get some work done for my boss! Don''t you hate when programming gets in the way of programming? :-) Armando On 4/5/07, Fabian Lange <Fabian.Lange-S0/GAf8tV78@public.gmane.org> wrote:> > > Hi, > you most likely are not updating the div with evalScripts = true, so the > new > draggable javascript coming in for that dropped piece is not executed > > .: Fabian > > -----Original Message----- > From: > grbounce-_Pkz0AUAAAB9-VKt0-RY8LHUELm10l3Y> fabian.lange=web.de@googlegroups.c > om > [mailto: > grbounce-_Pkz0AUAAAB9-VKt0-RY8LHUELm10l3Y=fabian.lange=web.de@google > groups.com] On Behalf Of bigyellow > Sent: Donnerstag, 5. April 2007 16:19 > To: Ruby on Rails: Spinoffs > Subject: [Rails-spinoffs] Trying to get drag and drop to revert when I > want > and stay at other times > > > Here''s the deal. I''m making an ajax-based chess game. It''s done but > there''s something I''d like changed. Right now, to move pieces, you > click on the piece you want and you click where you want the piece to > go. People expect that, but they also expect the ability to simply > drag and drop the piece. So I''ve been using the draggables and > droppables, but I can''t quite get the affect I want. I want it so that > when the draggable (the piece) is dropped on a droppable (a square) my > code is run to see if the move is legal. If it''s not, it snaps back to > where it was. However, if it''s legal, it should stay where the user > put it. That should be nothing more than messing with the "revert" > attribute, right? Btw, I haven''t been able to figure out how to > dynamically change that property, so I don''t even know how to do that. > > However, I don''t quite want that. Why? Because when a move is good, I > don''t want the piece to just stay where the player put it. I want it > to re-center itself on the new square that the user placed it at. So > here''s what I tried. > > I created the draggables with a revert of true. Like I said, I don''t > know how to modify this property on the fly. I''m sure it''s easy, but I > couldn''t figure it out. Then, if the move is illegal, it just snaps > back. If it''s legal, what I was trying to do is clear out the div that > holds the piece (in it''s old location) and re-write the div inside the > new square with the draggable object. Visually it looks fine until I > try and drag the piece again. At the point, I lose the ability to drag > it again. It''s as if the piece never had a draggable property attached > to it. > > I''m a little stuck here. Am I going about this wrong? Any advice would > be greatly appreciated. > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Red
2007-Apr-06 14:30 UTC
Re: Trying to get drag and drop to revert when I want and stay at other times
Hmmmm...evalscripts didn''t work for me. Let me post some code to show you what I''m doing ======================================================================<script language="JavaScript"> var drag_a1 = null; function doStuff() { drag_a1 = new Draggable(''piece_a1'', {revert:true}); Droppables.add(''kfed'', { accept: ''piece_a1'', hoverclass: ''armie'', onDrop: function(element) { alert("Hello there! " + document.getElementById (''tookie'').innerHTML); document.getElementById(''kfed'').innerHTML document.getElementById(''tookie'').innerHTML; document.getElementById(''kfed'').evalScripts(); document.getElementById(''tookie'').innerHTML " "; } }); } </script> </head> <body onload="doStuff()"> <div id="tookie"> <img src="piece.gif" border="0" class="piece_a1" id="piece_a1" style="z-index:2; "></div> <div id="kfed" style="width:200px; height:200px; z-index:1; background: #cccccc"> </div> ====================================================================== So I have revert set to true. When the piece is dragged over div "kfed" (clearly I was bored with the naming of stuff!) the onDrop function is called. I try and take the image out of the tookie div and put it in the kfed div. Again, I''m doing all of this so that the piece gets recentered in the new location and doesn''t just sit where the player put it. What happens now is that a second piece is also placed in the div. One is not draggable and the other is. However, when I try and drag the one that is, it immediately jumps to it''s original location. I''ll keep playing with this to figure out a way to do it, but if anyone has any advice, I''d be greatly appreciative. On 4/5/07, Red <redlocyellow-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Ah, didn''t even know evalScripts existed. Thanks Fabian. I''ll try this as > soon as I get some work done for my boss! Don''t you hate when programming > gets in the way of programming? :-) > > Armando > > On 4/5/07, Fabian Lange <Fabian.Lange-S0/GAf8tV78@public.gmane.org> wrote: > > > > > > Hi, > > you most likely are not updating the div with evalScripts = true, so the > > new > > draggable javascript coming in for that dropped piece is not executed > > > > .: Fabian > > > > -----Original Message----- > > From: > > grbounce-_Pkz0AUAAAB9-VKt0-RY8LHUELm10l3Y> > fabian.lange=web.de@googlegroups.c > > om > > [mailto:grbounce-_Pkz0AUAAAB9-VKt0-RY8LHUELm10l3Y=fabian.lange=web.de@google > > groups.com] On Behalf Of bigyellow > > Sent: Donnerstag, 5. April 2007 16:19 > > To: Ruby on Rails: Spinoffs > > Subject: [Rails-spinoffs] Trying to get drag and drop to revert when I > > want > > and stay at other times > > > > > > Here''s the deal. I''m making an ajax-based chess game. It''s done but > > there''s something I''d like changed. Right now, to move pieces, you > > click on the piece you want and you click where you want the piece to > > go. People expect that, but they also expect the ability to simply > > drag and drop the piece. So I''ve been using the draggables and > > droppables, but I can''t quite get the affect I want. I want it so that > > when the draggable (the piece) is dropped on a droppable (a square) my > > code is run to see if the move is legal. If it''s not, it snaps back to > > where it was. However, if it''s legal, it should stay where the user > > put it. That should be nothing more than messing with the "revert" > > attribute, right? Btw, I haven''t been able to figure out how to > > dynamically change that property, so I don''t even know how to do that. > > > > However, I don''t quite want that. Why? Because when a move is good, I > > don''t want the piece to just stay where the player put it. I want it > > to re-center itself on the new square that the user placed it at. So > > here''s what I tried. > > > > I created the draggables with a revert of true. Like I said, I don''t > > know how to modify this property on the fly. I''m sure it''s easy, but I > > couldn''t figure it out. Then, if the move is illegal, it just snaps > > back. If it''s legal, what I was trying to do is clear out the div that > > holds the piece (in it''s old location) and re-write the div inside the > > new square with the draggable object. Visually it looks fine until I > > try and drag the piece again. At the point, I lose the ability to drag > > it again. It''s as if the piece never had a draggable property attached > > to it. > > > > I''m a little stuck here. Am I going about this wrong? Any advice would > > be greatly appreciated. > > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---