Magic Icon Sorting: Drag N Drop (): Magic JavaScript

Quick Jump ↵

Usage

Add <link href="/PATH/TO/magic/tricks/drag_n_drop/drag_n_drop..css" rel="stylesheet">
<script type="text/javascript" src="/PATH/TO/magic/tricks/drag_n_drop/drag_n_drop..js" charset="UTF-8"></script>

below your <script type="text/javascript" src="/PATH/TO/magic/wand..js" charset="UTF-8"></script>

Add <script type="text/javascript">$m.trick.drag_n_drop.sort = true;</script> inside your <body> tag.

Use the examples below to build your own!

Examples

1. Simple sorting

Sort Box 1.1

Sort Box 1.2

Sort Box 1.3

Sort Box 1.4

2. Sorting and recording values

Sort Box 2.1

Sort Box 2.2

Sort Box 2.3

Sort Box 2.4

The data-mjf_drag_n_drop_update_field attribute should be set to an existing form field's ID.

After sorting, the field's value will be set to a sorted, pipe-delimited string.

The data-mjf_drag_n_drop_value attributes should be set to whatever values you'd like to record.

3. Sorting and deleting

Sort Box 3.1

Sort Box 3.2

Sort Box 3.3

Sort Box 3.4

When the data-mjf_drag_n_drop_remove attribute is set to "true" a Remove will appear on each sortable item.

4. Dragging to different containers

Sort Box 4.1

Sort Box 4.2

Sort Box 4.3

Sort Box 4.4

Sort Box 5.1

Sort Box 5.2

Sort Box 5.3

Sort Box 5.4

By default, sortable elements cannot be dragged from one container to another.

This can be disabled by adding data-mjf_dnds_set_parent="any" to the primary container that contains the data-mjf="drag_n_drop_sort".

5. Sorting and then fire a JavaScript callback

Sort Box 6.1

Sort Box 6.2

Sort Box 6.3

Sort Box 6.4

The data-mjf_drag_n_drop_callback attribute should be set to an existing JavaScript function's name.

It will be passed the newly dropped element as an object.

Notes

The various data-mjf_drag_and_drop_* attributes can be mixed and matched as needed.

By default, any elements inside a class="dnd_sort_box" will trigger the drag and drop operation. If you wish certain elements NOT to do this, add data-mjf_drag_n_drop_ignore="true" to that element.

To Do

« Back to Drag N Drop

« Back to the main documentation