Skip to content

Commit 0212da3

Browse files
committed
Update pages. See main branch for changes
1 parent 27fbd12 commit 0212da3

File tree

7 files changed

+87
-30
lines changed

7 files changed

+87
-30
lines changed

index.html

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ <h1>jQuery Sortable</h1>
7979
Download
8080
<a href='js/jquery-sortable-min.js'>minified</a>
8181
version
82-
(8.3 kb)
82+
(8.2 kb, gzipped ~2.7 kb)
8383
</small>
8484
</p>
8585
</div>
@@ -263,7 +263,9 @@ <h2>Connected lists with drop animation</h2>
263263
<div class='row'>
264264
<div class="span12 example">
265265
<div class="CodeRay">
266-
<div class="code"><pre><span class="predefined">$</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">ol.simple_with_animation</span><span class="delimiter">&quot;</span></span>).sortable({
266+
<div class="code"><pre><span class="keyword">var</span> adjustment
267+
268+
<span class="predefined">$</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">ol.simple_with_animation</span><span class="delimiter">&quot;</span></span>).sortable({
267269
<span class="key">group</span>: <span class="string"><span class="delimiter">'</span><span class="content">simple_with_animation</span><span class="delimiter">'</span></span>,
268270
<span class="key">pullPlaceholder</span>: <span class="predefined-constant">false</span>,
269271
<span class="function">onDrop</span>: <span class="keyword">function</span> (item, targetContainer, _super) {
@@ -275,6 +277,23 @@ <h2>Connected lists with drop animation</h2>
275277
clonedItem.detach()
276278
_super(item)
277279
})
280+
},
281+
<span class="function">onDragStart</span>: <span class="keyword">function</span> (<span class="predefined">$item</span>, container, _super) {
282+
<span class="keyword">var</span> offset = <span class="predefined">$item</span>.offset(),
283+
pointer = container.rootGroup.pointer
284+
285+
adjustment = {
286+
<span class="key">left</span>: pointer.left - offset.left,
287+
<span class="key">top</span>: pointer.top - offset.top
288+
}
289+
290+
_super(<span class="predefined">$item</span>, container)
291+
},
292+
<span class="function">onDrag</span>: <span class="keyword">function</span> (<span class="predefined">$item</span>, position) {
293+
<span class="predefined">$item</span>.css({
294+
<span class="key">left</span>: position.left - adjustment.left,
295+
<span class="key">top</span>: position.top - adjustment.top
296+
})
278297
}
279298
})</pre></div>
280299
</div>
@@ -295,7 +314,7 @@ <h2>Connected lists with drop animation</h2>
295314
<strong>above a container</strong>
296315
</li>
297316
</ul>
298-
<p><div class="btn btn-primary show-code" data-toggle="button"><i class="icon-chevron-down"></i> show me the code</div></p>
317+
<p><div data-toggle="button" class="btn btn-primary show-code"><i class="icon-chevron-down"></i> show me the code</div></p>
299318
</div>
300319
<div class='span4'>
301320
<ol class='simple_with_animation vertical'>
@@ -361,7 +380,7 @@ <h2>Sort handle and limited drag/drop</h2>
361380
items on drag
362381
</li>
363382
</ul>
364-
<p><div class="btn btn-primary show-code" data-toggle="button"><i class="icon-chevron-down"></i> show me the code</div></p>
383+
<p><div data-toggle="button" class="btn btn-primary show-code"><i class="icon-chevron-down"></i> show me the code</div></p>
365384
</div>
366385
<div class='span4'>
367386
<h3>I'm draggable and droppable</h3>
@@ -468,7 +487,7 @@ <h2>Toggable nested lists</h2>
468487
lists
469488
</li>
470489
</ul>
471-
<p><div class="btn btn-primary show-code" data-toggle="button"><i class="icon-chevron-down"></i> show me the code</div></p>
490+
<p><div data-toggle="button" class="btn btn-primary show-code"><i class="icon-chevron-down"></i> show me the code</div></p>
472491
</div>
473492
<div class='span4'>
474493
<div class='switch-container'>
@@ -575,7 +594,7 @@ <h2>Connected lists with limited drop targets</h2>
575594
of the lists
576595
</li>
577596
</ul>
578-
<p><div class="btn btn-primary show-code" data-toggle="button"><i class="icon-chevron-down"></i> show me the code</div></p>
597+
<p><div data-toggle="button" class="btn btn-primary show-code"><i class="icon-chevron-down"></i> show me the code</div></p>
579598
<h3>Serialize result</h3>
580599
<pre id='serialize_output'></pre>
581600
</div>
@@ -776,7 +795,7 @@ <h2>
776795
to change the sorting behaviour
777796
</li>
778797
</ul>
779-
<p><div class="btn btn-primary show-code" data-toggle="button"><i class="icon-chevron-down"></i> show me the code</div></p>
798+
<p><div data-toggle="button" class="btn btn-primary show-code"><i class="icon-chevron-down"></i> show me the code</div></p>
780799
</div>
781800
<div class='span4'>
782801
<h3>Sortable Rows</h3>

