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

Create HTML templates for modals #1425

Merged
merged 10 commits into from
Oct 5, 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
4 changes: 2 additions & 2 deletions ext/js/display/search-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ await Application.main(true, async (application) => {
const searchDisplayController = new SearchDisplayController(display, displayAudio, searchPersistentStateController);
await searchDisplayController.prepare();

const modalController = new ModalController();
modalController.prepare();
const modalController = new ModalController([]);
await modalController.prepare();

const settingsController = new SettingsController(application);
await settingsController.prepare();
Expand Down
4 changes: 2 additions & 2 deletions ext/js/pages/permissions-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ function setupPermissionsToggles() {
}

await Application.main(true, async (application) => {
const modalController = new ModalController();
modalController.prepare();
const modalController = new ModalController([]);
await modalController.prepare();

const settingsController = new SettingsController(application);
await settingsController.prepare();
Expand Down
20 changes: 18 additions & 2 deletions ext/js/pages/settings/modal-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,34 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import {HtmlTemplateCollection} from '../../dom/html-template-collection.js';
import {Modal} from './modal.js';

export class ModalController {
constructor() {
/**
* @param {string[]} templateNames
*/
constructor(templateNames) {
/** @type {Modal[]} */
this._modals = [];
/** @type {Map<string|Element, Modal>} */
this._modalMap = new Map();
/** @type {HtmlTemplateCollection} */
this._templates = new HtmlTemplateCollection();
/** @type {string[]} */
this._templateNames = templateNames;
}

/** */
prepare() {
async prepare() {
if (this._templateNames.length > 0) {
await this._templates.loadFromFiles(['/templates-modals.html']);
for (const name of this._templateNames) {
const template = this._templates.getTemplateContent(name);
document.body.appendChild(template);
}
}

const idSuffix = '-modal';
for (const node of /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('.modal'))) {
let {id} = node;
Expand Down
4 changes: 2 additions & 2 deletions ext/js/pages/settings/settings-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ await Application.main(true, async (application) => {

const preparePromises = [];

const modalController = new ModalController();
modalController.prepare();
const modalController = new ModalController(['shared-modals', 'settings-modals']);
await modalController.prepare();

const settingsController = new SettingsController(application);
await settingsController.prepare();
Expand Down
4 changes: 2 additions & 2 deletions ext/js/pages/welcome-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ async function checkNeedsCustomTemplatesWarning() {
}

await Application.main(true, async (application) => {
const modalController = new ModalController();
modalController.prepare();
const modalController = new ModalController(['shared-modals']);
await modalController.prepare();

const settingsController = new SettingsController(application);
await settingsController.prepare();
Expand Down
1,476 changes: 0 additions & 1,476 deletions ext/settings.html

Large diffs are not rendered by default.

1,477 changes: 1,477 additions & 0 deletions ext/templates-modals.html

Large diffs are not rendered by default.

333 changes: 0 additions & 333 deletions ext/welcome.html

Large diffs are not rendered by default.

Loading