diff --git a/src/dragAndDropHandler/index.ts b/src/dragAndDropHandler/index.ts index dd00ff37..c262ea9c 100644 --- a/src/dragAndDropHandler/index.ts +++ b/src/dragAndDropHandler/index.ts @@ -43,7 +43,7 @@ interface DragAndDropHandlerParams { openNode: OpenNode; refreshElements: RefreshElements; slide: boolean; - $treeElement: JQuery; + treeElement: HTMLElement; triggerEvent: TriggerEvent; } @@ -70,7 +70,7 @@ export class DragAndDropHandler { private previousGhost: DropHint | null; private refreshElements: RefreshElements; private slide: boolean; - private $treeElement: JQuery; + private treeElement: HTMLElement; private triggerEvent: TriggerEvent; constructor({ @@ -87,7 +87,7 @@ export class DragAndDropHandler { openNode, refreshElements, slide, - $treeElement, + treeElement, triggerEvent, }: DragAndDropHandlerParams) { this.autoEscape = autoEscape; @@ -103,7 +103,7 @@ export class DragAndDropHandler { this.openNode = openNode; this.refreshElements = refreshElements; this.slide = slide; - this.$treeElement = $treeElement; + this.treeElement = treeElement; this.triggerEvent = triggerEvent; this.hoveredArea = null; @@ -157,7 +157,7 @@ export class DragAndDropHandler { nodeName: node.name, offsetX: positionInfo.pageX - left, offsetY: positionInfo.pageY - top, - treeElement: this.$treeElement.get(0) as HTMLElement, + treeElement: this.treeElement, }); this.isDragging = true; @@ -424,7 +424,8 @@ export class DragAndDropHandler { if (tree) { tree.moveNode(movedNode, targetNode, position); - this.$treeElement.empty(); + + this.treeElement.textContent = ""; this.refreshElements(null); } }; @@ -449,22 +450,14 @@ export class DragAndDropHandler { private getTreeDimensions(): Dimensions { // Return the dimensions of the tree. Add a margin to the bottom to allow // to drag-and-drop after the last element. - const offset = this.$treeElement.offset(); - - if (!offset) { - return { left: 0, top: 0, right: 0, bottom: 0 }; - } else { - const el = this.$treeElement; - const width = el.width() || 0; - const height = el.height() || 0; - const left = offset.left + this.getScrollLeft(); - - return { - left, - top: offset.top, - right: left + width, - bottom: offset.top + height + 16, - }; - } + const left = this.treeElement.offsetLeft + this.getScrollLeft(); + const top = this.treeElement.offsetTop; + + return { + left, + top, + right: left + this.treeElement.clientWidth, + bottom: top + this.treeElement.clientHeight + 16, + }; } } diff --git a/src/tree.jquery.ts b/src/tree.jquery.ts index 5e3b7797..f2506f17 100644 --- a/src/tree.jquery.ts +++ b/src/tree.jquery.ts @@ -1229,6 +1229,7 @@ export class JqTreeWidget extends MouseWidget { const refreshHitAreas = this.refreshHitAreas.bind(this); const selectNode = this.selectNode.bind(this); const $treeElement = this.element; + const treeElement = this.element.get(0) as HTMLElement; const triggerEvent = this._triggerEvent.bind(this); const selectNodeHandler = new SelectNodeHandler({ @@ -1280,7 +1281,7 @@ export class JqTreeWidget extends MouseWidget { openNode, refreshElements, slide, - $treeElement, + treeElement, triggerEvent, });