Skip to content

Bug fixes #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 40 additions & 6 deletions src/angular-sortable-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
}

var sortingInProgress;
var isDisabled = false;

var ROOTS_MAP = Object.create(null);
// window.ROOTS_MAP = ROOTS_MAP; // for debug purposes

Expand Down Expand Up @@ -56,6 +58,16 @@
return sortingInProgress;
};

if ($attrs.svDisabled) {
$scope.$watch($attrs.svDisabled, function(disabled) {
isDisabled = disabled === true;
});
}

this.isDisabled = function() {
return isDisabled;
};

if($attrs.svGrid){ // sv-grid determined explicite
isGrid = $attrs.svGrid === "true" ? true : $attrs.svGrid === "false" ? false : null;
if(isGrid === null)
Expand Down Expand Up @@ -353,12 +365,14 @@
return $scope.$index;
}
};
var handle = $element;

$controllers[1].addToSortableElements(sortableElement);
$scope.$on('$destroy', function(){
$controllers[1].removeFromSortableElements(sortableElement);
handle.off('mousedown touchstart', onMousedown);
});

var handle = $element;
handle.on('mousedown touchstart', onMousedown);
$scope.$watch('$ctrl.handle', function(customHandle){
if(customHandle){
Expand Down Expand Up @@ -390,7 +404,7 @@
function onMousedown(e){
touchFix(e);

if($controllers[1].sortingInProgress()) return;
if($controllers[1].isDisabled() || $controllers[1].sortingInProgress()) return;
if(e.button != 0 && e.type === 'mousedown') return;

moveExecuted = false;
Expand All @@ -406,6 +420,7 @@

var target = $element;
var clientRect = $element[0].getBoundingClientRect();
var parentRect = getPositionedParentRect($element[0]);
var clone;

if(!helper) helper = $controllers[0].helper;
Expand Down Expand Up @@ -444,6 +459,11 @@
targetLeft = containmentRect.left + body.scrollLeft;
if(targetLeft + helperRect.width > containmentRect.left + body.scrollLeft + containmentRect.width) // right boundary
targetLeft = containmentRect.left + body.scrollLeft + containmentRect.width - helperRect.width;

if (parentRect) {
targetLeft -= parentRect.left;
targetTop -= parentRect.top;
}
}
this.style.left = targetLeft - body.scrollLeft + 'px';
this.style.top = targetTop - body.scrollTop + 'px';
Expand All @@ -465,19 +485,33 @@
});

// onMousemove(e);
function onMousemove(e){
touchFix(e);
function onMousemove(moveEv){
touchFix(moveEv);
var jiggle = Math.abs(moveEv.clientY - e.clientY)
+ Math.abs(moveEv.clientX - e.clientX);
if (jiggle < 10) return;
if(!moveExecuted){
$element.parent().prepend(clone);
moveExecuted = true;
}

$controllers[1].$moveUpdate(opts, {
x: e.clientX,
y: e.clientY,
x: moveEv.clientX,
y: moveEv.clientY,
offset: pointerOffset
}, clone, $element, placeholder, $controllers[0].getPart(), $scope.$index);
}
}

function getPositionedParentRect(el) {
while (el !== document.documentElement) {
el = el.parentNode;
var cssPos = window.getComputedStyle(el, null).position;
if (cssPos != '' && cssPos != 'static') {
return el.getBoundingClientRect();
}
}
}
}
};
}]);
Expand Down
Loading