REDIPS.drag documentation

More...
Namespace Summary
Constructor Attributes Constructor Name and Description
 
REDIPS.drag Version 4.6.16.

REDIPS.drag is a JavaScript drag and drop library focused on dragging table content and table rows.
See:
REDIPS.drag documentation - Appendix A

Drag and drop table content plus animation
Drag and drop table rows
Drag and Drop table content
JavaScript drag and drop plus content shift

Field Summary
Field Attributes Field Name and Description
 
Animation pause (lower values means the animation will go faster).
 
Shift drop option animation.
 
Animation step (minimum is 1).
 
Enable / disable autoscroll option.
 
Border style for enabled element.
 
Border style for disabled element.
 
Bound size for triggering page autoscroll or autoscroll of scrollable DIV container.
 
If set to "true", all DIV elements on tables could be cloned with pressed SHIFT key.
 
If set to "true", table rows could be cloned with pressed SHIFT key.
 
Reference to current table cell.
 
Delete cloned DIV element if dropped outside of any table.
 
Delete shifted elements (the most right or the most left elements).
 
Property defines working types of REDIPS.drag library: multiple, single, switch, switching, overwrite and shift.
 
Hover object contains 4 properties: color_td, color_tr, border_td and border_tr.
 
Table cells marked with "mark" class name can be allowed or forbidden for accessing (with exceptions) - default is "deny".
 
Dragging mode "cell" or "row" (readonly).
 
Property defines "top" or "bottom" position of dropped element in table cell (if cell already contains DIV elements).
 
obj
Currently moved DIV element.
 
Previously moved DIV element (before clicked or cloned).
 
Table cells marked with "only" class name can accept only defined DIV elements.
 
Opacity level for disabled elements.
 
Reference to previous table cell.
 
Color of empty row.
 
Save content parameter name.
 
Shift elements to empty cell after DIV element is deleted (moved to the trash cell).
 
Property defines shift modes: horizontal1, horizontal2, vertical1 and vertical2.
 
Reference to source table cell.
 
Autoscroll pause in milliseconds.
 
Table sort is feature where tables inside drop container are sorted on each element click.
 
Reference to target table cell.
 
Confirm element deletion.
 
Confirm row deletion.
 
Table cell class name where DIV elements will be deleted.
Method Summary
Method Attributes Method Name and Description
 
clone_div(div, drag)
Method clones DIV element and returns reference of the cloned element.
 
Method deletes DIV element from table.
 
Method removes elements from table cell.
 
enable_drag(enable_flag, el, type)
Method attaches / detaches onmousedown, ontouchstart and ondblclick events to DIV elements and attaches onscroll event to the scrollable containers in initialization phase.
 
enable_table(enable_flag, el)
This method can select tables by class name and mark them as enabled / disabled.
 
find_cell(param, el)
Method returns data (cell reference, row index and column index) for first or last cell in table or row / column.
 
find_parent(tag_name, el, skip)
Method returns a reference of the required parent element.
 
Method returns position as array with members tableIndex, rowIndex and cellIndex (array length is 3).
 
get_style(el, style_name)
Method returns style value for requested HTML element and style name.
 
Method returns current page scroll position as array.
 
init(dc)
Drag container initialization.
 
Method will calculate parameters and start animation (DIV element to the destination table cell).
 
relocate(from, to, mode)
Method relocates DIV elements from source table cell to the target table cell (with optional animation).
 
row_empty(tbl_id, row_idx, color)
Method marks selected row as empty.
 
row_opacity(el, opacity, color)
Method sets opacity to table row or deletes row content.
 
save_content(tbl, type)
Method scans table content and prepares query string or JSON format for submitting to the server.
 
shift_cells(td1, td2)
Method shifts table content horizontally or vertically.
Event Summary
Event Attributes Event Name and Description
 
myhandler_changed(current_cell)
Event handler invoked on every change of current (highlighted) table cell.
 
myhandler_clicked(current_cell)
Event handler invoked if a mouse button is pressed down while the mouse pointer is over DIV element.
 
Event handler invoked if DIV element is cloned.
 
Event handler invoked after cloned DIV element is dropped.
 
Event handler invoked if last element is cloned (type 1).
 
Event handler invoked if last element is cloned (type 2).
 
Event handler invoked if a mouse button is clicked twice while the mouse pointer is over DIV element.
 
Event handler invoked if element is deleted (dropped to the "trash" table cell).
 
myhandler_dropped(target_cell)
Event handler invoked if element is dropped to the table cell.
 
Event handler invoked if mouse button is released but before element is dropped to the table cell.
 
Event handler invoked if element is moved from home position.
 
Event handler invoked if cloned element is dropped on start position or cloned element is dropped outside current table with "delete_cloned" property set to true.
 
Event handler invoked if a mouse button is pressed down and released while the mouse pointer is over DIV element (element was not actually moved).
 
