2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-07-28 16:00:58 +02:00
|
|
|
import {user_settings} from "./user_settings";
|
2020-08-01 03:43:15 +02:00
|
|
|
|
2020-10-23 02:43:28 +02:00
|
|
|
// A few of our width properties in Zulip depend on the width of the
|
2019-05-09 23:04:50 +02:00
|
|
|
// browser scrollbar that is generated at the far right side of the
|
|
|
|
// page, which unfortunately varies depending on the browser and
|
|
|
|
// cannot be detected directly using CSS. As a result, we adjust a
|
|
|
|
// number of element widths based on the value detected here.
|
|
|
|
//
|
2017-08-22 21:15:20 +02:00
|
|
|
// From https://stackoverflow.com/questions/13382516/getting-scroll-bar-width-using-javascript
|
|
|
|
function getScrollbarWidth() {
|
2019-11-02 00:06:25 +01:00
|
|
|
const outer = document.createElement("div");
|
2017-08-22 21:15:20 +02:00
|
|
|
outer.style.visibility = "hidden";
|
|
|
|
outer.style.width = "100px";
|
|
|
|
outer.style.msOverflowStyle = "scrollbar"; // needed for WinJS apps
|
2014-03-13 19:16:11 +01:00
|
|
|
|
2020-10-07 11:57:32 +02:00
|
|
|
document.body.append(outer);
|
2014-03-13 19:16:11 +01:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const widthNoScroll = outer.offsetWidth;
|
2017-08-22 21:15:20 +02:00
|
|
|
// force scrollbars
|
|
|
|
outer.style.overflow = "scroll";
|
|
|
|
|
2022-02-08 00:13:33 +01:00
|
|
|
// add inner div
|
2019-11-02 00:06:25 +01:00
|
|
|
const inner = document.createElement("div");
|
2017-08-22 21:15:20 +02:00
|
|
|
inner.style.width = "100%";
|
2020-10-07 11:57:32 +02:00
|
|
|
outer.append(inner);
|
2017-08-22 21:15:20 +02:00
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const widthWithScroll = inner.offsetWidth;
|
2017-08-22 21:15:20 +02:00
|
|
|
|
|
|
|
// remove divs
|
2020-10-07 11:57:32 +02:00
|
|
|
outer.remove();
|
2017-08-22 21:15:20 +02:00
|
|
|
|
|
|
|
return widthNoScroll - widthWithScroll;
|
2014-03-13 19:16:11 +01:00
|
|
|
}
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
let sbWidth;
|
2019-05-10 20:44:27 +02:00
|
|
|
|
2021-02-28 01:01:53 +01:00
|
|
|
export function initialize() {
|
2020-07-15 00:34:28 +02:00
|
|
|
// Workaround for browsers with fixed scrollbars
|
2019-05-10 20:44:27 +02:00
|
|
|
sbWidth = getScrollbarWidth();
|
2018-05-06 21:43:17 +02:00
|
|
|
if (sbWidth > 0) {
|
2022-01-06 07:04:52 +01:00
|
|
|
// Reduce width of screen-wide parent containers, whose width doesn't vary with scrollbar width, by scrollbar width.
|
2022-12-19 09:16:05 +01:00
|
|
|
$("#navbar-container .header, #compose").css("width", `calc(100% - ${sbWidth}px)`);
|
2019-04-16 18:46:17 +02:00
|
|
|
}
|
2021-02-28 01:01:53 +01:00
|
|
|
set_layout_width();
|
|
|
|
}
|
2018-06-19 20:16:00 +02:00
|
|
|
|
2021-02-28 01:01:53 +01:00
|
|
|
export function set_layout_width() {
|
2021-07-28 16:00:58 +02:00
|
|
|
if (user_settings.fluid_layout_width) {
|
2022-12-19 09:16:05 +01:00
|
|
|
$(".header-main, .app .app-main, #compose-container").css("max-width", "inherit");
|
2019-04-16 18:46:17 +02:00
|
|
|
} else {
|
2022-12-19 09:16:05 +01:00
|
|
|
$(".header-main, .app .app-main, #compose-container").css("max-width", "1400px");
|
2019-04-16 18:46:17 +02:00
|
|
|
}
|
2021-02-28 01:01:53 +01:00
|
|
|
}
|