ad9121b27360d7c59d060fa94aab1f0d03d61dd95e875aa25dae0e71c60ae8ca13cf2fd41597af03039f3a2da6bee5840d205629e2b84e65938b39ceb7010d 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. # Sortable   [![Financial Contributors on Open Collective](https://opencollective.com/Sortable/all/badge.svg?label=financial+contributors)](https://opencollective.com/Sortable) [![CircleCI](https://circleci.com/gh/SortableJS/Sortable.svg?style=svg)](https://circleci.com/gh/SortableJS/Sortable) [![DeepScan grade](https://deepscan.io/api/teams/3901/projects/5666/branches/43977/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=3901&pid=5666&bid=43977) [![](https://data.jsdelivr.com/v1/package/npm/sortablejs/badge)](https://www.jsdelivr.com/package/npm/sortablejs) [![npm](https://img.shields.io/npm/v/sortablejs.svg)](https://www.npmjs.com/package/sortablejs)
  2. Sortable is a JavaScript library for reorderable drag-and-drop lists.
  3. Demo: http://sortablejs.github.io/Sortable/
  4. [<img width="250px" src="https://raw.githubusercontent.com/SortableJS/Sortable/HEAD/st/saucelabs.svg?sanitize=true">](https://saucelabs.com/)
  5. ## Features
  6. * Supports touch devices and [modern](http://caniuse.com/#search=drag) browsers (including IE9)
  7. * Can drag from one list to another or within the same list
  8. * CSS animation when moving items
  9. * Supports drag handles *and selectable text* (better than voidberg's html5sortable)
  10. * Smart auto-scrolling
  11. * Advanced swap detection
  12. * Smooth animations
  13. * [Multi-drag](https://github.com/SortableJS/Sortable/tree/master/plugins/MultiDrag) support
  14. * Support for CSS transforms
  15. * Built using native HTML5 drag and drop API
  16. * Supports
  17. * [Meteor](https://github.com/SortableJS/meteor-sortablejs)
  18. * Angular
  19. * [2.0+](https://github.com/SortableJS/angular-sortablejs)
  20. * [1.&ast;](https://github.com/SortableJS/angular-legacy-sortablejs)
  21. * React
  22. * [ES2015+](https://github.com/SortableJS/react-sortablejs)
  23. * [Mixin](https://github.com/SortableJS/react-mixin-sortablejs)
  24. * [Knockout](https://github.com/SortableJS/knockout-sortablejs)
  25. * [Polymer](https://github.com/SortableJS/polymer-sortablejs)
  26. * [Vue](https://github.com/SortableJS/Vue.Draggable)
  27. * [Ember](https://github.com/SortableJS/ember-sortablejs)
  28. * Supports any CSS library, e.g. [Bootstrap](#bs)
  29. * Simple API
  30. * Support for [plugins](#plugins)
  31. * [CDN](#cdn)
  32. * No jQuery required (but there is [support](https://github.com/SortableJS/jquery-sortablejs))
  33. * Typescript definitions at `@types/sortablejs`
  34. <br/>
  35. ### Articles
  36. * [Dragging Multiple Items in Sortable](https://github.com/SortableJS/Sortable/wiki/Dragging-Multiple-Items-in-Sortable) (April 26, 2019)
  37. * [Swap Thresholds and Direction](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction) (December 2, 2018)
  38. * [Sortable v1.0 — New capabilities](https://github.com/SortableJS/Sortable/wiki/Sortable-v1.0-—-New-capabilities/) (December 22, 2014)
  39. * [Sorting with the help of HTML5 Drag'n'Drop API](https://github.com/SortableJS/Sortable/wiki/Sorting-with-the-help-of-HTML5-Drag'n'Drop-API/) (December 23, 2013)
  40. <br/>
  41. ### Getting Started
  42. Install with NPM:
  43. ```bash
  44. $ npm install sortablejs --save
  45. ```
  46. Install with Bower:
  47. ```bash
  48. $ bower install --save sortablejs
  49. ```
  50. Import into your project:
  51. ```js
  52. // Default SortableJS
  53. import Sortable from 'sortablejs';
  54. // Core SortableJS (without default plugins)
  55. import Sortable from 'sortablejs/modular/sortable.core.esm.js';
  56. // Complete SortableJS (with all plugins)
  57. import Sortable from 'sortablejs/modular/sortable.complete.esm.js';
  58. ```
  59. Cherrypick plugins:
  60. ```js
  61. // Cherrypick extra plugins
  62. import Sortable, { MultiDrag, Swap } from 'sortablejs';
  63. Sortable.mount(new MultiDrag(), new Swap());
  64. // Cherrypick default plugins
  65. import Sortable, { AutoScroll } from 'sortablejs/modular/sortable.core.esm.js';
  66. Sortable.mount(new AutoScroll());
  67. ```
  68. ---
  69. ### Usage
  70. ```html
  71. <ul id="items">
  72. <li>item 1</li>
  73. <li>item 2</li>
  74. <li>item 3</li>
  75. </ul>
  76. ```
  77. ```js
  78. var el = document.getElementById('items');
  79. var sortable = Sortable.create(el);
  80. ```
  81. You can use any element for the list and its elements, not just `ul`/`li`. Here is an [example with `div`s](https://jsbin.com/visimub/edit?html,js,output).
  82. ---
  83. ### Options
  84. ```js
  85. var sortable = new Sortable(el, {
  86. group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] }
  87. sort: true, // sorting inside list
  88. delay: 0, // time in milliseconds to define when the sorting should start
  89. delayOnTouchOnly: false, // only delay if user is using touch
  90. touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event
  91. disabled: false, // Disables the sortable if set to true.
  92. store: null, // @see Store
  93. animation: 150, // ms, animation speed moving items when sorting, `0` — without animation
  94. easing: "cubic-bezier(1, 0, 0, 1)", // Easing for animation. Defaults to null. See https://easings.net/ for examples.
  95. handle: ".my-handle", // Drag handle selector within list items
  96. filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function)
  97. preventOnFilter: true, // Call `event.preventDefault()` when triggered `filter`
  98. draggable: ".item", // Specifies which items inside the element should be draggable
  99. dataIdAttr: 'data-id', // HTML attribute that is used by the `toArray()` method
  100. ghostClass: "sortable-ghost", // Class name for the drop placeholder
  101. chosenClass: "sortable-chosen", // Class name for the chosen item
  102. dragClass: "sortable-drag", // Class name for the dragging item
  103. swapThreshold: 1, // Threshold of the swap zone
  104. invertSwap: false, // Will always use inverted swap zone if set to true
  105. invertedSwapThreshold: 1, // Threshold of the inverted swap zone (will be set to swapThreshold value by default)
  106. direction: 'horizontal', // Direction of Sortable (will be detected automatically if not given)
  107. forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in
  108. fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback
  109. fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body
  110. fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag.
  111. dragoverBubble: false,
  112. removeCloneOnHide: true, // Remove the clone element when it is not showing, rather than just hiding it
  113. emptyInsertThreshold: 5, // px, distance mouse must be from empty sortable to insert drag element into it
  114. setData: function (/** DataTransfer */dataTransfer, /** HTMLElement*/dragEl) {
  115. dataTransfer.setData('Text', dragEl.textContent); // `dataTransfer` object of HTML5 DragEvent
  116. },
  117. // Element is chosen
  118. onChoose: function (/**Event*/evt) {
  119. evt.oldIndex; // element index within parent
  120. },
  121. // Element is unchosen
  122. onUnchoose: function(/**Event*/evt) {
  123. // same properties as onEnd
  124. },
  125. // Element dragging started
  126. onStart: function (/**Event*/evt) {
  127. evt.oldIndex; // element index within parent
  128. },
  129. // Element dragging ended
  130. onEnd: function (/**Event*/evt) {
  131. var itemEl = evt.item; // dragged HTMLElement
  132. evt.to; // target list
  133. evt.from; // previous list
  134. evt.oldIndex; // element's old index within old parent
  135. evt.newIndex; // element's new index within new parent
  136. evt.oldDraggableIndex; // element's old index within old parent, only counting draggable elements
  137. evt.newDraggableIndex; // element's new index within new parent, only counting draggable elements
  138. evt.clone // the clone element
  139. evt.pullMode; // when item is in another sortable: `"clone"` if cloning, `true` if moving
  140. },
  141. // Element is dropped into the list from another list
  142. onAdd: function (/**Event*/evt) {
  143. // same properties as onEnd
  144. },
  145. // Changed sorting within list
  146. onUpdate: function (/**Event*/evt) {
  147. // same properties as onEnd
  148. },
  149. // Called by any change to the list (add / update / remove)
  150. onSort: function (/**Event*/evt) {
  151. // same properties as onEnd
  152. },
  153. // Element is removed from the list into another list
  154. onRemove: function (/**Event*/evt) {
  155. // same properties as onEnd
  156. },
  157. // Attempt to drag a filtered element
  158. onFilter: function (/**Event*/evt) {
  159. var itemEl = evt.item; // HTMLElement receiving the `mousedown|tapstart` event.
  160. },
  161. // Event when you move an item in the list or between lists
  162. onMove: function (/**Event*/evt, /**Event*/originalEvent) {
  163. // Example: https://jsbin.com/nawahef/edit?js,output
  164. evt.dragged; // dragged HTMLElement
  165. evt.draggedRect; // DOMRect {left, top, right, bottom}
  166. evt.related; // HTMLElement on which have guided
  167. evt.relatedRect; // DOMRect
  168. evt.willInsertAfter; // Boolean that is true if Sortable will insert drag element after target by default
  169. originalEvent.clientY; // mouse position
  170. // return false; — for cancel
  171. // return -1; — insert before target
  172. // return 1; — insert after target
  173. // return true; — keep default insertion point based on the direction
  174. // return void; — keep default insertion point based on the direction
  175. },
  176. // Called when creating a clone of element
  177. onClone: function (/**Event*/evt) {
  178. var origEl = evt.item;
  179. var cloneEl = evt.clone;
  180. },
  181. // Called when dragging element changes position
  182. onChange: function(/**Event*/evt) {
  183. evt.newIndex // most likely why this event is used is to get the dragging element's current index
  184. // same properties as onEnd
  185. }
  186. });
  187. ```
  188. ---
  189. #### `group` option
  190. To drag elements from one list into another, both lists must have the same `group` value.
  191. You can also define whether lists can give away, give and keep a copy (`clone`), and receive elements.
  192. * name: `String` — group name
  193. * pull: `true|false|["foo", "bar"]|'clone'|function` — ability to move from the list. `clone` — copy the item, rather than move. Or an array of group names which the elements may be put in. Defaults to `true`.
  194. * put: `true|false|["baz", "qux"]|function` — whether elements can be added from other lists, or an array of group names from which elements can be added.
  195. * revertClone: `boolean` — revert cloned element to initial position after moving to a another list.
  196. Demo:
  197. - https://jsbin.com/hijetos/edit?js,output
  198. - https://jsbin.com/nacoyah/edit?js,output — use of complex logic in the `pull` and` put`
  199. - https://jsbin.com/bifuyab/edit?js,output — use `revertClone: true`
  200. ---
  201. #### `sort` option
  202. Allow sorting inside list.
  203. Demo: https://jsbin.com/jayedig/edit?js,output
  204. ---
  205. #### `delay` option
  206. Time in milliseconds to define when the sorting should start.
  207. Unfortunately, due to browser restrictions, delaying is not possible on IE or Edge with native drag & drop.
  208. Demo: https://jsbin.com/zosiwah/edit?js,output
  209. ---
  210. #### `delayOnTouchOnly` option
  211. Whether or not the delay should be applied only if the user is using touch (eg. on a mobile device). No delay will be applied in any other case. Defaults to `false`.
  212. ---
  213. #### `swapThreshold` option
  214. Percentage of the target that the swap zone will take up, as a float between `0` and `1`.
  215. [Read more](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#swap-threshold)
  216. Demo: http://sortablejs.github.io/Sortable#thresholds
  217. ---
  218. #### `invertSwap` option
  219. Set to `true` to set the swap zone to the sides of the target, for the effect of sorting "in between" items.
  220. [Read more](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#forcing-inverted-swap-zone)
  221. Demo: http://sortablejs.github.io/Sortable#thresholds
  222. ---
  223. #### `invertedSwapThreshold` option
  224. Percentage of the target that the inverted swap zone will take up, as a float between `0` and `1`. If not given, will default to `swapThreshold`.
  225. [Read more](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#dealing-with-swap-glitching)
  226. ---
  227. #### `direction` option
  228. Direction that the Sortable should sort in. Can be set to `'vertical'`, `'horizontal'`, or a function, which will be called whenever a target is dragged over. Must return `'vertical'` or `'horizontal'`.
  229. [Read more](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#direction)
  230. Example of direction detection for vertical list that includes full column and half column elements:
  231. ```js
  232. Sortable.create(el, {
  233. direction: function(evt, target, dragEl) {
  234. if (target !== null && target.className.includes('half-column') && dragEl.className.includes('half-column')) {
  235. return 'horizontal';
  236. }
  237. return 'vertical';
  238. }
  239. });
  240. ```
  241. ---
  242. #### `touchStartThreshold` option
  243. This option is similar to `fallbackTolerance` option.
  244. When the `delay` option is set, some phones with very sensitive touch displays like the Samsung Galaxy S8 will fire
  245. unwanted touchmove events even when your finger is not moving, resulting in the sort not triggering.
  246. This option sets the minimum pointer movement that must occur before the delayed sorting is cancelled.
  247. Values between 3 to 5 are good.
  248. ---
  249. #### `disabled` options
  250. Disables the sortable if set to `true`.
  251. Demo: https://jsbin.com/sewokud/edit?js,output
  252. ```js
  253. var sortable = Sortable.create(list);
  254. document.getElementById("switcher").onclick = function () {
  255. var state = sortable.option("disabled"); // get
  256. sortable.option("disabled", !state); // set
  257. };
  258. ```
  259. ---
  260. #### `handle` option
  261. To make list items draggable, Sortable disables text selection by the user.
  262. That's not always desirable. To allow text selection, define a drag handler,
  263. which is an area of every list element that allows it to be dragged around.
  264. Demo: https://jsbin.com/numakuh/edit?html,js,output
  265. ```js
  266. Sortable.create(el, {
  267. handle: ".my-handle"
  268. });
  269. ```
  270. ```html
  271. <ul>
  272. <li><span class="my-handle">::</span> list item text one
  273. <li><span class="my-handle">::</span> list item text two
  274. </ul>
  275. ```
  276. ```css
  277. .my-handle {
  278. cursor: move;
  279. cursor: -webkit-grabbing;
  280. }
  281. ```
  282. ---
  283. #### `filter` option
  284. ```js
  285. Sortable.create(list, {
  286. filter: ".js-remove, .js-edit",
  287. onFilter: function (evt) {
  288. var item = evt.item,
  289. ctrl = evt.target;
  290. if (Sortable.utils.is(ctrl, ".js-remove")) { // Click on remove button
  291. item.parentNode.removeChild(item); // remove sortable item
  292. }
  293. else if (Sortable.utils.is(ctrl, ".js-edit")) { // Click on edit link
  294. // ...
  295. }
  296. }
  297. })
  298. ```
  299. ---
  300. #### `ghostClass` option
  301. Class name for the drop placeholder (default `sortable-ghost`).
  302. Demo: https://jsbin.com/henuyiw/edit?css,js,output
  303. ```css
  304. .ghost {
  305. opacity: 0.4;
  306. }
  307. ```
  308. ```js
  309. Sortable.create(list, {
  310. ghostClass: "ghost"
  311. });
  312. ```
  313. ---
  314. #### `chosenClass` option
  315. Class name for the chosen item (default `sortable-chosen`).
  316. Demo: https://jsbin.com/hoqufox/edit?css,js,output
  317. ```css
  318. .chosen {
  319. color: #fff;
  320. background-color: #c00;
  321. }
  322. ```
  323. ```js
  324. Sortable.create(list, {
  325. delay: 500,
  326. chosenClass: "chosen"
  327. });
  328. ```
  329. ---
  330. #### `forceFallback` option
  331. If set to `true`, the Fallback for non HTML5 Browser will be used, even if we are using an HTML5 Browser.
  332. This gives us the possibility to test the behaviour for older Browsers even in newer Browser, or make the Drag 'n Drop feel more consistent between Desktop , Mobile and old Browsers.
  333. On top of that, the Fallback always generates a copy of that DOM Element and appends the class `fallbackClass` defined in the options. This behaviour controls the look of this 'dragged' Element.
  334. Demo: https://jsbin.com/sibiput/edit?html,css,js,output
  335. ---
  336. #### `fallbackTolerance` option
  337. Emulates the native drag threshold. Specify in pixels how far the mouse should move before it's considered as a drag.
  338. Useful if the items are also clickable like in a list of links.
  339. When the user clicks inside a sortable element, it's not uncommon for your hand to move a little between the time you press and the time you release.
  340. Dragging only starts if you move the pointer past a certain tolerance, so that you don't accidentally start dragging every time you click.
  341. 3 to 5 are probably good values.
  342. ---
  343. #### `dragoverBubble` option
  344. If set to `true`, the dragover event will bubble to parent sortables. Works on both fallback and native dragover event.
  345. By default, it is false, but Sortable will only stop bubbling the event once the element has been inserted into a parent Sortable, or *can* be inserted into a parent Sortable, but isn't at that specific time (due to animation, etc).
  346. Since 1.8.0, you will probably want to leave this option as false. Before 1.8.0, it may need to be `true` for nested sortables to work.
  347. ---
  348. #### `removeCloneOnHide` option
  349. If set to `false`, the clone is hidden by having it's CSS `display` property set to `none`.
  350. By default, this option is `true`, meaning Sortable will remove the cloned element from the DOM when it is supposed to be hidden.
  351. ---
  352. #### `emptyInsertThreshold` option
  353. The distance (in pixels) the mouse must be from an empty sortable while dragging for the drag element to be inserted into that sortable. Defaults to `5`. Set to `0` to disable this feature.
  354. Demo: https://jsbin.com/becavoj/edit?js,output
  355. An alternative to this option would be to set a padding on your list when it is empty.
  356. For example:
  357. ```css
  358. ul:empty {
  359. padding-bottom: 20px;
  360. }
  361. ```
  362. Warning: For `:empty` to work, it must have no node inside (even text one).
  363. Demo:
  364. https://jsbin.com/yunakeg/edit?html,css,js,output
  365. ---
  366. ### Event object ([demo](https://jsbin.com/fogujiv/edit?js,output))
  367. - to:`HTMLElement` — list, in which moved element
  368. - from:`HTMLElement` — previous list
  369. - item:`HTMLElement` — dragged element
  370. - clone:`HTMLElement`
  371. - oldIndex:`Number|undefined` — old index within parent
  372. - newIndex:`Number|undefined` — new index within parent
  373. - oldDraggableIndex: `Number|undefined` — old index within parent, only counting draggable elements
  374. - newDraggableIndex: `Number|undefined` — new index within parent, only counting draggable elements
  375. - pullMode:`String|Boolean|undefined` — Pull mode if dragging into another sortable (`"clone"`, `true`, or `false`), otherwise undefined
  376. #### `move` event object
  377. - to:`HTMLElement`
  378. - from:`HTMLElement`
  379. - dragged:`HTMLElement`
  380. - draggedRect:`DOMRect`
  381. - related:`HTMLElement` — element on which have guided
  382. - relatedRect:`DOMRect`
  383. - willInsertAfter:`Boolean` — `true` if will element be inserted after target (or `false` if before)
  384. ---
  385. ### Methods
  386. ##### option(name:`String`[, value:`*`]):`*`
  387. Get or set the option.
  388. ##### closest(el:`HTMLElement`[, selector:`String`]):`HTMLElement|null`
  389. For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
  390. ##### toArray():`String[]`
  391. Serializes the sortable's item `data-id`'s (`dataIdAttr` option) into an array of string.
  392. ##### sort(order:`String[]`, useAnimation:`Boolean`)
  393. Sorts the elements according to the array.
  394. ```js
  395. var order = sortable.toArray();
  396. sortable.sort(order.reverse(), true); // apply
  397. ```
  398. ##### save()
  399. Save the current sorting (see [store](#store))
  400. ##### destroy()
  401. Removes the sortable functionality completely.
  402. ---
  403. <a name="store"></a>
  404. ### Store
  405. Saving and restoring of the sort.
  406. ```html
  407. <ul>
  408. <li data-id="1">order</li>
  409. <li data-id="2">save</li>
  410. <li data-id="3">restore</li>
  411. </ul>
  412. ```
  413. ```js
  414. Sortable.create(el, {
  415. group: "localStorage-example",
  416. store: {
  417. /**
  418. * Get the order of elements. Called once during initialization.
  419. * @param {Sortable} sortable
  420. * @returns {Array}
  421. */
  422. get: function (sortable) {
  423. var order = localStorage.getItem(sortable.options.group.name);
  424. return order ? order.split('|') : [];
  425. },
  426. /**
  427. * Save the order of elements. Called onEnd (when the item is dropped).
  428. * @param {Sortable} sortable
  429. */
  430. set: function (sortable) {
  431. var order = sortable.toArray();
  432. localStorage.setItem(sortable.options.group.name, order.join('|'));
  433. }
  434. }
  435. })
  436. ```
  437. ---
  438. <a name="bs"></a>
  439. ### Bootstrap
  440. Demo: https://jsbin.com/visimub/edit?html,js,output
  441. ```html
  442. <!-- Latest compiled and minified CSS -->
  443. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/>
  444. <!-- Latest Sortable -->
  445. <script src="http://SortableJS.github.io/Sortable/Sortable.js"></script>
  446. <!-- Simple List -->
  447. <ul id="simpleList" class="list-group">
  448. <li class="list-group-item">This is <a href="http://SortableJS.github.io/Sortable/">Sortable</a></li>
  449. <li class="list-group-item">It works with Bootstrap...</li>
  450. <li class="list-group-item">...out of the box.</li>
  451. <li class="list-group-item">It has support for touch devices.</li>
  452. <li class="list-group-item">Just drag some elements around.</li>
  453. </ul>
  454. <script>
  455. // Simple list
  456. Sortable.create(simpleList, { /* options */ });
  457. </script>
  458. ```
  459. ---
  460. ### Static methods & properties
  461. ##### Sortable.create(el:`HTMLElement`[, options:`Object`]):`Sortable`
  462. Create new instance.
  463. ---
  464. ##### Sortable.active:`Sortable`
  465. The active Sortable instance.
  466. ---
  467. ##### Sortable.dragged:`HTMLElement`
  468. The element being dragged.
  469. ---
  470. ##### Sortable.ghost:`HTMLElement`
  471. The ghost element.
  472. ---
  473. ##### Sortable.clone:`HTMLElement`
  474. The clone element.
  475. ---
  476. ##### Sortable.get(element:`HTMLElement`):`Sortable`
  477. Get the Sortable instance on an element.
  478. ---
  479. ##### Sortable.mount(plugin:`...SortablePlugin|SortablePlugin[]`)
  480. Mounts a plugin to Sortable.
  481. ---
  482. ##### Sortable.utils
  483. * on(el`:HTMLElement`, event`:String`, fn`:Function`) — attach an event handler function
  484. * off(el`:HTMLElement`, event`:String`, fn`:Function`) — remove an event handler
  485. * css(el`:HTMLElement`)`:Object` — get the values of all the CSS properties
  486. * css(el`:HTMLElement`, prop`:String`)`:Mixed` — get the value of style properties
  487. * css(el`:HTMLElement`, prop`:String`, value`:String`) — set one CSS properties
  488. * css(el`:HTMLElement`, props`:Object`) — set more CSS properties
  489. * find(ctx`:HTMLElement`, tagName`:String`[, iterator`:Function`])`:Array` — get elements by tag name
  490. * bind(ctx`:Mixed`, fn`:Function`)`:Function` — Takes a function and returns a new one that will always have a particular context
  491. * is(el`:HTMLElement`, selector`:String`)`:Boolean` — check the current matched set of elements against a selector
  492. * closest(el`:HTMLElement`, selector`:String`[, ctx`:HTMLElement`])`:HTMLElement|Null` — for each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree
  493. * clone(el`:HTMLElement`)`:HTMLElement` — create a deep copy of the set of matched elements
  494. * toggleClass(el`:HTMLElement`, name`:String`, state`:Boolean`) — add or remove one classes from each element
  495. * detectDirection(el`:HTMLElement`)`:String` — automatically detect the [direction](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#direction) of the element as either `'vertical'` or `'horizontal'`
  496. ---
  497. ### Plugins
  498. #### Extra Plugins (included in complete versions)
  499. - [MultiDrag](https://github.com/SortableJS/Sortable/tree/master/plugins/MultiDrag)
  500. - [Swap](https://github.com/SortableJS/Sortable/tree/master/plugins/Swap)
  501. #### Default Plugins (included in default versions)
  502. - [AutoScroll](https://github.com/SortableJS/Sortable/tree/master/plugins/AutoScroll)
  503. - [OnSpill](https://github.com/SortableJS/Sortable/tree/master/plugins/OnSpill)
  504. ---
  505. <a name="cdn"></a>
  506. ### CDN
  507. ```html
  508. <!-- jsDelivr :: Sortable :: Latest (https://www.jsdelivr.com/package/npm/sortablejs) -->
  509. <script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
  510. ```
  511. ---
  512. ### Contributing (Issue/PR)
  513. Please, [read this](CONTRIBUTING.md).
  514. ---
  515. ## Contributors
  516. ### Code Contributors
  517. This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
  518. <a href="https://github.com/SortableJS/Sortable/graphs/contributors"><img src="https://opencollective.com/Sortable/contributors.svg?width=890&button=false" /></a>
  519. ### Financial Contributors
  520. Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/Sortable/contribute)]
  521. #### Individuals
  522. <a href="https://opencollective.com/Sortable"><img src="https://opencollective.com/Sortable/individuals.svg?width=890"></a>
  523. #### Organizations
  524. Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/Sortable/contribute)]
  525. <a href="https://opencollective.com/Sortable/organization/0/website"><img src="https://opencollective.com/Sortable/organization/0/avatar.svg"></a>
  526. <a href="https://opencollective.com/Sortable/organization/1/website"><img src="https://opencollective.com/Sortable/organization/1/avatar.svg"></a>
  527. <a href="https://opencollective.com/Sortable/organization/2/website"><img src="https://opencollective.com/Sortable/organization/2/avatar.svg"></a>
  528. <a href="https://opencollective.com/Sortable/organization/3/website"><img src="https://opencollective.com/Sortable/organization/3/avatar.svg"></a>
  529. <a href="https://opencollective.com/Sortable/organization/4/website"><img src="https://opencollective.com/Sortable/organization/4/avatar.svg"></a>
  530. <a href="https://opencollective.com/Sortable/organization/5/website"><img src="https://opencollective.com/Sortable/organization/5/avatar.svg"></a>
  531. <a href="https://opencollective.com/Sortable/organization/6/website"><img src="https://opencollective.com/Sortable/organization/6/avatar.svg"></a>
  532. <a href="https://opencollective.com/Sortable/organization/7/website"><img src="https://opencollective.com/Sortable/organization/7/avatar.svg"></a>
  533. <a href="https://opencollective.com/Sortable/organization/8/website"><img src="https://opencollective.com/Sortable/organization/8/avatar.svg"></a>
  534. <a href="https://opencollective.com/Sortable/organization/9/website"><img src="https://opencollective.com/Sortable/organization/9/avatar.svg"></a>
  535. ## MIT LICENSE
  536. Permission is hereby granted, free of charge, to any person obtaining
  537. a copy of this software and associated documentation files (the
  538. "Software"), to deal in the Software without restriction, including
  539. without limitation the rights to use, copy, modify, merge, publish,
  540. distribute, sublicense, and/or sell copies of the Software, and to
  541. permit persons to whom the Software is furnished to do so, subject to
  542. the following conditions:
  543. The above copyright notice and this permission notice shall be
  544. included in all copies or substantial portions of the Software.
  545. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  546. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  547. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  548. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  549. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  550. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  551. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.