2019-05-09 23:04:50 +02:00
|
|
|
// A few of our width properties in zulip depend on the width of the
|
|
|
|
// 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
|
|
|
|
2017-08-22 21:15:20 +02:00
|
|
|
document.body.appendChild(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%";
|
|
|
|
outer.appendChild(inner);
|
|
|
|
|
2019-11-02 00:06:25 +01:00
|
|
|
const widthWithScroll = inner.offsetWidth;
|
2017-08-22 21:15:20 +02:00
|
|
|
|
|
|
|
// remove divs
|
|
|
|
outer.parentNode.removeChild(outer);
|
|
|
|
|
|
|
|
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(
|
|
|
|
"<style> @media (max-width: 1165px) { .compose-content, .header-main .column-middle { margin-right: " +
|
|
|
|
(7 + sbWidth) +
|
|
|
|
"px !important; } } " +
|
|
|
|
"@media (max-width: 775px) { .fixed-app .column-middle { margin-left: " +
|
|
|
|
(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;
|