Skip to content

Commit c8363dc

Browse files
committed
+ Intermediate version before release
2 parents c196b32 + b81f20c commit c8363dc

10 files changed

Lines changed: 771 additions & 219 deletions

File tree

Gruntfile.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,49 @@
1-
'use strict';
1+
module.exports = function (grunt) {
2+
'use strict';
23

3-
module.exports = function (grunt){
44
grunt.initConfig({
55
pkg: grunt.file.readJSON('package.json'),
66

77
version: {
88
src: ['<%= pkg.exportName %>.js', '*.json']
99
},
1010

11+
jshint: {
12+
all: ['*.js', '!*.min.js'],
13+
14+
options: {
15+
strict: true,
16+
newcap: false, // "Tolerate uncapitalized constructors"
17+
node: true,
18+
expr: true, // - true && call() "Expected an assignment or function call and instead saw an expression."
19+
supernew: true, // - "Missing '()' invoking a constructor."
20+
laxbreak: true,
21+
white: true,
22+
globals: {
23+
define: true,
24+
test: true,
25+
expect: true,
26+
module: true,
27+
asyncTest: true,
28+
start: true,
29+
ok: true,
30+
equal: true,
31+
notEqual: true,
32+
deepEqual: true,
33+
window: true,
34+
document: true,
35+
performance: true
36+
}
37+
}
38+
},
39+
1140
uglify: {
1241
options: {
1342
banner: '/*! <%= pkg.exportName %> <%= pkg.version %> - <%= pkg.license %> | <%= pkg.repository.url %> */\n'
1443
},
1544
dist: {
1645
files: {
17-
'<%= pkg.exportName %>.min.js': ['<%= pkg.exportName %>.js']
46+
'<%= pkg.exportName %>.min.js': ['<%= pkg.exportName %>.js']
1847
}
1948
}
2049
},
@@ -31,8 +60,8 @@ module.exports = function (grunt){
3160
});
3261

3362

34-
// These plugins provide necessary tasks.
3563
grunt.loadNpmTasks('grunt-version');
64+
grunt.loadNpmTasks('grunt-contrib-jshint');
3665
grunt.loadNpmTasks('grunt-contrib-uglify');
3766
grunt.loadNpmTasks('grunt-shell');
3867

@@ -44,6 +73,6 @@ module.exports = function (grunt){
4473
// grunt.regsterTask('meteor', ['shell:meteor-test', 'shell:meteor-publish']);
4574
grunt.registerTask('meteor', 'shell:meteor-publish');
4675

47-
// Default task.
48-
grunt.registerTask('default', ['version', 'uglify']);
76+
grunt.registerTask('tests', ['jshint']);
77+
grunt.registerTask('default', ['tests', 'version', 'uglify']);
4978
};

README.md

Lines changed: 93 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# Sortable
2-
32
Sortable is a minimalist JavaScript library for reorderable drag-and-drop lists.
43

54
Demo: http://rubaxa.github.io/Sortable/
65

6+
77
## Features
8-
* Supports touch devices and [modern](http://caniuse.com/#search=drag) browsers
9-
* Built using native HTML5 drag and drop API
10-
* Can drag from one list to another or within the same list
11-
* Supports drag handles *and selectable text* (better than voidberg's html5sortable)
12-
* Simple API
13-
* Lightweight, 2KB gzipped
14-
* No jQuery
8+
9+
* Supports touch devices and [modern](http://caniuse.com/#search=drag) browsers
10+
* Can drag from one list to another or within the same list
11+
* Animation moving items when sorting (css animation)
12+
* Supports drag handles *and selectable text* (better than voidberg's html5sortable)
13+
* Built using native HTML5 drag and drop API
14+
* Support [AngularJS](#ng)
15+
* Simple API
16+
* No jQuery
1517

1618

1719
### Usage
@@ -25,7 +27,7 @@ Demo: http://rubaxa.github.io/Sortable/
2527

2628
```js
2729
var el = document.getElementById('items');
28-
new Sortable(el);
30+
var sortable = Sortable.create(el);
2931
```
3032

3133

@@ -34,25 +36,39 @@ new Sortable(el);
3436

3537
### Options
3638
```js
37-
new Sortable(el, {
38-
group: "name",
39+
var sortabel = new Sortable(el, {
40+
group: "name", // or { name: "..", pull: [true, false, clone], put: [true, false, array] }
41+
sort: true, // sorting inside list
3942
store: null, // @see Store
43+
animation: 150, // ms, animation speed moving items when sorting, `0` — without animation
4044
handle: ".my-handle", // Drag handle selector within list items
41-
filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function)
45+
filter: ".ignor-elements", // Selectors that do not lead to dragging (String or Function)
4246
draggable: ".item", // Specifies which items inside the element should be sortable
4347
ghostClass: "sortable-ghost",
44-
48+
setData: function (dataTransfer, dragEl) {
49+
dataTransfer.setData('Text', dragEl.textContent);
50+
},
51+
4552
onStart: function (/**Event*/evt) { /* dragging */ },
4653
onEnd: function (/**Event*/evt) { /* dragging */ },
4754

55+
// Element is added to the list
4856
onAdd: function (/**Event*/evt){
4957
var itemEl = evt.item; // dragged HTMLElement
58+
itemEl.from; // previous list
5059
},
5160

61+
// Changed sorting in list
5262
onUpdate: function (/**Event*/evt){
5363
var itemEl = evt.item; // dragged HTMLElement
5464
},
5565

66+
// Called by any change to the list (add / update / remove)
67+
onSort: function (/**Event*/evt){
68+
var itemEl = evt.item; // dragged HTMLElement
69+
},
70+
71+
// The element is removed from the list
5672
onRemove: function (/**Event*/evt){
5773
var itemEl = evt.item; // dragged HTMLElement
5874
},
@@ -63,20 +79,24 @@ new Sortable(el, {
6379
});
6480
```
6581

66-
#### handle
82+
83+
---
84+
85+
86+
#### `handle` option
6787

6888
To make list items draggable, Sortable disables text selection by the user. That's not always desirable. To allow text selection, define a drag handler, which is an area of every list element that allows it to be dragged around.
6989

7090
```js
71-
new Sortable(el, {
91+
var sortable = new Sortable(el, {
7292
handle: ".my-handle",
7393
});
7494
```
7595

7696
```html
7797
<ul>
78-
<li><span class="my-handle">:: </span> list item text one
79-
<li><span class="my-handle">:: </span> list item text two
98+
<li><span class="my-handle">::</span> list item text one
99+
<li><span class="my-handle">::</span> list item text two
80100
</ul>
81101
```
82102

@@ -86,10 +106,61 @@ new Sortable(el, {
86106
}
87107
```
88108

109+
110+
---
111+
112+
113+
### `group` option
114+
115+
* name:`string` — group name
116+
* pull:`true|false|'clone'` — ability to move from the list. `clone` — cloning drag item when moving from the list.
117+
* put:`true|false|["foo", "bar"]` — the possibility of adding an element from the other list, or an array of names groups, which can be taken.
118+
119+
120+
---
121+
122+
<a name="ng"></a>
123+
### Support AngularJS
124+
Include [ng-sortable.js](ng-sortable.js)
125+
126+
```html
127+
<div ng-app"myApp">
128+
<ul ng-sortable>
129+
<li ng-repeat="item in items">{{item}}</li>
130+
</ul>
131+
132+
<ul ng-sortable="{ group: 'foobar' }">
133+
<li ng-repeat="item in foo">{{item}}</li>
134+
</ul>
135+
136+
<ul ng-sortable="barConfig">
137+
<li ng-repeat="item in bar">{{item}}</li>
138+
</ul>
139+
</div>
140+
```
141+
142+
143+
```js
144+
angular.module('myApp', ['ng-sortable'])
145+
.controller(function () {
146+
this.items = ['item 1', 'item 2'];
147+
this.foo = ['foo 1', '..'];
148+
this.bar = ['bar 1', '..'];
149+
this.barConfig = { group: 'foobar', animation: 150 };
150+
});
151+
```
152+
153+
89154
---
90155

91156

92-
### Methods
157+
### Method
158+
159+
160+
##### option(name:`String`[, value:`*`]):`*`
161+
Get or set the option.
162+
163+
93164

94165
##### closest(el:`String`[, selector:`HTMLElement`]):`HTMLElement|null`
95166
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.
@@ -117,13 +188,15 @@ Serializes the sortable's item `data-id`'s into an array of string.
117188

118189
##### sort(order:`String[]`)
119190
Sorts the elements according to the array.
191+
120192
```js
121193
var order = sortable.toArray();
122194
sortable.sort(order.reverse()); // apply
123195
```
124196

125197

126198
##### destroy()
199+
Removes the sortable functionality completely.
127200

128201

129202
---
@@ -141,7 +214,7 @@ Saving and restoring of the sort.
141214
```
142215

143216
```js
144-
new Sortable(el, {
217+
Sortable.create(el, {
145218
group: "localStorage-example",
146219
store: {
147220
/**
@@ -185,6 +258,7 @@ new Sortable(el, {
185258
* toggleClass(el`:HTMLElement`, name`:String`, state`:Boolean`) — add or remove one classes from each element
186259

187260

261+
188262
---
189263

190264

0 commit comments

Comments
 (0)