org.odlabs.wiquery.ui.draggable
Class DraggableBehavior

java.lang.Object
  extended by org.apache.wicket.behavior.Behavior
      extended by org.odlabs.wiquery.core.behavior.WiQueryAbstractBehavior
          extended by org.odlabs.wiquery.ui.draggable.DraggableBehavior
All Implemented Interfaces:
Serializable, org.apache.wicket.IClusterable, org.apache.wicket.IComponentAwareEventSink, org.apache.wicket.markup.html.IComponentAwareHeaderContributor, IWiQueryPlugin

public class DraggableBehavior
extends WiQueryAbstractBehavior

$Id$

Sets the attached component draggable.

Since:
1.0
Author:
Lionel Armanet
See Also:
Serialized Form

Nested Class Summary
static class DraggableBehavior.AxisEnum
          Enumeration for the axis option
static class DraggableBehavior.CursorAtEnum
          Enumeration for the cursorAt option
static class DraggableBehavior.SnapModeEnum
          Enumeration for the snapMode option
 
Field Summary
static String UI_HELPER
          Properties on the ui parameter (use it into callback functions) : the jQuery object representing the helper that's being dragged
static String UI_OFFSET
          Properties on the ui parameter (use it into callback functions) : current absolute position of the helper as { top, left } object, relative to page
static String UI_POSITION
          Properties on the ui parameter (use it into callback functions) : current position of the helper as { top, left } object, relative to the offset element
 
Constructor Summary
DraggableBehavior()
          Default constructor
 
