On 2/27/06, Robin Haswell <rob-gyMb1R/nBgNh8AIihN9Rc9BPR1lH4CV8@public.gmane.org> wrote:> I have an interesting problem - I have some draggable elements (sortable > actually), with links (<A>) inside them. I want the user to be able to > click on the link, however if the user drags the element I don''t want > the link to get fired. Can anyone think of a way to do this? It only > needs to work in Firefox.In the past when this issue has come up, the common wisdom has been to use a drag handle; it''s an option to Draggable. Todd
Hey guys I have an interesting problem - I have some draggable elements (sortable actually), with links (<A>) inside them. I want the user to be able to click on the link, however if the user drags the element I don''t want the link to get fired. Can anyone think of a way to do this? It only needs to work in Firefox. Cheers -Rob
Yeah I''m aware of this option. It''s not ideal, as this is a CMS and I don''t want the admin view of the site to be too different. Plus these elements are really small. I''d rather get a proper solution rather than a hack :-/ -Rob Todd Ross wrote:> On 2/27/06, Robin Haswell <rob-gyMb1R/nBgNh8AIihN9Rc9BPR1lH4CV8@public.gmane.org> wrote: > >>I have an interesting problem - I have some draggable elements (sortable >>actually), with links (<A>) inside them. I want the user to be able to >>click on the link, however if the user drags the element I don''t want >>the link to get fired. Can anyone think of a way to do this? It only >>needs to work in Firefox. > > > In the past when this issue has come up, the common wisdom has been to > use a drag handle; it''s an option to Draggable. > > Todd > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
* Robin Haswell wrote (27/02/06 12:12):> Yeah I''m aware of this option. It''s not ideal, as this is a CMS and I > don''t want the admin view of the site to be too different. Plus these > elements are really small. I''d rather get a proper solution rather than > a hack :-/Draggables have onStart and onEnd events. You could use these to change the onClick event for the <a> tag to a null event when the draggable is being dragged, and back again when it stops, maybe. I don''t know whether this will work, because I use handles myself. Chris
Assign an event handler to the links that stops event propagation (a.k.a "bubbling"). - David Am 27.02.2006 um 12:58 schrieb Robin Haswell:> Hey guys > > I have an interesting problem - I have some draggable elements > (sortable > actually), with links (<A>) inside them. I want the user to be able to > click on the link, however if the user drags the element I don''t want > the link to get fired. Can anyone think of a way to do this? It only > needs to work in Firefox. > > Cheers > > -Rob > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
I think this would work, I can set the onclick to evaluate a false function, this is my stanrd method of doing things like this. Strangely I don''t think the event.observe(el, "click") method works for this. Cheers -Rob Chris Lear wrote:> * Robin Haswell wrote (27/02/06 12:12): > >> Yeah I''m aware of this option. It''s not ideal, as this is a CMS and I >> don''t want the admin view of the site to be too different. Plus these >> elements are really small. I''d rather get a proper solution rather than >> a hack :-/ >> > > Draggables have onStart and onEnd events. You could use these to change > the onClick event for the <a> tag to a null event when the draggable is > being dragged, and back again when it stops, maybe. I don''t know whether > this will work, because I use handles myself. > > Chris > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 2/27/06, Robin Haswell <rob-gyMb1R/nBgNh8AIihN9Rc9BPR1lH4CV8@public.gmane.org> wrote:> I think this would work, I can set the onclick to evaluate a false > function, this is my stanrd method of doing things like this. Strangely I > don''t think the event.observe(el, "click") method works for this.When binding an event handler via DOM2 methods, the return value of the functions does not matter. You stop the propagation by other means, abstracted to Event.stop(event_object) in prototype.js Bye, Martin
> When binding an event handler via DOM2 methods, the return value of > the functions does not matter. You stop the propagation by other > means, abstracted to Event.stop(event_object) in prototype.js > > Bye, > MartinThe main problem is that Event.stop stops the onclick event, but it does not stop the link from firing (at least, in my experience). Use the ''handle'' option to have another item be the actual draggable part (SPAN is great for this). Greg
This might be a bit complicated to implement, but I think I have an idea that will help. For your links, instead of setting up click handlers, use mousedown and mouseup handlers. When the initial mousedown event comes in, set some flag ("timerActive" for instance) to true and start a timer (pick some smallish number of milliseconds, like 50 or so). When the timer expires, toggle the flag back to false. If the mouseup event comes in while the timer flag is still true, treat it as a click and navigate... If, however, the timer expires and the flag is false when the mouseup comes in, then assume a drag was done, and don''t do anything with the link. You can probably extend the theory to be more complicated. For instance if you click and hold down the mouse, but don''t actually move the mouse at all, then still treat it as a click since no dragging was done...etc.. But the basic idea just might do the trick. -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Gregory Hill Sent: Monday, February 27, 2006 5:10 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] Disabling anchor clicking in a draggable> When binding an event handler via DOM2 methods, the return value of > the functions does not matter. You stop the propagation by other > means, abstracted to Event.stop(event_object) in prototype.js > > Bye, > MartinThe main problem is that Event.stop stops the onclick event, but it does not stop the link from firing (at least, in my experience). Use the ''handle'' option to have another item be the actual draggable part (SPAN is great for this). Greg _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
> The main problem is that Event.stop stops the onclick event, but it does > not stop the link from firingIt sure does. Must be something else in your code. I disable Links on form edit like (excerpt) Event.observe(document.body, "click", noAction.bindAsEventListener(this)); noAction: function(ev){ var el = Event.findElement(ev, "a"); if (!isUndefined(el.tagName) && el.tagName.toUpperCase() == "A" && Element.hasClassName(el, this.disabledClass)) Event.stop(ev); }
> I disable Links on form edit like (excerpt) > > Event.observe(document.body, "click",noAction.bindAsEventListener(this));> > noAction: function(ev){ > var el = Event.findElement(ev, "a"); > if (!isUndefined(el.tagName) && el.tagName.toUpperCase()=> "A" &&> Element.hasClassName(el, this.disabledClass)) > Event.stop(ev); > }Hmm... that''s an interesting approach. Does that work on all browsers? The case I was doing was attaching the event to the anchor element itself, and Event.stop did not prevent the actual link from firing, although that may have only been in certain browsers. I can''t remember for sure; I just changed my design and moved on. Greg
On 2/28/06, Gregory Hill <Gregory_Hill-l9nu40+TWxQ@public.gmane.org> wrote:> Hmm... that''s an interesting approach. Does that work on all browsers?Now that you say it: preventDefault() is broken in Safari. It has been fixed in the nightly builds. But Safari crashes on the app I am building anyway (to heavy on DOM manipulation it seams), so it is of no concern for me for the time being. And Safari messes up with styling form controls. I like them to stay in the system look, and something triggers a "plain" rendering some times :-(