jQuery plugin to allow dragging and dropping of elements and sorting of lists and other nested structures.

Overview

Drag and Drop

Basic jQuery plugin to allow drag and drop:

  • dragging
  • dropping of dragged elements
  • sorting of lists and other nested html structures (ul, ol, div etc.)

Requirements

  • jQuery

Usage

See demo.html for a working demo.

  1. Install draganddrop:

    $ bower install -S gardiner/draganddrop
  2. Include jQuery and draganddrop in document head:

    <link href='bower_components/draganddrop/src/draganddrop.css' rel='stylesheet' type='text/css'/>
    <script src='bower_components/jquery/dist/jquery.min.js' type='text/javascript'></script>
    <script src='bower_components/draganddrop/src/draganddrop.js' type='text/javascript'></script>
  3. Create html structure:

    <ul id="list">
        <li>Item 1</li>
        <li>Item 2
            <ul>
                <li>Subitem 1</li>
                <li>Subitem 2
                    <ul>
                        <li>Sub-Subitem 1</li>
                    </ul>
                </li>
            </ul>
        </li>
        <li>Item 3</li>
    </ul>
    
    <button id="drag">Drag me</button>
  4. Initialize draggable and sortable:

    $('#drag').draggable(/* options/callbacks or command */);
    $('#list').sortable(/* options/callbacks or command */);

Draggable

Options and callbacks:

  • handle (string) - selector of handle element (if null the complete element will be used as handle)
  • delegate (string) - selector of delegate element (allows delegate-binding, delegate will be referenced as this in the event callbacks)
  • revert (boolean) - if true the element reverts to its origin after dropping
  • placeholder (boolean) - if true a transparent clone of the element is left at the origin while dragging
  • droptarget (string) - selector for valid drop targets
  • scroll (boolean) - if true the scrolling parent will be automatically scrolled while dragging
  • update (function) - callback after dragging. Arguments: event, Draggable instance. This: draggable element.
  • drop (function) - callback after dropping on valid droptarget. Arguments: event, droptarget element. This: draggable.element

Commands:

$('#drag').draggable('destroy');
  • destroy - deactivates the Draggable instance and unbinds all listeners

Limitations/Issues:

When placeholder or revert is set to true, click events on the draggable element would be swallowed by the generated clone. For most browsers (except Internet Explorer) this has been fixed by setting the clone to pointer-events: none;.

Sortable

Options and callbacks:

  • handle (string) - selector of handle element (if null the complete element will be used as handle)
  • container (string) - selector for container elements
  • nodes (string) - selector for node elements
  • autocreate (boolean) - automatically create nested containers within nodes
  • group (boolean) - if true all elements in the jQuery object are grouped (items can dragged between them)
  • scroll (boolean) - if true the scrolling parent will be automatically scrolled while dragging
  • update (function) - callback after sorting. Arguments: event, Sortable instance. This: sortable element.

Commands:

$('#list').sortable('serialize');
$('#list').sortable('destroy');
  • serialize - returns an object representing the structure of the nested list
  • destroy - deactivates the Sortable instance and unbinds all listeners
