[PDFSidebarResizer] Re-factor the resize
event listener to improve readability
I've absolutely no idea why I wrote the code that way originally, since the nested `if`s are not really helping readability one bit. Hence this patch which changes things to use early `return`s instead, to help readability.
This commit is contained in:
parent
9e4552d792
commit
32d16ab5f6
@ -151,14 +151,22 @@ class PDFSidebarResizer {
|
|||||||
this.eventBus.on('resize', (evt) => {
|
this.eventBus.on('resize', (evt) => {
|
||||||
// When the *entire* viewer is resized, such that it becomes narrower,
|
// When the *entire* viewer is resized, such that it becomes narrower,
|
||||||
// ensure that the sidebar doesn't end up being too wide.
|
// ensure that the sidebar doesn't end up being too wide.
|
||||||
if (evt && evt.source === window) {
|
if (!evt || evt.source !== window) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Always reset the cached width when the viewer is resized.
|
// Always reset the cached width when the viewer is resized.
|
||||||
this._outerContainerWidth = null;
|
this._outerContainerWidth = null;
|
||||||
|
|
||||||
if (this._width) {
|
if (!this._width) {
|
||||||
|
// The sidebar hasn't been resized, hence no need to adjust its width.
|
||||||
|
return;
|
||||||
|
}
|
||||||
// NOTE: If the sidebar is closed, we don't need to worry about
|
// NOTE: If the sidebar is closed, we don't need to worry about
|
||||||
// visual glitches nor ensure that rendering is triggered.
|
// visual glitches nor ensure that rendering is triggered.
|
||||||
if (this.sidebarOpen) {
|
if (!this.sidebarOpen) {
|
||||||
|
this._updateWidth(this._width);
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
|
this.outerContainer.classList.add(SIDEBAR_RESIZING_CLASS);
|
||||||
let updated = this._updateWidth(this._width);
|
let updated = this._updateWidth(this._width);
|
||||||
|
|
||||||
@ -170,11 +178,6 @@ class PDFSidebarResizer {
|
|||||||
this.eventBus.dispatch('resize', { source: this, });
|
this.eventBus.dispatch('resize', { source: this, });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
this._updateWidth(this._width);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user