stop resize operation when cursor leaves viewport

as mouseup can't be detected outside of viewport
This commit is contained in:
Bruno Windels 2019-01-11 18:20:34 +01:00
parent a413f358f7
commit 136dd4a556

View file

@ -115,16 +115,17 @@ export class Resizer {
}; };
const body = document.body; const body = document.body;
const onMouseUp = (event) => { const finishResize = () => {
if (this.classNames.resizing) { if (this.classNames.resizing) {
this.container.classList.remove(this.classNames.resizing); this.container.classList.remove(this.classNames.resizing);
} }
distributor.finish(); distributor.finish();
body.removeEventListener("mouseup", onMouseUp, false); body.removeEventListener("mouseup", finishResize, false);
document.removeEventListener("mouseleave", finishResize, false);
body.removeEventListener("mousemove", onMouseMove, false); body.removeEventListener("mousemove", onMouseMove, false);
}; };
// TODO: listen for mouseout on document here as well body.addEventListener("mouseup", finishResize, false);
body.addEventListener("mouseup", onMouseUp, false); document.addEventListener("mouseleave", finishResize, false);
body.addEventListener("mousemove", onMouseMove, false); body.addEventListener("mousemove", onMouseMove, false);
} }