酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 26 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  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',
  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. },
  174. // Called when creating a clone of element
  175. onClone: function (/**Event*/evt) {
  176. var origEl = evt.item;
  177. var cloneEl = evt.clone;
  178. },
  179. // Called when dragging element changes position
  180. onChange: function(/**Event*/evt) {
  181. evt.newIndex // most likely why this event is used is to get the dragging element's current index
  182. // same properties as onEnd
  183. }
  184. });
  185. ```
  186. ---
  187. #### `group` option
  188. To drag elements from one list into another, both lists must have the same `group` value.
  189. You can also define whether lists can give away, give and keep a copy (`clone`), and receive elements.
  190. * name: `String` — group name
  191. * 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`.
  192. * 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.
  193. * revertClone: `boolean` — revert cloned element to initial position after moving to a another list.
  194. Demo:
  195. - https://jsbin.com/hijetos/edit?js,output
  196. - https://jsbin.com/nacoyah/edit?js,output — use of complex logic in the `pull` and` put`
  197. - https://jsbin.com/bifuyab/edit?js,output — use `revertClone: true`
  198. ---
  199. #### `sort` option
  200. Allow sorting inside list.
  201. Demo: https://jsbin.com/jayedig/edit?js,output
  202. ---
  203. #### `delay` option
  204. Time in milliseconds to define when the sorting should start.
  205. Unfortunately, due to browser restrictions, delaying is not possible on IE or Edge with native drag & drop.
  206. Demo: https://jsbin.com/zosiwah/edit?js,output
  207. ---
  208. #### `delayOnTouchOnly` option
  209. 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`.
  210. ---
  211. #### `swapThreshold` option
  212. Percentage of the target that the swap zone will take up, as a float between `0` and `1`.
  213. [Read more](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#swap-threshold)
  214. Demo: http://sortablejs.github.io/Sortable#thresholds
  215. ---
  216. #### `invertSwap` option
  217. Set to `true` to set the swap zone to the sides of the target, for the effect of sorting "in between" items.
  218. [Read more](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#forcing-inverted-swap-zone)
  219. Demo: http://sortablejs.github.io/Sortable#thresholds
  220. ---
  221. #### `invertedSwapThreshold` option
  222. 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`.
  223. [Read more](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#dealing-with-swap-glitching)
  224. ---
  225. #### `direction` option
  226. 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'`.
  227. [Read more](https://github.com/SortableJS/Sortable/wiki/Swap-Thresholds-and-Direction#direction)
  228. Example of direction detection for vertical list that includes full column and half column elements:
  229. ```js
  230. Sortable.create(el, {
  231. direction: function(evt, target, dragEl) {
  232. if (target !== null && target.className.includes('half-column') && dragEl.className.includes('half-column')) {
  233. return 'horizontal';
  234. }
  235. return 'vertical';
  236. }
  237. });
  238. ```
  239. ---
  240. #### `touchStartThreshold` option
  241. This option is similar to `fallbackTolerance` option.
  242. When the `delay` option is set, some phones with very sensitive touch displays like the Samsung Galaxy S8 will fire
  243. unwanted touchmove events even when your finger is not moving, resulting in the sort not triggering.
  244. This option sets the minimum pointer movement that must occur before the delayed sorting is cancelled.
  245. Values between 3 to 5 are good.
  246. ---
  247. #### `disabled` options
  248. Disables the sortable if set to `true`.
  249. Demo: https://jsbin.com/sewokud/edit?js,output
  250. ```js
  251. var sortable = Sortable.create(list);
  252. document.getElementById("switcher").onclick = function () {
  253. var state = sortable.option("disabled"); // get
  254. sortable.option("disabled", !state); // set
  255. };
  256. ```
  257. ---
  258. #### `handle` option
  259. To make list items draggable, Sortable disables text selection by the user.
  260. That's not always desirable. To allow text selection, define a drag handler,
  261. which is an area of every list element that allows it to be dragged around.
  262. Demo: https://jsbin.com/numakuh/edit?html,js,output
  263. ```js
  264. Sortable.create(el, {
  265. handle: ".my-handle"
  266. });
  267. ```
  268. ```html
  269. <ul>
  270. <li><span class="my-handle">::</span> list item text one
  271. <li><span class="my-handle">::</span> list item text two
  272. </ul>
  273. ```
  274. ```css
  275. .my-handle {
  276. cursor: move;
  277. cursor: -webkit-grabbing;
  278. }
  279. ```
  280. ---
  281. #### `filter` option
  282. ```js
  283. Sortable.create(list, {
  284. filter: ".js-remove, .js-edit",
  285. onFilter: function (evt) {
  286. var item = evt.item,
  287. ctrl = evt.target;
  288. if (Sortable.utils.is(ctrl, ".js-remove")) { // Click on remove button
  289. item.parentNode.removeChild(item); // remove sortable item
  290. }
  291. else if (Sortable.utils.is(ctrl, ".js-edit")) { // Click on edit link
  292. // ...
  293. }
  294. }
  295. })
  296. ```
  297. ---
  298. #### `ghostClass` option
  299. Class name for the drop placeholder (default `sortable-ghost`).
  300. Demo: https://jsbin.com/henuyiw/edit?css,js,output
  301. ```css
  302. .ghost {
  303. opacity: 0.4;
  304. }
  305. ```
  306. ```js
  307. Sortable.create(list, {
  308. ghostClass: "ghost"
  309. });
  310. ```
  311. ---
  312. #### `chosenClass` option
  313. Class name for the chosen item (default `sortable-chosen`).
  314. Demo: https://jsbin.com/hoqufox/edit?css,js,output
  315. ```css
  316. .chosen {
  317. color: #fff;
  318. background-color: #c00;
  319. }
  320. ```
  321. ```js
  322. Sortable.create(list, {
  323. delay: 500,
  324. chosenClass: "chosen"
  325. });
  326. ```
  327. ---
  328. #### `forceFallback` option
  329. If set to `true`, the Fallback for non HTML5 Browser will be used, even if we are using an HTML5 Browser.
  330. 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.
  331. 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.
  332. Demo: https://jsbin.com/sibiput/edit?html,css,js,output
  333. ---
  334. #### `fallbackTolerance` option
  335. Emulates the native drag threshold. Specify in pixels how far the mouse should move before it's considered as a drag.
  336. Useful if the items are also clickable like in a list of links.
  337. 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.
  338. Dragging only starts if you move the pointer past a certain tolerance, so that you don't accidentally start dragging every time you click.
  339. 3 to 5 are probably good values.
  340. ---
  341. #### `dragoverBubble` option
  342. If set to `true`, the dragover event will bubble to parent sortables. Works on both fallback and native dragover event.
  343. 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).
  344. 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.
  345. ---
  346. #### `removeCloneOnHide` option
  347. If set to `false`, the clone is hidden by having it's CSS `display` property set to `none`.
  348. By default, this option is `true`, meaning Sortable will remove the cloned element from the DOM when it is supposed to be hidden.
  349. ---
  350. #### `emptyInsertThreshold` option
  351. 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.
  352. Demo: https://jsbin.com/becavoj/edit?js,output
  353. ---
  354. ### Event object ([demo](https://jsbin.com/fogujiv/edit?js,output))
  355. - to:`HTMLElement` — list, in which moved element
  356. - from:`HTMLElement` — previous list
  357. - item:`HTMLElement` — dragged element
  358. - clone:`HTMLElement`
  359. - oldIndex:`Number|undefined` — old index within parent
  360. - newIndex:`Number|undefined` — new index within parent
  361. - oldDraggableIndex: `Number|undefined` — old index within parent, only counting draggable elements
  362. - newDraggableIndex: `Number|undefined` — new index within parent, only counting draggable elements
  363. - pullMode:`String|Boolean|undefined` — Pull mode if dragging into another sortable (`"clone"`, `true`, or `false`), otherwise undefined
  364. #### `move` event object
  365. - to:`HTMLElement`
  366. - from:`HTMLElement`
  367. - dragged:`HTMLElement`
  368. - draggedRect:`DOMRect`
  369. - related:`HTMLElement` — element on which have guided
  370. - relatedRect:`DOMRect`
  371. - willInsertAfter:`Boolean` — `true` if will element be inserted after target (or `false` if before)
  372. ---
  373. ### Method
  374. ##### option(name:`String`[, value:`*`]):`*`
  375. Get or set the option.
  376. ##### closest(el:`String`[, selector:`HTMLElement`]):`HTMLElement|null`
  377. 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.
  378. ##### toArray():`String[]`
  379. Serializes the sortable's item `data-id`'s (`dataIdAttr` option) into an array of string.
  380. ##### sort(order:`String[]`)
  381. Sorts the elements according to the array.
  382. ```js
  383. var order = sortable.toArray();
  384. sortable.sort(order.reverse()); // apply
  385. ```
  386. ##### save()
  387. Save the current sorting (see [store](#store))
  388. ##### destroy()
  389. Removes the sortable functionality completely.
  390. ---
  391. <a name="store"></a>
  392. ### Store
  393. Saving and restoring of the sort.
  394. ```html
  395. <ul>
  396. <li data-id="1">order</li>
  397. <li data-id="2">save</li>
  398. <li data-id="3">restore</li>
  399. </ul>
  400. ```
  401. ```js
  402. Sortable.create(el, {
  403. group: "localStorage-example",
  404. store: {
  405. /**
  406. * Get the order of elements. Called once during initialization.
  407. * @param {Sortable} sortable
  408. * @returns {Array}
  409. */
  410. get: function (sortable) {
  411. var order = localStorage.getItem(sortable.options.group.name);
  412. return order ? order.split('|') : [];
  413. },
  414. /**
  415. * Save the order of elements. Called onEnd (when the item is dropped).
  416. * @param {Sortable} sortable
  417. */
  418. set: function (sortable) {
  419. var order = sortable.toArray();
  420. localStorage.setItem(sortable.options.group.name, order.join('|'));
  421. }
  422. }
  423. })
  424. ```
  425. ---
  426. <a name="bs"></a>
  427. ### Bootstrap
  428. Demo: https://jsbin.com/visimub/edit?html,js,output
  429. ```html
  430. <!-- Latest compiled and minified CSS -->
  431. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/>
  432. <!-- Latest Sortable -->
  433. <script src="http://SortableJS.github.io/Sortable/Sortable.js"></script>
  434. <!-- Simple List -->
  435. <ul id="simpleList" class="list-group">
  436. <li class="list-group-item">This is <a href="http://SortableJS.github.io/Sortable/">Sortable</a></li>
  437. <li class="list-group-item">It works with Bootstrap...</li>
  438. <li class="list-group-item">...out of the box.</li>
  439. <li class="list-group-item">It has support for touch devices.</li>
  440. <li class="list-group-item">Just drag some elements around.</li>
  441. </ul>
  442. <script>
  443. // Simple list
  444. Sortable.create(simpleList, { /* options */ });
  445. </script>
  446. ```
  447. ---
  448. ### Static methods & properties
  449. ##### Sortable.create(el:`HTMLElement`[, options:`Object`]):`Sortable`
  450. Create new instance.
  451. ---
  452. ##### Sortable.active:`Sortable`
  453. The active Sortable instance.
  454. ---
  455. ##### Sortable.dragged:`HTMLElement`
  456. The element being dragged.
  457. ---
  458. ##### Sortable.ghost:`HTMLElement`
  459. The ghost element.
  460. ---
  461. ##### Sortable.clone:`HTMLElement`
  462. The clone element.
  463. ---
  464. ##### Sortable.get(element:`HTMLElement`):`Sortable`
  465. Get the Sortable instance on an element.
  466. ---
  467. ##### Sortable.mount(plugin:`...SortablePlugin|SortablePlugin[]`)
  468. Mounts a plugin to Sortable.
  469. ---
  470. ##### Sortable.utils
  471. * on(el`:HTMLElement`, event`:String`, fn`:Function`) — attach an event handler function
  472. * off(el`:HTMLElement`, event`:String`, fn`:Function`) — remove an event handler
  473. * css(el`:HTMLElement`)`:Object` — get the values of all the CSS properties
  474. * css(el`:HTMLElement`, prop`:String`)`:Mixed` — get the value of style properties
  475. * css(el`:HTMLElement`, prop`:String`, value`:String`) — set one CSS properties
  476. * css(el`:HTMLElement`, props`:Object`) — set more CSS properties
  477. * find(ctx`:HTMLElement`, tagName`:String`[, iterator`:Function`])`:Array` — get elements by tag name
  478. * bind(ctx`:Mixed`, fn`:Function`)`:Function` — Takes a function and returns a new one that will always have a particular context
  479. * is(el`:HTMLElement`, selector`:String`)`:Boolean` — check the current matched set of elements against a selector
  480. * 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
  481. * clone(el`:HTMLElement`)`:HTMLElement` — create a deep copy of the set of matched elements
  482. * toggleClass(el`:HTMLElement`, name`:String`, state`:Boolean`) — add or remove one classes from each element
  483. * 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'`
  484. ---
  485. ### Plugins
  486. #### Extra Plugins (included in complete versions)
  487. - [MultiDrag](https://github.com/SortableJS/Sortable/tree/master/plugins/MultiDrag)
  488. - [Swap](https://github.com/SortableJS/Sortable/tree/master/plugins/Swap)
  489. #### Default Plugins (included in default versions)
  490. - [AutoScroll](https://github.com/SortableJS/Sortable/tree/master/plugins/AutoScroll)
  491. - [OnSpill](https://github.com/SortableJS/Sortable/tree/master/plugins/OnSpill)
  492. ---
  493. <a name="cdn"></a>
  494. ### CDN
  495. ```html
  496. <!-- jsDelivr :: Sortable :: Latest (https://www.jsdelivr.com/package/npm/sortablejs) -->
  497. <script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
  498. ```
  499. ---
  500. ### Contributing (Issue/PR)
  501. Please, [read this](CONTRIBUTING.md).
  502. ---
  503. ## Contributors
  504. ### Code Contributors
  505. This project exists thanks to all the people who contribute. [[Contribute](CONTRIBUTING.md)].
  506. <a href="https://github.com/SortableJS/Sortable/graphs/contributors"><img src="https://opencollective.com/Sortable/contributors.svg?width=890&button=false" /></a>
  507. ### Financial Contributors
  508. Become a financial contributor and help us sustain our community. [[Contribute](https://opencollective.com/Sortable/contribute)]
  509. #### Individuals
  510. <a href="https://opencollective.com/Sortable"><img src="https://opencollective.com/Sortable/individuals.svg?width=890"></a>
  511. #### Organizations
  512. Support this project with your organization. Your logo will show up here with a link to your website. [[Contribute](https://opencollective.com/Sortable/contribute)]
  513. <a href="https://opencollective.com/Sortable/organization/0/website"><img src="https://opencollective.com/Sortable/organization/0/avatar.svg"></a>
  514. <a href="https://opencollective.com/Sortable/organization/1/website"><img src="https://opencollective.com/Sortable/organization/1/avatar.svg"></a>
  515. <a href="https://opencollective.com/Sortable/organization/2/website"><img src="https://opencollective.com/Sortable/organization/2/avatar.svg"></a>
  516. <a href="https://opencollective.com/Sortable/organization/3/website"><img src="https://opencollective.com/Sortable/organization/3/avatar.svg"></a>
  517. <a href="https://opencollective.com/Sortable/organization/4/website"><img src="https://opencollective.com/Sortable/organization/4/avatar.svg"></a>
  518. <a href="https://opencollective.com/Sortable/organization/5/website"><img src="https://opencollective.com/Sortable/organization/5/avatar.svg"></a>
  519. <a href="https://opencollective.com/Sortable/organization/6/website"><img src="https://opencollective.com/Sortable/organization/6/avatar.svg"></a>
  520. <a href="https://opencollective.com/Sortable/organization/7/website"><img src="https://opencollective.com/Sortable/organization/7/avatar.svg"></a>
  521. <a href="https://opencollective.com/Sortable/organization/8/website"><img src="https://opencollective.com/Sortable/organization/8/avatar.svg"></a>
  522. <a href="https://opencollective.com/Sortable/organization/9/website"><img src="https://opencollective.com/Sortable/organization/9/avatar.svg"></a>
  523. ## MIT LICENSE
  524. Permission is hereby granted, free of charge, to any person obtaining
  525. a copy of this software and associated documentation files (the
  526. "Software"), to deal in the Software without restriction, including
  527. without limitation the rights to use, copy, modify, merge, publish,
  528. distribute, sublicense, and/or sell copies of the Software, and to
  529. permit persons to whom the Software is furnished to do so, subject to
  530. the following conditions:
  531. The above copyright notice and this permission notice shall be
  532. included in all copies or substantial portions of the Software.
  533. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  534. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  535. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  536. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  537. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  538. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  539. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.