-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
174 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/example/ | ||
/node_modules/ | ||
/package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,80 @@ | ||
# THIS PROJECT NEEDS A MAINTAINER. | ||
# jQuery SortableJS | ||
|
||
--- | ||
A jQuery binding for SortableJS | ||
|
||
# HELP WANTED ;] | ||
## Installation | ||
|
||
### Webpack/Browserify | ||
Install package: | ||
``` | ||
npm i -D jquery-sortablejs | ||
``` | ||
|
||
Import into project: | ||
```javascript | ||
import 'jquery-sortablejs'; | ||
``` | ||
|
||
### CDN: | ||
```HTML | ||
<script src="CDN HERE"></script> | ||
``` | ||
|
||
## Usage | ||
|
||
### Initialization | ||
```javascript | ||
// Without options: | ||
$('#my-list').sortable(); | ||
|
||
// With options: | ||
$('#my-list').sortable({ | ||
// SortableJS options go here | ||
// See: (https://github.com/SortableJS/Sortable#options) | ||
|
||
handle: '.handle', | ||
invertSwap: true, | ||
// . . . | ||
}) | ||
``` | ||
|
||
### Getting Sortable instance | ||
```javascript | ||
$('#my-list').sortable(); | ||
|
||
|
||
var mySortableList = $('#my-list').sortable('widget'); | ||
``` | ||
|
||
### Getting/Setting options | ||
Call `.sortable()` with the first argument as the option name and the second as the option value | ||
```javascript | ||
// Get an option | ||
var isDisabled = $('#my-list').sortable('disabled'); | ||
|
||
// Set an option | ||
$('#my-list').sortable('disabled', !isDisabled); | ||
``` | ||
|
||
### Destroying Sortable | ||
Pass `'destroy'` argument into `.sortable()` | ||
```javascript | ||
// Destroy Sortable | ||
$('#my-list').sortable('destroy'); | ||
``` | ||
|
||
### Calling Sortable functions | ||
Pass the name of the function as string into `.sortable()`, followed by any arguments | ||
```javascript | ||
// Sortable toArray | ||
var order = $('#my-list').sortable('toArray'); | ||
``` | ||
|
||
## License | ||
MIT License | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
(function (factory) { | ||
"use strict"; | ||
var sortable, | ||
jq, | ||
_this = this | ||
; | ||
|
||
if (typeof define === "function" && define.amd) { | ||
try { | ||
define(["sortablejs", "jquery"], function(Sortable, $) { | ||
sortable = Sortable; | ||
jq = $; | ||
checkErrors(); | ||
factory(Sortable, $); | ||
}); | ||
} catch(err) { | ||
checkErrors(); | ||
} | ||
return; | ||
} else if (typeof exports === 'object') { | ||
try { | ||
sortable = require('sortablejs'); | ||
jq = require('jquery'); | ||
} catch(err) { } | ||
} | ||
|
||
if (typeof jQuery === 'function' || typeof $ === 'function') { | ||
jq = jQuery || $; | ||
} | ||
|
||
if (typeof Sortable !== 'undefined') { | ||
sortable = Sortable; | ||
} | ||
|
||
function checkErrors() { | ||
if (!jq) { | ||
throw new Error('jQuery is required for jquery-sortablejs'); | ||
} | ||
|
||
if (!sortable) { | ||
throw new Error('SortableJS is required for jquery-sortablejs (https://github.com/SortableJS/Sortable)'); | ||
} | ||
} | ||
checkErrors(); | ||
factory(sortable, jq); | ||
})(function (Sortable, $) { | ||
"use strict"; | ||
|
||
$.fn.sortable = function (options) { | ||
var retVal, | ||
args = arguments; | ||
|
||
this.each(function () { | ||
var $el = $(this), | ||
sortable = $el.data('sortable'); | ||
|
||
if (!sortable && (options instanceof Object || !options)) { | ||
sortable = new Sortable(this, options); | ||
$el.data('sortable', sortable); | ||
} else if (sortable) { | ||
if (options === 'destroy') { | ||
sortable.destroy(); | ||
$el.removeData('sortable'); | ||
} else if (options === 'widget') { | ||
retVal = sortable; | ||
} else if (typeof sortable[options] === 'function') { | ||
retVal = sortable[options].apply(sortable, [].slice.call(args, 1)); | ||
} else if (options in sortable.options) { | ||
retVal = sortable.option.apply(sortable, args); | ||
} | ||
} | ||
}); | ||
|
||
return (retVal === void 0) ? this : retVal; | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
{ | ||
"name": "jquery-sortablejs", | ||
"version": "0.1.0", | ||
"description": "A jQuery binding to SortableJS.", | ||
"main": "jquery-sortable.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"version": "1.0.0", | ||
"description": "A jQuery binding for SortableJS", | ||
"main": "./jquery-sortable.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/SortableJS/jquery-sortablejs.git" | ||
}, | ||
"keywords": [ | ||
"jquery", | ||
"sortable" | ||
"sortable", | ||
"jQuery", | ||
"drag", | ||
"drop", | ||
"draggable", | ||
"sort", | ||
"reordering" | ||
], | ||
"author": "", | ||
"peerDependencies": { | ||
"jquery": "*", | ||
"sortablejs": "*" | ||
}, | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/SortableJS/jquery-sortablejs/issues" | ||
}, | ||
"files": [ | ||
"jquery-sortable.js" | ||
], | ||
"homepage": "https://github.com/SortableJS/jquery-sortablejs#readme" | ||
} |