Skip to content

Commit 1999bcf

Browse files
committed
first version
1 parent f329d4a commit 1999bcf

File tree

4 files changed

+174
-12
lines changed

4 files changed

+174
-12
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/example/
2+
/node_modules/
3+
/package-lock.json

README.md

+78-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,80 @@
1-
# THIS PROJECT NEEDS A MAINTAINER.
1+
# jQuery SortableJS
22

3-
---
3+
A jQuery binding for SortableJS
44

5-
# HELP WANTED ;]
5+
## Installation
6+
7+
### Webpack/Browserify
8+
Install package:
9+
```
10+
npm i -D jquery-sortablejs
11+
```
12+
13+
Import into project:
14+
```javascript
15+
import 'jquery-sortablejs';
16+
```
17+
18+
### CDN:
19+
```HTML
20+
<script src="CDN HERE"></script>
21+
```
22+
23+
## Usage
24+
25+
### Initialization
26+
```javascript
27+
// Without options:
28+
$('#my-list').sortable();
29+
30+
// With options:
31+
$('#my-list').sortable({
32+
// SortableJS options go here
33+
// See: (https://github.com/SortableJS/Sortable#options)
34+
35+
handle: '.handle',
36+
invertSwap: true,
37+
// . . .
38+
})
39+
```
40+
41+
### Getting Sortable instance
42+
```javascript
43+
$('#my-list').sortable();
44+
45+
46+
var mySortableList = $('#my-list').sortable('widget');
47+
```
48+
49+
### Getting/Setting options
50+
Call `.sortable()` with the first argument as the option name and the second as the option value
51+
```javascript
52+
// Get an option
53+
var isDisabled = $('#my-list').sortable('disabled');
54+
55+
// Set an option
56+
$('#my-list').sortable('disabled', !isDisabled);
57+
```
58+
59+
### Destroying Sortable
60+
Pass `'destroy'` argument into `.sortable()`
61+
```javascript
62+
// Destroy Sortable
63+
$('#my-list').sortable('destroy');
64+
```
65+
66+
### Calling Sortable functions
67+
Pass the name of the function as string into `.sortable()`, followed by any arguments
68+
```javascript
69+
// Sortable toArray
70+
var order = $('#my-list').sortable('toArray');
71+
```
72+
73+
## License
74+
MIT License
75+
76+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
77+
78+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
79+
80+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

jquery-sortable.js

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
(function (factory) {
2+
"use strict";
3+
var sortable,
4+
jq,
5+
_this = this
6+
;
7+
8+
if (typeof define === "function" && define.amd) {
9+
try {
10+
define(["sortablejs", "jquery"], function(Sortable, $) {
11+
sortable = Sortable;
12+
jq = $;
13+
checkErrors();
14+
factory(Sortable, $);
15+
});
16+
} catch(err) {
17+
checkErrors();
18+
}
19+
return;
20+
} else if (typeof exports === 'object') {
21+
try {
22+
sortable = require('sortablejs');
23+
jq = require('jquery');
24+
} catch(err) { }
25+
}
26+
27+
if (typeof jQuery === 'function' || typeof $ === 'function') {
28+
jq = jQuery || $;
29+
}
30+
31+
if (typeof Sortable !== 'undefined') {
32+
sortable = Sortable;
33+
}
34+
35+
function checkErrors() {
36+
if (!jq) {
37+
throw new Error('jQuery is required for jquery-sortablejs');
38+
}
39+
40+
if (!sortable) {
41+
throw new Error('SortableJS is required for jquery-sortablejs (https://github.com/SortableJS/Sortable)');
42+
}
43+
}
44+
checkErrors();
45+
factory(sortable, jq);
46+
})(function (Sortable, $) {
47+
"use strict";
48+
49+
$.fn.sortable = function (options) {
50+
var retVal,
51+
args = arguments;
52+
53+
this.each(function () {
54+
var $el = $(this),
55+
sortable = $el.data('sortable');
56+
57+
if (!sortable && (options instanceof Object || !options)) {
58+
sortable = new Sortable(this, options);
59+
$el.data('sortable', sortable);
60+
} else if (sortable) {
61+
if (options === 'destroy') {
62+
sortable.destroy();
63+
$el.removeData('sortable');
64+
} else if (options === 'widget') {
65+
retVal = sortable;
66+
} else if (typeof sortable[options] === 'function') {
67+
retVal = sortable[options].apply(sortable, [].slice.call(args, 1));
68+
} else if (options in sortable.options) {
69+
retVal = sortable.option.apply(sortable, args);
70+
}
71+
}
72+
});
73+
74+
return (retVal === void 0) ? this : retVal;
75+
};
76+
});

package.json

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,31 @@
11
{
22
"name": "jquery-sortablejs",
3-
"version": "0.1.0",
4-
"description": "A jQuery binding to SortableJS.",
5-
"main": "jquery-sortable.js",
6-
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
8-
},
3+
"version": "1.0.0",
4+
"description": "A jQuery binding for SortableJS",
5+
"main": "./jquery-sortable.js",
96
"repository": {
107
"type": "git",
118
"url": "git+https://github.com/SortableJS/jquery-sortablejs.git"
129
},
1310
"keywords": [
14-
"jquery",
15-
"sortable"
11+
"sortable",
12+
"jQuery",
13+
"drag",
14+
"drop",
15+
"draggable",
16+
"sort",
17+
"reordering"
1618
],
17-
"author": "",
19+
"peerDependencies": {
20+
"jquery": "*",
21+
"sortablejs": "*"
22+
},
1823
"license": "MIT",
1924
"bugs": {
2025
"url": "https://github.com/SortableJS/jquery-sortablejs/issues"
2126
},
27+
"files": [
28+
"jquery-sortable.js"
29+
],
2230
"homepage": "https://github.com/SortableJS/jquery-sortablejs#readme"
2331
}

0 commit comments

Comments
 (0)