dijit/tree/dndSource (version 1.10)

dijit/tree/_dndSelector

Summary

Handles drag and drop operations (as a source or a target) for dijit.Tree

Usage

var foo = new dndSource(tree,params);
dijit/tree/dndSource
Parameter Type Description
tree dijit/Tree
params dijit/tree/dndSource

See the dijit/tree/dndSource reference documentation for more information.

Property Summary

  • __ItemNew item to be added to the Tree, like:
  • acceptList of accepted types (text strings) for the Tree; defaults to ["text"]
  • betweenThresholdDistance from upper/lower edge of node to allow drop to reorder nodes
  • copyOnlyCopy items, if true, use a state of Ctrl key otherwise
  • currentThe currently hovered TreeNode.
  • dragThresholdThe move delay in pixels before detecting a drag; 5 by default
  • generateText
  • isSourceCan be used as a DnD source.
  • selection(id to DomNode) map for every TreeNode that's currently selected.
  • singularAllows selection of only one element, if true.

Method Summary

  • _addItemClass(node,type) Adds a class with prefix "dojoDndItem"
  • _changeState(type,newState) Changes a named state to new state value
  • _compareNodes(n1,n2)
  • _isParentChildDrop(source,targetRow) Checks whether the dragged items are parent rows in the tree which are being dragged into their own children.
  • _markDndStatus(copy) Changes source's state based on "copy" status
  • _removeItemClass(node,type) Removes a class with prefix "dojoDndItem"
  • _setDifference(xs,ys) Returns a copy of xs which lacks any objects occurring in ys.
  • _unmarkTargetAnchor() Removes hover class of the current target anchor
  • _updateSelectionProperties() Update the following tree properties from the current selection: path[s], selectedItem[s], selectedNode[s]
  • addTreeNode(node,isAnchor) add node to current selection
  • checkAcceptance(source,nodes) Checks if the target can accept nodes from this source
  • checkItemAcceptance(target,source,position) Stub function to be overridden if one wants to check for the ability to drop at the node/item level
  • copyState(keyPressed) Returns true, if we need to copy items, false to move.
  • destroy() Prepares the object to be garbage-collected.
  • forInSelectedItems(f,o) Iterates over selected items; see dojo/dnd/Container.forInItems() for details
  • getItem(key) Returns the dojo/dnd/Container._Item (representing a dragged node) by it's key (id).
  • getSelectedTreeNodes() Returns a list of selected node(s).
  • isTreeNodeSelected(node) return true if node is currently selected
  • itemCreator(nodes,target,source) Returns objects passed to Tree.model.newItem() based on DnD nodes dropped onto the tree.
  • removeTreeNode(node) remove node and it's descendants from current selection
  • selectNone() Unselects all items
  • setSelection(newSelection) set the list of selected nodes to be exactly newSelection.
  • userSelect(node,multi,range) Add or remove the given node from selection, responding to a user action such as a click or keypress.

Event Summary

  • _onDragMouse(e,firstTime) Helper method for processing onmousemove/onmouseover events while drag is in progress.
  • onClickPress(e) Event processor for onmousedown/ontouchstart/onkeydown corresponding to a click event
  • onClickRelease(e) Event processor for onmouseup/ontouchend/onkeyup corresponding to a click event
  • onDndCancel() Topic event processor for /dnd/cancel, called to cancel the DnD operation
  • onDndDrop(source,nodes,copy) Topic event processor for /dnd/drop, called to finish the DnD operation.
  • onDndSourceOver(source) Topic event processor for /dnd/source/over, called when detected a current source.
  • onDndStart(source,nodes,copy) Topic event processor for /dnd/start, called to initiate the DnD operation
  • onMouseDown(e) Event processor for onmousedown/ontouchstart
  • onMouseMove(e) Called for any onmousemove/ontouchmove events over the Tree
  • onMouseOut() Event processor for when mouse is moved away from a TreeNode
  • onMouseOver(widget,evt) Called when mouse is moved over a TreeNode
  • onMouseUp(e) Event processor for onmouseup/ontouchend
  • onOutEvent() This method is called when mouse is moved out of our container (like onmouseleave)
  • onOverEvent() This method is called when mouse is moved over our container (like onmouseenter)

Properties

__Item
Defined by: dijit/tree/dndSource

New item to be added to the Tree, like:

accept
Defined by: dijit/tree/dndSource

List of accepted types (text strings) for the Tree; defaults to ["text"]

