Class: tableDrag

Drupal. tableDrag

new Drupal.tableDrag(table, tableSettings)

Provides table and field manipulation.

Name Type Description
table HTMLElement

DOM object for the table to be made draggable.

tableSettings object

Settings for the table added via drupal_add_dragtable().

Members

$tablejQuery

changedbool

Whether anything in the entire table has changed.

nullabledragObjectHTMLElement

Used to hold information about a current drag operation.

indentAmountnumber

indentCountnumber

Total width of indents, set in makeDraggable.

indentEnabledbool

Check this table's settings for parent relationships.

For efficiency, large sections of code can be skipped if we don't need to track horizontal movement and indentations.

maxDepthnumber

Maximum amount of allowed parenting.

nullableoldRowElementHTMLElement

Remember the previous element.

oldYnumber

Used to determine up or down direction from last mouse move.

nullablerowObjectHTMLElement

Provides operations for row manipulation.

rtlnumber

Direction of the table.

nullablescrollIntervalnumber

scrollSettingsobject

Configure the scroll settings.

Properties:
Name Type Description
amount number
interval number
trigger number

scrollYnumber

stripingbool

tableHTMLElement

tableSettingsobject

windowHeightnumber

Methods

addColspanClass(columnIndex){function}

Mark cells that have colspan.

In order to adjust the colspan instead of hiding them altogether.

Name Type Description
columnIndex number

The column index to add colspan class to.

Returns:
Type Description
function Function to add colspan class.

checkScroll(cursorY){number}

Check the suggested scroll of the table.

Name Type Description
cursorY number

The Y position of the cursor.

Returns:
Type Description
number The suggested scroll.

copyDragClasses(sourceRow, targetRow, group)

Copy all tableDrag related classes from one row to another.

Copy all special tableDrag classes from one row's form elements to a different one, removing any special classes that the destination row may have had.

Name Type Description
sourceRow HTMLElement

The element for the source row.

targetRow HTMLElement

The element for the target row.

group string

The group selector.

displayColumns(displayWeight)

Hide or display weight columns. Triggers an event on change.

Name Type Description
displayWeight bool

'true' will show weight columns.

Fires:

dragRow(event, self){bool|undefined}

Pointer movement handler, bound to document.

Name Type Description
event jQuery.Event

The pointer event.

self Drupal.tableDrag

The tableDrag instance.

Returns:
Type Description
bool | undefined Undefined if no dragObject is defined, false otherwise.

dragStart(event, self, item)

Pointer event initiator, creates drag object and information.

Name Type Description
event jQuery.Event

The event object that trigger the drag.

self Drupal.tableDrag

The drag handle.

item HTMLElement

The item that that is being dragged.

dropRow(event, self)

Pointerup behavior.

Name Type Description
event jQuery.Event

The pointer event.

self Drupal.tableDrag

The tableDrag instance.

findDropTargetRow(x, y){*}

Find the row the mouse is currently over.

This row is then taken and swapped with the one being dragged.

Name Type Description
x number

The x coordinate of the mouse on the page (not the screen).

y number

The y coordinate of the mouse on the page (not the screen).

Returns:
Type Description
* The drop target row, if found.

getPointerOffset(target, event){object}

Get the event offset from the target element.

Given a target element and a pointer event, get the event offset from that element. To do this we need the element's position and the target position.

Name Type Description
target HTMLElement

The target HTML element.

event jQuery.Event

The pointer event.

Returns:
Type Description
object An object with x and y keys indicating the position.

hideColumns()

Hide the columns containing weight/parent form elements.

Undo showColumns().

initColumns()

Initialize columns containing form elements to be hidden by default.

Identify and mark each cell with a CSS class so we can easily toggle show/hide it. Finally, hide columns if user does not have a 'Drupal.tableDrag.showWeight' localStorage value.

makeDraggable(item)

Take an item and add event handlers to make it become draggable.

Name Type Description
item HTMLElement

The item to add event handlers to.

onDrag(){null}

Stub function. Allows a custom handler when a row begins dragging.

Returns:
Type Description
null Returns null when the stub function is used.

onDrop(){null}

Stub function. Allows a custom handler when a row is dropped.

Returns:
Type Description
null Returns null when the stub function is used.

pointerCoords(event){object}

Get the coordinates from the event (allowing for browser differences).

Name Type Description
event jQuery.Event

The pointer event.

Returns:
Type Description
object An object with x and y keys indicating the position.

restripeTable()

Command to restripe table properly.

row(tableRow, method, indentEnabled, maxDepth, addClasses)

Constructor to make a new object to manipulate a table row.

Name Type Description
tableRow HTMLElement

The DOM element for the table row we will be manipulating.

method string

The method in which this row is being moved. Either 'keyboard' or 'mouse'.

indentEnabled bool

Whether the containing table uses indentations. Used for optimizations.

maxDepth number

The maximum amount of indentations this row may contain.

addClasses bool

Whether we want to add classes to this row to indicate child relationships.

rowSettings(group, row){object}

Find the target used within a particular row and group.

Name Type Description
group string

Group selector.

row HTMLElement

The row HTML element.

Returns:
Type Description
object The table row settings.

setScroll(scrollAmount)

Set the scroll for the table.

Name Type Description
scrollAmount number

The amount of scroll to apply to the window.

showColumns()

Show the columns containing weight/parent form elements.

Undo hideColumns().

toggleColumns()

Toggle the weight column depending on 'showWeight' value.

Store only default override.

updateField(changedRow, group)

After the row is dropped, update a single table field.

Name Type Description
changedRow HTMLElement

DOM object for the row that was just dropped.

group string

The settings group on which field updates will occur.

updateFields(changedRow)

After the row is dropped, update the table fields.

Name Type Description
changedRow HTMLElement

DOM object for the row that was just dropped.