FEATURE: Keyboard shortcut for opening the topic admin menu (#8568)

* Keyboard shortcut for opening the topic admin menu

* Review changes

* Attrubute and target class renaming
This commit is contained in:
Hector Bustillos 2019-12-19 12:18:14 -07:00 committed by Robin Ward
parent ef5d9a6cb5
commit 87c04ebe39
8 changed files with 33 additions and 3 deletions

View File

@ -102,5 +102,6 @@ export default MountWidget.extend(Docking, {
} }
this.dispatch("topic:current-post-scrolled", "timeline-scrollarea"); this.dispatch("topic:current-post-scrolled", "timeline-scrollarea");
this.dispatch("topic:toggle-actions", "topic-admin-menu-button");
} }
}); });

View File

@ -167,6 +167,10 @@ export default Controller.extend(ModalFunctionality, {
defer: buildShortcut("actions.defer", { defer: buildShortcut("actions.defer", {
keys1: [SHIFT, "u"], keys1: [SHIFT, "u"],
keysDelimiter: PLUS keysDelimiter: PLUS
}),
topic_admin_actions: buildShortcut("actions.topic_admin_actions", {
keys1: [SHIFT, "a"],
keysDelimiter: PLUS
}) })
} }
} }

View File

@ -71,6 +71,7 @@ const bindings = {
"shift+z shift+z": { handler: "logout" }, "shift+z shift+z": { handler: "logout" },
"shift+f11": { handler: "fullscreenComposer", global: true }, "shift+f11": { handler: "fullscreenComposer", global: true },
"shift+u": { handler: "deferTopic" }, "shift+u": { handler: "deferTopic" },
"shift+a": { handler: "toggleAdminActions" },
t: { postAction: "replyAsNewTopic" }, t: { postAction: "replyAsNewTopic" },
u: { handler: "goBack", anonymous: true }, u: { handler: "goBack", anonymous: true },
"x r": { "x r": {
@ -638,5 +639,9 @@ export default {
deferTopic() { deferTopic() {
this.container.lookup("controller:topic").send("deferTopic"); this.container.lookup("controller:topic").send("deferTopic");
},
toggleAdminActions() {
this.appEvents.trigger("topic:toggle-actions");
} }
}; };

View File

@ -67,6 +67,7 @@
<li>{{{shortcuts.actions.mark_watching}}}</li> <li>{{{shortcuts.actions.mark_watching}}}</li>
<li>{{{shortcuts.actions.defer}}}</li> <li>{{{shortcuts.actions.defer}}}</li>
<li>{{{shortcuts.actions.print}}}</li> <li>{{{shortcuts.actions.print}}}</li>
<li>{{{shortcuts.actions.topic_admin_actions}}}</li>
</ul> </ul>
</div> </div>
</div> </div>

View File

@ -52,7 +52,8 @@ createWidget("topic-admin-menu-button", {
this.attach("button", { this.attach("button", {
className: className:
"btn-default toggle-admin-menu" + "btn-default toggle-admin-menu" +
(attrs.fixed ? " show-topic-admin" : ""), (attrs.fixed ? " show-topic-admin" : "") +
(attrs.addKeyboardTargetClass ? " keyboard-target-admin-menu" : ""),
title: "topic_admin_menu", title: "topic_admin_menu",
icon: "wrench", icon: "wrench",
action: "showAdminMenu", action: "showAdminMenu",
@ -75,9 +76,16 @@ createWidget("topic-admin-menu-button", {
showAdminMenu(e) { showAdminMenu(e) {
this.state.expanded = true; this.state.expanded = true;
let $button;
if (e === undefined) {
$button = $(".keyboard-target-admin-menu");
} else {
$button = $(e.target).closest("button");
}
const $button = $(e.target).closest("button");
const position = $button.position(); const position = $button.position();
const rtl = $("html").hasClass("rtl"); const rtl = $("html").hasClass("rtl");
position.left = position.left; position.left = position.left;
position.outerHeight = $button.outerHeight(); position.outerHeight = $button.outerHeight();
@ -90,6 +98,10 @@ createWidget("topic-admin-menu-button", {
position.left += $button.width() - 203; position.left += $button.width() - 203;
} }
this.state.position = position; this.state.position = position;
},
topicToggleActions() {
this.state.expanded ? this.hideAdminMenu() : this.showAdminMenu();
} }
}); });

View File

@ -322,7 +322,12 @@ createWidget("timeline-controls", {
const { fullScreen, currentUser, topic } = attrs; const { fullScreen, currentUser, topic } = attrs;
if (!fullScreen && currentUser) { if (!fullScreen && currentUser) {
controls.push(this.attach("topic-admin-menu-button", { topic })); controls.push(
this.attach("topic-admin-menu-button", {
topic,
addKeyboardTargetClass: true
})
);
} }
return controls; return controls;

View File

@ -3042,6 +3042,7 @@ en:
mark_watching: "%{shortcut} Watch topic" mark_watching: "%{shortcut} Watch topic"
print: "%{shortcut} Print topic" print: "%{shortcut} Print topic"
defer: "%{shortcut} Defer topic" defer: "%{shortcut} Defer topic"
topic_admin_actions: "%{shortcut} Open topic admin actions"
badges: badges:
earned_n_times: earned_n_times:

View File

@ -2785,6 +2785,7 @@ es:
mark_watching: "%{shortcut} Vigilar Tema" mark_watching: "%{shortcut} Vigilar Tema"
print: "%{shortcut} Imprimir tema" print: "%{shortcut} Imprimir tema"
defer: "%{shortcut} Aplazar el tema" defer: "%{shortcut} Aplazar el tema"
topic_admin_actions: "%{shortcut} Abrir acciones de administrador para el tema"
badges: badges:
earned_n_times: earned_n_times:
one: "Ganó esta medalla %{count} vez" one: "Ganó esta medalla %{count} vez"