View
 

Draggable

Page history last edited by Richard D. Worth 1 yr ago

 

type: interaction

release: 1.0

priority: -

status: complete

documentation: http://docs.jquery.com/UI/Draggable

demo: http://jqueryui.com/demos/draggable

 


 

1 - Description:

 

A draggable is behaviour that you can assign to any element. The element can then be repositioned using the mouse, and when used with the Droppable component, dropped on a specific target. The visual and logical behaviour is highly configurable and comes with all kinds of different options.

 


 

2 - Visual Design:

 

N/A

 


 

 

3 - Functional Specifications/Requirements:

 

Options/Methods/Callbacks

  • options:
    • addClasses (Boolean | default: true)
    • appendTo (Element, Selector | default: 'parent')
    • axis (String | default: false)
      • Possibe string values: 'x', 'y'
    • cancel (Selector | default: ':input,option')
    • connectToSortable (Selector | default: false)
    • containment (Selector, Element, String, Array | default: false)
      • Possible string values: 'parent', 'document', 'window'
      • Array values: [x1, y1, x2, y2]
    • cursor (string | default: 'auto')
    • cursorAt (Object | default: false)
      • Object properties: { top, left, right, bottom }
    • delay (Integer | default: 0)
    • distance (Integer | default: 1)
    • grid (Array | default: false)
      • Array values: [x, y]
    • handle (Element, Selector | default: false)
    • helper (String, Function | default: 'original')
      • Possible string values: 'original', 'clone'
      • Function return type: DOMElement
    • iframeFix (Boolean, Selector | default: false)
    • opacity (Float | default: false)
    • refreshPositions (Boolean | default: false)
    • revert (Boolean, String | default: false)
      • Possible string values: 'valid', 'invalid'
    • revertDuration (Integer | default: 500)
    • scope (String | default: 'default')
    • scroll (Boolean | default: true)
    • scrollSensitivity (Integer | default: 20)
    • scrollSpeed (Integer | default: 20)
    • snap (Boolean, Object | default: false)
      • Object properties: { items: Selector, snap: Function, release: Function }
    • snapMode (String | default: 'both')
      • Possible string values: 'outer', 'inner', 'both'
    • snapTolerance (Integer | default: 20)
    • stack (Object | default: false)
      • Object properties: { group: Selector, min: Integer }
    • zIndex (Integer | default: false)
  • methods:
    • (none)
  • callbacks:
    • start (events: mousedown)
    • drag (events: mousemove)
    • stop (events: mouseup)

 

Specifications

  • if the helper is set to 'original', the dragged element must not have position 'static'
  • the mousedown is automatically cancelled (like the cancel option) on resizable handles (.ui-resizable-handle) to not conflict
  • the helper is only appended to options.appendTo if it's not already in the DOM
  • draggable supports relative, fixed and static positioning. 'absolute' is the default, special implementations for the others. 'relative' substracts the current relative position from the result, 'fixed' substracts unwanted scroll offsets
  • on mousedown, the draggable needs to know if it was dropped on a valid target and therefore checks back with droppables/sortables. It's then used for the revert 'invalid/valid' options for instance.
  • start callback: triggers when movement starts via mouse(mousedown).
  • drag callback: triggers during movement via mouse(drag/mousemove).
  • stop callback: triggers when movement stops via mouse(mouseup). Fires after normalization and reverting has happened.

 


 

4 - Markup & Style:

 

     4.1 Initial markup examples

 

     (not applicable)

 

     4.2 Recommended transformed HTML markup

 

     (not applicable)

 

     4.3 Accessibility recommendation

 

    (Detailed recommendations for ARIA, HTML markup, CSS and javascript that will contribute to universal access and full section 508 accessibility for screen readers, mobile devices and any other devices) 

 

     4.4 CSS & Theme

 

    (not applicable) 

 


 

5 - Latest version of plugin:

 

http://jquery-ui.googlecode.com/svn/trunk/ui/ui.draggable.js

 


 

6 - Open issues being discussed

 

(Use this area to place things that we're hashing out like featuresand options we're not sure we should include, questions about how this fits into UI and relates to other widgets and utilities, known problems, whether features should be broken across multiple releases, etc.)

 


 

 

 

 

Comments (2)

profile picture

Richard D. Worth said

at 7:27 am on Jan 29, 2009

I wonder if it might make sense to remove the greedy option in 1.7. Now that we have custom events bubbling (in jQuery 1.3), couldn't we leave it up to a drop callback whether to return false or stop propagation?

profile picture

Carsten Klein said

at 8:41 am on Aug 12, 2009


Just reading through the code and found the following special case test in _mouseCapture

[...]
if (this.helper || o.disabled || $(event.target).is('.ui-resizable-handle'))
return false;

Would'nt it be nicer and even more future safe to test for '.ui-do-not-drag' or something similar instead of explicitly testing for '.ui-resizable-handle'?
I mean, there are plenty of use cases for future plugins and other, similar things, that would make it necessary for the draggable plugin to special case
on _mouseCapture.

Having said this, the resizable plugin now would assign the class .ui-do-not-drag to its handles, in order to make it compatible with the draggable
plugin. That way around, future other plugins could reuse the same behaviour instead of the draggable plugin having to be changed once again in
order to support the other plugins.

Besides that, in the same method, there is

//Quit if we're not on a valid handle
this.handle = this._getHandle(event);
if (!this.handle)
return false;

return true;

The latter could be rewritten so, since _getHandle is actually a _getIsValidHandle.

return this._getIsValidHandle

Yielding a new _mouseCapture method

_mouseCapture: function(event) {

if (this.helper || this.options.disabled || $(event.target).is('.ui-do-not-drag'))
return false;

//Quit if we're not on a valid handle
return this._isValidHandle();
},

_getHandle would then be renamed to _isValidHandle since it expresses the exact nature of the method more explicitly as it does only return boolean value.
_getHandle for me implies that it actually returns a drag handle of some sort.

You don't have permission to comment on this page.