From 1a45d18b9473addddbc2c025f4d327eab48a834c Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 13 Oct 2020 12:28:23 +0100 Subject: [PATCH] Iterate the resizer Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/resizer/distributors/fixed.ts | 10 +++++++++- src/resizer/distributors/percentage.ts | 1 + src/resizer/item.ts | 14 +++++++++++--- src/resizer/resizer.ts | 4 ++-- src/resizer/sizer.ts | 14 +++++++++++--- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/resizer/distributors/fixed.ts b/src/resizer/distributors/fixed.ts index 10539a412a..9f987e7b24 100644 --- a/src/resizer/distributors/fixed.ts +++ b/src/resizer/distributors/fixed.ts @@ -39,10 +39,18 @@ export default class FixedDistributor { - protected readonly domNode: HTMLElement; + public readonly domNode: HTMLElement; protected readonly id: string; protected reverse: boolean; constructor( handle: HTMLElement, public readonly resizer: Resizer, - protected readonly sizer: Sizer, + public readonly sizer: Sizer, ) { const id = handle.getAttribute("data-id"); const reverse = resizer.isReverseResizeHandle(handle); @@ -89,8 +89,16 @@ export default class ResizeItem { this.sizer.finish(this.domNode); } - public setSize(size: number) { + public getSize() { + return this.sizer.getDesiredItemSize(this.domNode); + } + + public setRawSize(size: string) { this.sizer.setItemSize(this.domNode, size); + } + + public setSize(size: number) { + this.setRawSize(`${Math.round(size)}px`); const callback = this.resizer.config.onResized; if (callback) { callback(size, this.id, this.domNode); diff --git a/src/resizer/resizer.ts b/src/resizer/resizer.ts index 692ce5e22f..3ab8914fb5 100644 --- a/src/resizer/resizer.ts +++ b/src/resizer/resizer.ts @@ -50,7 +50,7 @@ export default class Resizer { // TODO move vertical/horizontal to config option/container class // as it doesn't make sense to mix them within one container/Resizer constructor( - private readonly container: HTMLElement, + public container: HTMLElement, private readonly distributorCtor: { new(item: ResizeItem): FixedDistributor; createItem(resizeHandle: HTMLDivElement, resizer: Resizer, sizer: Sizer): ResizeItem; @@ -145,10 +145,10 @@ export default class Resizer { if (this.classNames.resizing) { this.container.classList.remove(this.classNames.resizing); } + distributor.finish(); if (this.config.onResizeStop) { this.config.onResizeStop(); } - distributor.finish(); body.removeEventListener("mouseup", finishResize, false); document.removeEventListener("mouseleave", finishResize, false); body.removeEventListener("mousemove", onMouseMove, false); diff --git a/src/resizer/sizer.ts b/src/resizer/sizer.ts index 16000806a2..ec3a8c113c 100644 --- a/src/resizer/sizer.ts +++ b/src/resizer/sizer.ts @@ -68,11 +68,19 @@ export default class Sizer { return offset; } - public setItemSize(item: HTMLElement, size: number) { + public getDesiredItemSize(item: HTMLElement) { if (this.vertical) { - item.style.height = `${Math.round(size)}px`; + return item.style.height; } else { - item.style.width = `${Math.round(size)}px`; + return item.style.width; + } + } + + public setItemSize(item: HTMLElement, size: string) { + if (this.vertical) { + item.style.height = size; + } else { + item.style.width = size; } }