betweenThreshold
Defined by: dijit/tree/dndSource

Distance from upper/lower edge of node to allow drop to reorder nodes

copyOnly
Defined by: dijit/tree/dndSource

Copy items, if true, use a state of Ctrl key otherwise

current

The currently hovered TreeNode. Not set to anything for keyboard operation. (TODO: change?)

dragThreshold
Defined by: dijit/tree/dndSource

The move delay in pixels before detecting a drag; 5 by default

generateText
Defined by: dijit/tree/dndSource
isSource
Defined by: dijit/tree/dndSource

Can be used as a DnD source.

selection

(id to DomNode) map for every TreeNode that's currently selected. The DOMNode is the TreeNode.rowNode.

singular

Allows selection of only one element, if true. Tree hasn't been tested in singular=true mode, unclear if it works.

Methods

_addItemClass(node,type)

Adds a class with prefix "dojoDndItem"

Parameter Type Description
node Node

A node

type String

A variable suffix for a class name

_changeState(type,newState)

Changes a named state to new state value

Parameter Type Description
type String

A name of the state to change

newState String

new state

_compareNodes(n1,n2)
Parameter Type Description
n1 undefined
n2 undefined
Returns:number | undefined
_isParentChildDrop(source,targetRow)

Checks whether the dragged items are parent rows in the tree which are being dragged into their own children.

Parameter Type Description
source undefined

The DragSource object.

targetRow undefined

The tree row onto which the dragged nodes are being dropped.

Returns:boolean | undefined
_markDndStatus(copy)

Changes source's state based on "copy" status

Parameter Type Description
copy undefined
_removeItemClass(node,type)

Removes a class with prefix "dojoDndItem"

Parameter Type Description
node Node

A node

type String

extension

_setDifference(xs,ys)

Returns a copy of xs which lacks any objects occurring in ys. Checks for membership by modifying and then reading the object, so it will not properly handle sets of numbers or strings.

Parameter Type Description
xs undefined
ys undefined
Returns:undefined
_unmarkTargetAnchor()

Removes hover class of the current target anchor

_updateSelectionProperties()

Update the following tree properties from the current selection: path[s], selectedItem[s], selectedNode[s]

addTreeNode(node,isAnchor)

add node to current selection

Parameter Type Description
node Node

node to add

isAnchor Boolean
Optional

Whether the node should become anchor.

Returns:Node

node to add

checkAcceptance(source,nodes)

Checks if the target can accept nodes from this source

Parameter Type Description
source dijit/tree/dndSource

The source which provides items

nodes DOMNode[]

Array of DOM nodes corresponding to nodes being dropped, dijitTreeRow nodes if source is a dijit/Tree.

Returns:boolean
checkItemAcceptance(target,source,position)

Stub function to be overridden if one wants to check for the ability to drop at the node/item level

In the base case, this is called to check if target can become a child of source. When betweenThreshold is set, position="before" or "after" means that we are asking if the source node can be dropped before/after the target node.

Parameter Type Description
target DOMNode

The dijitTreeRoot DOM node inside of the TreeNode that we are dropping on to Use dijit.getEnclosingWidget(target) to get the TreeNode.

source dijit/tree/dndSource

The (set of) nodes we are dropping

position String

"over", "before", or "after"

Returns:boolean
copyState(keyPressed)

Returns true, if we need to copy items, false to move. It is separated to be overwritten dynamically, if needed.

Parameter Type Description
keyPressed Boolean

The "copy" control key was pressed

Returns:undefined
destroy()

Prepares the object to be garbage-collected.

forInSelectedItems(f,o)

Iterates over selected items; see dojo/dnd/Container.forInItems() for details

Parameter Type Description
f Function
o Object
Optional
getItem(key)

Returns the dojo/dnd/Container._Item (representing a dragged node) by it's key (id). Called by dojo/dnd/Source.checkAcceptance().

Parameter Type Description
key String
Returns:object
getSelectedTreeNodes()

Returns a list of selected node(s). Used by dndSource on the start of a drag.

Returns:Array
isTreeNodeSelected(node)

return true if node is currently selected

Parameter Type Description
node Node

the node to check whether it's in the current selection

Returns:undefined
itemCreator(nodes,target,source)

Returns objects passed to Tree.model.newItem() based on DnD nodes dropped onto the tree. Developer must override this method to enable dropping from external sources onto this Tree, unless the Tree.model's items happen to look like {id: 123, name: "Apple" } with no other attributes.

