2014-03-13 19:03:31 +01:00
|
|
|
var resize = (function () {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
var narrow_window = false;
|
|
|
|
|
|
|
|
function confine_to_range(lo, val, hi) {
|
|
|
|
if (val < lo) {
|
|
|
|
return lo;
|
|
|
|
}
|
|
|
|
if (val > hi) {
|
|
|
|
return hi;
|
|
|
|
}
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
function size_blocks(blocks, usable_height) {
|
|
|
|
var sum_height = 0;
|
|
|
|
_.each(blocks, function (block) {
|
|
|
|
sum_height += block.real_height;
|
|
|
|
});
|
|
|
|
|
|
|
|
_.each(blocks, function (block) {
|
|
|
|
var ratio = block.real_height / sum_height;
|
|
|
|
ratio = confine_to_range(0.05, ratio, 0.85);
|
2017-01-09 11:38:38 +01:00
|
|
|
block.max_height = confine_to_range(80, usable_height * ratio, 1.2 * block.real_height);
|
2014-03-13 19:03:31 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-07-26 20:17:34 +02:00
|
|
|
function set_user_list_heights(res, usable_height, buddy_list_wrapper, group_pms) {
|
2014-03-13 19:03:31 +01:00
|
|
|
// Calculate these heights:
|
2018-07-26 20:17:34 +02:00
|
|
|
// res.buddy_list_wrapper_max_height
|
2014-03-13 19:03:31 +01:00
|
|
|
// res.group_pms_max_height
|
|
|
|
var blocks = [
|
|
|
|
{
|
2018-07-26 20:17:34 +02:00
|
|
|
real_height: buddy_list_wrapper.prop('scrollHeight'),
|
2014-03-13 19:03:31 +01:00
|
|
|
},
|
|
|
|
{
|
2017-01-12 00:17:43 +01:00
|
|
|
real_height: group_pms.prop('scrollHeight'),
|
|
|
|
},
|
2014-03-13 19:03:31 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
size_blocks(blocks, usable_height);
|
|
|
|
|
2018-07-26 20:17:34 +02:00
|
|
|
res.buddy_list_wrapper_max_height = blocks[0].max_height;
|
2014-03-13 19:03:31 +01:00
|
|
|
res.group_pms_max_height = blocks[1].max_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
function get_new_heights() {
|
|
|
|
var res = {};
|
2017-03-10 23:48:51 +01:00
|
|
|
var viewport_height = message_viewport.height();
|
2017-07-27 21:40:26 +02:00
|
|
|
var top_navbar_height = $("#top_navbar").safeOuterHeight(true);
|
|
|
|
var invite_user_link_height = $("#invite-user-link").safeOuterHeight(true) || 0;
|
2014-03-13 19:03:31 +01:00
|
|
|
|
|
|
|
res.bottom_whitespace_height = viewport_height * 0.4;
|
|
|
|
|
|
|
|
res.main_div_min_height = viewport_height - top_navbar_height;
|
|
|
|
|
2017-09-15 23:16:45 +02:00
|
|
|
res.bottom_sidebar_height = viewport_height - top_navbar_height;
|
2014-03-13 19:03:31 +01:00
|
|
|
|
|
|
|
res.right_sidebar_height = viewport_height - parseInt($("#right-sidebar").css("marginTop"), 10);
|
|
|
|
|
|
|
|
res.stream_filters_max_height =
|
|
|
|
res.bottom_sidebar_height
|
2017-07-27 21:40:26 +02:00
|
|
|
- $("#global_filters").safeOuterHeight(true)
|
|
|
|
- $("#streams_header").safeOuterHeight(true)
|
2014-03-13 19:03:31 +01:00
|
|
|
- 10; // stream_filters margin-bottom
|
|
|
|
|
|
|
|
// Don't let us crush the stream sidebar completely out of view
|
2017-01-09 11:38:38 +01:00
|
|
|
res.stream_filters_max_height = Math.max(80, res.stream_filters_max_height);
|
2014-03-13 19:03:31 +01:00
|
|
|
|
|
|
|
// RIGHT SIDEBAR
|
2018-07-26 20:17:34 +02:00
|
|
|
var buddy_list_wrapper = $('#buddy_list_wrapper').expectOne();
|
2014-03-13 19:03:31 +01:00
|
|
|
var group_pms = $('#group-pms').expectOne();
|
2018-08-19 23:18:51 +02:00
|
|
|
var keyboard_popover_shortcut = $('#keyboard-icon').expectOne();
|
2014-03-13 19:03:31 +01:00
|
|
|
|
|
|
|
var usable_height =
|
|
|
|
res.right_sidebar_height
|
2017-07-27 21:40:26 +02:00
|
|
|
- $("#feedback_section").safeOuterHeight(true)
|
2018-07-26 20:17:34 +02:00
|
|
|
- parseInt(buddy_list_wrapper.css("marginTop"),10)
|
|
|
|
- parseInt(buddy_list_wrapper.css("marginBottom"), 10)
|
2017-07-27 21:40:26 +02:00
|
|
|
- $("#userlist-header").safeOuterHeight(true)
|
|
|
|
- $(".user-list-filter").safeOuterHeight(true)
|
2014-03-13 19:03:31 +01:00
|
|
|
- invite_user_link_height
|
|
|
|
- parseInt(group_pms.css("marginTop"),10)
|
|
|
|
- parseInt(group_pms.css("marginBottom"), 10)
|
2018-05-08 00:04:58 +02:00
|
|
|
- $("#group-pm-header").safeOuterHeight(true)
|
|
|
|
- keyboard_popover_shortcut.safeOuterHeight(true)
|
|
|
|
- parseInt(keyboard_popover_shortcut.css("marginBottom"), 10);
|
2014-03-13 19:03:31 +01:00
|
|
|
|
|
|
|
// set these
|
2018-07-26 20:17:34 +02:00
|
|
|
// res.buddy_list_wrapper_max_height
|
2014-03-13 19:03:31 +01:00
|
|
|
// res.group_pms_max_height
|
|
|
|
set_user_list_heights(
|
|
|
|
res,
|
|
|
|
usable_height,
|
2018-07-26 20:17:34 +02:00
|
|
|
buddy_list_wrapper,
|
2014-03-13 19:03:31 +01:00
|
|
|
group_pms
|
|
|
|
);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function left_userlist_get_new_heights() {
|
|
|
|
|
|
|
|
var res = {};
|
2017-03-10 23:48:51 +01:00
|
|
|
var viewport_height = message_viewport.height();
|
|
|
|
var viewport_width = message_viewport.width();
|
2017-07-27 21:40:26 +02:00
|
|
|
var top_navbar_height = $(".header").safeOuterHeight(true);
|
2014-03-13 19:03:31 +01:00
|
|
|
|
|
|
|
var stream_filters = $('#stream_filters').expectOne();
|
2018-07-26 20:17:34 +02:00
|
|
|
var buddy_list_wrapper = $('#buddy_list_wrapper').expectOne();
|
2014-03-13 19:03:31 +01:00
|
|
|
var group_pms = $('#group-pms').expectOne();
|
|
|
|
|
|
|
|
var stream_filters_real_height = stream_filters.prop("scrollHeight");
|
2018-07-26 20:17:34 +02:00
|
|
|
var user_list_real_height = buddy_list_wrapper.prop("scrollHeight");
|
2014-03-13 19:03:31 +01:00
|
|
|
var group_pms_real_height = group_pms.prop("scrollHeight");
|
|
|
|
|
|
|
|
res.bottom_whitespace_height = viewport_height * 0.4;
|
|
|
|
|
|
|
|
res.main_div_min_height = viewport_height - top_navbar_height;
|
|
|
|
|
|
|
|
res.bottom_sidebar_height = viewport_height
|
|
|
|
- parseInt($("#left-sidebar").css("marginTop"),10)
|
|
|
|
- parseInt($(".bottom_sidebar").css("marginTop"),10);
|
|
|
|
|
|
|
|
|
|
|
|
res.total_leftlist_height = res.bottom_sidebar_height
|
2017-07-27 21:40:26 +02:00
|
|
|
- $("#global_filters").safeOuterHeight(true)
|
|
|
|
- $("#streams_header").safeOuterHeight(true)
|
|
|
|
- $("#userlist-header").safeOuterHeight(true)
|
|
|
|
- $(".user-list-filter").safeOuterHeight(true)
|
|
|
|
- $("#group-pm-header").safeOuterHeight(true)
|
2014-03-13 19:03:31 +01:00
|
|
|
- parseInt(stream_filters.css("marginBottom"),10)
|
2018-07-26 20:17:34 +02:00
|
|
|
- parseInt(buddy_list_wrapper.css("marginTop"), 10)
|
|
|
|
- parseInt(buddy_list_wrapper.css("marginBottom"), 10)
|
2014-03-13 19:03:31 +01:00
|
|
|
- parseInt(group_pms.css("marginTop"), 10)
|
|
|
|
- parseInt(group_pms.css("marginBottom"), 10)
|
|
|
|
- 15;
|
|
|
|
|
|
|
|
var blocks = [
|
|
|
|
{
|
2017-01-12 00:17:43 +01:00
|
|
|
real_height: stream_filters_real_height,
|
2014-03-13 19:03:31 +01:00
|
|
|
},
|
|
|
|
{
|
2017-01-12 00:17:43 +01:00
|
|
|
real_height: user_list_real_height,
|
2014-03-13 19:03:31 +01:00
|
|
|
},
|
|
|
|
{
|
2017-01-12 00:17:43 +01:00
|
|
|
real_height: group_pms_real_height,
|
|
|
|
},
|
2014-03-13 19:03:31 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
size_blocks(blocks, res.total_leftlist_height);
|
|
|
|
|
|
|
|
res.stream_filters_max_height = blocks[0].max_height;
|
2018-07-26 20:17:34 +02:00
|
|
|
res.buddy_list_wrapper_max_height = blocks[1].max_height;
|
2014-03-13 19:03:31 +01:00
|
|
|
res.group_pms_max_height = blocks[2].max_height;
|
|
|
|
|
|
|
|
res.viewport_height = viewport_height;
|
|
|
|
res.viewport_width = viewport_width;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2017-04-22 22:34:18 +02:00
|
|
|
exports.watch_manual_resize = function (element) {
|
2017-04-26 04:30:35 +02:00
|
|
|
return (function on_box_resize(cb) {
|
2017-05-11 18:28:33 +02:00
|
|
|
var box = document.querySelector(element);
|
|
|
|
|
|
|
|
if (!box) {
|
|
|
|
blueslip.error('Bad selector in watch_manual_resize: ' + element);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-22 22:34:18 +02:00
|
|
|
var meta = {
|
2017-05-11 18:28:33 +02:00
|
|
|
box: box,
|
2017-04-22 22:34:18 +02:00
|
|
|
height: null,
|
|
|
|
mousedown: false,
|
|
|
|
};
|
|
|
|
|
2017-04-26 04:30:35 +02:00
|
|
|
var box_handler = function () {
|
2017-04-22 22:34:18 +02:00
|
|
|
meta.mousedown = true;
|
|
|
|
meta.height = meta.box.clientHeight;
|
2017-04-26 04:30:35 +02:00
|
|
|
};
|
|
|
|
meta.box.addEventListener("mousedown", box_handler);
|
2017-04-22 22:34:18 +02:00
|
|
|
|
|
|
|
// If the user resizes the textarea manually, we use the
|
|
|
|
// callback to stop autosize from adjusting the height.
|
2017-04-26 04:30:35 +02:00
|
|
|
var body_handler = function () {
|
2017-04-22 22:34:18 +02:00
|
|
|
if (meta.mousedown === true) {
|
|
|
|
meta.mousedown = false;
|
|
|
|
if (meta.height !== meta.box.clientHeight) {
|
|
|
|
meta.height = meta.box.clientHeight;
|
|
|
|
cb.call(meta.box, meta.height);
|
|
|
|
}
|
|
|
|
}
|
2017-04-26 04:30:35 +02:00
|
|
|
};
|
|
|
|
document.body.addEventListener("mouseup", body_handler);
|
|
|
|
|
|
|
|
return [box_handler, body_handler];
|
2017-04-22 22:34:18 +02:00
|
|
|
}(function (height) {
|
|
|
|
// This callback disables autosize on the textarea. It
|
|
|
|
// will be re-enabled when this component is next opened.
|
|
|
|
$(element).trigger("autosize.destroy")
|
|
|
|
.height(height + "px");
|
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
2014-03-13 19:03:31 +01:00
|
|
|
exports.resize_bottom_whitespace = function (h) {
|
2017-12-27 13:17:58 +01:00
|
|
|
if (h !== undefined) {
|
2014-03-13 19:03:31 +01:00
|
|
|
$("#bottom_whitespace").height(h.bottom_whitespace_height);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-25 18:41:32 +01:00
|
|
|
exports.resize_stream_filters_container = function (h) {
|
|
|
|
h = narrow_window ? left_userlist_get_new_heights() : get_new_heights();
|
|
|
|
exports.resize_bottom_whitespace(h);
|
|
|
|
$("#stream-filters-container").css('max-height', h.stream_filters_max_height);
|
2018-03-12 03:40:56 +01:00
|
|
|
ui.update_scrollbar($("#stream-filters-container"));
|
2015-11-25 18:41:32 +01:00
|
|
|
};
|
|
|
|
|
2014-03-13 19:03:31 +01:00
|
|
|
exports.resize_page_components = function () {
|
|
|
|
var h;
|
|
|
|
var sidebar;
|
|
|
|
|
2015-08-20 23:59:44 +02:00
|
|
|
if (page_params.left_side_userlist) {
|
2017-03-10 23:48:51 +01:00
|
|
|
var css_narrow_mode = message_viewport.is_narrow();
|
2014-03-13 19:03:31 +01:00
|
|
|
|
|
|
|
$("#top_navbar").removeClass("rightside-userlist");
|
|
|
|
|
|
|
|
if (css_narrow_mode && !narrow_window) {
|
|
|
|
// move stuff to the left sidebar (skinny mode)
|
|
|
|
narrow_window = true;
|
|
|
|
popovers.set_userlist_placement("left");
|
|
|
|
sidebar = $(".bottom_sidebar").expectOne();
|
|
|
|
sidebar.append($("#user-list").expectOne());
|
|
|
|
sidebar.append($("#group-pm-list").expectOne());
|
2018-07-26 20:17:34 +02:00
|
|
|
$("#buddy_list_wrapper").css("margin", "0px");
|
2014-03-13 19:03:31 +01:00
|
|
|
$("#group-pms").css("margin", "0px");
|
|
|
|
$("#userlist-toggle").css("display", "none");
|
|
|
|
$("#invite-user-link").hide();
|
2016-06-09 23:05:34 +02:00
|
|
|
} else if (!css_narrow_mode && narrow_window) {
|
2014-03-13 19:03:31 +01:00
|
|
|
// move stuff to the right sidebar (wide mode)
|
|
|
|
narrow_window = false;
|
|
|
|
popovers.set_userlist_placement("right");
|
|
|
|
sidebar = $("#right-sidebar").expectOne();
|
|
|
|
sidebar.append($("#user-list").expectOne());
|
|
|
|
sidebar.append($("#group-pm-list").expectOne());
|
2018-07-26 20:17:34 +02:00
|
|
|
$("#buddy_list_wrapper").css("margin", '');
|
2014-03-13 19:03:31 +01:00
|
|
|
$("#group-pms").css("margin", '');
|
|
|
|
$("#userlist-toggle").css("display", '');
|
|
|
|
$("#invite-user-link").show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
h = narrow_window ? left_userlist_get_new_heights() : get_new_heights();
|
|
|
|
|
|
|
|
exports.resize_bottom_whitespace(h);
|
2018-07-26 20:17:34 +02:00
|
|
|
$("#buddy_list_wrapper").css('max-height', h.buddy_list_wrapper_max_height);
|
2014-03-13 19:03:31 +01:00
|
|
|
$("#group-pms").css('max-height', h.group_pms_max_height);
|
|
|
|
|
2018-03-12 03:40:56 +01:00
|
|
|
$("#stream-filters-container").css('max-height', h.stream_filters_max_height);
|
|
|
|
ui.update_scrollbar($("#stream-filters-container"));
|
2017-09-27 20:41:19 +02:00
|
|
|
|
|
|
|
activity.update_scrollbar.users();
|
|
|
|
activity.update_scrollbar.group_pms();
|
2017-10-13 00:13:51 +02:00
|
|
|
|
2018-01-31 01:11:21 +01:00
|
|
|
panels.resize_app();
|
2014-03-13 19:03:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
var _old_width = $(window).width();
|
|
|
|
|
2016-12-02 14:06:06 +01:00
|
|
|
exports.handler = function () {
|
2014-03-13 19:03:31 +01:00
|
|
|
var new_width = $(window).width();
|
|
|
|
|
|
|
|
if (new_width !== _old_width) {
|
|
|
|
_old_width = new_width;
|
2014-03-13 20:22:09 +01:00
|
|
|
condense.clear_message_content_height_cache();
|
2014-03-13 19:03:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
popovers.hide_all();
|
|
|
|
exports.resize_page_components();
|
|
|
|
|
2018-03-26 19:26:24 +02:00
|
|
|
// Re-compute and display/remove [More] links to messages
|
|
|
|
condense.condense_and_collapse($("div.message_row"));
|
|
|
|
|
2014-03-13 19:03:31 +01:00
|
|
|
// This function might run onReady (if we're in a narrow window),
|
|
|
|
// but before we've loaded in the messages; in that case, don't
|
|
|
|
// try to scroll to one.
|
|
|
|
if (current_msg_list.selected_id() !== -1) {
|
2016-05-25 13:26:57 +02:00
|
|
|
navigate.scroll_to_selected();
|
2014-03-13 19:03:31 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
}());
|
2016-12-04 08:59:56 +01:00
|
|
|
|
|
|
|
if (typeof module !== 'undefined') {
|
|
|
|
module.exports = resize;
|
|
|
|
}
|
2018-05-28 08:04:36 +02:00
|
|
|
window.resize = resize;
|