Skip to content

Commit

Permalink
Merge pull request #26 from Tuch/bugs/issue-25
Browse files Browse the repository at this point in the history
issue-25 fix bug with useAsPoint
  • Loading branch information
Tuch committed Jun 19, 2015
2 parents 15975d8 + af29295 commit 77dbd21
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 25 deletions.
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
ng-click = "click(!$dragged && !$resized && !$rotated, $dropmodel)"

dnd-draggable = "true"
dnd-draggable-opts = "{layer: 'layer1', useAsPoint: true }"
dnd-draggable-opts = "{layer: 'layer1' }"
dnd-on-dragstart = "main.dragstart($dropmodel, $dragmodel)"
dnd-on-drag = "main.drag($dropmodel, $dragmodel)"
dnd-on-dragend = "main.dragend($dropmodel, $dragmodel)"
Expand Down
28 changes: 17 additions & 11 deletions dist/angular-dnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ var module = angular.module('dnd', []);
this._manipulator.removeFromTargets();
},
useAsPoint: function(value) {
return this._manipulator.asPoint = value === false ? false : true;
return this._manipulator.asPoint = !(value === false);
},
setBounderElement: function(node) {
this._manipulator.$bounder = angular.element(node);
Expand Down Expand Up @@ -1199,6 +1199,18 @@ var module = angular.module('dnd', []);
return true;
},

_isTriggerByPoint: function (p, r) {
return (p.x > r.left) && (p.x < r.right) && (p.y > r.top) && (p.y < r.bottom);
},

_isTriggerByRect: function (a, b) {
return a.top <= b.top && b.top <= a.bottom && ( a.left <= b.left && b.left <= a.right || a.left <= b.right && b.right <= a.right ) ||
a.top <= b.bottom && b.bottom <= a.bottom && ( a.left <= b.left && b.left <= a.right || a.left <= b.right && b.right <= a.right ) ||
a.left >= b.left && a.right <= b.right && ( b.top <= a.bottom && a.bottom <= b.bottom || b.bottom >= a.top && a.top >= b.top || a.top <= b.top && a.bottom >= b.bottom) ||
a.top >= b.top && a.bottom <= b.bottom && ( b.left <= a.right && a.right <= b.right || b.right >= a.left && a.left >= b.left || a.left <= b.left && a.right >= b.right) ||
a.top >= b.top && a.right <= b.right && a.bottom <= b.bottom && a.left >= b.left
},

progress: function (event) {
this.event = event;

Expand All @@ -1217,18 +1229,15 @@ var module = angular.module('dnd', []);

this.dnd.trigger('drag', this.api);

var axis = this.getBorderedAxis(), x = axis.x, y = axis.y, asPoint = this.asPoint;
var isTrigger = this.asPoint ? this._isTriggerByPoint.bind(this, this.getBorderedAxis()) :
this._isTriggerByRect.bind(this, angular.element(this.dnd.el).dndClientRect());
var dragenter = [];
var dragover = [];
var dragleave = [];

for(var i = 0; i < regions.length; i++) {
var region = regions[i],
left = region.rect.left,
right = left + region.rect.width,
top = region.rect.top,
bottom = top + region.rect.height,
trigger = (x > left ) && (x < right) && (y > top) && (y < bottom),
trigger = isTrigger(region.rect),
targetIndex = this.targets.indexOf(region.dnd.el);

if ( trigger ) {
Expand Down Expand Up @@ -1812,9 +1821,6 @@ function ($timeout, $parse, $http, $compile, $q, $templateCache, EventEmitter) {

updatePosition: function () {
var position = this.api.getRelBorderedAxis(this.borderOffset).plus(this._offset);
if (debug.mode) {
console.log(this.api.getRelBorderedAxis());
}

wrapper.dndCss(position.getAsCss());
},
Expand All @@ -1835,7 +1841,7 @@ function ($timeout, $parse, $http, $compile, $q, $templateCache, EventEmitter) {

var defaults = {
layer: 'common',
useAsPoint: false,
useAsPoint: true,
helper: null,
handle: ''
};
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-dnd.min.js

Large diffs are not rendered by default.

23 changes: 16 additions & 7 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ var module = angular.module('dnd', []);
this._manipulator.removeFromTargets();
},
useAsPoint: function(value) {
return this._manipulator.asPoint = value === false ? false : true;
return this._manipulator.asPoint = !(value === false);
},
setBounderElement: function(node) {
this._manipulator.$bounder = angular.element(node);
Expand Down Expand Up @@ -1197,6 +1197,18 @@ var module = angular.module('dnd', []);
return true;
},

_isTriggerByPoint: function (p, r) {
return (p.x > r.left) && (p.x < r.right) && (p.y > r.top) && (p.y < r.bottom);
},

_isTriggerByRect: function (a, b) {
return a.top <= b.top && b.top <= a.bottom && ( a.left <= b.left && b.left <= a.right || a.left <= b.right && b.right <= a.right ) ||
a.top <= b.bottom && b.bottom <= a.bottom && ( a.left <= b.left && b.left <= a.right || a.left <= b.right && b.right <= a.right ) ||
a.left >= b.left && a.right <= b.right && ( b.top <= a.bottom && a.bottom <= b.bottom || b.bottom >= a.top && a.top >= b.top || a.top <= b.top && a.bottom >= b.bottom) ||
a.top >= b.top && a.bottom <= b.bottom && ( b.left <= a.right && a.right <= b.right || b.right >= a.left && a.left >= b.left || a.left <= b.left && a.right >= b.right) ||
a.top >= b.top && a.right <= b.right && a.bottom <= b.bottom && a.left >= b.left
},

progress: function (event) {
this.event = event;

Expand All @@ -1215,18 +1227,15 @@ var module = angular.module('dnd', []);

this.dnd.trigger('drag', this.api);

var axis = this.getBorderedAxis(), x = axis.x, y = axis.y, asPoint = this.asPoint;
var isTrigger = this.asPoint ? this._isTriggerByPoint.bind(this, this.getBorderedAxis()) :
this._isTriggerByRect.bind(this, angular.element(this.dnd.el).dndClientRect());
var dragenter = [];
var dragover = [];
var dragleave = [];

for(var i = 0; i < regions.length; i++) {
var region = regions[i],
left = region.rect.left,
right = left + region.rect.width,
top = region.rect.top,
bottom = top + region.rect.height,
trigger = (x > left ) && (x < right) && (y > top) && (y < bottom),
trigger = isTrigger(region.rect),
targetIndex = this.targets.indexOf(region.dnd.el);

if ( trigger ) {
Expand Down
5 changes: 1 addition & 4 deletions src/directives/dndDraggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ function ($timeout, $parse, $http, $compile, $q, $templateCache, EventEmitter) {

updatePosition: function () {
var position = this.api.getRelBorderedAxis(this.borderOffset).plus(this._offset);
if (debug.mode) {
console.log(this.api.getRelBorderedAxis());
}

wrapper.dndCss(position.getAsCss());
},
Expand All @@ -175,7 +172,7 @@ function ($timeout, $parse, $http, $compile, $q, $templateCache, EventEmitter) {

var defaults = {
layer: 'common',
useAsPoint: false,
useAsPoint: true,
helper: null,
handle: ''
};
Expand Down

0 comments on commit 77dbd21

Please sign in to comment.