js/application.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,10 +1215,10 @@ colors = jQuery.Color.names = {
12151215
return x+y;
12161216
}
12171217

1218-
Array.prototype.remove = function(from, to) {
1219-
var rest = this.slice((to || from) + 1 || this.length);
1220-
this.length = from < 0 ? this.length + from : from;
1221-
return this.push.apply(this, rest);
1218+
function remove(array, from, to) {
1219+
var rest = array.slice((to || from) + 1 || array.length);
1220+
array.length = from < 0 ? array.length + from : from;
1221+
return array.push.apply(array, rest);
12221222
}
12231223

12241224
function setDimensions(array, dimensions, useOffset) {
@@ -1456,7 +1456,7 @@ colors = jQuery.Color.names = {
14561456
},
14571457
removeContainer: function (container) {
14581458
var i = this.containers.indexOf(container)
1459-
this.containers.remove(i);
1459+
remove(this.containers, i);
14601460
},
14611461
scrolled: function (e) {
14621462
this.clearDimensions()
@@ -1609,7 +1609,7 @@ colors = jQuery.Color.names = {
16091609
var that = this,
16101610
childType = isContainer ? "item" : "container",
16111611

1612-
children = this.$getChildren(parent, childType).map(function () {
1612+
children = this.$getChildren(parent, childType).not(this.options.exclude).map(function () {
16131613
return that._serialize($(this), !isContainer)
16141614
}).get()
16151615

@@ -1729,6 +1729,8 @@ $(function () {
17291729
})
17301730
;
17311731
$(function () {
1732+
var adjustment
1733+
17321734
$("ol.simple_with_animation").sortable({
17331735
group: 'simple_with_animation',
17341736
pullPlaceholder: false,
@@ -1741,6 +1743,23 @@ $(function () {
17411743
clonedItem.detach()
17421744
_super(item)
17431745
})
1746+
},
1747+
onDragStart: function ($item, container, _super) {
1748+
var offset = $item.offset(),
1749+
pointer = container.rootGroup.pointer
1750+
1751+
adjustment = {
1752+
left: pointer.left - offset.left,
1753+
top: pointer.top - offset.top
1754+
}
1755+
1756+
_super($item, container)
1757+
},
1758+
onDrag: function ($item, position) {
1759+
$item.css({
1760+
left: position.left - adjustment.left,
1761+
top: position.top - adjustment.top
1762+
})
17441763
}
17451764
})
17461765
})

js/examples/simple_with_animation.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
$(function () {
2+
var adjustment
3+
24
$("ol.simple_with_animation").sortable({
35
group: 'simple_with_animation',
46
pullPlaceholder: false,
@@ -11,6 +13,23 @@ $(function () {
1113
clonedItem.detach()
1214
_super(item)
1315
})
16+
},
17+
onDragStart: function ($item, container, _super) {
18+
var offset = $item.offset(),
19+
pointer = container.rootGroup.pointer
20+
21+
adjustment = {
22+
left: pointer.left - offset.left,
23+
top: pointer.top - offset.top
24+
}
25+
26+
_super($item, container)
27+
},
28+
onDrag: function ($item, position) {
29+
$item.css({
30+
left: position.left - adjustment.left,
31+
top: position.top - adjustment.top
32+
})
1433
}
1534
})
1635
})

0 commit comments

Comments
 (0)