mirror of
https://github.com/zulip/zulip.git
synced 2025-11-16 03:41:58 +00:00
js: Simplify more code using default parameters and destructuring.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
166bfa4cf8
commit
fa81ae3aa4
@@ -2,8 +2,7 @@ import $ from "jquery";
|
|||||||
|
|
||||||
import render_loader from "../templates/loader.hbs";
|
import render_loader from "../templates/loader.hbs";
|
||||||
|
|
||||||
export function make_indicator(outer_container, opts) {
|
export function make_indicator(outer_container, {abs_positioned = false, text} = {}) {
|
||||||
opts = opts || {};
|
|
||||||
let container = outer_container;
|
let container = outer_container;
|
||||||
|
|
||||||
// TODO: We set white-space to 'nowrap' because under some
|
// TODO: We set white-space to 'nowrap' because under some
|
||||||
@@ -15,7 +14,7 @@ export function make_indicator(outer_container, opts) {
|
|||||||
|
|
||||||
container.empty();
|
container.empty();
|
||||||
|
|
||||||
if (opts.abs_positioned !== undefined && opts.abs_positioned) {
|
if (abs_positioned) {
|
||||||
// Create some additional containers to facilitate absolutely
|
// Create some additional containers to facilitate absolutely
|
||||||
// positioned spinners.
|
// positioned spinners.
|
||||||
const container_id = container.attr("id");
|
const container_id = container.attr("id");
|
||||||
@@ -32,12 +31,12 @@ export function make_indicator(outer_container, opts) {
|
|||||||
container.append(spinner_elem);
|
container.append(spinner_elem);
|
||||||
let text_width = 0;
|
let text_width = 0;
|
||||||
|
|
||||||
if (opts.text !== undefined && opts.text !== "") {
|
if (text !== undefined) {
|
||||||
const text_elem = $('<span class="loading_indicator_text"></span>');
|
const text_elem = $('<span class="loading_indicator_text"></span>');
|
||||||
text_elem.text(opts.text);
|
text_elem.text(text);
|
||||||
container.append(text_elem);
|
container.append(text_elem);
|
||||||
// See note, below
|
// See note, below
|
||||||
if (!(opts.abs_positioned !== undefined && opts.abs_positioned)) {
|
if (!abs_positioned) {
|
||||||
text_width = 20 + text_elem.width();
|
text_width = 20 + text_elem.width();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -342,9 +342,7 @@ export function user_initiated_animate_scroll(scroll_amount) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function recenter_view(message, opts) {
|
export function recenter_view(message, {from_scroll = false, force_center = false} = {}) {
|
||||||
opts = opts || {};
|
|
||||||
|
|
||||||
// BarnOwl-style recentering: if the pointer is too high, move it to
|
// BarnOwl-style recentering: if the pointer is too high, move it to
|
||||||
// the 1/2 marks. If the pointer is too low, move it to the 1/7 mark.
|
// the 1/2 marks. If the pointer is too low, move it to the 1/7 mark.
|
||||||
// See keep_pointer_in_view() for related logic to keep the pointer onscreen.
|
// See keep_pointer_in_view() for related logic to keep the pointer onscreen.
|
||||||
@@ -361,7 +359,7 @@ export function recenter_view(message, opts) {
|
|||||||
const is_above = message_top < top_threshold;
|
const is_above = message_top < top_threshold;
|
||||||
const is_below = message_bottom > bottom_threshold;
|
const is_below = message_bottom > bottom_threshold;
|
||||||
|
|
||||||
if (opts.from_scroll) {
|
if (from_scroll) {
|
||||||
// If the message you're trying to center on is already in view AND
|
// If the message you're trying to center on is already in view AND
|
||||||
// you're already trying to move in the direction of that message,
|
// you're already trying to move in the direction of that message,
|
||||||
// don't try to recenter. This avoids disorienting jumps when the
|
// don't try to recenter. This avoids disorienting jumps when the
|
||||||
@@ -375,7 +373,7 @@ export function recenter_view(message, opts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_above || opts.force_center) {
|
if (is_above || force_center) {
|
||||||
set_message_position(message_top, message_height, viewport_info, 1 / 2);
|
set_message_position(message_top, message_height, viewport_info, 1 / 2);
|
||||||
} else if (is_below) {
|
} else if (is_below) {
|
||||||
set_message_position(message_top, message_height, viewport_info, 1 / 7);
|
set_message_position(message_top, message_height, viewport_info, 1 / 7);
|
||||||
|
|||||||
@@ -75,8 +75,7 @@ export function process_read_messages_event(message_ids) {
|
|||||||
|
|
||||||
// Takes a list of messages and marks them as read.
|
// Takes a list of messages and marks them as read.
|
||||||
// Skips any messages that are already marked as read.
|
// Skips any messages that are already marked as read.
|
||||||
export function notify_server_messages_read(messages, options) {
|
export function notify_server_messages_read(messages, options = {}) {
|
||||||
options = options || {};
|
|
||||||
messages = unread.get_unread_messages(messages);
|
messages = unread.get_unread_messages(messages);
|
||||||
if (messages.length === 0) {
|
if (messages.length === 0) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user