|
|
@ -1,55 +1,61 @@ |
|
|
|
|
|
|
|
/*global ko*/ |
|
|
|
|
|
|
|
|
|
|
|
(function (factory) { |
|
|
|
(function (factory) { |
|
|
|
"use strict"; |
|
|
|
"use strict"; |
|
|
|
//get ko ref via global or require
|
|
|
|
//get ko ref via global or require
|
|
|
|
var koRef; |
|
|
|
var koRef; |
|
|
|
if (typeof ko !== 'undefined') { |
|
|
|
if (typeof ko !== 'undefined') { |
|
|
|
//global ref already defined
|
|
|
|
//global ref already defined
|
|
|
|
koRef = ko; |
|
|
|
koRef = ko; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') { |
|
|
|
else if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') { |
|
|
|
//commonjs / node.js
|
|
|
|
//commonjs / node.js
|
|
|
|
koRef = require('knockout'); |
|
|
|
koRef = require('knockout'); |
|
|
|
} |
|
|
|
} |
|
|
|
//get sortable ref via global or require
|
|
|
|
//get sortable ref via global or require
|
|
|
|
var sortableRef; |
|
|
|
var sortableRef; |
|
|
|
if (typeof Sortable !== 'undefined') { |
|
|
|
if (typeof Sortable !== 'undefined') { |
|
|
|
//global ref already defined
|
|
|
|
//global ref already defined
|
|
|
|
sortableRef = Sortable; |
|
|
|
sortableRef = Sortable; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') { |
|
|
|
else if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') { |
|
|
|
//commonjs / node.js
|
|
|
|
//commonjs / node.js
|
|
|
|
sortableRef = require('sortablejs'); |
|
|
|
sortableRef = require('sortablejs'); |
|
|
|
} |
|
|
|
} |
|
|
|
//use references if we found them
|
|
|
|
//use references if we found them
|
|
|
|
if (koRef !== undefined && sortableRef !== undefined) { |
|
|
|
if (koRef !== undefined && sortableRef !== undefined) { |
|
|
|
factory(koRef, sortableRef); |
|
|
|
factory(koRef, sortableRef); |
|
|
|
} |
|
|
|
} |
|
|
|
//if both references aren't found yet, get via AMD if available
|
|
|
|
//if both references aren't found yet, get via AMD if available
|
|
|
|
else if (typeof define === 'function' && define.amd){ |
|
|
|
else if (typeof define === 'function' && define.amd) { |
|
|
|
//we may have a reference to only 1, or none
|
|
|
|
//we may have a reference to only 1, or none
|
|
|
|
if (koRef !== undefined && sortableRef === undefined) { |
|
|
|
if (koRef !== undefined && sortableRef === undefined) { |
|
|
|
define(['./Sortable'], function(amdSortableRef){ factory(koRef, amdSortableRef); }); |
|
|
|
define(['./Sortable'], function (amdSortableRef) { |
|
|
|
} |
|
|
|
factory(koRef, amdSortableRef); |
|
|
|
else if (koRef === undefined && sortableRef !== undefined) { |
|
|
|
}); |
|
|
|
define(['knockout'], function(amdKnockout){ factory(amdKnockout, sortableRef); }); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (koRef === undefined && sortableRef !== undefined) { |
|
|
|
else if (koRef === undefined && sortableRef === undefined) { |
|
|
|
define(['knockout'], function (amdKnockout) { |
|
|
|
define(['knockout', './Sortable'], factory); |
|
|
|
factory(amdKnockout, sortableRef); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
//no more routes to get references
|
|
|
|
else if (koRef === undefined && sortableRef === undefined) { |
|
|
|
else { |
|
|
|
define(['knockout', './Sortable'], factory); |
|
|
|
//report specific error
|
|
|
|
} |
|
|
|
if (koRef !== undefined && sortableRef === undefined) { |
|
|
|
} |
|
|
|
throw new Error('knockout-sortable could not get reference to Sortable'); |
|
|
|
//no more routes to get references
|
|
|
|
} |
|
|
|
else { |
|
|
|
else if (koRef === undefined && sortableRef !== undefined) { |
|
|
|
//report specific error
|
|
|
|
throw new Error('knockout-sortable could not get reference to Knockout'); |
|
|
|
if (koRef !== undefined && sortableRef === undefined) { |
|
|
|
} |
|
|
|
throw new Error('knockout-sortable could not get reference to Sortable'); |
|
|
|
else if (koRef === undefined && sortableRef === undefined) { |
|
|
|
} |
|
|
|
throw new Error('knockout-sortable could not get reference to Knockout or Sortable'); |
|
|
|
else if (koRef === undefined && sortableRef !== undefined) { |
|
|
|
} |
|
|
|
throw new Error('knockout-sortable could not get reference to Knockout'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (koRef === undefined && sortableRef === undefined) { |
|
|
|
|
|
|
|
throw new Error('knockout-sortable could not get reference to Knockout or Sortable'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
})(function (ko, Sortable) { |
|
|
|
})(function (ko, Sortable) { |
|
|
|
"use strict"; |
|
|
|
"use strict"; |
|
|
|
|
|
|
|
|
|
|
@ -127,7 +133,7 @@ |
|
|
|
originalIndex = fromArray.indexOf(itemVM), |
|
|
|
originalIndex = fromArray.indexOf(itemVM), |
|
|
|
newIndex = e.newIndex; |
|
|
|
newIndex = e.newIndex; |
|
|
|
|
|
|
|
|
|
|
|
// We have to find out the actual desired index of the to array,
|
|
|
|
// We have to find out the actual desired index of the to array,
|
|
|
|
// as this might be a computed array. We could otherwise potentially
|
|
|
|
// as this might be a computed array. We could otherwise potentially
|
|
|
|
// drop an item above the 3rd visible item, but the 2nd visible item
|
|
|
|
// drop an item above the 3rd visible item, but the 2nd visible item
|
|
|
|
// has an actual index of 5.
|
|
|
|
// has an actual index of 5.
|
|
|
|