Skip to content

Commit 9d49e1b

Browse files
author
Xie, Ziyu
authored
Merge pull request #124 from xieziyu/dev
Release v2.1.9
2 parents a3b327c + d2e7bec commit 9d49e1b

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ angular2-draggable has angular directives that make the DOM element draggable an
2727
+ provided since v2.0, requires Angular >= 6
2828

2929
# Latest Update
30+
+ 2018.11.29: 2.1.9
31+
+ **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))
32+
3033
+ 2018.11.11: 2.1.8
3134
+ **ngResizable**: add [preventDefaultEvent] flag to ngResizable mousedown ([by mecp](https://github.com/mecp) - [PR #119](https://github.com/xieziyu/angular2-draggable/pull/119))
3235

projects/angular2-draggable/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular2-draggable",
3-
"version": "2.1.8",
3+
"version": "2.1.9",
44
"author": "Xie, Ziyu",
55
"license": "MIT",
66
"keywords": [

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export class AngularDraggableDirective implements OnInit, OnDestroy, OnChanges,
2828
*/
2929
private _helperBlock: HelperBlock = null;
3030

31+
/**
32+
* Flag to indicate whether the element is dragged once after being initialised
33+
*/
34+
private isDragged = false;
35+
3136
@Output() started = new EventEmitter<any>();
3237
@Output() stopped = new EventEmitter<any>();
3338
@Output() edge = new EventEmitter<any>();
@@ -102,7 +107,6 @@ export class AngularDraggableDirective implements OnInit, OnDestroy, OnChanges,
102107
let element = this.handle ? this.handle : this.el.nativeElement;
103108
this.renderer.addClass(element, 'ng-draggable');
104109
}
105-
106110
this.resetPosition();
107111
}
108112

@@ -133,6 +137,11 @@ export class AngularDraggableDirective implements OnInit, OnDestroy, OnChanges,
133137
this.needTransform = true;
134138
}
135139
}
140+
141+
if (changes['scale'] && !changes['scale'].isFirstChange()) {
142+
this.oldTrans.x = this.currTrans.x * this.scale;
143+
this.oldTrans.y = this.currTrans.y * this.scale;
144+
}
136145
}
137146

138147
ngAfterViewInit() {
@@ -178,12 +187,23 @@ export class AngularDraggableDirective implements OnInit, OnDestroy, OnChanges,
178187
translateY = Math.round(translateY / this.gridSize) * this.gridSize;
179188
}
180189

181-
let value = `translate(${translateX}px, ${translateY}px)`;
190+
// done to prevent the element from bouncing off when
191+
// the parent element is scaled and element is dragged for first time
192+
if (this.tempTrans.x !== 0 || this.tempTrans.y !== 0) {
193+
if (this.isDragged === false) {
194+
this.oldTrans.x = this.currTrans.x * this.scale;
195+
this.oldTrans.y = this.currTrans.y * this.scale;
196+
}
197+
this.isDragged = true;
198+
}
182199

183-
if (this.scale !== 1) {
184-
value += ` scale(${this.scale})`;
200+
if (this.scale && this.scale !== 0 && this.isDragged) {
201+
translateX = translateX / this.scale;
202+
translateY = translateY / this.scale;
185203
}
186204

205+
let value = `translate(${translateX}px, ${translateY}px)`;
206+
187207
this.renderer.setStyle(this.el.nativeElement, 'transform', value);
188208
this.renderer.setStyle(this.el.nativeElement, '-webkit-transform', value);
189209
this.renderer.setStyle(this.el.nativeElement, '-ms-transform', value);

projects/angular2-draggable/src/lib/models/position.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export class Position implements IPosition {
3636
}
3737
}
3838

39-
static copy(p: Position) {
39+
static copy(p: IPosition) {
4040
return new Position(0, 0).set(p);
4141
}
4242

src/assets/CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.1.9 (2018-11-29)
2+
3+
#### Bugfix
4+
+ **ngDraggable**: [#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))
5+
6+
---
7+
18
## 2.1.8 (2018-11-11)
29

310
#### New
@@ -8,7 +15,7 @@
815
## 2.1.7 (2018-10-31)
916

1017
#### Bugfix
11-
+ **ngResizable**: ngResizable Locks Height When rzHandles Includes Only e, w. [#116](https://github.com/xieziyu/angular2-draggable/issues/116) (Thanks to [Yamazaki93](https://github.com/Yamazaki93))
18+
+ **ngResizable**: [#116](https://github.com/xieziyu/angular2-draggable/issues/116) ngResizable Locks Height When rzHandles Includes Only e, w. (Thanks to [Yamazaki93](https://github.com/Yamazaki93))
1219

1320
---
1421

0 commit comments

Comments
 (0)