2021-03-11 05:43:45 +01:00
|
|
|
import $ from "jquery";
|
2023-10-13 12:51:35 +02:00
|
|
|
import WinChan from "winchan";
|
2021-03-11 05:43:45 +01:00
|
|
|
|
2023-10-13 12:51:35 +02:00
|
|
|
import render_gear_menu_popover from "../templates/gear_menu_popover.hbs";
|
2021-06-14 12:38:43 +02:00
|
|
|
|
2023-10-13 12:51:35 +02:00
|
|
|
import * as blueslip from "./blueslip";
|
|
|
|
import * as channel from "./channel";
|
|
|
|
import * as dark_theme from "./dark_theme";
|
|
|
|
import * as message_lists from "./message_lists";
|
|
|
|
import * as popover_menus from "./popover_menus";
|
2023-10-13 11:50:18 +02:00
|
|
|
import * as popover_menus_data from "./popover_menus_data";
|
2023-10-13 12:51:35 +02:00
|
|
|
import * as popovers from "./popovers";
|
2024-01-09 20:36:02 +01:00
|
|
|
import * as settings_preferences from "./settings_preferences";
|
2023-10-13 12:51:35 +02:00
|
|
|
import {parse_html} from "./ui_util";
|
2021-02-28 00:42:00 +01:00
|
|
|
|
2018-08-29 19:50:12 +02:00
|
|
|
/*
|
|
|
|
For various historical reasons there isn't one
|
|
|
|
single chunk of code that really makes our gear
|
|
|
|
menu function. In this comment I try to help
|
|
|
|
you know where to look for relevant code.
|
|
|
|
|
|
|
|
The module that you're reading now doesn't
|
2020-12-20 13:03:32 +01:00
|
|
|
actually do much of the work.
|
2018-08-29 19:50:12 +02:00
|
|
|
|
|
|
|
Our gear menu has these choices:
|
|
|
|
|
|
|
|
=================
|
2023-11-17 17:53:41 +01:00
|
|
|
hash: Stream settings
|
2018-08-29 19:50:12 +02:00
|
|
|
hash: Settings
|
|
|
|
hash: Organization settings
|
2021-05-12 16:56:51 +02:00
|
|
|
link: Usage statistics
|
2018-08-29 19:50:12 +02:00
|
|
|
---
|
|
|
|
link: Help center
|
|
|
|
info: Keyboard shortcuts
|
|
|
|
info: Message formatting
|
2022-12-09 04:13:09 +01:00
|
|
|
info: Search filters
|
2021-02-09 11:16:52 +01:00
|
|
|
hash: About Zulip
|
2018-08-29 19:50:12 +02:00
|
|
|
---
|
|
|
|
link: Desktop & mobile apps
|
|
|
|
link: Integrations
|
|
|
|
link: API documentation
|
2021-05-12 16:56:51 +02:00
|
|
|
link: Sponsor Zulip
|
|
|
|
link: Plans and pricing
|
2018-08-29 19:50:12 +02:00
|
|
|
---
|
|
|
|
hash: Invite users
|
|
|
|
---
|
|
|
|
misc: Logout
|
|
|
|
=================
|
|
|
|
|
|
|
|
Depending on settings, there may also be choices
|
|
|
|
like "Feedback" or "Debug".
|
|
|
|
|
2023-10-18 09:07:31 +02:00
|
|
|
The menu items get built in a handlebars template
|
|
|
|
called gear_menu_popover.hbs.
|
2018-08-29 19:50:12 +02:00
|
|
|
|
|
|
|
The menu itself has the selector
|
|
|
|
"settings-dropdown".
|
|
|
|
|
|
|
|
The items with the prefix of "hash:" are in-page
|
|
|
|
links:
|
|
|
|
|
|
|
|
#streams
|
|
|
|
#settings
|
|
|
|
#organization
|
2021-02-09 11:16:52 +01:00
|
|
|
#about-zulip
|
2018-08-29 19:50:12 +02:00
|
|
|
#invite
|
|
|
|
|
|
|
|
When you click on the links there is a function
|
2023-02-22 23:03:47 +01:00
|
|
|
called hashchanged() in web/src/hashchange.js
|
2021-05-20 01:50:32 +02:00
|
|
|
that gets invoked. (We register this as a listener
|
|
|
|
for the hashchange event.) This function then
|
2018-08-29 19:50:12 +02:00
|
|
|
launches the appropriate modal for each menu item.
|
|
|
|
Look for things like subs.launch(...) or
|
|
|
|
invite.launch() in that code.
|
|
|
|
|
|
|
|
Some items above are prefixed with "link:". Those
|
|
|
|
items, when clicked, just use the normal browser
|
|
|
|
mechanism to link to external pages, and they
|
|
|
|
have a target of "_blank".
|
|
|
|
|
|
|
|
The "info:" items use our info overlay system
|
2024-03-21 11:48:52 +01:00
|
|
|
in web/src/info_overlay.ts. They are dispatched
|
2023-02-22 23:03:47 +01:00
|
|
|
using a click handler in web/src/click_handlers.js.
|
2018-08-29 19:50:12 +02:00
|
|
|
The click handler uses "[data-overlay-trigger]" as
|
2021-03-22 16:09:12 +01:00
|
|
|
the selector and then calls browser_history.go_to_location.
|
2018-08-29 19:50:12 +02:00
|
|
|
*/
|
|
|
|
|
2023-10-13 12:51:35 +02:00
|
|
|
function render(instance) {
|
|
|
|
const rendered_gear_menu = render_gear_menu_popover(
|
|
|
|
popover_menus_data.get_gear_menu_content_context(),
|
|
|
|
);
|
|
|
|
instance.setContent(parse_html(rendered_gear_menu));
|
2021-02-28 01:02:12 +01:00
|
|
|
}
|
2014-03-13 21:55:47 +01:00
|
|
|
|
2023-10-13 12:51:35 +02:00
|
|
|
export function initialize() {
|
|
|
|
popover_menus.register_popover_menu("#gear-menu", {
|
2024-04-04 22:33:25 +02:00
|
|
|
theme: "popover-menu",
|
2023-10-13 12:51:35 +02:00
|
|
|
placement: "bottom",
|
|
|
|
offset: [-50, 0],
|
|
|
|
popperOptions: {
|
|
|
|
strategy: "fixed",
|
|
|
|
modifiers: [
|
|
|
|
{
|
|
|
|
name: "eventListeners",
|
|
|
|
options: {
|
|
|
|
scroll: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
onMount(instance) {
|
|
|
|
const $popper = $(instance.popper);
|
|
|
|
popover_menus.popover_instances.gear_menu = instance;
|
|
|
|
$popper.on("click", ".webathena_login", (e) => {
|
|
|
|
$("#zephyr-mirror-error").removeClass("show");
|
|
|
|
const principal = ["zephyr", "zephyr"];
|
|
|
|
WinChan.open(
|
|
|
|
{
|
|
|
|
url: "https://webathena.mit.edu/#!request_ticket_v1",
|
|
|
|
relay_url: "https://webathena.mit.edu/relay.html",
|
|
|
|
params: {
|
|
|
|
realm: "ATHENA.MIT.EDU",
|
|
|
|
principal,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
(err, r) => {
|
|
|
|
if (err) {
|
|
|
|
blueslip.warn(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (r.status !== "OK") {
|
|
|
|
blueslip.warn(r);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel.post({
|
|
|
|
url: "/accounts/webathena_kerberos_login/",
|
|
|
|
data: {cred: JSON.stringify(r.session)},
|
|
|
|
success() {
|
|
|
|
$("#zephyr-mirror-error").removeClass("show");
|
|
|
|
},
|
|
|
|
error() {
|
|
|
|
$("#zephyr-mirror-error").addClass("show");
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
);
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-13 12:51:35 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
});
|
|
|
|
|
|
|
|
$popper.on("click", ".change-language-spectator", (e) => {
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-13 12:51:35 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2024-01-09 20:36:02 +01:00
|
|
|
settings_preferences.launch_default_language_setting_modal();
|
2023-10-13 12:51:35 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// We cannot update recipient bar color using dark_theme.enable/disable due to
|
|
|
|
// it being called before message lists are initialized and the order cannot be changed.
|
|
|
|
// Also, since these buttons are only visible for spectators which doesn't have events,
|
|
|
|
// if theme is changed in a different tab, the theme of this tab remains the same.
|
2023-10-19 20:13:00 +02:00
|
|
|
$popper.on("click", "#gear-menu-dropdown .gear-menu-select-dark-theme", (e) => {
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-13 12:51:35 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
dark_theme.enable();
|
|
|
|
message_lists.update_recipient_bar_background_color();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-10-19 20:13:00 +02:00
|
|
|
$popper.on("click", "#gear-menu-dropdown .gear-menu-select-light-theme", (e) => {
|
2024-04-02 09:29:56 +02:00
|
|
|
popover_menus.hide_current_popover_if_visible(instance);
|
2023-10-13 12:51:35 +02:00
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
dark_theme.disable();
|
|
|
|
message_lists.update_recipient_bar_background_color();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onShow: render,
|
|
|
|
onHidden(instance) {
|
|
|
|
instance.destroy();
|
|
|
|
popover_menus.popover_instances.gear_menu = undefined;
|
|
|
|
},
|
|
|
|
});
|
2021-02-28 01:02:12 +01:00
|
|
|
}
|
2017-03-18 20:30:20 +01:00
|
|
|
|
2023-10-13 12:51:35 +02:00
|
|
|
export function toggle() {
|
|
|
|
if (popover_menus.is_gear_menu_popover_displayed()) {
|
|
|
|
popovers.hide_all();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since this can be called via hotkey, we need to
|
|
|
|
// hide any other popovers that may be open before.
|
|
|
|
if (popovers.any_active()) {
|
|
|
|
popovers.hide_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
$("#gear-menu").trigger("click");
|
2021-02-28 01:02:12 +01:00
|
|
|
}
|
2017-05-22 04:28:52 +02:00
|
|
|
|
2023-10-13 12:51:35 +02:00
|
|
|
export function rerender() {
|
|
|
|
if (popover_menus.is_gear_menu_popover_displayed()) {
|
|
|
|
render(popover_menus.get_gear_menu_instance());
|
2017-05-22 04:28:52 +02:00
|
|
|
}
|
2021-02-28 01:02:12 +01:00
|
|
|
}
|