From afdb2e2f9f3fd43880fd54c837ff4c33fba3fb6c Mon Sep 17 00:00:00 2001 From: Isaac Brown Date: Wed, 4 Feb 2015 14:23:46 -0800 Subject: [PATCH] Explicit parent added attribute to explicitly state a relative parent to base the offset off of. --- src/angular-sortable-view.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/angular-sortable-view.js b/src/angular-sortable-view.js index c87c3de..68c15e1 100644 --- a/src/angular-sortable-view.js +++ b/src/angular-sortable-view.js @@ -39,7 +39,8 @@ var $target; // last best candidate var isGrid = false; var onSort = $parse($attrs.svOnSort); - + var parentIsRelative = $attrs.hasRelativeParent ? $($attrs.hasRelativeParent) : false; + // ----- hack due to https://github.com/angular/angular.js/issues/8044 $attrs.svOnStart = $attrs.$$element[0].attributes['sv-on-start']; $attrs.svOnStart = $attrs.svOnStart && $attrs.svOnStart.value; @@ -71,7 +72,7 @@ }).map(function(item){ return { part: item.getPart().id, - y: item.element[0].getBoundingClientRect().top + y: !parentIsRelative ? item.element[0].getBoundingClientRect().top : (item.element[0].getBoundingClientRect().top - parentIsRelative.offset().top ) }; }); var dict = Object.create(null); @@ -93,7 +94,18 @@ }); }); } + + this.relativeParentOffset = function() { + if (!parentIsRelative) + return { + top: 0, + left: 0 + }; + + return $(parentIsRelative).offset(); + }; + this.$moveUpdate = function(opts, mouse, svElement, svOriginal, svPlaceholder, originatingPart, originatingIndex){ var svRect = svElement[0].getBoundingClientRect(); if(opts.tolerance === 'element') @@ -138,8 +150,8 @@ // ----- move the element $helper[0].reposition({ - x: mouse.x + document.body.scrollLeft - mouse.offset.x*svRect.width, - y: mouse.y + document.body.scrollTop - mouse.offset.y*svRect.height + x: (mouse.x + document.body.scrollLeft - mouse.offset.x*svRect.width) - that.relativeParentOffset().left, + y: (mouse.y + document.body.scrollTop - mouse.offset.y*svRect.height) - that.relativeParentOffset().top }); // ----- manage candidates @@ -605,4 +617,4 @@ return angular.element(); }; -})(window, window.angular); \ No newline at end of file +})(window, window.angular);