ducksboard / gridster.js

gridster.js is a jQuery plugin that makes building intuitive draggable layouts from elements spanning multiple columns
http://gridster.net/
MIT License
6.03k stars 1.2k forks source link

check for descendants of drag-handle #334

Closed hrosenbauer closed 10 years ago

hrosenbauer commented 10 years ago

(this is a updated version of my old pull-request at https://github.com/ducksboard/gridster.js/pull/326) Function ignore_drag checks if event.target is a descendant of or the handle itself. This allows the handle to have child elements and dragging still works. See http://jsbin.com/fuwunuyi/2 for a demo scenario: I added a span inside the header and now the widgets can't be dragged.

jmealo commented 10 years ago

I would like to see this merged. :+1:

I'd also like to be able to pass in a function to determine the drag handle and resize handle.

hrosenbauer commented 10 years ago

This was fixed by allowing a custom ignore_dragging function. Example:

ignore_dragging: function (event) {
    var $handle = $(event.target);

    // ignore special elements
    if ($handle.is('INPUT, TEXTAREA, SELECT, BUTTON')) {
        return true;
    }
    // ignore all elements that are inside the .handle element
    // (which is in my case the drag-handle)
    return !$handle.closest('.handle').length;
}