Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

scroll_bar: Simplify module.

Aman Agrawalb0dd063bb8d2
diff --git a/static/js/scroll_bar.js b/static/js/scroll_bar.js
index 22717214265..17042583b70 100644
--- a/static/js/scroll_bar.js
+++ b/static/js/scroll_bar.js
@@ -1,6 +1,5 @@
import $ from "jquery";
-import {media_breakpoints} from "./css_variables";
import {user_settings} from "./user_settings";
// A few of our width properties in Zulip depend on the width of the
@@ -40,59 +39,30 @@ let sbWidth;
export function initialize() {
// Workaround for browsers with fixed scrollbars
sbWidth = getScrollbarWidth();
- // These need to agree with zulip.css
- const left_sidebar_width = 270;
- const right_sidebar_width = 250;
-
if (sbWidth > 0) {
- $(".header").css("left", "-" + sbWidth + "px");
- $(".header-main").css("left", sbWidth + "px");
- $(".header-main .column-middle").css("margin-right", 7 + sbWidth + "px");
-
- $(".fixed-app").css("left", "-" + sbWidth + "px");
- $(".fixed-app .column-middle").css("margin-left", 7 + sbWidth + "px");
-
- $(".column-right").css("right", sbWidth + "px");
- $(".app-main .right-sidebar").css({
- "margin-left": sbWidth + "px",
- width: right_sidebar_width - sbWidth + "px",
- });
+ // Reduce width of screen-wide parent containers, whose width doesn't vary with scrollbar width, by scrollbar width.
+ $("#navbar-container .header, .fixed-app .app-main, #compose").css(
+ "width",
+ `calc(100% - ${sbWidth}px)`,
+ );
- $("#compose").css("left", "-" + sbWidth + "px");
- $("#compose-content").css({left: sbWidth + "px", "margin-right": 7 + sbWidth + "px"});
+ // Align floating recipient bar with the middle column.
+ $(".fixed-app").css("left", "-" + sbWidth / 2 + "px");
$("#keyboard-icon").css({"margin-right": sbWidth + "px"});
-
- $("head").append(
- "<style> @media (min-width: " +
- media_breakpoints.xl_min +
- ") { #compose-content, .header-main .column-middle { margin-right: " +
- (right_sidebar_width + sbWidth) +
- "px !important; } } " +
- "@media (min-width: " +
- media_breakpoints.md_min +
- ") { .fixed-app .column-middle { margin-left: " +
- (left_sidebar_width + sbWidth) +
- "px !important; } } " +
- "</style>",
- );
}
set_layout_width();
}
export function set_layout_width() {
- // This logic unfortunately leads to a flash of mispositioned
- // content when reloading a Zulip browser window. More details
- // are available in the comments on the max-width of 1400px in
- // the .app-main CSS rules.
if (user_settings.fluid_layout_width) {
- $(".header-main").css("max-width", "inherit");
- $(".app .app-main").css("max-width", "inherit");
- $(".fixed-app .app-main").css("max-width", "inherit");
- $("#compose-container").css("max-width", "inherit");
+ $(".header-main, .app .app-main, .fixed-app .app-main, #compose-container").css(
+ "max-width",
+ "inherit",
+ );
} else {
- $(".header-main").css("max-width", 1400 + sbWidth + "px");
- $(".app .app-main").css("max-width", 1400 + "px");
- $(".fixed-app .app-main").css("max-width", 1400 + sbWidth + "px");
- $("#compose-container").css("max-width", 1400 + sbWidth + "px");
+ $(".header-main, .app .app-main, .fixed-app .app-main, #compose-container").css(
+ "max-width",
+ "1400px",
+ );
}
}
diff --git a/static/styles/zulip.css b/static/styles/zulip.css
index 1c507102fd4..25f898372c4 100644
--- a/static/styles/zulip.css
+++ b/static/styles/zulip.css
@@ -339,16 +339,9 @@ p.n-margin {
.app-main,
.header-main {
width: 100%;
- /* TODO: This 1400px is wrong, but it's hard to do better. On
- browsers with a nonzero default scrollbar width (i.e. not
- macOS), we actually want a max-width of 1400px+the width of the
- scrollbar, which is done as an override in
- static/js/scroll_bar.js.
-
- And with the fluid_layout_width setting, we don't want a
- max-width at all. The consequence is that if you reload a
- Zulip window, there's a brief flash where the content is
- misplaced before the JS code can fix it. */
+ /* `max-width` is changed based on `fluid_layout_width` setting in
+ `scroll_bar.js`. User may or may not see a flash of mispositioned content
+ based on how quickly the JS code is executed. */
max-width: 1400px;
min-width: 950px;
margin: 0 auto;