myhandler_row_changed(current_cell)
Event handler invoked on every change of current (highlighted) table row.
 
myhandler_row_clicked(current_cell)
Event handler invoked if a mouse button is pressed down while the mouse pointer is over row handler (div class="drag row").
 
Event handler invoked if table row is cloned.
 
Event handler invoked if row is deleted (dropped to the "trash" table cell).
 
myhandler_row_dropped(target_cell)
Event handler invoked after row is dropped to the table cell.
 
Event handler invoked if mouse button is released but before row is dropped to the table.
 
Event handler invoked if row is moved around and dropped to the home position.
 
Event handler invoked if row is moved from home position.
 
Event handler invoked if cloned row is dropped to the source row.
 
Event handler invoked if a mouse button is pressed down and released while the mouse pointer is over row handler (row was not actually moved).
 
Event handler invoked if row is undeleted.
 
myhandler_switched(target_cell)
Event handler invoked if DIV elements are switched (drop_option is set to "switch").
 
Event handler invoked if element is undeleted.
Field Detail

{Integer} animation_pause
Animation pause (lower values means the animation will go faster).
Default Value:
20 (milliseconds)

{Boolean} animation_shift
Shift drop option animation. If set to true, table content will be relocated with animation in case of "shift" drop option.
Default Value:
false

{Integer} animation_step
Animation step (minimum is 1). Property defines number of pixels in each step. Higher values means bigger step (faster animation) but with less smoothness.
Default Value:
2 px

