Skip to content

Commit

Permalink
Merge pull request #18543 from calixteman/disable_create_alttext_button
Browse files Browse the repository at this point in the history
[Editor] Avoid to have the create alt-text button without a click listener
  • Loading branch information
calixteman authored Aug 2, 2024
2 parents 464d534 + 271bd4d commit 08821a3
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions web/new_alt_text_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,6 @@ class NewAltTextManager {
class ImageAltTextSettings {
#aiModelSettings;

#boundOnClickCreateModel;

#createModelButton;

#dialog;
Expand Down Expand Up @@ -504,17 +502,12 @@ class ImageAltTextSettings {
this.#overlayManager = overlayManager;
this.#eventBus = eventBus;
this.#mlManager = mlManager;
this.#boundOnClickCreateModel = this.#togglePref.bind(
this,
"enableGuessAltText"
);

const { altTextLearnMoreUrl } = mlManager;
if (altTextLearnMoreUrl) {
learnMore.href = altTextLearnMoreUrl;
}

dialog.addEventListener("close", this.#close.bind(this));
dialog.addEventListener("contextmenu", noContextMenu);

createModelButton.addEventListener("click", async e => {
Expand All @@ -531,10 +524,7 @@ class ImageAltTextSettings {
await mlManager.deleteModel("altText");

aiModelSettings.classList.toggle("download", true);
createModelButton.removeEventListener(
"click",
this.#boundOnClickCreateModel
);
createModelButton.disabled = true;
createModelButton.setAttribute("aria-pressed", false);
this.#setPref("enableGuessAltText", false);
this.#setPref("enableAltTextModelDownload", false);
Expand All @@ -554,10 +544,7 @@ class ImageAltTextSettings {
"data-l10n-id",
"pdfjs-editor-alt-text-settings-download-model-button"
);
createModelButton.addEventListener(
"click",
this.#boundOnClickCreateModel
);
createModelButton.disabled = false;
createModelButton.setAttribute("aria-pressed", true);
this.#setPref("enableGuessAltText", true);
mlManager.toggleService("altText", true);
Expand Down Expand Up @@ -585,12 +572,7 @@ class ImageAltTextSettings {
!enableAltTextModelDownload
);

try {
await this.#overlayManager.open(this.#dialog);
} catch (ex) {
this.#close();
throw ex;
}
await this.#overlayManager.open(this.#dialog);
}

#togglePref(name, { target }) {
Expand All @@ -613,13 +595,6 @@ class ImageAltTextSettings {
this.#overlayManager.close(this.#dialog);
}
}

#close() {
this.#createModelButton.removeEventListener(
"click",
this.#boundOnClickCreateModel
);
}
}

export { ImageAltTextSettings, NewAltTextManager };

0 comments on commit 08821a3

Please sign in to comment.