Jump to content
GreenSock

FAKS

Draggable - How to check if Object is disable or not

Recommended Posts

Hello,

 

I am using your amazing Draggable classes to drag and drop divs and I'm looking for a way to detect if a draggable object is enabled or not...

 

This is my list of draggables divs:

var DraggableList = Draggable.create(myDivsArray, { type:"xy"});

After some user actions, I need to disable divs, so I use:

DraggableList[divIndex].disable();

But how can I check if a div is enabled or not?

// Something like that for example:
if(DraggableList[divIndex].enabled){
    // this div is enabled for the drag...
}else{
    // this div is NOT enabled for the drag...
}

I checked the Draggable object and I didn't se any "enabled" properties...

Do you know if there is way to check the state of a Draggable div?

 

If there isn't, it could be great to add this feature to the Draggable object.

Thanks!

 

Link to comment
Share on other sites

I'm sure Jack or Carl could answer this question fully.. but after inspecting the Draggable.create() variable outputted to the console.. I saw that:

 

When Draggable is disabled:

 

_eventTarget.onselectstart is null

 

When Draggable is enabled:

 

_eventTarget.onselectstart is function()

 

So if you console out your Draggable.create variable you should be able to see when _eventTarget.onselectstart is null .. like this:

// if enabled _eventTarget.onselectstart is a function()
// if disabled _eventTarget.onselectstart is null
console.log(DraggableList[divIndex]._eventTarget.onselectstart);

if(DraggableList[divIndex]._eventTarget.onselectstart !== null){
    // this div is enabled for the drag...
}else{
    // this div is NOT enabled for the drag...
}

Again .. Jack and Carl would be able to help better than I..

 

but see if that helps? :)

  • Like 2
Link to comment
Share on other sites

Thank you Jonathan.

 

You right, I tried, your solution could do the trick :)

If there is no other way to check the state of a draggable div, I will do like this.

 

Have a good day!

Link to comment
Share on other sites

There isn't currently a way to check that, but I'll add an enabled() function to the next release so that you can check it (or set it). That should end up taking the place of both enable() and disable() methods anyway. Thanks for asking about this. 

  • Like 4
Link to comment
Share on other sites

Nice!

Thank you Jack, you and your team did an amazing work :) Bravo!

  • Like 1
Link to comment
Share on other sites

  • 6 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×