{Boolean} autoscroll
Enable / disable autoscroll option. By default autoscroll is enabled but it can be usefull in some cases to completely turn off autoscroll (if application doesn't need autoscrolling page nor autoscrolling DIV container). Turning off autoscroll will speed up application because extra calculations will be skipped.
Default Value:
true

{String} border
Border style for enabled element.
Default Value:
solid

{String} border_disabled
Border style for disabled element.
Default Value:
dotted

{Integer} bound
Bound size for triggering page autoscroll or autoscroll of scrollable DIV container.
Default Value:
25 (px)

{Boolean} clone_shiftKey
If set to "true", all DIV elements on tables could be cloned with pressed SHIFT key. Just press SHIFT key and try to drag element. Instead of moving current element, DIV element will be cloned and ready for dragging.
Default Value:
false

{Boolean} clone_shiftKey_row
If set to "true", table rows could be cloned with pressed SHIFT key. Just press SHIFT key and start dragging table row. Source row will not be deleted.
Default Value:
false

{HTMLElement} current_cell
Reference to current table cell.
See:
source_cell
previous_cell
target_cell

{Boolean} delete_cloned
Delete cloned DIV element if dropped outside of any table. If property is set to "false" then cloned DIV element will be dropped to the last possible table cell.
Default Value:
true

{Boolean} delete_shifted
Delete shifted elements (the most right or the most left elements).
Default Value:
false

{String} drop_option
Property defines working types of REDIPS.drag library: multiple, single, switch, switching, overwrite and shift.
// elements can be dropped to all table cells (multiple elements in table cell)
REDIPS.drag.drop_option = 'multiple';

// elements can be dropped only to the empty table cells
REDIPS.drag.drop_option = 'single';

// switch content
REDIPS.drag.drop_option = 'switch';

// switching content continuously
REDIPS.drag.drop_option = 'switching';

// overwrite content in table cell
REDIPS.drag.drop_option = 'overwrite';

// shift table content after element is dropped or moved to trash cell
REDIPS.drag.drop_option = 'shift';
Default Value:
multiple

{Object} hover
Hover object contains 4 properties: color_td, color_tr, border_td and border_tr. color_td and color_tr defines hover color for DIV element and table row. If border_td is defined, then highlighted cell will have border. If border_tr is defined then highlighted row will have only top or bottom border. Top border shows that row will be placed above current row, while bottom border shows that current row will be placed below current row. Some browsers may have problem with "border-collapse:collapse" table style and border highlighting. In that case try without collapsing TD borders (e.g set "border-spacing:0" and smaller "td.border-width").
// set "#9BB3DA" as hover color for TD
REDIPS.drag.hover.color_td = '#9BB3DA';

// or set "Lime" as hover color for TR
REDIPS.drag.hover.color_tr = 'Lime';

// set red border for highlighted TD
REDIPS.drag.hover.border_td = '2px solid red';

{Object} mark
Table cells marked with "mark" class name can be allowed or forbidden for accessing (with exceptions) - default is "deny". This is useful to define table cells forbidden for every DIV element with exceptions (or contrary, define table cells allowed for all DIV elements except some). Object contains:
  • {String} action - allow / deny table cell (default is "deny")
  • {String} cname - class name of marked cells (default is "mark")
  • {Array} exception - defined DIV elements can be dropped to the table cells marked with class "mark" (DIV id -> class name)
// only element with Id "d8" can be dropped to the cell with class name "mark smile"
REDIPS.drag.mark.exception.d8 = 'smile';
See:
only

{String} mode
Dragging mode "cell" or "row" (readonly). This is readonly property defined in a moment when DIV element or row handler is clicked.

{String} multiple_drop
Property defines "top" or "bottom" position of dropped element in table cell (if cell already contains DIV elements). It has affect only in case of drop_option="multiple".
// place dropped elements to cell top
REDIPS.drag.multiple_drop = 'top';
Default Value:
bottom

{HTMLElement} obj
Currently moved DIV element.

{HTMLElement} obj_old
Previously moved DIV element (before clicked or cloned).

{Object} only
Table cells marked with "only" class name can accept only defined DIV elements. Object contains:
  • {Array} div - defined DIV elements can be dropped only to the table cells marked with class name "only" (DIV id -> class name)
  • {String} cname - class name of marked cells (default is "only")
  • {String} other - allow / deny dropping DIV elements to other table cells (default is "deny")
// only element with Id "a1" can be dropped to the cell with class name "only last"
REDIPS.drag.only.div.a1 = 'last';

// DIV elements mentioned in REDIPS.drag.only.div cannot be dropped to other cells
REDIPS.drag.only.other = 'deny';
See:
mark

{Integer} opacity_disabled
Opacity level for disabled elements.

{HTMLElement} previous_cell
Reference to previous table cell.
See:
source_cell
current_cell
target_cell

{String} row_empty_color
Color of empty row.
See:
row_empty
Default Value:
White

{String} save_pname
Save content parameter name. Parameter name should be short because it will be repeated for every DIV element. It is irrelevant in case of JSON format.
See:
save_content
Default Value:
p

{Boolean} shift_after
Shift elements to empty cell after DIV element is deleted (moved to the trash cell). If set to false, table content will not be shifted. This property will have effect only if drop_option is set to "shift".
See:
drop_option
Default Value:
true

{String} shift_option
Property defines shift modes: horizontal1, horizontal2, vertical1 and vertical2. horizontal1 - horizontal shift (element shift can affect more rows) horizontal2 - horizontal shift (each row is treated separately) vertical1 - vertical shift (element shift can affect more columns) vertical2 - vertical shift (each column is treated separately)
// DIV elements will be shifted vertically (each column is treated separately)
REDIPS.drag.shift_option = 'vertical2';
See:
shift_cells
Default Value:
horizontal1

{HTMLElement} source_cell
Reference to source table cell.
See:
previous_cell
current_cell
target_cell

{Integer} speed
Autoscroll pause in milliseconds.
Default Value:
20 (milliseconds)

{Boolean} table_sort
Table sort is feature where tables inside drop container are sorted on each element click. Clicked DIV element defines table that should be placed on the array top. Tables order is important for highlighting current cell in case of nested tables. But sometimes this feature should be turned off when one table overlays the other using "position" style relative, fixed or absolute.
Default Value:
true

{HTMLElement} target_cell
Reference to target table cell. Target table cell is defined in a moment of dropping element to the table cell.
See:
source_cell
current_cell
previous_cell

{Boolean} trash_ask
Confirm element deletion. If set to "true" popup with question: "Are you sure you want to delete?" will appear.
Default Value:
true

{Boolean} trash_ask_row
Confirm row deletion. If set to "true" popup with question: "Are you sure you want to delete row?" will appear.
Default Value:
true

{String} trash_cname
Table cell class name where DIV elements will be deleted.
Default Value:
trash
Method Detail

{HTMLElement} clone_div(div, drag)
Method clones DIV element and returns reference of the cloned element. "clone" class name will not be copied in cloned element (in case if source element contains "clone" class name). This method is called internally also.
Parameters:
{HTMLElement} div
DIV element to clone.
{Boolean} drag Optional
If set to true, then cloned DIV element will be ready for dragging (otherwise element will be only cloned).
Returns:
{HTMLElement} Returns cloned DIV element.

delete_object(el)
Method deletes DIV element from table. Input parameter is DIV reference or id of DIV element.
// delete DIV element in myhandler_dropped() event handler
rd.myhandler_dropped = function () {
    rd.delete_object(rd.obj);
}

// delete DIV element with id="d1"
rd.delete_object('d1');
Parameters:
{String|HTMLElement} el
Id of DIV element or reference of DIV element that should be deleted.

{Boolean} empty_cell(td)
Method removes elements from table cell.
// set REDIPS.drag reference
var rd = REDIPS.drag;
// search for TABLE element (from cell reference)
tbl = rd.empty_cell(td);
Parameters:
{HTMLElement} td
Table cell reference from which all the elements will be deleted.
Returns:
{Boolean} Returns false if input element is not table cell.

enable_drag(enable_flag, el, type)
Method attaches / detaches onmousedown, ontouchstart and ondblclick events to DIV elements and attaches onscroll event to the scrollable containers in initialization phase. It also can be used for element initialization after DIV element was manually added to the table. If class attribute of DIV container contains "noautoscroll" class name then autoscroll option will be disabled.
// enable element with id="id123"
enable_drag(true, 'id123');

// or init manually added element with known id
REDIPS.drag.enable_drag(true, 'id234');

// disable all elements in drag1 subtree
enable_drag(false, 'drag1', 'subtree')

// init all DIV elements in dragging area (including newly added DIV element)
REDIPS.drag.enable_drag('init');

// init added element with known reference
REDIPS.drag.enable_drag(true, my_el);
Parameters:
{String|Boolean} enable_flag
Enable / disable element (or element subtree like table, dragging container ...).
{String|HTMLElement} el Optional
Element id (or subtree) to enable / disable. Parameter defines element id or element reference of DIV element(s) to enable / disable.
{String} type Optional
Type definition for the second parameter el - element or subtree.
See:
enable_table

enable_table(enable_flag, el)
This method can select tables by class name and mark them as enabled / disabled. Instead of class name, it it possible to send table reference for enable / disable. By default, all tables are enabled to accept dropped elements.
// disable tables with class name 'mini'
enable_table(false, 'mini');
Parameters:
{Boolean} enable_flag
Enable / disable one or more tables.
{String|HTMLElement} el
Class name of table(s) to enable/disable or table reference to enable/disable.
See:
enable_drag

{Array} find_cell(param, el)
Method returns data (cell reference, row index and column index) for first or last cell in table or row / column.
// find first cell in row (el is table cell reference)
firstInRow = find_cell('firstInRow', el);
// find last cell in table (el is reference of any cell inside table)
last = find_cell('last', el);
// find last cell in column (el is table cell reference)
lastInColumn = find_cell('lastInColumn', el);
Parameters:
{String} param
Parameter defines first or last table cell (values are "first", "firstInColumn", "firstInRow", "last", "lastInColumn", "lastInRow").
{HTMLElement} el
Table cell reference (td). For "first" or "last" request, el can be any HTMLElement within table.
Returns:
{Array} Returns array with row index, column index and cell reference,

{HTMLElement} find_parent(tag_name, el, skip)
Method returns a reference of the required parent element.
// find parent TABLE element (from cell reference)
tbl = find_parent('TABLE', cell);

// find reference of the outside table (start node is TD in inner table - first TABLE node should be skipped)
tbl = find_parent('TABLE', cell, 1);
Parameters:
{String} tag_name
Tag name of parent element.
{HTMLElement} el
Start position to search.
{Integer} skip Optional
How many found nodes should be skipped. For example when start node is TD in inner table and find_parent() should return reference of the outside table.
Returns:
{HTMLElement} Returns reference of the found parent element.

{Array} get_position(ip)
Method returns position as array with members tableIndex, rowIndex and cellIndex (array length is 3). If input parameter is not defined then method will return array with current and source positions (array length will be 6).
// set REDIPS.drag reference
var rd = REDIPS.drag;
// display target and source position of dropped element
rd.myhandler_dropped = function () {
   // get target and source position (method returns positions as array)
   // pos[0] - target table index
   // pos[1] - target row index
   // pos[2] - target cell (column) index
   // pos[3] - source table index
   // pos[4] - source row index
   // pos[5] - source cell (column) index
   var pos = rd.get_position();
   // display element positions
   console.log(pos);
};
Parameters:
{String|HTMLElement} ip Optional
DIV element id / reference or table cell id / reference.
Returns:
{Array} Returns array with members tableIndex, rowIndex and cellIndex.

{String} get_style(el, style_name)
Method returns style value for requested HTML element and style name.
Parameters:
{HTMLElement} el
Requested HTML element.
{String} style_name
Asked style name.
Returns:
{String} Returns style value.
See:
http://www.quirksmode.org/dom/getstyles.html

{Array} getScrollPosition()
Method returns current page scroll position as array.
Returns:
{Array} Returns array with two members [ scrollX, scrollY ].

init(dc)
Drag container initialization. It should be called at least once (it is possible to call a method multiple times). Every page should have at least one drag container. If REDIPS.drag.init() is called without input parameter, library will search for drag container with id="drag". Only tables inside drag container will be scanned. It is possible to have several drag containers totaly separated (elements from one container will not be visible to other drag containers).
// init drag container (with default id="drag")
REDIPS.drag.init();

// init drag container with id="drag1"
REDIPS.drag.init('drag1');
Parameters:
{String} dc Optional
Drag container Id (default id "drag").

{Array} move_object(ip)
Method will calculate parameters and start animation (DIV element to the destination table cell). If "target" property is not defined then current location will be used. Here is properties definition of input parameter:
  • {String} id - id of element to animate - DIV element or row handler (div class="drag row")
  • {String} obj - reference of element to animate - DIV element or row handler (if "id" parameter exists, "obj" parameter will be ignored)
  • {String} mode - animation mode (if mode="row" then source and target properties should be defined)
  • {Array} source - source position (table index and row index)
  • {Array} target - target position (table, row and cell index (optional for "row" mode)
  • {Function} callback - callback function executed after animation is finished

Method returns array containing reference of two object. In "cell" mode returned objects are:

  • Array[0] - dragged element
  • Array[1] - dragged element

In "row" mode returned objects are:

  • Array[0] - table_mini
  • Array[1] - source row
// move element with id="a1" to the current location and after
// animation is finished display alert "Finished"
rd.move_object({
    id: 'a1',
    callback: function () {
        alert('Finished');
    }
});

// move element with id="a2" to the first table, second row and third cell
rd.move_object({
    id: 'a2',
    target: [0, 1, 2]
});
// move DIV element with reference "mydiv" to the first table, second row and third cell
rd.move_object({
    obj: mydiv,
    target: [0, 1, 2]
});
// move first row and after animation is finished call "enable_button" function
// "move_object" returns Array with references of table_mini and source row
row = rd.move_object({
          mode: 'row',            // animation mode - row
          source: [0, 0],         // source position (table index and row index)
          target: [0, 6],         // target position
          callback: enable_button // function to call after animation is over
       });
Parameters:
{Object} ip
Object with properties: id, mode, source, target and callback.
Returns:
{Array} Returns reference of two elements in array. In "cell" mode both elements are dragged element, while in "row" mode first element is table_mini and second element is source row.

relocate(from, to, mode)
Method relocates DIV elements from source table cell to the target table cell (with optional animation). If animation is enabled, then target table will be disabled until animated element reaches destination cell.
Parameters:
{HTMLElement} from
Source table cell.
{HTMLElement} to
Target table cell.
{String} mode Optional
Relocation mode "instant" or "animation". Default is "instant".

row_empty(tbl_id, row_idx, color)
Method marks selected row as empty. Could be needed for displaying initially empty table. Input parameters are table id and row index.
// set reference to the REDIPS.drag library
rd = REDIPS.drag;
// mark first row as empty in table with id="tbl1"
rd.row_empty('tbl1', 0);
Parameters:
{String} tbl_id
Table id.
{Integer} row_idx
Row index (starts from 0).
{String} color Optional
Color of empty row (default is "White" or defined with REDIPS.drag.row_empty_color parameter).
See:
row_empty_color

row_opacity(el, opacity, color)
Method sets opacity to table row or deletes row content. Input parameter "el" is reference to the table row or reference to the cloned mini table (when row is moved).
// set reference to the REDIPS.drag library
rd = REDIPS.drag;
// make row semi-transparent
rd.row_opacity(row_obj, 50);
// set row as empty and white (content in table cells will be deleted)
rd.row_opacity(row_obj, 'empty', 'White');
Parameters:
{HTMLElement|String} el
Id of row handler (div class="drag row") or reference to element (source row or mini table).
{Integer|String} opacity
Opacity level (from 0 to 100) or "empty" (then content of table cells in row will be deleted - in that case first parameter should be TR).
{String} color Optional
Background color.

{String} save_content(tbl, type)
Method scans table content and prepares query string or JSON format for submitting to the server. Input parameters are id / table reference and optional output format.
Query string:
'p[]='+id+'_'+r+'_'+c+'&p[]='+id+'_'+r+'_'+c + ...

JSON:
[["id",r,c],["id",r,c],...]

id - element id
r  - row index
c  - cell index

Query string example:
p[]=d1_1_0&p[]=d2_1_1&p[]=d3_5_2&p[]=d4_5_3

JSON example:
[["d1",1,0],["d2",1,1],["d3",5,2],["d4",5,3]]
Parameters:
{String|HTMLElement} tbl
Id or reference of table that will be scanned.
{String} type Optional
Type defines output format. If set to "json" then output will be JSON format otherwise output will be query string.
Returns:
{String} Returns table content as query string or in JSON format.
See:
save_pname

shift_cells(td1, td2)
Method shifts table content horizontally or vertically. REDIPS.drag.shift_option defines the way of how content will be shifted. Useful for sorting table content in any direction.
// define first and last table cell
var firstCell = document.getElementById('firstCellOnTable'),
    lastCell = document.getElementById('lastCellOnTable');
// enable animation
REDIPS.drag.animation_shift = true;
// shift content
REDIPS.drag.shift_cells(lastCell, firstCell);
Parameters:
{HTMLElement} td1
Source table cell.
{HTMLElement} td2
Target table cell.
See:
shift_option
Event Detail

myhandler_changed(current_cell)
Event handler invoked on every change of current (highlighted) table cell.
// set REDIPS.drag reference
var rd = REDIPS.drag;
// define myhandler_changed event handler
rd.myhandler_changed = function () {
  // get current position (method returns positions as array)
  var pos = rd.get_position();
  // display current row and current cell
  console.log('Changed: ' + pos[1] + ' ' + pos[2]);
};
Parameters:
{HTMLElement} current_cell Optional
Reference to the current (highlighted) table cell.
See:
get_position

myhandler_clicked(current_cell)
Event handler invoked if a mouse button is pressed down while the mouse pointer is over DIV element.
Parameters:
{HTMLElement} current_cell Optional
Reference to the table cell of clicked element.

myhandler_cloned()
Event handler invoked if DIV element is cloned.

myhandler_cloned_dropped(target_cell)
Event handler invoked after cloned DIV element is dropped.
Parameters:
{HTMLElement} target_cell Optional
Reference to the target table cell.

myhandler_clonedend1()
Event handler invoked if last element is cloned (type 1). Element has defined "climit1_X" class name where X defines number of elements to clone. Last element can be dragged.

myhandler_clonedend2()
Event handler invoked if last element is cloned (type 2). Element has defined "climit2_X" class name where X defines number of elements to clone. Last element can't be dragged and stays static.

myhandler_dblclicked()
Event handler invoked if a mouse button is clicked twice while the mouse pointer is over DIV element.

myhandler_deleted(cloned)
Event handler invoked if element is deleted (dropped to the "trash" table cell).
Parameters:
{Boolean} cloned Optional
True if cloned element is directly moved to the trash (in one move). If cloned element is dropped to the table and then moved to the trash then "cloned" parameter will be set to false.

myhandler_dropped(target_cell)
Event handler invoked if element is dropped to the table cell.
Parameters:
{HTMLElement} target_cell Optional
Target cell reference.

myhandler_dropped_before(target_cell)
Event handler invoked if mouse button is released but before element is dropped to the table cell. If boolen "false" is returned from event handler then element drop will be canceled. Dragged element will be returned to the start position while cloned element will be deleted.
Parameters:
{HTMLElement} target_cell Optional
Target cell reference.

myhandler_moved()
Event handler invoked if element is moved from home position.

myhandler_notcloned()
Event handler invoked if cloned element is dropped on start position or cloned element is dropped outside current table with "delete_cloned" property set to true. This event handler could be also invoked if "clone" type element is placed inside forbidden table cell.
See:
delete_cloned

myhandler_notmoved()
Event handler invoked if a mouse button is pressed down and released while the mouse pointer is over DIV element (element was not actually moved).

myhandler_row_changed(current_cell)
Event handler invoked on every change of current (highlighted) table row.
Parameters:
{HTMLElement} current_cell Optional
Reference to the current (highlighted) table cell.

myhandler_row_clicked(current_cell)
Event handler invoked if a mouse button is pressed down while the mouse pointer is over row handler (div class="drag row").
Parameters:
{HTMLElement} current_cell Optional
Reference to the table cell of clicked element.

myhandler_row_cloned()
Event handler invoked if table row is cloned.

myhandler_row_deleted()
Event handler invoked if row is deleted (dropped to the "trash" table cell).

myhandler_row_dropped(target_cell)
Event handler invoked after row is dropped to the table cell.
Parameters:
{HTMLElement} target_cell Optional
Reference to the target table cell.

myhandler_row_dropped_before()
Event handler invoked if mouse button is released but before row is dropped to the table. If boolen "false" is returned from event handler then row drop will be canceled.

myhandler_row_dropped_source(target_cell)
Event handler invoked if row is moved around and dropped to the home position.
Parameters:
{HTMLElement} target_cell Optional
Reference to the target table cell.

myhandler_row_moved()
Event handler invoked if row is moved from home position.

myhandler_row_notcloned()
Event handler invoked if cloned row is dropped to the source row.

myhandler_row_notmoved()
Event handler invoked if a mouse button is pressed down and released while the mouse pointer is over row handler (row was not actually moved).

myhandler_row_undeleted()
Event handler invoked if row is undeleted. After row is dropped to the "trash" table cell and "trash_ask_row" property is set to true then popup with question: "Are you sure you want to delete row?" will appear. Clicking on "Cancel" will undelete row and call this event handler.
See:
trask_ask_row

myhandler_switched(target_cell)
Event handler invoked if DIV elements are switched (drop_option is set to "switch").
Parameters:
{HTMLElement} target_cell Optional
Reference to the target table cell.
See:
drop_option

myhandler_undeleted()
Event handler invoked if element is undeleted. After element is dropped to the "trash" table cell and "trash_ask" property is set to true then popup with question: "Are you sure you want to delete?" will appear. Clicking on "Cancel" will undelete element and call this event handler.
See:
trask_ask
This entry was posted on July 3, 2011 and is filed under Drag and Drop, JavaScript

Related posts

39 Responses to REDIPS.drag documentation

  1. Steve says:

    Please help. I am trying to get the undelete to function. I have looked over you examples and have not been able to figure out how to restore the item back to its original cell when the user cancels a delete.

    Thanks,
    Steve

  2. dbunic says:

    @Steve - In a moment when element is dropped to the Trash cell, DIV element is deleted from DOM. Please find the following lines in redips-drag.js file (line 975):

    // remove child from DOM (node still exists in memory)
    obj.parentNode.removeChild(obj);
    

    Browser will delete DIV element but element will still exist in memory. It is only important to remeber reference to the delete element. If user decides to cancel element deletion, element can be appended to the previous table cell (or any other element in DOM). Here is how:

    // append removed object to the source table cell
    tables[table_source].rows[row_source].cells[cell_source].appendChild(obj);
    

    Hope this short info will be helpful to you.
    Cheers!

  3. Omkar says:

    This is brilliant stuff. I've seen this just today and its my bad luck that I haven't seen it last month, when I started a jquery dragndrop application and now I'm stuck with it - not able to customize it to my needs. This just fits like a glove. Many many thanks :)

    But I'd like to know if there is a way to customize a table as a drop zone such that when the cloned drag item is dropped on the table (in this case the entire drop-zone-table would be highlighted), it'll align itself into the first empty td. Please guide me through.

  4. dbunic says:

    @Omkar - Table can be customized as a drop zone. In a code below, red border will show selected table. You can easily modify this code to change background color of whole table. As you certainly know, background color of table cell has higher priority, so this implies that your table should not have defined table cell color.

    /* set border for tables */
    #drag table {
        border: 2px solid white;
    }
    
    var redips_init,
        clear_border,
        tables;
    
    // REDIPS.drag initialization
    redips_init = function () {
        // reference to the REDIPS.drag library
        var rd = REDIPS.drag;
        // set reference to all tables within DIV "drag"
        tables = document.getElementById('drag').getElementsByTagName('TABLE');
        // initialization
        rd.init();
        // my handler changed
        rd.myhandler_changed = function (cell) {
            // define current table
            var current_table = rd.find_parent('TABLE', cell);
            // clear border from all tables
            clear_border();
            // set border color for selected table
            current_table.style.borderColor = 'red';
        };
        // my handler dropped
        rd.myhandler_dropped = function () {
            // clear border from all tables
            clear_border();
        };
    };
    
    // clear border from all tables
    clear_border = function () {
        var i;
        for (i = 0; i < tables.length; i++) {
            tables[i].style.borderColor = 'white';
        }
    };
    
    // add onload event listener
    if (window.addEventListener) {
        window.addEventListener('load', redips_init, false);
    }
    else if (window.attachEvent) {
        window.attachEvent('onload', redips_init);
    }
    

    After element is dropped to the highlighted table, it can be relocated to the first empty table cell. You will need to create a function that will return empty cell and with relocate() method dropped element can be moved to desired destination.

  5. Jim says:

    Excellent script with great documentation! Already used it in one project and now working on another. Wondering if it is possible to set clone to automatically execute without having to use shift key?

  6. Jim says:

    Actually, I now see the tic-tac-toe example which is what I'm trying to achieve. Will take a closer look to see if I can do it. thanks!

  7. Chris says:

    Update the hover_color property

    Documented online as:
    // set "#9BB3DA" as hover color
    REDIPS.drag.hover_color('#9BB3DA');

    Correction needed:
    REDIPS.drag.hover_color = '#9BB3DA';

  8. dbunic says:

    @Jim - To enable element cloning it is only needed to define "clone" class name next to "drag" class name. Here is example for DIV element:

    <div id="cln" class="drag clone" title="infinite cloning">Clone</div>
    

    @Chris - Thank you, documentation for hover_color is corrected.

  9. He-Man says:

    I'm looking to adapt one of your examples to create a table with the following properties.
    -- When a cell at position (a,b) is dragged onto a another cell at position (x,y)
    -- The rows and columns swap position such that
    -- row_a and row_x are swapped
    -- column_b and column_y are swapped

    Which example do you think I should work off of? Thanks!

  10. dbunic says:

    @He-Man - I suppose that you want to swap content of rows and columns. Maybe the best example to start would be example17 "Move object (animation)" and example18 "Simple element animation". In a moment when DIV element is dropped from position [a,b] to position [x,y], JavaScript function should move elements in row and column. You should open loop for each cell in row "a" and move element to row "x" and vice versa. After row content is swapped, the same process for swapping columns can be started. The main trick is to create loops for rows and columns. I would also include counter for moved elements to wait last DIV element in row content swapping. It isn't so simple but it isn't impossible. If you have basic JavaScript skills, you will be able to create this example.

  11. Ramon Pena says:

    You have done a great job with this library!

    I am starting to customize it for a project and I cannot find how to limit drag and drop of some divs to specific cells; In my project I will have two set of tags(divs) in the left area of a page; one set for Materials and set for Packages; in the right area of the page I will have a table with some empty rows where the user will drop Tags to create a sequence; I want to allow these tags to be cloned but the materials tags will only be allowed to be dropped inside the materials cells while the Package tags will be allowed in all the cells. It is similar to your School timetable example but imagine you would like to limit 'History' and 'English' to be dropped only in the cells after lunch or only on Mondays and Fridays cells. I have been trying to do it with the Only property that the library have for that without success.

    Thanks.

  12. dbunic says:

    @Ramon Pena - A new example is prepared Example07: E F. It contains two types of elements: E and F. E elements can be placed everywhere while F elements can be placed only to the bottom cells. Hope this example will be a good start point so you can continue with your project.

    And thank you for supporting my work, it's very appreciated.
    Cheers!

  13. Ramon Pena says:

    Thanks for your prompt answer Darko; I got another question for you hoping you can help me with this one too:

    Is there a way to avoid that rows from one table are dropped to another table? In my project I have a table that will have a nested table in one of its rows and I want to enable functionality to drag and drop rows but only within the same table, and I need drag and drop rows enabled for both tables, the inner and the outer one; I also want to prevent the highlighting of the cells that your library does whenever the user drags rows from the inner table over the outer table and vice versa.

    Thanks!

  14. dbunic says:

    @Ramon Pena - Yes, you can drag and drop rows only within one (or several) tables. In this scenario, dragged element or row could not be placed to other tables. Please take a look to Example 19 - Groups and table rows. Rows in nested tables can be moved only within nested tables while rows of main table can be dropped only to the main table. Tables are marked with different class names and inside myhandler_row_clicked event handler, enable_table() method enables / disables tables. Here is part from script.js file for illustration:

    rd.myhandler_row_clicked = function () {
        // find table
        var tbl = rd.find_parent('TABLE', rd.obj);
        // if row belongs to the "main" table
        if (tbl.className.indexOf('main') > -1) {
            rd.enable_table(false, 'view');
            rd.enable_table(true, 'main');
        }
        // row belongs to the "view" table
        else {
            rd.enable_table(true, 'view');
            rd.enable_table(false, 'main');
        }
    };
    
  15. Mark Davies says:

    Is there a call to delete a DIV element without dragging it to trash? I would like to have a lot of elements in the table and use visibility to select what I want and then delete those that are hidden or add and option to save to save only those that are visible.

    Thanks,

  16. dbunic says:

    @Mark Davies - New REDIPS.drag version is published (documentation will be updated later). In version 4.6.6 exists delete_object() public method to delete any DIV element in table. Here is example how to use new method:

    // set REDIPS.drag reference
    var rd = REDIPS.drag;
    
    // delete DIV element in myhandler_dropped() event handler
    rd.myhandler_dropped = function () {
        rd.delete_object(rd.obj);
    }
    
    // delete DIV element with id="d1"
    rd.delete_object('d1');
    
  17. John says:

    Hi,
    i am working on a drag and drog module for my jsp project.
    This suit my needs. lets say i save the state in my db. Can you tell me, once we retrieve it from the data, how can we display it back to what it should look like?

  18. dbunic says:

    @John - REDIPS.drag contains simple save_content() method. Element ID and coordinates will be prepared to sent with URL. Please peek to the Example 3: School timetable where is implemented saving to database (preview version is static and without server side communication). Iniside example03 directory you will find instructions in readme.txt and database.sql to create two simple tables.

  19. Anthony says:

    Is it possible to drag and drop entire columns in the same way that you can drag and drop entire rows?

    Sorry another question, how would you configure two DIVs for drag and drop so that items (rows) from one DIV element cannot be dropped into the DIV element. The second DIV element is a child to the the first DIV.

  20. dbunic says:

    @Anthony - REDIPS.drag currently doesn't have functionality for column dragging. It is in my plans when I will have more free time - hopefully during this year.

    And your second question - DIV element can only be dropped to table cell not to other DIV element, so can you please clarify your question. Anyway, here are few REDIPS.drag options:
    - DIV elements can be cloned
    - drop option can be defined as single (only one DIV element can be dropped to the table cell)
    - table can be placed to separated containers (elements from first table can't be dropped to second table)
    - table cell can be marked to accept only certain DIV element
    - table cell can be marked as forbidden
    ...

Leave a Reply

Your email address will not be published. Required fields are marked *

*

In case of posting HTML tags or JavaScript code please convert special characters to HTML entities.
Especially pay attention to convert "<" to "&lt;" character!