Skip to content

Commit

Permalink
Update to v0.14.0. Handle KO deferred updates. Update to KO 3.4.
Browse files Browse the repository at this point in the history
  • Loading branch information
rniemeyer committed Jun 17, 2016
1 parent 569bf61 commit 484c4fa
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 163 deletions.
1 change: 0 additions & 1 deletion bower.json
Expand Up @@ -6,7 +6,6 @@
{ "name": "Ryan Niemeyer" }
],
"license": "MIT",
"version": "0.13.1",
"main": "./build/knockout-sortable.min.js",
"ignore": [
"examples",
Expand Down
31 changes: 22 additions & 9 deletions build/knockout-sortable.js
@@ -1,4 +1,4 @@
// knockout-sortable 0.13.1 | (c) 2016 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
// knockout-sortable 0.14.0 | (c) 2016 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
;(function(factory) {
if (typeof define === "function" && define.amd) {
// AMD anonymous module
Expand Down Expand Up @@ -168,6 +168,8 @@
//initialize sortable binding after template binding has rendered in update function
var createTimeout = setTimeout(function() {
var dragItem;
var originalReceive = sortable.options.receive;

$element.sortable(ko.utils.extend(sortable.options, {
start: function(event, ui) {
//track original index
Expand All @@ -181,6 +183,11 @@
}
},
receive: function(event, ui) {
//optionally apply an existing receive handler
if (typeof originalReceive === "function") {
originalReceive.call(this, event, ui);
}

dragItem = dataGet(ui.item[0], DRAGKEY);
if (dragItem) {
//copy the model item, if a clone option is provided
Expand All @@ -200,6 +207,9 @@
parentEl = ui.item.parent()[0],
item = dataGet(el, ITEMKEY) || dragItem;

if (!item) {
$(el).remove();
}
dragItem = null;

//make sure that moves only run once, as update fires on multiple containers
Expand Down Expand Up @@ -259,6 +269,11 @@
if (ko.processAllDeferredBindingUpdates) {
ko.processAllDeferredBindingUpdates();
}

//if using deferred updates on knockout 3.4, force updates
if (ko.options.deferUpdates) {
ko.tasks.runEarly();
}
}

targetParent.splice(targetIndex, 0, item);
Expand All @@ -274,12 +289,6 @@
// moving from one list to another

sourceParent.splice(sourceIndex, 1);

//if using deferred updates plugin, force updates
if (ko.processAllDeferredBindingUpdates) {
ko.processAllDeferredBindingUpdates();
}

targetParent.splice(targetIndex, 0, item);

//rendering is handled by manipulating the observableArray; ignore dropped element
Expand All @@ -291,15 +300,19 @@
var underlyingList = unwrap(sourceParent);

// notify 'beforeChange' subscribers
sourceParent.valueWillMutate();
if (sourceParent.valueWillMutate) {
sourceParent.valueWillMutate();
}

// move from source index ...
underlyingList.splice(sourceIndex, 1);
// ... to target index
underlyingList.splice(targetIndex, 0, item);

// notify subscribers
sourceParent.valueHasMutated();
if (sourceParent.valueHasMutated) {
sourceParent.valueHasMutated();
}
}
}
else {
Expand Down
4 changes: 2 additions & 2 deletions build/knockout-sortable.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/connectedLists.html
Expand Up @@ -7,7 +7,7 @@
<script type='text/javascript' src='../ext/jquery-1.9.1.js'></script>
<script type="text/javascript" src="../ext/jquery-ui.js"></script>

<script type='text/javascript' src="../ext/knockout-3.3.0.js"></script>
<script type='text/javascript' src="../ext/knockout-3.4.0.js"></script>
<script type='text/javascript' src="../build/knockout-sortable.min.js"></script>

<style type='text/css'>
Expand Down
6 changes: 3 additions & 3 deletions examples/draggable.html
Expand Up @@ -7,7 +7,7 @@
<script type='text/javascript' src='../ext/jquery-1.9.1.js'></script>
<script type="text/javascript" src="../ext/jquery-ui.js"></script>

<script type='text/javascript' src="../ext/knockout-3.3.0.js"></script>
<script type='text/javascript' src="../ext/knockout-3.4.0.js"></script>
<script type='text/javascript' src="../build/knockout-sortable.min.js"></script>

<style type='text/css'>
Expand Down Expand Up @@ -86,7 +86,7 @@ <h3>Tasks</h3>
</span>
<span data-bind="visibleAndSelect: $root.isTaskSelected($data)">
<input data-bind="value: name, event: { blur: $root.clearTask }" />
</span>
</span>
</div>
</div>

Expand Down Expand Up @@ -160,4 +160,4 @@ <h3>Tasks</h3>
ko.applyBindings(new ViewModel());
</script>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions examples/seatingChart.html
Expand Up @@ -57,8 +57,8 @@

<script type='text/javascript' src='../ext/jquery-1.9.1.js'></script>
<script type="text/javascript" src="../ext/jquery-ui.js"></script>
<script type='text/javascript' src="../ext/knockout-3.3.0.js"></script>
<script type='text/javascript' src="../ext/knockout-3.4.0.js"></script>
<script type='text/javascript' src="../build/knockout-sortable.min.js"></script>
<script type='text/javascript' src="seatingChart.js"></script>
</body>
</html>
</html>
6 changes: 3 additions & 3 deletions examples/singleList.html
Expand Up @@ -7,7 +7,7 @@
<script type='text/javascript' src='../ext/jquery-1.9.1.js'></script>
<script type="text/javascript" src="../ext/jquery-ui.js"></script>

<script type='text/javascript' src="../ext/knockout-3.3.0.js"></script>
<script type='text/javascript' src="../ext/knockout-3.4.0.js"></script>
<script type='text/javascript' src="../build/knockout-sortable.js"></script>

<style type='text/css'>
Expand Down Expand Up @@ -81,7 +81,7 @@ <h3>Tasks</h3>
</span>
<span data-bind="visibleAndSelect: $root.isTaskSelected($data)">
<input data-bind="value: name, event: { blur: $root.clearTask }" />
</span>
</span>
</div>
<!-- trailing comment -->
</div>
Expand Down Expand Up @@ -141,4 +141,4 @@ <h3>Tasks</h3>
ko.applyBindings(new ViewModel());
</script>
</body>
</html>
</html>

0 comments on commit 484c4fa

Please sign in to comment.