|
1 | | -// knockout-sortable 0.12.0 | (c) 2016 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license |
| 1 | +// knockout-sortable 0.13.0 | (c) 2016 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license |
2 | 2 | ;(function(factory) { |
3 | 3 | if (typeof define === "function" && define.amd) { |
4 | 4 | // AMD anonymous module |
|
247 | 247 | if (arg && arg.cancelDrop) { |
248 | 248 | return; |
249 | 249 | } |
250 | | - |
251 | | - //do the actual move |
252 | | - if (targetIndex >= 0) { |
253 | | - if (sourceParent) { |
254 | | - sourceParent.splice(sourceIndex, 1); |
255 | | - |
256 | | - //if using deferred updates plugin, force updates |
257 | | - if (ko.processAllDeferredBindingUpdates) { |
258 | | - ko.processAllDeferredBindingUpdates(); |
259 | | - } |
260 | | - } |
261 | | - |
262 | | - targetParent.splice(targetIndex, 0, item); |
263 | | - } |
264 | | - |
265 | | - //rendering is handled by manipulating the observableArray; ignore dropped element |
266 | | - dataSet(el, ITEMKEY, null); |
267 | | - |
| 250 | + |
| 251 | + //if the strategy option is unset or false, employ the order strategy involving removal and insertion of items |
| 252 | + if(!sortable.hasOwnProperty("strategyMove") || sortable.strategyMove === false) |
| 253 | + { |
| 254 | + //do the actual move |
| 255 | + if (targetIndex >= 0) { |
| 256 | + if (sourceParent) { |
| 257 | + sourceParent.splice(sourceIndex, 1); |
| 258 | + |
| 259 | + //if using deferred updates plugin, force updates |
| 260 | + if (ko.processAllDeferredBindingUpdates) { |
| 261 | + ko.processAllDeferredBindingUpdates(); |
| 262 | + } |
| 263 | + } |
| 264 | + |
| 265 | + targetParent.splice(targetIndex, 0, item); |
| 266 | + } |
| 267 | + |
| 268 | + //rendering is handled by manipulating the observableArray; ignore dropped element |
| 269 | + dataSet(el, ITEMKEY, null); |
| 270 | + } |
| 271 | + else { //employ the strategy of moving items |
| 272 | + if (targetIndex >= 0) { |
| 273 | + if (sourceParent) { |
| 274 | + if (sourceParent !== targetParent) { |
| 275 | + // moving from one list to another |
| 276 | + |
| 277 | + sourceParent.splice(sourceIndex, 1); |
| 278 | + |
| 279 | + //if using deferred updates plugin, force updates |
| 280 | + if (ko.processAllDeferredBindingUpdates) { |
| 281 | + ko.processAllDeferredBindingUpdates(); |
| 282 | + } |
| 283 | + |
| 284 | + targetParent.splice(targetIndex, 0, item); |
| 285 | + |
| 286 | + //rendering is handled by manipulating the observableArray; ignore dropped element |
| 287 | + dataSet(el, ITEMKEY, null); |
| 288 | + ui.item.remove(); |
| 289 | + } |
| 290 | + else { |
| 291 | + // moving within same list |
| 292 | + var underlyingList = unwrap(sourceParent); |
| 293 | + |
| 294 | + // notify 'beforeChange' subscribers |
| 295 | + sourceParent.valueWillMutate(); |
| 296 | + |
| 297 | + // move from source index ... |
| 298 | + underlyingList.splice(sourceIndex, 1); |
| 299 | + // ... to target index |
| 300 | + underlyingList.splice(targetIndex, 0, item); |
| 301 | + |
| 302 | + // notify subscribers |
| 303 | + sourceParent.valueHasMutated(); |
| 304 | + } |
| 305 | + } |
| 306 | + else { |
| 307 | + // drop new element from outside |
| 308 | + targetParent.splice(targetIndex, 0, item); |
| 309 | + |
| 310 | + //rendering is handled by manipulating the observableArray; ignore dropped element |
| 311 | + dataSet(el, ITEMKEY, null); |
| 312 | + ui.item.remove(); |
| 313 | + } |
| 314 | + } |
| 315 | + } |
| 316 | + |
268 | 317 | //if using deferred updates plugin, force updates |
269 | 318 | if (ko.processAllDeferredBindingUpdates) { |
270 | 319 | ko.processAllDeferredBindingUpdates(); |
|
0 commit comments