From 0da75e4de7373ed361b5d76be4ee192453146dde Mon Sep 17 00:00:00 2001 From: Jon Reid Date: Tue, 19 Jun 2012 18:04:06 -0700 Subject: Timeline: Re-enable drag-and-drop of layers, now with bonus DOM manipulation! --- js/mediators/element-mediator.js | 43 ++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'js/mediators/element-mediator.js') diff --git a/js/mediators/element-mediator.js b/js/mediators/element-mediator.js index bd0ae3cb..99d2f822 100755 --- a/js/mediators/element-mediator.js +++ b/js/mediators/element-mediator.js @@ -483,30 +483,25 @@ exports.ElementMediator = Montage.create(Component, { }, reArrangeDOM:{ - value: function(layersDraggedArray, layerDroppedAfter) { - var documentRoot,length; - - documentRoot = this.application.ninja.currentDocument.model.documentRoot; - length = layersDraggedArray.length; - - for(var i=0; documentRoot.children[i]; i++) { - if(documentRoot.children[i] === layerDroppedAfter.layerData.stageElement) { - if(length >0){ - documentRoot.children[i].parentNode.insertBefore(layersDraggedArray[length-1].layerData.stageElement, documentRoot.children[i]); - } - - /* Will require for Multiple Drag n Drop */ - //length = length-1; - //index = i; - //if(length>0) { - //while(layersDraggedArray[length]) { - //documentRoot.children[index].parentNode.insertBefore(layersDraggedArray[length-1].layerData.elementsList[0],documentRoot.children[k].nextSibling); - //length--; - //index++; - //} - //} - } - } + value: function(arrLayersDragged, dropTargetElement) { + var i = 0, + arrLayersDraggedLength = arrLayersDragged.length, + targetParentNode, + targetElement; + + if (arrLayersDraggedLength === 0) { + // Nothing was dragged, so return. + return; + } + + // Get the target parent node (this will be the parentNode of any of the dragging items) + targetParentNode = arrLayersDragged[0].parentNode; + + + // Loop through arrLayersDragged and insertBefore the drop target element + for (i = 0; i < arrLayersDraggedLength; i++) { + targetParentNode.insertBefore(arrLayersDragged[i], dropTargetElement); + } } } }); \ No newline at end of file -- cgit v1.2.3