Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery UI Draggable - How to know an element is draggable initialized?

My logic is

if( !this.draginited() ) // a drag-disabled element shouldn't get pass here, as it is inited
  this.draggable({...})

I searched a lot and couldn't find a way to implement this logic, any ideas?

like image 440
Edward Avatar asked Apr 06 '10 13:04

Edward


People also ask

How does jQuery ui draggable work?

jQueryUI provides draggable() method to make any DOM element draggable. Once the element is draggable, you can move that element by clicking on it with the mouse and dragging it anywhere within the viewport.

What is the syntax of the draggable function?

Syntax: $(selector, context). draggable ("action", [params]);

Why is draggable not working?

Check whether your draggable object is already loaded in the viewport. If it is not, it won't work properly. JUST AFTER the draggable object to be absolutely sure that everything is loaded at the correct time.

How do you make something draggable in jQuery?

Using jQuery UI, we can make the DOM(Document Object Model) elements to drag anywhere within the view port. This can be done by clicking on the draggable object by mouse and dragging it anywhere within the view port. If the value of this option is set to false, it will prevent the DOM elements to be dragged .


1 Answers

Maybe there's an easier way, but the docs say:

Draggable elements gets a class of ui-draggable

so you could do something like:

if(!$("#foo").hasClass("ui-draggable")) {
    ...
}

so to wrap that up (untested):

$.fn.isDraggable = function() {
    return $(this).hasClass("ui-draggable");
}

console.log($("#someElement").isDraggable());
like image 192
karim79 Avatar answered Nov 14 '22 23:11

karim79