Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profile selector to mobile action-popup #1105

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions ext/action-popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
<div class="nav-button-container">
<button type="button" class="nav-button action-select-profile" title="Change primary profile" hidden>
<span class="icon" data-icon="profile"></span>
<span class="profile-select-container"><select class="profile-select" id="profile-select">
<optgroup label="Primary Profile" id="profile-select-option-group"></optgroup>
<span class="profile-select-container"><select class="profile-select">
<optgroup label="Primary Profile" class="profile-select-option-group"></optgroup>
</select></span>
</button>
<a tabindex="0" class="nav-button action-open-settings" title="Settings" data-hotkey='["global:openSettingsPage","title","Settings ({0})"]'>
Expand Down Expand Up @@ -70,6 +70,13 @@ <h3 id="extension-info">Yomitan</h3>
<span class="toggle-handle"></span>
</div>
</label>
<a tabindex="0" class="link-group action-select-profile">
<span class="link-group-icon" data-icon="profile"></span>
<span class="link-group-label">Profile</span>
<span class="profile-select-container"><select class="profile-select">
<optgroup label="Primary Profile" class="profile-select-option-group"></optgroup>
</select></span>
</a>
<a tabindex="0" class="link-group action-open-settings">
<span class="link-group-icon" data-icon="cog"></span>
<span class="link-group-label">Settings</span>
Expand Down
1 change: 1 addition & 0 deletions ext/css/action-popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ label {
.link-group-icon[data-icon=key] { background-image: url(/images/key.svg); filter: var(--svg-filter); }
.link-group-icon[data-icon=magnifying-glass] { background-image: url(/images/magnifying-glass.svg); filter: var(--svg-filter); }
.link-group-icon[data-icon=question-mark-circle] { background-image: url(/images/question-mark-circle.svg); filter: var(--svg-filter); }
.link-group-icon[data-icon=profile] { background-image: url(/images/profile.svg); filter: var(--svg-filter); }

.link-group-label {
vertical-align: middle;
Expand Down
43 changes: 23 additions & 20 deletions ext/js/pages/action-popup-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import {ThemeController} from '../app/theme-controller.js';
import {Application} from '../application.js';
import {getAllPermissions, hasRequiredPermissionsForOptions} from '../data/permissions-util.js';
import {querySelectorNotNull} from '../dom/query-selector.js';
import {HotkeyHelpController} from '../input/hotkey-help-controller.js';

class DisplayController {
Expand Down Expand Up @@ -67,9 +66,11 @@ class DisplayController {
this._setupOptions(primaryProfile);
}

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

this._updateProfileSelect(profiles, profileCurrent);

Expand Down Expand Up @@ -231,23 +232,25 @@ class DisplayController {
* @param {number} profileCurrent
*/
_updateProfileSelect(profiles, profileCurrent) {
/** @type {HTMLSelectElement} */
const select = querySelectorNotNull(document, '#profile-select');
/** @type {HTMLElement} */
const optionGroup = querySelectorNotNull(document, '#profile-select-option-group');
const fragment = document.createDocumentFragment();
for (let i = 0, ii = profiles.length; i < ii; ++i) {
const {name} = profiles[i];
const option = document.createElement('option');
option.textContent = name;
option.value = `${i}`;
fragment.appendChild(option);
}
optionGroup.textContent = '';
optionGroup.appendChild(fragment);
select.value = `${profileCurrent}`;
/** @type {NodeListOf<HTMLSelectElement>} */
const selects = document.querySelectorAll('.profile-select');
/** @type {NodeListOf<HTMLElement>} */
const optionGroups = document.querySelectorAll('.profile-select-option-group');
for (let i = 0; i < Math.min(selects.length, optionGroups.length); i++) {
const fragment = document.createDocumentFragment();
for (let j = 0, jj = profiles.length; j < jj; ++j) {
const {name} = profiles[j];
const option = document.createElement('option');
option.textContent = name;
option.value = `${j}`;
fragment.appendChild(option);
}
optionGroups[i].textContent = '';
optionGroups[i].appendChild(fragment);
selects[i].value = `${profileCurrent}`;

select.addEventListener('change', this._onProfileSelectChange.bind(this), false);
selects[i].addEventListener('change', this._onProfileSelectChange.bind(this), false);
}
}

/**
Expand Down