Hi all, Is it possible to use Prototype to add control-click behaviour to a link? What I want is to fire one Ajax request if a user clicks on a box, and a different request if they control-click on the same box. I know this is possible in some JS frameworks (e.g. Mootools), but unfortunately I''m limited to Prototype - does anyone know how to do this? Many thanks, Adam --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> unfortunately I''m limited to PrototypeGosh, you *are* a sweet-talker. ;-) Google "javascript control key". Just about all modern browsers support the "ctrlKey", "shiftKey", and "altKey" properties on the click event, and just about all but IE support "metaKey" as well. So if you observe your link: $(''linkGo'').observe(''click'', clickHandler); ...you can tell whether a modifier key was down: function clickHandler(evt) { alert( "Control: " + evt.ctrlKey + "\n" + "Shift: " + evt.shiftKey + "\n" + "Alt: " + evt.altKey + "\n" + "Meta: " + evt.metaKey); evt.stop(); } Stopping the event prevents the default action from happening. -- T.J. Crowder tj / crowder software / com On Jun 9, 9:41 am, Adam <adampennycu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > Is it possible to use Prototype to add control-click behaviour to a > link? What I want is to fire one Ajax request if a user clicks on a > box, and a different request if they control-click on the same box. I > know this is possible in some JS frameworks (e.g. Mootools), but > unfortunately I''m limited to Prototype - does anyone know how to do > this? > > Many thanks, > Adam--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > unfortunately I''m limited to PrototypeHehe, sorry about that, that didn''t come out quite how I meant it! That solution was exactly what I was looking for. Thanks for your help, I take back all criticism of Prototype :) On 9 Jun, 10:10, "T.J. Crowder" <tjcrow...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > unfortunately I''m limited to Prototype > > Gosh, you *are* a sweet-talker. ;-) > > Google "javascript control key". Just about all modern browsers > support the "ctrlKey", "shiftKey", and "altKey" properties on the > click event, and just about all but IE support "metaKey" as well. So > if you observe your link: > > $(''linkGo'').observe(''click'', clickHandler); > > ...you can tell whether a modifier key was down: > > function clickHandler(evt) > { > alert( > "Control: " + evt.ctrlKey + "\n" + > "Shift: " + evt.shiftKey + "\n" + > "Alt: " + evt.altKey + "\n" + > "Meta: " + evt.metaKey); > evt.stop(); > > } > > Stopping the event prevents the default action from happening. > -- > T.J. Crowder > tj / crowder software / com > > On Jun 9, 9:41 am, Adam <adampennycu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi all, > > > Is it possible to use Prototype to add control-click behaviour to a > > link? What I want is to fire one Ajax request if a user clicks on a > > box, and a different request if they control-click on the same box. I > > know this is possible in some JS frameworks (e.g. Mootools), but > > unfortunately I''m limited to Prototype - does anyone know how to do > > this? > > > Many thanks, > > Adam--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Well that''s just plain JavaScript; though I think Prototype does add some value by defining mnemonic constants for various keys and SHIFT/CTRL/ALT on the Event object. -Fred On Mon, Jun 9, 2008 at 5:05 AM, Adam <adampennycuick-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > unfortunately I''m limited to Prototype > > Hehe, sorry about that, that didn''t come out quite how I meant it! > > That solution was exactly what I was looking for. Thanks for your > help, I take back all criticism of Prototype :)-- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---