Skip to content

Commit fc9d177

Browse files
committed
Adding ability to include/exclude items. Fixes #4.
1 parent 98ce56a commit fc9d177

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

index.html

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@
1818
width: 460px;
1919
font-size: 0.9em;
2020
}
21-
.connected, .sortable {
21+
.connected, .sortable, .exclude {
2222
margin: auto;
2323
padding: 0;
24-
}
25-
.sortable.list {
26-
width: 300px;
24+
width: 310px;
25+
-webkit-touch-callout: none;
26+
-webkit-user-select: none;
27+
-khtml-user-select: none;
28+
-moz-user-select: none;
29+
-ms-user-select: none;
30+
user-select: none;
2731
}
2832
.sortable.grid {
29-
width: 410px;
3033
overflow: hidden;
3134
}
32-
.connected li, .sortable li {
35+
.connected li, .sortable li, .exclude li {
3336
list-style: none;
3437
border: 1px solid #CCC;
3538
background: #F6F6F6;
@@ -39,6 +42,9 @@
3942
padding: 5px;
4043
height: 22px;
4144
}
45+
li.disabled {
46+
opacity: 0.5;
47+
}
4248
.sortable.grid li {
4349
line-height: 80px;
4450
float: left;
@@ -92,8 +98,6 @@ <h2>Sortable List</h2>
9298
<li>Item 4</li>
9399
<li>Item 5</li>
94100
<li>Item 6</li>
95-
<li>Item 7</li>
96-
<li>Item 8</li>
97101
</ul>
98102
</section>
99103
<section>
@@ -105,8 +109,17 @@ <h2>Sortable Grid</h2>
105109
<li>Item 4</li>
106110
<li>Item 5</li>
107111
<li>Item 6</li>
108-
<li>Item 7</li>
109-
<li>Item 8</li>
112+
</ul>
113+
</section>
114+
<section>
115+
<h2>Exclude Items</h2>
116+
<ul class="exclude list">
117+
<li>Item 1</li>
118+
<li>Item 2</li>
119+
<li>Item 3</li>
120+
<li class="disabled">Item 4</li>
121+
<li class="disabled">Item 5</li>
122+
<li class="disabled">Item 6</li>
110123
</ul>
111124
</section>
112125
<section id="connected">
@@ -118,8 +131,6 @@ <h2>Connected Sortable Lists</h2>
118131
<li>Item 4</li>
119132
<li>Item 5</li>
120133
<li>Item 6</li>
121-
<li>Item 7</li>
122-
<li>Item 8</li>
123134
</ul>
124135
<ul class="connected list no2">
125136
<li class="highlight">Item 1</li>
@@ -128,8 +139,6 @@ <h2>Connected Sortable Lists</h2>
128139
<li class="highlight">Item 4</li>
129140
<li class="highlight">Item 5</li>
130141
<li class="highlight">Item 6</li>
131-
<li class="highlight">Item 7</li>
132-
<li class="highlight">Item 8</li>
133142
</ul>
134143
</section>
135144
<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>
@@ -141,6 +150,9 @@ <h2>Connected Sortable Lists</h2>
141150
$('.connected').sortable({
142151
connectWith: '.connected'
143152
});
153+
$('.exclude').sortable({
154+
items: ':not(.disabled)'
155+
});
144156
});
145157
</script>
146158
</body>

jquery.sortable.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
(function($) {
99
var dragging, placeholders = $();
1010
$.fn.sortable = function(options) {
11+
options = options || {};
1112
return this.each(function() {
12-
var index, items = $(this).children(), connectWith = false;
13+
var index, items = $(this).children(options.items), connectWith = options.connectWith || false;
1314
var placeholder = $('<' + items[0].tagName + '>').addClass('sortable-placeholder');
1415
placeholders = placeholders.add(placeholder);
15-
if (options && options.connectWith) {
16-
$(connectWith = options.connectWith).add(this).data('connectWith', connectWith);
17-
}
16+
$(connectWith).add(connectWith && this).data('connectWith', connectWith);
1817
items.attr('draggable', 'true').bind('dragstart', function(e) {
1918
var dt = e.originalEvent.dataTransfer;
2019
dt.effectAllowed = 'move';

0 commit comments

Comments
 (0)