Advanced touch-compatible Drag'n'Drop library providing Draggable, Droppable and Sortable for Zepto.js and jQuery
Controls which elements are accepted by the droppable.
$('#list-accept-selector').sortable({ accept: '.a' })
.on('sortable:receive', function(e, ui) {
ui.item.removeClass('draggable')
})
$('#example-accept-selector .draggable').draggable({ connectWith: '#list-accept-selector' })
$('#list-accept-function').sortable({ accept: function(el) { return el.hasClass('b') } })
.on('sortable:receive', function(e, ui) {
ui.item.removeClass('draggable')
})
$('#example-accept-function .draggable').draggable({ connectWith: '#list-accept-function' })
If specified, the class will be added to the sortable while an acceptable draggable is being dragged.
$('#example-activeClass').sortable({ activeClass: 'active' })
Prevents sorting if you start on elements matching the selector.
$('#example-cancel').sortable({ cancel: '.title' })
A selector of other sortable or droppable elements that the items from this list should be connected to.
$('#lhs').sortable({ connectWith: '#rhs' })
$('#rhs').sortable()
Disables the sortable if set to true
.
$('#example-disabled').sortable({ disabled: true })
If true
, forces the helper to have a size.
$('#example-forcePlaceholderSize').sortable({
forcePlaceholderSize: true
})
Restricts sort start click to the specified element.
$('#example-handle').sortable({ handle: '.title' })
Specifies which items inside the element should be sortable.
$('#example-items').sortable({ items: 'li.task' })
jQuery's default is '> *', but it is currently not possible to use this children selector for event delegation in Zepto.
A class name that gets applied to the otherwise white space.
$('#example-placeholder').sortable({ placeholder: 'dummy' })
This option could be used to manually set the HTML tag used to create the placeholder. If this option is not set, the HTML tag is detected automatically.
$('#example-placeholder').sortable({ placeholderTag: 'section' })
This function can be used to override the default update behavior.
This function can be used to override the default receive behavior.
Removes the draggable functionality completely.
$('#example-destroy').sortable()
$('#example-destroy').sortable('destroy')
Disables the draggable.
$('#example-disable').sortable('disable')
Enables the draggable.
$('#example-enable').sortable('enable')
Gets an object containing key/value pairs representing the current draggable options hash.
var options = $('#example-option').sortable('option')
Gets the value currently associated with the specified optionName
.
var isDisabled = $('#example-option').sortable('option', 'disabled')
Sets the value of the sortable option associated with the specified optionName
.
$('#example-option').sortable('option', 'disabled', true)
Sets one or more options for the sortable.
$('#example-option').sortable('option', { disabled: true })
New items ar recognized automatically.
Serializes the sortable's item ids into a form/ajax submittable string. Calling this method produces a hash that can be appended to any url to easily submit a new item order back to the server.
It works by default by looking at the id of each item in the format "setname_number"
, and it spits out a hash like "setname[]=number&setname[]=number"
.
var arr = $('#example-toArray').sortable('toArray', {
attribute: 'data-foobar'
})
Triggered when an accepted draggable starts dragging. Can be an item of the list itself or an item of a connect sortable or draggable.
$(function() {
$('#example-activate-a').sortable()
.on('sortable:activate', function(e, ui) {
$('#example-activate-result').append('✓')
})
$('#example-activate-b').sortable({ connectWith: '#example-activate-a' })
$('.draggable.example-activate').draggable({ connectWith: '#example-activate-a' })
})
This event is triggered when sorting stops, but when the placeholder/helper is still available.
This event is triggered during sorting.
$(function() {
$('#example-change').sortable()
.on('sortable:change', function() {
$('#example-change-result').append('✓')
})
})
Triggered when the droppable is created.
Triggered when an accepted draggable stops dragging. Can be an item of the list itself or an item of a connect sortable or draggable.
$(function() {
$('#example-deactivate-a').sortable()
.on('sortable:deactivate', function(e, ui) {
$('#example-deactivate-result').append('✓')
})
$('#example-deactivate-b').sortable({ connectWith: '#example-deactivate-a' })
$('.draggable.example-deactivate').draggable({ connectWith: '#example-deactivate-a' })
})
This event is triggered when a connected sortable list has received a draggable or an item from another list.
$(function() {
$('#example-receive-a').sortable()
.on('sortable:receive', function(e, ui) {
$('#example-receive-result').append('✓')
})
$('#example-receive-b').sortable({ connectWith: '#example-receive-a' })
$('.draggable.example-receive').draggable({ connectWith: '#example-receive-a' })
})
This event is triggered when sorting starts.
This event is triggered when sorting has stopped.
This event is triggered when the user stopped sorting.
$(function() {
$('#example-update').sortable()
.on('sortable:update', function() {
$('#example-update-result').append('✓')
})
})