For each node in nodes[], which came from source, create a hash of name/value pairs to be passed to Tree.model.newItem(). Returns array of those hashes.

Parameter Type Description
nodes DomNode[]
target DomNode
source dojo/dnd/Source
Returns:__Item[] | undefined

Array of name/value hashes for each new item to be added to the Tree

removeTreeNode(node)

remove node and it's descendants from current selection

Parameter Type Description
node Node

node to remove

Returns:Node

node to remove

selectNone()

Unselects all items

Returns:function

Unselects all items

setSelection(newSelection)

set the list of selected nodes to be exactly newSelection. All changes to the selection should be passed through this function, which ensures that derived attributes are kept up to date. Anchor will be deleted if it has been removed from the selection, but no new anchor will be added by this function.

Parameter Type Description
newSelection Node[]

list of tree nodes to make selected

userSelect(node,multi,range)

Add or remove the given node from selection, responding to a user action such as a click or keypress.

Parameter Type Description
node undefined
multi Boolean

Indicates whether this is meant to be a multi-select action (e.g. ctrl-click)

range Boolean

Indicates whether this is meant to be a ranged action (e.g. shift-click)

Events

_onDragMouse(e,firstTime)
Defined by: dijit/tree/dndSource

Helper method for processing onmousemove/onmouseover events while drag is in progress. Keeps track of current drop target.

Parameter Type Description
e Event

The mousemove event.

firstTime Boolean
Optional

If this flag is set, this is the first mouse move event of the drag, so call m.canDrop() etc. even if newTarget == null because the user quickly dragged a node in the Tree to a position over Tree.containerNode but not over any TreeNode (#7971)

onClickPress(e)

Event processor for onmousedown/ontouchstart/onkeydown corresponding to a click event

Parameter Type Description
e Event

onmousedown/ontouchstart/onkeydown event

onClickRelease(e)

Event processor for onmouseup/ontouchend/onkeyup corresponding to a click event

Parameter Type Description
e Event

onmouseup/ontouchend/onkeyup event

onDndCancel()
Defined by: dijit/tree/dndSource

Topic event processor for /dnd/cancel, called to cancel the DnD operation

onDndDrop(source,nodes,copy)
Defined by: dijit/tree/dndSource

Topic event processor for /dnd/drop, called to finish the DnD operation.

Updates data store items according to where node was dragged from and dropped to. The tree will then respond to those data store updates and redraw itself.

Parameter Type Description
source Object

The dijit/tree/dndSource / dojo/dnd/Source which is providing the items

nodes DomNode[]

The list of transferred items, dndTreeNode nodes if dragging from a Tree

copy Boolean

Copy items, if true, move items otherwise

onDndSourceOver(source)
Defined by: dijit/tree/dndSource

Topic event processor for /dnd/source/over, called when detected a current source.

Parameter Type Description
source Object

The dijit/tree/dndSource / dojo/dnd/Source which has the mouse over it

onDndStart(source,nodes,copy)
Defined by: dijit/tree/dndSource

Topic event processor for /dnd/start, called to initiate the DnD operation

Parameter Type Description
source Object

The dijit/tree/dndSource / dojo/dnd/Source which is providing the items

nodes DomNode[]

The list of transferred items, dndTreeNode nodes if dragging from a Tree

copy Boolean

Copy items, if true, move items otherwise

onMouseDown(e)
Defined by: dijit/tree/dndSource

Event processor for onmousedown/ontouchstart

Parameter Type Description
e Event

onmousedown/ontouchend event

onMouseMove(e)
Defined by: dijit/tree/dndSource

Called for any onmousemove/ontouchmove events over the Tree

Parameter Type Description
e Event

onmousemouse/ontouchmove event

onMouseOut()
Defined by: dijit/tree/dndSource

Event processor for when mouse is moved away from a TreeNode

onMouseOver(widget,evt)

Called when mouse is moved over a TreeNode

Parameter Type Description
widget TreeNode
evt Event
onMouseUp(e)
Defined by: dijit/tree/dndSource

Event processor for onmouseup/ontouchend

Parameter Type Description
e Event

onmouseup/ontouchend event

onOutEvent()
Defined by: dijit/tree/dndSource

This method is called when mouse is moved out of our container (like onmouseleave)

onOverEvent()
Defined by: dijit/tree/dndSource

This method is called when mouse is moved over our container (like onmouseenter)

Error in the documentation? Can’t find what you are looking for? Let us know!