2020-08-01 03:43:15 +02:00
|
|
|
"use strict";
|
|
|
|
|
2021-01-25 14:58:46 +01:00
|
|
|
const {media_breakpoints} = require("./css_variables");
|
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
|
|
|
|
2018-06-19 20:16:00 +02:00
|
|
|
exports.initialize = function () {
|
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");
|
2018-06-06 18:50:09 +02:00
|
|
|
$(".header-main .column-middle").css("margin-right", 250 + sbWidth + "px");
|
2018-05-06 21:43:17 +02:00
|
|
|
|
|
|
|
$(".fixed-app").css("left", "-" + sbWidth + "px");
|
2018-06-06 18:50:09 +02:00
|
|
|
$(".fixed-app .column-middle").css("margin-left", 250 + 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");
|
2020-07-15 00:34:28 +02:00
|
|
|
$(".compose-content").css({left: sbWidth + "px", "margin-right": 250 + sbWidth + "px"});
|
2020-07-15 01:29:15 +02:00
|
|
|
$("#keyboard-icon").css({right: sbWidth + 35 + "px"});
|
2018-05-06 21:43:17 +02:00
|
|
|
|
2020-07-15 00:34:28 +02:00
|
|
|
$("head").append(
|
2021-01-25 14:58:46 +01:00
|
|
|
"<style> @media (max-width: " +
|
2021-01-25 09:18:09 +01:00
|
|
|
media_breakpoints.xl_max +
|
2021-01-25 14:58:46 +01:00
|
|
|
") { .compose-content, .header-main .column-middle { margin-right: " +
|
2020-07-15 00:34:28 +02:00
|
|
|
(7 + sbWidth) +
|
|
|
|
"px !important; } } " +
|
2020-10-31 10:35:21 +01:00
|
|
|
"@media (max-width: " +
|
2021-01-27 18:28:58 +01:00
|
|
|
media_breakpoints.md_max +
|
2020-10-31 10:35:21 +01:00
|
|
|
") { .fixed-app .column-middle { margin-left: " +
|
2020-07-15 00:34:28 +02:00
|
|
|
(7 + sbWidth) +
|
|
|
|
"px !important; } } " +
|
|
|
|
"</style>",
|
|
|
|
);
|
2019-04-16 18:46:17 +02:00
|
|
|
}
|
2019-06-30 22:44:22 +02:00
|
|
|
exports.set_layout_width();
|
2018-06-19 20:16:00 +02:00
|
|
|
};
|
|
|
|
|
2019-04-16 18:46:17 +02:00
|
|
|
exports.set_layout_width = function () {
|
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");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-10-25 09:45:13 +02:00
|
|
|
window.scroll_bar = exports;
|