How difficult would it be to get the x and y coordinates returned of a draggable? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Frank, frank a écrit :> How difficult would it be to get the x and y coordinates returned of a > draggable?''depends on the coordinates system you''d like to use. The snap callback function gets the current X/Y as arguments #1 and #2. Even if you *don''t* intend to snap, you can get those this way (don''t forget to return a [X,Y] array anyway). ''HTH -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Christophe, Thanks for the reply. If I have new Draggable(''dragme'', {revert:false,snap:function(x,y){ return [x,y]}}) defining the draggable, how would I actually recieve the coordinates? What would be the name of the array that contains the values? ...or is the above incorrect... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Frank, frank a écrit :> new Draggable(''dragme'', {revert:false,snap:function(x,y){ return > [x,y]}}) > > defining the draggable, how would I actually recieve the coordinates? > What would be the name of the array that contains the values? ...or is > the above incorrect...I don''t get where you have a problem: your snap function GETS the coordinates, from its two arguments. What more do you need? -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
How would I actually access the values? Let''s say I want to display the coordinates. Something like var text = ''the value of x is '' + x + '' and the the value of y is '' + y; document.write(text); is clearly wrong... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey, frank a écrit :> How would I actually access the values? Let''s say I want to display the > coordinates. Something like > > var text = ''the value of x is '' + x + '' and the the value of y is '' + > y; > document.write(text);Well yes, document.write is clearly wrong :-) It''s something you do very seldom, and then only at page creation time. But you could use some element somewhere and its extended update function, or if you''re using Firebug, the console.log call. Fromwithin your snap function, you DO have access to x and y, which are provided as your two arguments. -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I''ve tried running an Ajax.Updater with the coordinates being some variables that are sent, but that doesn''t appear to be working. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Something like this doesn''t appear to work either... new Draggable(''app'', {revert:false,snap:function(x,y){ return [x,y]},onChange:updateCoords}) function updateCoords() { var options = { parameters : ''x='' + x + ''&y='' + y }; new Ajax.Request(''testing.php'', options );} --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
function updateCoords(x, y) { ... } Note the x and y in the param list. You have to declare your function such that it expects to receive 2 parameters. On 10/28/06, frank <FrankWitt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Something like this doesn''t appear to work either... > > new Draggable(''app'', {revert:false,snap:function(x,y){ return > [x,y]},onChange:updateCoords}) > > function updateCoords() { var options = { parameters : ''x='' + x + ''&y='' > + y }; new Ajax.Request(''testing.php'', options );} > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the reply. Unfortunately, that doesn''t seem to work. I just tried having this: <input type="button" value="click" onclick="updateCoords(''1'',''2'');" /> activate the function independantly of the draggable, and that doesn''t work either. Looks like the error could be lying elsewhere. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Never mind, I got the button activation to work. I''m yet to be successfull at getting any coordinates. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
After about an hour of messing around, this is as close as I''ve gotten: new Draggable(''app'', {revert:false,snap:function(x,y){ return [x,y]},onDrag:function updateCoords(x,y) { var options = { parameters : ''x='' + x + ''&y='' + y}; new Ajax.Request(''testing.php'', options );} }) So far x has a value of [object Object] and y has a value of [object MouseEvent]. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hey Frank, frank a écrit :> After about an hour of messing around, this is as close as I''ve gotten:Why don''t you try and read the source, before trying every possible combination and relying on guesswork? You''re squandering your time!> new Draggable(''app'', {revert:false,snap:function(x,y){ return > [x,y]},onDrag:function updateCoords(x,y) { var options = { parameters : > ''x='' + x + ''&y='' + y}; new Ajax.Request(''testing.php'', options );} }) > > So far x has a value of [object Object] and y has a value of [object > MouseEvent].Of course it has: the first element is the draggable object, the second is the event. onDrag is not for such a use. Depending on the kind of coordinates you''re looking for, the MouseEvent object may provide it though. Look at: http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-MouseEvent The snap function does receive x and y as its first arguments, so you might handle your stuff in it: new Draggable(''app'', { revert: false, snap: function(x, y) { // Whatever handling you want of X and Y here... return [x, y]; } }); HOWEVER, let me advise against the whole thing you''re trying, namely, doing on Ajax call per event: that could amount to tens of calls per second, which makes no sense whatsoever from an ergonomical standpoint, and would most certainly saturate the browser! What functionality are you attempting to create here? What''s the bigger picture? -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Christophe, What I''m trying to do is to remember the position of a draggable. After dragging something and clicking a button, I would want the coordinates of the draggable stored in a database. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey again Frank (boy aren''t we pretty pen-pals)! frank a écrit :> What I''m trying to do is to remember the position of a draggable. After > dragging something and clicking a button, I would want the coordinates > of the draggable stored in a database.OK. Don''t do that on the fly. Do that after the drag. There is a onEnd callback option, whose second argument is the draggable (therefore, arg2.element is your dragged element). You could get its position for your purposes using Prototype''s Position namespace (as for the exact method within Position, you''ll have to try them, I''m no expert. Maybe Thomas will chime in on this, he''s the expert). Something like: new Draggable(..., { ..., onEnd: function(foo, draggable) { Position.prepare(); var pos = Position.theProperFunction(draggable.element); new Ajax.Request(..., { method: ''post'', parameters: ''x='' + pos[0] + ''&y='' + pos[1] }); }}); The proper function for your needs might be page, cumulativeOffset, or realOffset... I just don''t know! I still have to figure out that stuff. Just give it a try. ''HTH -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Christophe, Is this what it should look like? The problem is that the draggable can''t be dropped...it always stays with the mouse. I''ve tried both cumulativeOffset and realOffset. new Draggable(''app'', { snap:function(x,y){ return [x,y]}, onEnd: function(foo, draggable) { Position.prepare(); var pos = Position.realOffset(draggable.element); new Ajax.Request(''testing.php'', { method: ''post'', parameters: ''x='' + pos[0] + ''&y='' + pos[1] }); }}); --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
frank a écrit :> Is this what it should look like? The problem is that the draggable > can''t be dropped...it always stays with the mouse. I''ve tried both > cumulativeOffset and realOffset.Hmmm... You mean, releasing the mouse button doesn''t stop the move? That''s odd. I see nothing in the source code that hints at this (at least from cursory perusal).> new Draggable(''app'', { snap:function(x,y){ return [x,y]}, onEnd: > function(foo, draggable) {BTW, sorry about that, there''s no need for the first ignored argument: the first argument will *indeed* be the draggable. My mistake.> Position.prepare(); > var pos = Position.realOffset(draggable.element); > new Ajax.Request(''testing.php'', { method: ''post'', > parameters: ''x='' + pos[0] + ''&y='' + pos[1] });''sounds like it (although I can''t vouch for realOffset. And GET RID of this useless snap function (it duplicates its default behavior). Still, removing the erroneous first argument of onEnd will help. -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---