[ 9 posts ]

oportell

  • Joined: Thu Mar 03, 2011 10:11 am
  • Posts: 10
  • Offline
  • Profile

Problems combining Drag and Drop and other event listeners..

Post Posted: Wed Oct 19, 2011 9:54 am
+0-
Hello,

I am trying to build a little search engine, where the results of every search are retrieved through an AJAX call and are presented in a pageable list (10 items per page) similar to those of a webmail system.

I want every single result item to be selectable only by clicking on it and, at the same time, draggable to a folder list, in other words, organizable.

In order to make the items selectable, I attach a "click" event listener to every LI element after the paged results are retrieved. (I detect whether the UL parent has the "multi-selectable-list" class and if the LI child element has the "selectable" class, an event is attached.)

And... after that, to make the LI elements draggable, I attach a DD.Delegate to the parent UL element in a different part of the JS/YUI code.

I need those things to happen in two times, because in my application not all selectable items are always draggable, and not all draggable items are always selectable. But this approach gives me a headache:

1) The first problem is the DD.Delegate overrides the select click event listener. How could I detect if an item was only clicked (in order to change its class to "selected") or if it was dragged and droped into a folder?

2) The second problem is... I attach the DD.Delegate to the UL list every time the results are updated. Therefore, when an item is dragged, the listeners are triggered two times after the second update, three times after the third, and so on... Is it possible to detach all the events from the DD.Delegate and then reatach them? I have tried it with detach() and detachAll() but it seems to do nothing on my DD.Delegate dom element.

Any ideas?

Thanks in advance,

- Oriol -

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: Problems combining Drag and Drop and other event listene

Post Posted: Wed Nov 16, 2011 8:43 am
+0-
You can set the haltDown config option to false and DD will not swallow the mousedown event: http://yuilibrary.com/yui/docs/api/clas ... r_haltDown

As for Delegate, it's designed so that you don't need to keep destroying it and recreating it. Since the parent is never destroyed the delegate does not need to be touched. The items underneath the Delegate container can be totally dynamic. Delegate does not attach any events to the children of the container, it listens for them at the container level and then dynamically makes that child draggable. So you can destroy all the children and create new ones (from an XHR request) and Delegate will still work with no changes to it at all.

tejasbhojak

  • Username: tejasbhojak
  • Joined: Mon May 17, 2010 2:14 am
  • Posts: 21
  • IRC: Soul
  • Offline
  • Profile

Re: Problems combining Drag and Drop and other event listene

Post Posted: Wed May 02, 2012 6:59 pm
+0-
I have a similar problem

i have attach click listeners on my drag elements

Code:
var dd = new Y.DD.Drag({
            node : node,
                                haltDown:true
         }).plug(Y.Plugin.DDProxy, {
             moveOnEnd: false,
             cloneNode:true
         }).plug(Y.Plugin.DDConstrained,{
            constrain2node : document.body
         }).plug(Y.Plugin.DDWinScroll);
and then on dd i have all
dd.on('drag:start').... events registered


my problem is when i test on ipad the
click on drag elements doesn't work.
but on safari browser on my desktop it works.

what should i do ?

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile
Tags:

Re: Problems combining Drag and Drop and other event listene

Post Posted: Wed May 02, 2012 7:10 pm
+0-
I haven't tested a 'click' on a 'dd' element on a touch device. This can be a really really messy interaction since a mousedown with a move (on a touch device is pretty easy to do) will mess with your interaction.

My recommendation is to not do that and really look at your interaction to see if clicking on and dragging the same element (without handles) is a good idea.

tejasbhojak

  • Username: tejasbhojak
  • Joined: Mon May 17, 2010 2:14 am
  • Posts: 21
  • IRC: Soul
  • Offline
  • Profile

Re: Problems combining Drag and Drop and other event listene

Post Posted: Thu May 03, 2012 1:36 am
+0-
i need to do many things when my drag elements are touched, apart from drag drop.
why is drag drop utility not bubbling the click event on drag element?
is this a bug ?
any other workarounds ??

Juan Ignacio Dopazo

YUI Contributor

  • Username: jdopazo
  • Joined: Fri Oct 02, 2009 5:39 am
  • Posts: 620
  • Location: Buenos Aires, Argentina
  • Twitter: juandopazo
  • GitHub: juandopazo
  • Gists: juandopazo
  • Offline
  • Profile
Tags:

Re: Problems combining Drag and Drop and other event listene

Post Posted: Thu May 03, 2012 4:51 am
+0-
But clickable and draggable elements are really common. Just look at Windows. You can click an icon and drag it.

Dav Glass

  • Username: davglass
  • Joined: Thu Aug 28, 2008 9:28 am
  • Posts: 2088
  • Location: Marion, IL, US
  • Twitter: davglass
  • GitHub: davglass
  • Gists: davglass
  • IRC: davglass
  • Offline
  • Profile

Re: Problems combining Drag and Drop and other event listene

Post Posted: Thu May 03, 2012 5:17 am
+0-
Like I said, it's likely an iOS thing since it "jacks up the mouseevents into a touch event", then file a repro case. I personally don't think it's a bug when it comes to iOS.

I can see your point on Windows. But look at iOS, to move something (icon for example) you must hold it for a couple of seconds then you are allowed to move it.

Same principle would apply here. They don't want you doing that interaction because it's not "right" for a touch device.

tejasbhojak

  • Username: tejasbhojak
  • Joined: Mon May 17, 2010 2:14 am
  • Posts: 21
  • IRC: Soul
  • Offline
  • Profile

Re: Problems combining Drag and Drop and other event listene

Post Posted: Sun May 06, 2012 8:20 pm
+0-
if i have like 50 drag element in the DOM.
and the DD.Proxy is already instantiated over them
how do i initiate drag:start when user holds over drag element ?
so that touch and drag are two distinct operation.

can u suggest any other way do do touch and drag on hold ?

Prashant Mothukuri

  • Username: prashantm
  • Joined: Wed Jun 27, 2012 3:03 am
  • Posts: 5
  • Offline
  • Profile
Tags:

Re: Problems combining Drag and Drop and other event listene

Post Posted: Wed Jun 27, 2012 3:32 am
+0-
I wanted to do similar functionality so I disabled drag based on thresh pixel. Drag starts only when time thresh is met. I modified dd-drag for this.
  [ 9 posts ]
Display posts from previous:  Sort by  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum