Skip to content

Commit a9b8468

Browse files
committed
Adding README and simplifing the code.
1 parent 870fe37 commit a9b8468

File tree

3 files changed

+43
-20
lines changed

3 files changed

+43
-20
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
HTML5 Sortable jQuery Plugin
2+
============================
3+
4+
**[See it in action](http://farhadi.github.com/html5sortable)**
5+
6+
Features
7+
--------
8+
* Less than 1KB (minified).
9+
* Built using native HTML5 drag and drop API.
10+
* Supports both list and grid style layouts.
11+
* Similar API and behaviour to jquery-ui sortable plugin.
12+
* Works in IE 6+, Firefox 3.5+, Chrome 3+, Safari 3+ and, Opera 12+.
13+
14+
Usage
15+
-----
16+
``` javascript
17+
$('.sortable').sortable().bind('sortupdate', function() {
18+
//Triggered when the user stopped sorting and the DOM position has changed.
19+
});
20+
```
21+
22+
License
23+
-------
24+
Released under the MIT license.

index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ <h2>Features</h2>
6060
<ul id="features">
6161
<li>Less than 1KB (minified).
6262
<li>Built using native HTML5 drag and drop API.</li>
63+
<li>Supports both list and grid style layouts.</li>
64+
<li>Similar API and behaviour to jquery-ui sortable plugin.</li>
6365
<li>Works in IE 6+, Firefox 3.5+, Chrome 3+, Safari 3+ and, Opera 12+.</li>
6466
<ul>
6567
</article>

jquery.sortable.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,8 @@
77
*/
88
jQuery.fn.sortable = function() {
99
return this.each(function() {
10-
var $ = jQuery, index, dragging, dropHandler, dragHandler, items = $(this).children();
11-
var dropHandler = function(e) {
12-
if (!dragging) return true;
13-
e.stopPropagation();
14-
placeholder.after(dragging);
15-
return false;
16-
};
17-
var dragHandler = function(e) {
18-
if (!dragging) return true;
19-
e.preventDefault();
20-
e.originalEvent.dataTransfer.dropEffect = 'move';
21-
if (items.is(this)) {
22-
dragging.hide();
23-
$(this)[placeholder.index() < $(this).index() ? 'after' : 'before'](placeholder);
24-
}
25-
return false;
26-
};
27-
var placeholder = $('<' + items[0].tagName + '>').addClass('sortable-placeholder')
28-
.bind('dragover', dragHandler).bind('drop', dropHandler);
10+
var $ = jQuery, index, dragging, items = $(this).children();
11+
var placeholder = $('<' + items[0].tagName + '>').addClass('sortable-placeholder');
2912

3013
items.attr('draggable', 'true').bind('dragstart', function(e) {
3114
var dt = e.originalEvent.dataTransfer;
@@ -43,6 +26,20 @@ jQuery.fn.sortable = function() {
4326
}).not('a[href], img').bind('selectstart', function() {
4427
this.dragDrop && this.dragDrop();
4528
return false;
46-
}).end().add(this).bind('dragover dragenter', dragHandler).bind('drop', dropHandler);
29+
}).end().add([this, placeholder]).bind('dragover dragenter', function(e) {
30+
if (!dragging) return true;
31+
e.preventDefault();
32+
e.originalEvent.dataTransfer.dropEffect = 'move';
33+
if (items.is(this)) {
34+
dragging.hide();
35+
$(this)[placeholder.index() < $(this).index() ? 'after' : 'before'](placeholder);
36+
}
37+
return false;
38+
}).bind('drop', function(e) {
39+
if (!dragging) return true;
40+
e.stopPropagation();
41+
placeholder.after(dragging);
42+
return false;
43+
});
4744
});
4845
};

0 commit comments

Comments
 (0)