Skip to content
This repository has been archived by the owner on Jun 19, 2018. It is now read-only.

Commit

Permalink
fix(resizeable): disable the cursor when resizing disabled events
Browse files Browse the repository at this point in the history
Closes #307
  • Loading branch information
Matt Lewis committed Mar 22, 2016
1 parent 834e1ee commit ad9beb7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
63 changes: 30 additions & 33 deletions src/directives/mwlResizable.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ angular
var originalDimensionsStyle = {};
var resizeEdge;

function canResize() {
return $parse($attrs.mwlResizable)($scope);
}

function getUnitsResized(edge, elm, gridDimensions) {
var unitsResized = {};
unitsResized.edge = edge;
Expand All @@ -52,19 +48,17 @@ angular
snap: snap,
onstart: function(event) {

if (canResize()) {
resizeEdge = 'end';
var elm = angular.element(event.target);
originalDimensions.height = elm[0].offsetHeight;
originalDimensions.width = elm[0].offsetWidth;
originalDimensionsStyle.height = elm.css('height');
originalDimensionsStyle.width = elm.css('width');
}
resizeEdge = 'end';
var elm = angular.element(event.target);
originalDimensions.height = elm[0].offsetHeight;
originalDimensions.width = elm[0].offsetWidth;
originalDimensionsStyle.height = elm.css('height');
originalDimensionsStyle.width = elm.css('width');

},
onmove: function(event) {

if (canResize() && event.rect.width > 0 && event.rect.height > 0) {
if (event.rect.width > 0 && event.rect.height > 0) {
var elm = angular.element(event.target);
var x = parseFloat(elm.data('x') || 0);
var y = parseFloat(elm.data('y') || 0);
Expand Down Expand Up @@ -97,31 +91,34 @@ angular
},
onend: function(event) {

if (canResize()) {

var elm = angular.element(event.target);
var unitsResized = getUnitsResized(resizeEdge, elm, snapGridDimensions);

$timeout(function() {
elm
.data('x', null)
.data('y', null)
.css({
transform: '',
width: originalDimensionsStyle.width,
height: originalDimensionsStyle.height
});
});

if ($attrs.onResizeEnd) {
$parse($attrs.onResizeEnd)($scope, unitsResized);
$scope.$apply();
}
var elm = angular.element(event.target);
var unitsResized = getUnitsResized(resizeEdge, elm, snapGridDimensions);

$timeout(function() {
elm
.data('x', null)
.data('y', null)
.css({
transform: '',
width: originalDimensionsStyle.width,
height: originalDimensionsStyle.height
});
});

if ($attrs.onResizeEnd) {
$parse($attrs.onResizeEnd)($scope, unitsResized);
$scope.$apply();
}

}
});

$scope.$watch($attrs.mwlResizable, function(enabled) {
interact($element[0]).resizable({
enabled: enabled
});
});

$scope.$on('$destroy', function() {
interact($element[0]).unset();
});
Expand Down
6 changes: 6 additions & 0 deletions test/unit/directives/mwlResizable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,10 @@ describe('mwlresizable directive', function() {
expect(interactInstance.unset).to.have.been.called;
});

it('should disable resizing on the event', function() {
scope.resizable = false;
scope.$apply();
expect(interactInstance.resizable).to.have.been.calledWith({enabled: false});
});

});

0 comments on commit ad9beb7

Please sign in to comment.