Comments
  • Link Inside Sortable Element

    Link Inside Sortable Element

    Hello, congratulations for the script, very useful !!!

    unfortunately I have found this problem, I have not found a way to insert a link, inside one or more sortable elements.

    Tips? regards

    opened by MatrixMediaSrl 5
  • Bump jquery from 2.2.4 to 3.5.0

    Bump jquery from 2.2.4 to 3.5.0

    Bumps jquery from 2.2.4 to 3.5.0.

    Commits
    • 7a0a850 3.5.0
    • 8570a08 Release: Update AUTHORS.txt
    • da3dd85 Ajax: Do not execute scripts for unsuccessful HTTP responses
    • 065143c Ajax: Overwrite s.contentType with content-type header value, if any
    • 1a4f10d Tests: Blacklist one focusin test in IE
    • 9e15d6b Event: Use only one focusin/out handler per matching window & document
    • 966a709 Manipulation: Skip the select wrapper for <option> outside of IE 9
    • 1d61fd9 Manipulation: Make jQuery.htmlPrefilter an identity function
    • 04bf577 Selector: Update Sizzle from 2.3.4 to 2.3.5
    • 7506c9c Build: Resolve Travis config warnings
    • Additional commits viewable in compare view
    Maintainer changes

    This version was pushed to npm by mgol, a new releaser for jquery since your current version.


    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump jquery from 2.2.4 to 3.4.1

    Bump jquery from 2.2.4 to 3.4.1

    Bumps jquery from 2.2.4 to 3.4.1.

    Commits
    • 75f7e96 3.4.1
    • 7dddb19 Core: Make isAttached work with iOS 10.0-10.2
    • 6c1e7db Event: Prevent leverageNative from registering duplicate dummy handlers
    • 24d71ac Event: Fix handling of multiple async focus events
    • b4fadc9 Build: Test on Node.js 12, stop testing on Node.js 6 & 11
    • 0d4af52 Build: Fix unresolved jQuery reference in finalPropName
    • 22caea8 Build: Updating the 3.4-stable version to 3.4.1-pre
    • 59ea765 Release: update AUTHORS.txt
    • 7c1ef15 Release: update version to 3.4.0-pre
    • d940bc0 Build: Update Sizzle from 2.3.3 to 2.3.4
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot ignore this [patch|minor|major] version will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Remove items from a sortable list

    Remove items from a sortable list

    I created now a sortable list of thumbnails. This works like charm. :grinning:

    I want also to allow users to remove a thumbnail from the list, either by just dragging the thumb outside the parent container or to another container, working as "waste bin". For the latter, I tried to apply .draggable simultanously to the sortable items with a callback function for the drop target. But this does not work. (Of course, should I say).

    Is there a way I could accomplish this remove function one or the other way?

    (I must admit that my js knowledge is too limited to understand what's going on in the draganddrop.js.)

    opened by Phaet 8
  • Newly appended elements do not become draggable/sortable

    Newly appended elements do not become draggable/sortable

    I want to create a list of items dynamically by means of $( "#list").append(item). I noticed, though, that the items do not become sortable. I also tried to apply $("#list").sortable() after the list creation has been completed, but this does not work either. Is there something like .sortable('refresh') similar to what JQuery UI provides?

    opened by Phaet 2
  • Enhencement : being able to call a function while dragging

    Enhencement : being able to call a function while dragging

    Should be interesting to have an event enabling to refuse/accept the dragging horizontal and/or vertical user action.

    Use case : I use the plugin for dragging a zoomed image within a viewport and I would like to refuse the dragging out of the container. This is to say top and left css attribute should be, for example, comprise within the [-15,+15] interval.

    opened by pierat 0
  • Revert event callback function

    Revert event callback function

    Hi there and thank you for creating this plugin! It works very well. I needed a revert event callback for Draggables, so I added an else block for the if ($droptarget) { in the dragstop event of the Draggable that does a simple check for a self.options.onrevert and triggers it. If you think it's useful, I could possibly include it in a PR.

    opened by mavrosxristoforos 3
  • How to add click event for sub-element?

    How to add click event for sub-element?

    Hi there,

    Could you tell me how to add a click event for sub-element?

    As the below code you see, when I click the 'del' the click event not working. <h3>List of DIVs</h3> <div class="list parent"> <div><a onclick="alert('balabala');" style="color:red;">del</a>Child 1</div> <div><a onclick="alert('balabala');" style="color:red;">del</a>Child 2</div> <div> Child 3 <div class="list"> <div>Subchild</div> </div> </div> </div>

    opened by mincovip 1
Owner
Ole Trenner
Ole Trenner
:clock8: The original jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago").

timeago: a jQuery plugin Timeago is a jQuery plugin that makes it easy to support automatically updating fuzzy timestamps (e.g. "4 minutes ago" or "ab

Ryan McGeary 3.8k Dec 25, 2022
Countdown - jQuery CountDown Clock - Simple countdown plugin for product special offers

TronLink Wallet Address TRX - BTC - BTT - USDT: TH9RyofE7WiDDVVFLMJgFns2ByBRmgQzNB jQuery Countdown Clock jQuery countdown plugin that accounts for ti

E-Piksel 33 Aug 30, 2022
Nepali Date Picker jQuery Plugin 🇳🇵

Nepali Date Picker Nepali Date Picker jQuery Plugin for everyone. ???? Installation npm install nepali-date-picker Demo and Documentation https://leap

Leapfrog Technology 70 Sep 29, 2022
jQuery Timer: Start/Stop/Resume/Remove pretty timer inside any HTML element.

jQuery Timer plugin Lightweight, well tested jQuery pretty timer plugin Start, Pause, Resume and Remove a timer inside any HTML element. Get notified

Walmik Deshpande 291 Nov 4, 2022
Lightweight and simple JS date formatting and parsing

fecha Lightweight date formatting and parsing (~2KB). Meant to replace parsing and formatting functionality of moment.js. NPM npm install fecha --save

Taylor Hakes 2k Jan 5, 2023
A tiny and fast zero-dependency date-picker built with vanilla Javascript and CSS.

A tiny zero-dependency and framework-agnostic date picker that is incredibly easy to use! Compatible with any web UI framework, vanilla JS projects, and even HTML-only projects!

Nezar 1 Jan 22, 2021
Parse, validate, manipulate, and display dates in javascript.

Moment.js A JavaScript date library for parsing, validating, manipulating, and formatting dates. Project Status Moment.js is a legacy project, now in

Moment.js 47.1k Jan 2, 2023
⏱ A library for working with dates and times in JS

Luxon Luxon is a library for working with dates and times in JavaScript. DateTime.now().setZone("America/New_York").minus({ weeks: 1 }).endOf("day").t

Moment.js 13.4k Jan 9, 2023
A simple and reusable datepicker component for React

React Date Picker A simple and reusable Datepicker component for React (Demo) Installation The package can be installed via npm: npm install react-dat

HackerOne 7k Jan 4, 2023
🕑 js-joda is an immutable date and time library for JavaScript.

js-joda is an immutable date and time library for JavaScript. It provides a simple, domain-driven and clean API based on the ISO8601 calendar.

null 1.5k Dec 27, 2022
⚡️ Fast parsing, formatting and timezone manipulations for dates

node-cctz CCTZ is a C++ library for translating between absolute and civil times using the rules of a time zone. Install You will need C++11 compatibl

Vsevolod Strukchinsky 59 Oct 3, 2022
CalendarPickerJS - A minimalistic and modern date-picker component/library 🗓️👨🏽‍💻 Written in Vanilla JS

CalendarPickerJS The simple and pretty way to let a user select a day! Supports all major browser. Entirely written in Vanilla JavaScript with no depe

Mathias Picker 15 Dec 6, 2022
Simple drag and drop with dragula

Drag and drop so simple it hurts Official Angular wrapper for dragula. Notice: v2 has been released It contains a number of breaking changes. Follow t

Valor Software 1.9k Dec 18, 2022
Create Persian Calendar as html helper with tag builder c# , and convert selected persian date to gregorian date

Persian-Calendar Use JS,Html,CSS,C# White theme for Persian Calendar , easy to use. Create Persian Calendar as html helper. Use Tag builder in c# for

Tareq Awwad 4 Feb 28, 2022
A date picker web component, and spiritual successor to duet date picker

<date-picker> A date picker web component, based on duet date picker, except authored with Lit and using shadow DOM. This is a work in progress. Todo:

Nick Williams 25 Aug 3, 2022
This library provide a fast and easy way to work with date.

Calendar.js Calendar.js provide a fast way to work with dates when you don't wanna deal with hours, minute, second and so on. It means that Calendar.j

ActuallyNotaDev 3 Apr 27, 2022
jQuery plugin to sorting lists also the tree structures.

jquery-sortable-lists jQuery plugin to sorting lists also the tree structures. $('#myList').sortableLists( options ); You can sort an items of html li

camo 208 Dec 13, 2022
Ordered lists, flat or nested, multiple formats ordered lists.

logseq-plugin-ol 有序列表,单级或多级、多种样式的有序列表。 Ordered lists, flat or nested, multiple formats ordered lists. 使用展示 (Usage) 在想要展示为有序列表的块上添加一个以 #.ol 开头的标签就可以了。有

Seth Yuan 25 Jan 1, 2023
Nested Sort is a JavaScript library which helps you to sort a nested list of items via drag and drop.

Nested Sort Nested Sort is a vanilla JavaScript library, without any dependencies, which helps you to sort a nested list of items via drag and drop. U

Hesam Bahrami 40 Dec 7, 2022
Sorting visualizer to introduce students to different sorting algorithms, how they work, and how to apply them

sorting-visualizer Sorting visualizer to introduce students to different sorting algorithms, how they work, and how to apply them Iteration 1 Demo: ht

Aditya Malik 1 Nov 14, 2022