The handle should really include any sub-elements of itself, so if I have a div with spans or other divs inside, those should also be part of the handle (except probably buttons).
I think this should make it behave in this way:
// Support Mouse Events:
@HostListener('mousedown', ['$event'])
onMouseDown(event: any) {
// 1. skip right click;
// 2. if handle is set, the element can only be moved by handle (or the handle's non-button children)
if (event.button == 2) {
return;
} else if (this.handle !== undefined && !this.checkChildren(event.target, this.handle)) {
return;
}
this.orignal = this.getPosition(event.clientX, event.clientY);
this.pickUp();
}
checkChildren(target: HTMLElement, element) {
// Checks if the target is the element clicked, then checks each child element of element as well
// Ignores button clicks
// Ignore elements of type button
if (element.tagName == 'BUTTON') return false;
// If the target was found, return true (handle was found)
if (element == target) return true;
// Recursively iterate this elements children
for (var child in element.children) {
if (element.children.hasOwnProperty(child)) {
if (this.checkChildren(target, element.children[child])) return true;
}
}
// Handle was not found in this lineage
// Note: return false is ignore unless it is the parent element
return false;
}
The handle should really include any sub-elements of itself, so if I have a div with spans or other divs inside, those should also be part of the handle (except probably buttons).
I think this should make it behave in this way: