Skip to content

Commit e189d26

Browse files
author
Xie, Ziyu
committed
Release v2.1.5
Bugfix: EndOffset event not working properly with SnapToGrid
1 parent 12b081a commit e189d26

File tree

5 files changed

+28
-9
lines changed

5 files changed

+28
-9
lines changed

README.md

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

2929
# Latest Update
3030

31+
+ 2018.10.15: 2.1.5
32+
+ **ngDraggable**: fix [issue #114](https://github.com/xieziyu/angular2-draggable/issues/114): EndOffset event not working properly with SnapToGrid
33+
3134
+ 2018.09.17: 2.1.4
3235
+ Fix a build issue.
3336
+ **ngResizable**: fix [issue #100](https://github.com/xieziyu/angular2-draggable/issues/100): Resize bounds on a draggable element inside a containment is off

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.4",
3+
"version": "2.1.5",
44
"author": "Xie, Ziyu",
55
"license": "MIT",
66
"keywords": [

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class AngularDraggableDirective implements OnInit, OnDestroy, OnChanges,
1717
private orignal: Position = null;
1818
private oldTrans = new Position(0, 0);
1919
private tempTrans = new Position(0, 0);
20+
private currTrans = new Position(0, 0);
2021
private oldZIndex = '';
2122
private _zIndex = '';
2223
private needTransform = false;
@@ -111,6 +112,7 @@ export class AngularDraggableDirective implements OnInit, OnDestroy, OnChanges,
111112
this.orignal = null;
112113
this.oldTrans = null;
113114
this.tempTrans = null;
115+
this.currTrans = null;
114116
this._helperBlock.dispose();
115117
this._helperBlock = null;
116118
}
@@ -161,10 +163,7 @@ export class AngularDraggableDirective implements OnInit, OnDestroy, OnChanges,
161163
this.edge.emit(this.boundsCheck());
162164
}
163165

164-
this.movingOffset.emit({
165-
x: this.tempTrans.x + this.oldTrans.x,
166-
y: this.tempTrans.y + this.oldTrans.y
167-
});
166+
this.movingOffset.emit(this.currTrans.value);
168167
}
169168
}
170169

@@ -190,6 +189,10 @@ export class AngularDraggableDirective implements OnInit, OnDestroy, OnChanges,
190189
this.renderer.setStyle(this.el.nativeElement, '-ms-transform', value);
191190
this.renderer.setStyle(this.el.nativeElement, '-moz-transform', value);
192191
this.renderer.setStyle(this.el.nativeElement, '-o-transform', value);
192+
193+
// save current position
194+
this.currTrans.x = translateX;
195+
this.currTrans.y = translateY;
193196
}
194197

195198
private pickUp() {
@@ -245,6 +248,11 @@ export class AngularDraggableDirective implements OnInit, OnDestroy, OnChanges,
245248
}
246249
}
247250

251+
/** Get current offset */
252+
getCurrentOffset() {
253+
return this.currTrans.value;
254+
}
255+
248256
private putBack() {
249257
if (this._zIndex) {
250258
this.renderer.setStyle(this.el.nativeElement, 'z-index', this._zIndex);
@@ -278,10 +286,7 @@ export class AngularDraggableDirective implements OnInit, OnDestroy, OnChanges,
278286
}
279287

280288
this.moving = false;
281-
this.endOffset.emit({
282-
x: this.tempTrans.x + this.oldTrans.x,
283-
y: this.tempTrans.y + this.oldTrans.y
284-
});
289+
this.endOffset.emit(this.currTrans.value);
285290

286291
if (this.trackPosition) {
287292
this.oldTrans.add(this.tempTrans);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ export class Position implements IPosition {
3838
return new Position(0, 0).set(p);
3939
}
4040

41+
get value(): IPosition {
42+
return { x: this.x, y: this.y };
43+
}
44+
4145
add(p: IPosition) {
4246
this.x += p.x;
4347
this.y += p.y;

src/assets/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.1.5 (2018-10-15)
2+
3+
#### Bugfix
4+
+ **ngDraggable**: EndOffset event not working properly with SnapToGrid. [#114](https://github.com/xieziyu/angular2-draggable/issues/114)
5+
6+
---
7+
18
## 2.1.4 (2018-09-17)
29

310
#### Bugfix

0 commit comments

Comments
 (0)