Method Summary
 JsStatement destroy()
          Method to destroy the draggable This will return the element back to its pre-init state.
 void destroy(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to destroy the draggable within the ajax request
 void detach(org.apache.wicket.Component component)
           
 JsStatement disable()
          Method to disable the draggable
 void disable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to disable the draggable within the ajax request
 JsStatement enable()
          Method to enable the draggable
 void enable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to enable the draggable within the ajax request
 String getAppendTo()
           
 DraggableBehavior.AxisEnum getAxis()
           
 String getCancel()
           
 String getConnectToSortable()
           
 DraggableContainment getContainment()
           
 String getCursor()
           
 DraggableBehavior.CursorAtEnum getCursorAt()
          Deprecated. will be changed in 1.2 to return a ListItemOptions
 ListItemOptions<DraggableCursorAt> getCursorAtComplex()
           
 int getDelay()
           
 int getDistance()
           
 ICollectionItemOptions getGrid()
           
 String getHandle()
           
 DraggableHelper getHelper()
           
 DraggableIframeFix getIframeFix()
           
 float getOpacity()
           
protected  Options getOptions()
          Method retrieving the options of the component
 DraggableRevert getRevert()
           
 int getRevertDuration()
           
 String getScope()
           
 int getScrollSensitivity()
           
 int getScrollSpeed()
           
 DraggableSnap getSnap()
           
 DraggableBehavior.SnapModeEnum getSnapMode()
          Returns the snapMode option
 int getSnapTolerance()
           
 String getStack()
           
 int getZIndex()
           
 boolean isAddClasses()
           
 boolean isDisabled()
           
 boolean isRefreshPositions()
           
 boolean isScroll()
           
 String isStack()
          Deprecated. will be removed in 1.2
 void onBind()
          Called when the component was bound to it's host component.
 void renderHead(org.apache.wicket.Component component, org.apache.wicket.markup.html.IHeaderResponse response)
           
 DraggableBehavior setAddClasses(boolean addClasses)
          If set to false, will prevent the ui-draggable class from being added.
 DraggableBehavior setAppendTo(String appendTo)
          The element passed to or selected by the appendTo option will be used as the draggable helper's container during dragging.
 DraggableBehavior setAxis(DraggableBehavior.AxisEnum axis)
          Constrains dragging to either the horizontal (x) or vertical (y) axis.
 DraggableBehavior setCancel(String cancel)
          Set's the prevent selecting if you start on elements matching the selector
 DraggableBehavior setConnectToSortable(String connectToSortable)
          Allows the draggable to be dropped onto the specified sortables.
 DraggableBehavior setContainment(DraggableContainment containment)
          Set's the constrains dragging to within the bounds of the specified element or region.
 DraggableBehavior setCursor(String cursor)
          Set the css cursor during the drag operation.
 DraggableBehavior setCursorAt(DraggableBehavior.CursorAtEnum cusorAt)
          Deprecated. will be removed in 1.2
 DraggableBehavior setCursorAt(ListItemOptions<DraggableCursorAt> cusorAt)
          Moves the dragging helper so the cursor always appears to drag from the same position.
 DraggableBehavior setDelay(int delay)
          Time in milliseconds after mousedown until dragging should start.
 DraggableBehavior setDisabled(boolean disabled)
          Disables (true) or enables (false) the draggable.
 DraggableBehavior setDistance(int distance)
          Set's the distance in pixels after mousedown the mouse must move before dragging should start.
 DraggableBehavior setDragEvent(JsScopeUiEvent drag)
          Set's the callback when the mouse is moved during the dragging
 DraggableBehavior setGrid(int x, int y)
          Snaps the dragging helper to a grid, every x and y pixels.
 DraggableBehavior setHandle(String handle)
          Restricts sort start click to the specified element.
 DraggableBehavior setHelper(DraggableHelper helper)
          Allows for a helper element to be used for dragging display.
 DraggableBehavior setIframeFix(DraggableIframeFix iframeFix)
          Prevent iframes from capturing the mousemove events during a drag.
 DraggableBehavior setOpacity(float opacity)
          Set's the opacity for the helper while being dragged.
 DraggableBehavior setRefreshPositions(boolean refreshPositions)
          If set to true, all droppable positions are calculated on every mousemove.
 DraggableBehavior setRevert(DraggableRevert revert)
          If set to true, the element will return to its start position when dragging stops.
 DraggableBehavior setRevertDuration(int revertDuration)
          Set's the duration of the revert animation, in milliseconds.
 DraggableBehavior setScope(String scope)
          Used to group sets of draggable and droppable items, in addition to droppable's accept option.
 DraggableBehavior setScroll(boolean scroll)
          If set to true, container auto-scrolls while dragging.
 DraggableBehavior setScrollSensitivity(int scrollSensitivity)
          Set's the distance in pixels from the edge of the viewport after which the viewport should scroll.
 DraggableBehavior setScrollSpeed(int scrollSpeed)
          Set's speed at which the window should scroll once the mouse pointer gets within the scrollSensitivity distance.
 DraggableBehavior setSnap(DraggableSnap snap)
          If set to a selector or to true (equivalent to '.ui-draggable'), the draggable will snap to the edges of the selected elements when near an edge of the element.
 DraggableBehavior setSnapMode(DraggableBehavior.SnapModeEnum snapMode)
          Sets the edges of snap elements the draggable will snap to.
 DraggableBehavior setSnapTolerance(int snapTolerance)
          Set's distance in pixels from the snap element edges at which snapping should occur.
 DraggableBehavior setStack(String stack)
          Controls the z-Index of the defined group (key 'group' in the hash, accepts jQuery selector) automatically, always brings to front the dragged item.
 DraggableBehavior setStartEvent(JsScopeUiEvent start)
          Set's the callback when the user starts dragging.
 DraggableBehavior setStopEvent(JsScopeUiEvent stop)
          Set's the callback when the user stops dragging.
 DraggableBehavior setZIndex(int zIndex)
          Set's the starting z-index
 JsStatement statement()
          Returns the main JsStatement used to create the plugin.
 JsStatement widget()
          Method to returns the .ui-draggable element
 void widget(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
          Method to returns the .ui-draggable element within the ajax request
 
Methods inherited from class org.odlabs.wiquery.core.behavior.WiQueryAbstractBehavior
bind, getComponent
 
Methods inherited from class org.apache.wicket.behavior.Behavior
afterRender, beforeRender, canCallListenerInterface, canCallListenerInterface, getStatelessHint, isEnabled, isTemporary, onComponentTag, onConfigure, onEvent, onException, unbind
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UI_HELPER

public static final String UI_HELPER
Properties on the ui parameter (use it into callback functions) : the jQuery object representing the helper that's being dragged

See Also:
Constant Field Values

UI_POSITION

public static final String UI_POSITION
Properties on the ui parameter (use it into callback functions) : current position of the helper as { top, left } object, relative to the offset element

See Also:
Constant Field Values

UI_OFFSET

public static final String UI_OFFSET
Properties on the ui parameter (use it into callback functions) : current absolute position of the helper as { top, left } object, relative to page

See Also:
Constant Field Values
Constructor Detail

DraggableBehavior

public DraggableBehavior()
Default constructor

Method Detail

detach

public void detach(org.apache.wicket.Component component)
Overrides:
detach in class org.apache.wicket.behavior.Behavior

onBind

public void onBind()
Description copied from class: WiQueryAbstractBehavior
Called when the component was bound to it's host component. You can get the bound host component by calling getComponent.

Overrides:
onBind in class WiQueryAbstractBehavior

renderHead

public void renderHead(org.apache.wicket.Component component,
                       org.apache.wicket.markup.html.IHeaderResponse response)
Specified by:
renderHead in interface org.apache.wicket.markup.html.IComponentAwareHeaderContributor
Overrides:
renderHead in class org.apache.wicket.behavior.Behavior

statement

public JsStatement statement()
Description copied from interface: IWiQueryPlugin
Returns the main JsStatement used to create the plugin.

Specified by:
statement in interface IWiQueryPlugin
Specified by:
statement in class WiQueryAbstractBehavior
Returns:
The JsStatement corresponding to this component.

getOptions

protected Options getOptions()
Method retrieving the options of the component

Returns:
the options

setAddClasses

public DraggableBehavior setAddClasses(boolean addClasses)
If set to false, will prevent the ui-draggable class from being added. This may be desired as a performance optimization when calling .draggable() init on many hundreds of elements.

Parameters:
addClasses -
Returns:
instance of the current behavior

isAddClasses

public boolean isAddClasses()
Returns:
the addClasses option

setAppendTo

public DraggableBehavior setAppendTo(String appendTo)
The element passed to or selected by the appendTo option will be used as the draggable helper's container during dragging. By default, the helper is appended to the same container as the draggable.

Parameters:
appendTo -
Returns:
instance of the current behavior

getAppendTo

public String getAppendTo()
Returns:
the appendTo option value

setAxis

public DraggableBehavior setAxis(DraggableBehavior.AxisEnum axis)
Constrains dragging to either the horizontal (x) or vertical (y) axis. Possible values: 'x', 'y'.

Parameters:
axis -
Returns:
instance of the current behavior

getAxis

public DraggableBehavior.AxisEnum getAxis()
Returns:
the axis option value

setCancel

public DraggableBehavior setCancel(String cancel)
Set's the prevent selecting if you start on elements matching the selector

Parameters:
cancel - Selector (default : ':input,option')
Returns:
instance of the current behavior

getCancel

public String getCancel()
Returns:
the cancel option value

setConnectToSortable

public DraggableBehavior setConnectToSortable(String connectToSortable)
Allows the draggable to be dropped onto the specified sortables. If this option is used (helper must be set to 'clone' in order to work flawlessly), a draggable can be dropped onto a sortable list and then becomes part of it.

Parameters:
connectToSortable -
Returns:
instance of the current behavior

getConnectToSortable

public String getConnectToSortable()
Returns:
the connectToSortable option value

setContainment

public DraggableBehavior setContainment(DraggableContainment containment)
Set's the constrains dragging to within the bounds of the specified element or region. Possible string values: 'parent', 'document', 'window', [x1, y1, x2, y2]

Parameters:
containment -
Returns:
instance of the current behavior

getContainment

public DraggableContainment getContainment()
Returns:
the containment option

setCursor

public DraggableBehavior setCursor(String cursor)
Set the css cursor during the drag operation.

Parameters:
cursor -
Returns:
instance of the current behavior

getCursor

public String getCursor()
Returns:
the cursor option value

setCursorAt

@Deprecated
public DraggableBehavior setCursorAt(DraggableBehavior.CursorAtEnum cusorAt)
Deprecated. will be removed in 1.2

Moves the dragging helper so the cursor always appears to drag from the same position. Coordinates can be given as a hash using a combination of one or two keys: { top, left, right, bottom }.

Parameters:
cusorAt -
Returns:
instance of the current behavior

setCursorAt

public DraggableBehavior setCursorAt(ListItemOptions<DraggableCursorAt> cusorAt)
Moves the dragging helper so the cursor always appears to drag from the same position. Coordinates can be given as a hash using a combination of one or two keys: { top, left, right, bottom }.

Parameters:
cusorAt -
Returns:
instance of the current behavior

getCursorAt

@Deprecated
public DraggableBehavior.CursorAtEnum getCursorAt()
Deprecated. will be changed in 1.2 to return a ListItemOptions

Returns:
the cursorAt option value

getCursorAtComplex

public ListItemOptions<DraggableCursorAt> getCursorAtComplex()
Returns:
the cursorAt option value

setDelay

public DraggableBehavior setDelay(int delay)
Time in milliseconds after mousedown until dragging should start. This option can be used to prevent unwanted drags when clicking on an element.

Parameters:
delay -
Returns:
instance of the current behavior

getDelay

public int getDelay()
Returns:
the delay option value

setDisabled

public DraggableBehavior setDisabled(boolean disabled)
Disables (true) or enables (false) the draggable. Can be set when initialising (first creating) the draggable.

Parameters:
disabled -
Returns:
instance of the current behavior

isDisabled

public boolean isDisabled()
Returns:
the disabled option

setDistance

public DraggableBehavior setDistance(int distance)
Set's the distance in pixels after mousedown the mouse must move before dragging should start. This option can be used to prevent unwanted drags when clicking on an element.

Parameters:
distance -
Returns:
instance of the current behavior

getDistance

public int getDistance()
Returns:
the distance option value

setGrid

public DraggableBehavior setGrid(int x,
                                 int y)
Snaps the dragging helper to a grid, every x and y pixels. Array values: [x, y]

Parameters:
x -
y -
Returns:
instance of the current behavior

getGrid

public ICollectionItemOptions getGrid()
Returns:
the grid option value

setHandle

public DraggableBehavior setHandle(String handle)
Restricts sort start click to the specified element.

Parameters:
handle -
Returns:
instance of the current behavior

getHandle

public String getHandle()
Returns:
the handle option value

setHelper

public DraggableBehavior setHelper(DraggableHelper helper)
Allows for a helper element to be used for dragging display. Possible values: 'original', 'clone', Function. If a function is specified, it must return a DOMElement.

Parameters:
helper -
Returns:
instance of the current behavior

getHelper

public DraggableHelper getHelper()
Returns:
the helper option

setIframeFix

public DraggableBehavior setIframeFix(DraggableIframeFix iframeFix)
Prevent iframes from capturing the mousemove events during a drag. Useful in combination with cursorAt, or in any case, if the mouse cursor is not over the helper. If set to true, transparent overlays will be placed over all iframes on the page. If a selector is supplied, the matched iframes will have an overlay placed over them.

Parameters:
iframeFix -
Returns:
instance of the current behavior

getIframeFix

public DraggableIframeFix getIframeFix()
Returns:
the iframeFix option

setOpacity

public DraggableBehavior setOpacity(float opacity)
Set's the opacity for the helper while being dragged.

Parameters:
opacity -
Returns:
instance of the current behavior

getOpacity

public float getOpacity()
Returns:
the opacity option

setRefreshPositions

public DraggableBehavior setRefreshPositions(boolean refreshPositions)
If set to true, all droppable positions are calculated on every mousemove. Caution: This solves issues on highly dynamic pages, but dramatically decreases performance.

Parameters:
refreshPositions -
Returns:
instance of the current behavior

isRefreshPositions

public boolean isRefreshPositions()
Returns:
the refreshPositions option

setRevert

public DraggableBehavior setRevert(DraggableRevert revert)
If set to true, the element will return to its start position when dragging stops. Possible string values: 'valid', 'invalid'. If set to invalid, revert will only occur if the draggable has not been dropped on a droppable. For valid, it's the other way around.

Parameters:
revert -
Returns:
instance of the current behavior

getRevert

public DraggableRevert getRevert()
Returns:
the revert option

setRevertDuration

public DraggableBehavior setRevertDuration(int revertDuration)
Set's the duration of the revert animation, in milliseconds. Ignored if revert is false.

Parameters:
revertDuration -
Returns:
instance of the current behavior

getRevertDuration

public int getRevertDuration()
Returns:
the revertDuration option

setScope

public DraggableBehavior setScope(String scope)
Used to group sets of draggable and droppable items, in addition to droppable's accept option. A draggable with the same scope value as a droppable will be accepted by the droppable.

Parameters:
scope -
Returns:
instance of the current behavior

getScope

public String getScope()
Returns:
the scope option

setScroll

public DraggableBehavior setScroll(boolean scroll)
If set to true, container auto-scrolls while dragging.

Parameters:
scroll -
Returns:
instance of the current behavior

isScroll

public boolean isScroll()
Returns:
the scroll option

setScrollSensitivity

public DraggableBehavior setScrollSensitivity(int scrollSensitivity)
Set's the distance in pixels from the edge of the viewport after which the viewport should scroll. Distance is relative to pointer, not the draggable.

Parameters:
scrollSensitivity -
Returns:
instance of the current behavior

getScrollSensitivity

public int getScrollSensitivity()
Returns:
the scrollSensitivity option

setScrollSpeed

public DraggableBehavior setScrollSpeed(int scrollSpeed)
Set's speed at which the window should scroll once the mouse pointer gets within the scrollSensitivity distance.

Parameters:
scrollSpeed -
Returns:
instance of the current behavior

getScrollSpeed

public int getScrollSpeed()
Returns:
the scrollSpeed option

setSnap

public DraggableBehavior setSnap(DraggableSnap snap)
If set to a selector or to true (equivalent to '.ui-draggable'), the draggable will snap to the edges of the selected elements when near an edge of the element.

Parameters:
snap -
Returns:
instance of the current behavior

getSnap

public DraggableSnap getSnap()
Returns:
the snap option

setSnapMode

public DraggableBehavior setSnapMode(DraggableBehavior.SnapModeEnum snapMode)
Sets the edges of snap elements the draggable will snap to. Ignored if snap is false. Possible values: 'inner', 'outer', 'both'

Parameters:
snapMode -
Returns:
instance of the current behavior

getSnapMode

public DraggableBehavior.SnapModeEnum getSnapMode()
Returns the snapMode option


setSnapTolerance

public DraggableBehavior setSnapTolerance(int snapTolerance)
Set's distance in pixels from the snap element edges at which snapping should occur. Ignored if snap is false.

Parameters:
snapTolerance -
Returns:
instance of the current behavior

getSnapTolerance

public int getSnapTolerance()
Returns:
the snapTolerance option

setStack

public DraggableBehavior setStack(String stack)
Controls the z-Index of the defined group (key 'group' in the hash, accepts jQuery selector) automatically, always brings to front the dragged item. Very useful in things like window managers. Optionally, a 'min' key can be set, so the zIndex cannot go below that value.

Parameters:
stack -
Returns:
instance of the current behavior

getStack

public String getStack()

isStack

@Deprecated
public String isStack()
Deprecated. will be removed in 1.2


setZIndex

public DraggableBehavior setZIndex(int zIndex)
Set's the starting z-index

Parameters:
zIndex -
Returns:
instance of the current behavior

getZIndex

public int getZIndex()
Returns:
the starting z-index

setDragEvent

public DraggableBehavior setDragEvent(JsScopeUiEvent drag)
Set's the callback when the mouse is moved during the dragging

Parameters:
drag -
Returns:
instance of the current behavior

setStartEvent

public DraggableBehavior setStartEvent(JsScopeUiEvent start)
Set's the callback when the user starts dragging.

Parameters:
start -
Returns:
instance of the current behavior

setStopEvent

public DraggableBehavior setStopEvent(JsScopeUiEvent stop)
Set's the callback when the user stops dragging.

Parameters:
stop -
Returns:
instance of the current behavior

destroy

public JsStatement destroy()
Method to destroy the draggable This will return the element back to its pre-init state.

Returns:
the associated JsStatement

destroy

public void destroy(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to destroy the draggable within the ajax request

Parameters:
ajaxRequestTarget -

disable

public JsStatement disable()
Method to disable the draggable

Returns:
the associated JsStatement

disable

public void disable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to disable the draggable within the ajax request

Parameters:
ajaxRequestTarget -

enable

public JsStatement enable()
Method to enable the draggable

Returns:
the associated JsStatement

enable

public void enable(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to enable the draggable within the ajax request

Parameters:
ajaxRequestTarget -

widget

public JsStatement widget()
Method to returns the .ui-draggable element

Returns:
the associated JsStatement

widget

public void widget(org.apache.wicket.ajax.AjaxRequestTarget ajaxRequestTarget)
Method to returns the .ui-draggable element within the ajax request

Parameters:
ajaxRequestTarget -


Copyright © 2012. All Rights Reserved.