Skip to content

Commit

Permalink
Merge pull request #46 from InteractiveIntelligence/rtl-move-columns
Browse files Browse the repository at this point in the history
Rtl move columns
  • Loading branch information
Jason Mobley committed Mar 7, 2016
2 parents 325ff38 + 67ee814 commit 78adadf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
37 changes: 18 additions & 19 deletions src/features/move-columns/js/column-movable.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,7 @@
$elm.parent().addClass('columnsMoving');
movingElm.addClass('movingColumn');
var movingElementStyles = {};
var elmLeft;
if (gridUtil.detectBrowser() === 'safari') {
//Correction for Safari getBoundingClientRect,
//which does not correctly compute when there is an horizontal scroll
elmLeft = $elm[0].offsetLeft + $elm[0].offsetWidth - $elm[0].getBoundingClientRect().width;
}
else {
elmLeft = $elm[0].getBoundingClientRect().left + $scope.colContainer.prevScrollLeft;
}
movingElementStyles.left = (elmLeft - gridLeft) + 'px';
movingElementStyles.left = $elm[0].offsetLeft + 'px';
var gridRight = $scope.grid.element[0].getBoundingClientRect().right;
var elmRight = $elm[0].getBoundingClientRect().right;
if (elmRight > gridRight) {
Expand All @@ -435,28 +426,36 @@
//Calculate total column width
var columns = $scope.grid.columns;
var gridRight = $scope.grid.element[0].getBoundingClientRect().right;
var scrolledGridRight = gridRight + $scope.colContainer.prevScrollLeft;
var totalColumnWidth = 0;
for (var i = 0; i < columns.length; i++) {
if (angular.isUndefined(columns[i].colDef.visible) || columns[i].colDef.visible === true) {
totalColumnWidth += columns[i].drawnWidth || columns[i].width || columns[i].colDef.width;
}
}

var newElementLeft = movingElm[0].offsetLeft + changeValue;
var newElementRight = newElementLeft + movingElm[0].offsetWidth;
//Calculate new position of left of column
var currentElmLeft = movingElm[0].getBoundingClientRect().left - 1;
var currentElmRight = movingElm[0].getBoundingClientRect().right;

var newElementLeft = currentElmLeft - gridLeft + changeValue;
newElementLeft = newElementLeft < rightMoveLimit ? newElementLeft : rightMoveLimit;

// move the column if it's in view. Else scroll if we need to
if (newElementLeft > $scope.colContainer.prevScrollLeft &&
newElementRight < scrolledGridRight && newElementRight < $scope.colContainer.canvasWidth) {
movingElm.css({visibility: 'visible', 'left': newElementLeft + 'px'});
}
else if (newElementRight < $scope.colContainer.canvasWidth && newElementLeft >= gridLeft) {
var delta;
if ((currentElmLeft >= gridLeft || changeValue > 0) && (currentElmRight <= rightMoveLimit || changeValue < 0)) {
delta = (newElementLeft < rightMoveLimit) ? changeValue : 0;
movingElm.css({visibility: 'visible', 'left': (movingElm[0].offsetLeft + delta) + 'px'});
} else if (totalColumnWidth > Math.ceil(uiGridCtrl.grid.gridWidth)) {
changeValue *= 8;
var scrollEvent = new ScrollEvent($scope.col.grid, null, null, 'uiGridHeaderCell.moveElement');
scrollEvent.x = {pixels: changeValue};
scrollEvent.grid.scrollContainers('',scrollEvent);
movingElm.css({visibility: 'visible', 'left': newElementLeft + changeValue + 'px'});
delta = (newElementLeft < rightMoveLimit) ? changeValue : 0;
var newLeft = movingElm[0].offsetLeft + delta;
// Have to recaluculate the bounds of the moving element since the scrolling will have changed it.
if (movingElm[0].getBoundingClientRect().left - 1 >= gridLeft && (movingElm[0].getBoundingClientRect().right <= rightMoveLimit)) {
movingElm.css({visibility: 'visible', 'left': newLeft + 'px'});
}
}

//Calculate total width of columns on the left of the moving column and the mouse movement
Expand Down
4 changes: 2 additions & 2 deletions src/js/core/factories/ScrollEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
throw new Error("No percentage or pixel value provided for scroll event X axis");
}

return Math.max(0, scrollXPercentage * scrollWidth);
return scrollXPercentage * scrollWidth;
}

return self.newScrollLeft;
Expand Down Expand Up @@ -163,4 +163,4 @@



})();
})();
12 changes: 6 additions & 6 deletions src/js/core/services/ui-grid-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1057,11 +1057,11 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
if (grid.isRTL()) {
switch (s.rtlScrollType()) {
case 'default':
return element.scrollWidth - scrollLeft - element.clientWidth;
return (element.scrollWidth - scrollLeft - element.clientWidth) * -1;
case 'negative':
return Math.abs(scrollLeft);
case 'reverse':
return scrollLeft;
case 'reverse':
return scrollLeft * -1;
}
}

Expand Down Expand Up @@ -1094,11 +1094,11 @@ module.service('gridUtil', ['$log', '$window', '$document', '$http', '$templateC
var maxScrollLeft = element.scrollWidth - element.clientWidth;

// Subtract the current scroll amount from the max scroll
return maxScrollLeft - scrollLeft;
return maxScrollLeft - (scrollLeft * -1);
case 'negative':
return scrollLeft * -1;
case 'reverse':
return scrollLeft;
case 'reverse':
return scrollLeft * -1;
}
}

Expand Down

0 comments on commit 78adadf

Please sign in to comment.