Skip to content

Commit 625f627

Browse files
author
Xie, Ziyu
committed
Fix issue #132
1 parent 48801bc commit 625f627

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ angular2-draggable has angular directives that make the DOM element draggable an
2828

2929
# Latest Update
3030
+ 2018.12.22: 2.2.0
31-
+ **ngDraggable**:
31+
+ **ngDraggable**:
3232
+ Performance update. Fix [issue #112](https://github.com/xieziyu/angular2-draggable/issues/112): Control change detection with HostListener events.
3333
+ Fix [issue #128](https://github.com/xieziyu/angular2-draggable/issues/128): Multiple phone draggables at the same time.
34+
+ **ngResizable**:
35+
+ Fix [issue #132](https://github.com/xieziyu/angular2-draggable/issues/132): Aspect ratio feature exits Y-Axis boundary on resize.
3436

3537
+ 2018.11.29: 2.1.9
3638
+ **ngDraggable**: fix [issue #31](https://github.com/xieziyu/angular2-draggable/issues/31): Problems when scale transform applied to parent. ([by rathodsanjay](https://github.com/rathodsanjay) - [PR #123](https://github.com/xieziyu/angular2-draggable/pull/123))

projects/angular2-draggable/src/lib/angular-resizable.directive.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,10 @@ export class AngularResizableDirective implements OnInit, OnChanges, OnDestroy,
447447
if (this._containment) {
448448
const maxWidth = this._bounding.width - this._bounding.pr - this.el.nativeElement.offsetLeft - this._bounding.translateX;
449449
const maxHeight = this._bounding.height - this._bounding.pb - this.el.nativeElement.offsetTop - this._bounding.translateY;
450+
const minHeight = !this.rzMinHeight ? 1 : this.rzMinHeight;
451+
const minWidth = !this.rzMinWidth ? 1 : this.rzMinWidth;
450452

451-
if (this._direction.n && (this._currPos.y + this._bounding.translateY) < 0) {
453+
if (this._direction.n && (this._currPos.y + this._bounding.translateY < 0)) {
452454
this._currPos.y = -this._bounding.translateY;
453455
this._currSize.height = this._origSize.height + this._origPos.y + this._bounding.translateY;
454456
}
@@ -465,6 +467,28 @@ export class AngularResizableDirective implements OnInit, OnChanges, OnDestroy,
465467
if (this._currSize.height > maxHeight) {
466468
this._currSize.height = maxHeight;
467469
}
470+
471+
/**
472+
* Fix Issue: Additional check for aspect ratio
473+
* https://github.com/xieziyu/angular2-draggable/issues/132
474+
*/
475+
if (this._aspectRatio) {
476+
if ((this._currSize.width / this._aspectRatio) > maxHeight) {
477+
this._currSize.width = maxHeight * this._aspectRatio;
478+
479+
if (this._direction.w) {
480+
this._currPos.x = this._origPos.x;
481+
}
482+
}
483+
484+
if ((this._currSize.height * this._aspectRatio) > maxWidth) {
485+
this._currSize.height = maxWidth / this._aspectRatio;
486+
487+
if (this._direction.n) {
488+
this._currPos.y = this._origPos.y;
489+
}
490+
}
491+
}
468492
}
469493
}
470494

src/app/views/resizable-demo/resize-containment-demo/resize-containment-demo.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<div id="container" class="widget-container">
44
<h4 class="widget-header">Containment</h4>
55
<!-- rzContainment could be a CSS selector string, 'parent' or an Element object -->
6-
<div ngResizable class="resizable-widget" rzContainment="#container" rzHandles="all">
6+
<div ngResizable [rzAspectRatio]="true" class="resizable-widget" rzContainment="#container" rzHandles="all">
77
<h4 class="widget-header">Resizable</h4>
88
</div>
99
</div>

src/assets/CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
## 2.2.0 (2018-12-22)
22

33
#### Bugfix
4-
+ **ngDraggable**: Performance update. Fix [issue #112](https://github.com/xieziyu/angular2-draggable/issues/112): Control change detection with HostListener events.
5-
4+
+ **ngDraggable**:
5+
+ Performance update. Fix [issue #112](https://github.com/xieziyu/angular2-draggable/issues/112): Control change detection with HostListener events.
6+
+ Fix [issue #128](https://github.com/xieziyu/angular2-draggable/issues/128): Multiple phone draggables at the same time.
7+
+ **ngResizable**:
8+
+ Fix [issue #132](https://github.com/xieziyu/angular2-draggable/issues/132): Aspect ratio feature exits Y-Axis boundary on resize.
69
---
710

811
## 2.1.9 (2018-11-29)

0 commit comments

Comments
 (0)