Skip to content

Commit 3aa5272

Browse files
committed
First commit
0 parents  commit 3aa5272

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

index.html

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<!doctype html>
2+
<head>
3+
<meta charset="utf-8">
4+
<title>HTML5 Sortable jQuery Plugin</title>
5+
<style>
6+
h1, h2 {
7+
text-align: center;
8+
}
9+
ul {
10+
margin: auto;
11+
padding: 0;
12+
}
13+
.sortable.list {
14+
width: 300px;
15+
}
16+
.sortable.grid {
17+
width: 410px;
18+
overflow: hidden;
19+
}
20+
.sortable li {
21+
list-style: none;
22+
border: 1px solid #CCC;
23+
background: #F6F6F6;
24+
font: normal 1em "Tahoma";
25+
color: #1C94C4;
26+
margin: 5px;
27+
padding: 5px;
28+
height: 22px;
29+
}
30+
.sortable.grid li {
31+
line-height: 80px;
32+
float: left;
33+
width: 80px;
34+
height: 80px;
35+
text-align: center;
36+
}
37+
li.sortable-placeholder {
38+
border: 1px dashed #CCC;
39+
background: none;
40+
}
41+
</style>
42+
</head>
43+
44+
<body>
45+
<header>
46+
<h1>HTML5 Sortable jQuery Plugin</h1>
47+
</header>
48+
<article>
49+
<h2>Sortable List</h2>
50+
<ul class="sortable list">
51+
<li>Item 1</li>
52+
<li>Item 2</li>
53+
<li>Item 3</li>
54+
<li>Item 4</li>
55+
<li>Item 5</li>
56+
<li>Item 6</li>
57+
<li>Item 7</li>
58+
<li>Item 8</li>
59+
</ul>
60+
</article>
61+
<article>
62+
<h2>Sortable Grid</h2>
63+
<ul class="sortable grid">
64+
<li>Item 1</li>
65+
<li>Item 2</li>
66+
<li>Item 3</li>
67+
<li>Item 4</li>
68+
<li>Item 5</li>
69+
<li>Item 6</li>
70+
<li>Item 7</li>
71+
<li>Item 8</li>
72+
</ul>
73+
</article>
74+
<a href="http://github.com/farhadi/html5sortable"><img style="position: absolute; top: 0; left: 0; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/edc6dae7a1079163caf7f17c60495bbb6d027c93/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f6c6566745f677265656e5f3030373230302e706e67" alt="Fork me on GitHub"></a>
75+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
76+
<script src="jquery.sortable.js"></script>
77+
<script>
78+
$(function() {
79+
$('.sortable').sortable();
80+
});
81+
</script>
82+
</body>
83+
</html>

jquery.sortable.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* HTML5 Sortable jQuery Plugin
3+
* http://farhadi.github.com/html5sortable
4+
*
5+
* Copyright 2012, Ali Farhadi
6+
* Released under the MIT license.
7+
*/
8+
jQuery.fn.sortable = function() {
9+
return this.each(function() {
10+
var $ = jQuery, 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 (this !== placeholder[0] && this !== placeholder.parent()[0]) {
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);
29+
30+
items.attr('draggable', 'true').bind('dragstart', function(e) {
31+
var dt = e.originalEvent.dataTransfer;
32+
dt.effectAllowed = 'move';
33+
dt.setData('Text', 'dummy');
34+
dragging = $(this).addClass('sortable-dragging');
35+
}).bind('dragend', function() {
36+
dragging.removeClass('sortable-dragging').fadeIn();
37+
placeholder.detach();
38+
dragging = null;
39+
}).not('a[href], img').bind('selectstart', function() {
40+
this.dragDrop && this.dragDrop();
41+
return false;
42+
}).end().add(this).bind('dragover dragenter', dragHandler).bind('drop', dropHandler);
43+
});
44+
};

0 commit comments

Comments
 (0)