Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

fix(resizeable): dont allow events to be resized to 0 height or width

Closes #287
  • Loading branch information...
Matt Lewis
Matt Lewis committed Feb 16, 2016
1 parent 583958f commit df410ae75ee268a9cbb296cb72316106b6f611bd
Showing with 49 additions and 3 deletions.
  1. +1 −1 src/directives/mwlResizable.js
  2. +48 −2 test/unit/directives/mwlResizable.spec.js
@@ -64,7 +64,7 @@ angular
},
onmove: function(event) {

if (canResize()) {
if (canResize() && 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);
@@ -105,11 +105,57 @@ describe('mwlresizable directive', function() {
expect(scope.onResize).to.have.been.calledWith(0, 2);
});

it('should not resize the element to height 0', function() {

var event = {
target: angular.element('<div></div>')[0],
rect: {
width: 100,
height: 0
},
deltaRect: {
left: 0,
top: -30
}
};
resizableOptions.onmove(event);
expect(angular.element(event.target).data('x')).to.be.undefined;
expect(angular.element(event.target).data('y')).to.be.undefined;
expect(angular.element(event.target).css('height')).to.equal('');
expect(angular.element(event.target).css('width')).to.equal('');
expect(angular.element(event.target).css('transform')).to.be.undefined;
expect(scope.onResize).not.to.have.been.called;

});

it('should not resize the element to width 0', function() {

var event = {
target: angular.element('<div></div>')[0],
rect: {
width: 0,
height: 100
},
deltaRect: {
left: 0,
top: -30
}
};
resizableOptions.onmove(event);
expect(angular.element(event.target).data('x')).to.be.undefined;
expect(angular.element(event.target).data('y')).to.be.undefined;
expect(angular.element(event.target).css('height')).to.equal('');
expect(angular.element(event.target).css('width')).to.equal('');
expect(angular.element(event.target).css('transform')).to.be.undefined;
expect(scope.onResize).not.to.have.been.called;

});

it('should handle on resize end', function() {
var event = {
target: angular.element('<div style="width: 30px; height: 30px;"></div>')[0],
rect: {
width: 0,
width: 1,
height: 120
},
deltaRect: {
@@ -122,7 +168,7 @@ describe('mwlresizable directive', function() {
resizableOptions.onmove(event);
resizableOptions.onend(event);
$timeout.flush();
expect(scope.onResizeEnd).to.have.been.calledWith(0, 4);
expect(scope.onResizeEnd).to.have.been.calledWith(1, 4);
expect(angular.element(event.target).css('transform')).to.eql('');
expect(angular.element(event.target).css('width')).to.eql('30px');
expect(angular.element(event.target).css('height')).to.eql('30px');

0 comments on commit df410ae

Please sign in to comment.
You can’t perform that action at this time.