2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
|
|
|
|
2021-02-28 01:01:53 +01:00
|
|
|
import {media_breakpoints} from "./css_variables";
|
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";
|
|
|
|
|
|
|
|
// add innerdiv
|
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) {
|
|
|
|
$(".header").css("left", "-" + sbWidth + "px");
|
|
|
|
$(".header-main").css("left", sbWidth + "px");
|
2021-02-04 02:47:46 +01:00
|
|
|
$(".header-main .column-middle").css("margin-right", 7 + sbWidth + "px");
|
2018-05-06 21:43:17 +02:00
|
|
|
|
|
|
|
$(".fixed-app").css("left", "-" + sbWidth + "px");
|
2021-02-04 02:47:46 +01:00
|
|
|
$(".fixed-app .column-middle").css("margin-left", 7 + sbWidth + "px");
|
2018-05-06 21:43:17 +02:00
|
|
|
|
|
|
|
$(".column-right").css("right", sbWidth + "px");
|
2020-07-15 00:34:28 +02:00
|
|
|
$(".app-main .right-sidebar").css({
|
|
|
|
"margin-left": sbWidth + "px",
|
|
|
|
width: 250 - sbWidth + "px",
|
|
|
|
});
|
2018-05-06 21:43:17 +02:00
|
|
|
|
|
|
|
$("#compose").css("left", "-" + sbWidth + "px");
|
2021-02-04 02:47:46 +01:00
|
|
|
$(".compose-content").css({left: sbWidth + "px", "margin-right": 7 + sbWidth + "px"});
|
2021-03-22 20:21:58 +01:00
|
|
|
$("#keyboard-icon").css({"margin-right": sbWidth + "px"});
|
2018-05-06 21:43:17 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("head").append(
|
2021-02-04 02:47:46 +01:00
|
|
|
"<style> @media (min-width: " +
|
|
|
|
media_breakpoints.xl_min +
|
2021-01-25 14:58:46 +01:00
|
|
|
") { .compose-content, .header-main .column-middle { margin-right: " +
|
2021-02-04 02:47:46 +01:00
|
|
|
(250 + sbWidth) +
|
2020-07-15 00:34:28 +02:00
|
|
|
"px !important; } } " +
|
2021-02-04 02:47:46 +01:00
|
|
|
"@media (min-width: " +
|
|
|
|
media_breakpoints.md_min +
|
2020-10-31 10:35:21 +01:00
|
|
|
") { .fixed-app .column-middle { margin-left: " +
|
2021-02-04 02:47:46 +01:00
|
|
|
(250 + sbWidth) +
|
2020-07-15 00:34:28 +02:00
|
|
|
"px !important; } } " +
|
|
|
|
"</style>",
|
|
|
|
);
|
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() {
|
2019-05-09 23:04:50 +02:00
|
|
|
// 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.
|
2019-04-16 18:46:17 +02:00
|
|
|
if (page_params.fluid_layout_width) {
|
|
|
|
$(".header-main").css("max-width", "inherit");
|
2019-05-13 20:27:00 +02:00
|
|
|
$(".app .app-main").css("max-width", "inherit");
|
2019-05-10 20:41:51 +02:00
|
|
|
$(".fixed-app .app-main").css("max-width", "inherit");
|
2019-04-16 18:46:17 +02:00
|
|
|
$("#compose-container").css("max-width", "inherit");
|
|
|
|
} else {
|
|
|
|
$(".header-main").css("max-width", 1400 + sbWidth + "px");
|
2019-05-13 20:27:00 +02:00
|
|
|
$(".app .app-main").css("max-width", 1400 + "px");
|
2019-05-10 20:41:51 +02:00
|
|
|
$(".fixed-app .app-main").css("max-width", 1400 + sbWidth + "px");
|
2019-04-16 18:46:17 +02:00
|
|
|
$("#compose-container").css("max-width", 1400 + sbWidth + "px");
|
|
|
|
}
|
2021-02-28 01:01:53 +01:00
|
|
|
}
|