Skip to content

Commit 1c609d9

Browse files
authored
Add profile selector to mobile action-popup (#1105)
1 parent 0513474 commit 1c609d9

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

ext/action-popup.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
<div class="nav-button-container">
3434
<button type="button" class="nav-button action-select-profile" title="Change primary profile" hidden>
3535
<span class="icon" data-icon="profile"></span>
36-
<span class="profile-select-container"><select class="profile-select" id="profile-select">
37-
<optgroup label="Primary Profile" id="profile-select-option-group"></optgroup>
36+
<span class="profile-select-container"><select class="profile-select">
37+
<optgroup label="Primary Profile" class="profile-select-option-group"></optgroup>
3838
</select></span>
3939
</button>
4040
<a tabindex="0" class="nav-button action-open-settings" title="Settings" data-hotkey='["global:openSettingsPage","title","Settings ({0})"]'>
@@ -70,6 +70,13 @@ <h3 id="extension-info">Yomitan</h3>
7070
<span class="toggle-handle"></span>
7171
</div>
7272
</label>
73+
<a tabindex="0" class="link-group action-select-profile">
74+
<span class="link-group-icon" data-icon="profile"></span>
75+
<span class="link-group-label">Profile</span>
76+
<span class="profile-select-container"><select class="profile-select">
77+
<optgroup label="Primary Profile" class="profile-select-option-group"></optgroup>
78+
</select></span>
79+
</a>
7380
<a tabindex="0" class="link-group action-open-settings">
7481
<span class="link-group-icon" data-icon="cog"></span>
7582
<span class="link-group-label">Settings</span>

ext/css/action-popup.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ label {
166166
.link-group-icon[data-icon=key] { background-image: url(/images/key.svg); filter: var(--svg-filter); }
167167
.link-group-icon[data-icon=magnifying-glass] { background-image: url(/images/magnifying-glass.svg); filter: var(--svg-filter); }
168168
.link-group-icon[data-icon=question-mark-circle] { background-image: url(/images/question-mark-circle.svg); filter: var(--svg-filter); }
169+
.link-group-icon[data-icon=profile] { background-image: url(/images/profile.svg); filter: var(--svg-filter); }
169170

170171
.link-group-label {
171172
vertical-align: middle;

ext/js/pages/action-popup-main.js

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import {ThemeController} from '../app/theme-controller.js';
2020
import {Application} from '../application.js';
2121
import {getAllPermissions, hasRequiredPermissionsForOptions} from '../data/permissions-util.js';
22-
import {querySelectorNotNull} from '../dom/query-selector.js';
2322
import {HotkeyHelpController} from '../input/hotkey-help-controller.js';
2423

2524
class DisplayController {
@@ -67,9 +66,11 @@ class DisplayController {
6766
this._setupOptions(primaryProfile);
6867
}
6968

70-
/** @type {HTMLElement} */
71-
const profileSelect = querySelectorNotNull(document, '.action-select-profile');
72-
profileSelect.hidden = (profiles.length <= 1);
69+
/** @type {NodeListOf<HTMLElement>} */
70+
const profileSelect = document.querySelectorAll('.action-select-profile');
71+
for (let i = 0; i < profileSelect.length; i++) {
72+
profileSelect[i].hidden = (profiles.length <= 1);
73+
}
7374

7475
this._updateProfileSelect(profiles, profileCurrent);
7576

@@ -231,23 +232,25 @@ class DisplayController {
231232
* @param {number} profileCurrent
232233
*/
233234
_updateProfileSelect(profiles, profileCurrent) {
234-
/** @type {HTMLSelectElement} */
235-
const select = querySelectorNotNull(document, '#profile-select');
236-
/** @type {HTMLElement} */
237-
const optionGroup = querySelectorNotNull(document, '#profile-select-option-group');
238-
const fragment = document.createDocumentFragment();
239-
for (let i = 0, ii = profiles.length; i < ii; ++i) {
240-
const {name} = profiles[i];
241-
const option = document.createElement('option');
242-
option.textContent = name;
243-
option.value = `${i}`;
244-
fragment.appendChild(option);
245-
}
246-
optionGroup.textContent = '';
247-
optionGroup.appendChild(fragment);
248-
select.value = `${profileCurrent}`;
235+
/** @type {NodeListOf<HTMLSelectElement>} */
236+
const selects = document.querySelectorAll('.profile-select');
237+
/** @type {NodeListOf<HTMLElement>} */
238+
const optionGroups = document.querySelectorAll('.profile-select-option-group');
239+
for (let i = 0; i < Math.min(selects.length, optionGroups.length); i++) {
240+
const fragment = document.createDocumentFragment();
241+
for (let j = 0, jj = profiles.length; j < jj; ++j) {
242+
const {name} = profiles[j];
243+
const option = document.createElement('option');
244+
option.textContent = name;
245+
option.value = `${j}`;
246+
fragment.appendChild(option);
247+
}
248+
optionGroups[i].textContent = '';
249+
optionGroups[i].appendChild(fragment);
250+
selects[i].value = `${profileCurrent}`;
249251

250-
select.addEventListener('change', this._onProfileSelectChange.bind(this), false);
252+
selects[i].addEventListener('change', this._onProfileSelectChange.bind(this), false);
253+
}
251254
}
252255

253256
/**

0 commit comments

Comments
 (0)