diff --git a/l10n/en-US/viewer.ftl b/l10n/en-US/viewer.ftl index 7b31fbc5f02ea..03d4400e0d74d 100644 --- a/l10n/en-US/viewer.ftl +++ b/l10n/en-US/viewer.ftl @@ -498,4 +498,4 @@ pdfjs-editor-alt-text-settings-close-button = Close # $type (String) - the type of annotation that was just removed with an optional quantity. pdfjs-editor-messagebar-annotation-removed-text = { $type } removed pdfjs-editor-messagebar-annotation-undo-button = Undo -pdfjs-editor-messagebar-annotation-close-button = Close \ No newline at end of file +pdfjs-editor-messagebar-annotation-close-button = Close diff --git a/src/display/editor/tools.js b/src/display/editor/tools.js index 2e82054ab8aaf..7d606ba9d581b 100644 --- a/src/display/editor/tools.js +++ b/src/display/editor/tools.js @@ -2006,11 +2006,11 @@ class AnnotationEditorUIManager { const editors = [...this.#selectedEditors]; const cmd = () => { - this.#toastManager.show( + this.#toastManager?.show( undo, editors.length > 1 ? `${editors.length} annotations` - : editors[0].constructor._type + : editors[0].editorType ); for (const editor of editors) { editor.remove(); diff --git a/web/message_bar.css b/web/message_bar.css index 305a0ff01cbd4..ed1e1a7834650 100644 --- a/web/message_bar.css +++ b/web/message_bar.css @@ -1,3 +1,18 @@ +/* Copyright 2024 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + .messageBar { --closing-button-icon: url(images/messageBar_closingButton.svg); --message-bar-close-button-color: var(--text-primary-color); diff --git a/web/pdf_viewer.css b/web/pdf_viewer.css index e9b2c475ba306..115a8f8532b82 100644 --- a/web/pdf_viewer.css +++ b/web/pdf_viewer.css @@ -12,11 +12,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +@import url(message_bar.css); @import url(dialog.css); @import url(text_layer_builder.css); @import url(annotation_layer_builder.css); @import url(xfa_layer_builder.css); -@import url(message_bar.css); /* Ignored in GECKOVIEW builds: */ @import url(annotation_editor_layer_builder.css); diff --git a/web/toast_manager.js b/web/toast_manager.js index a256643d23b75..15a595fd4ad45 100644 --- a/web/toast_manager.js +++ b/web/toast_manager.js @@ -1,3 +1,18 @@ +/* Copyright 2024 Mozilla Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + class ToastManager { #toastElement; @@ -7,17 +22,24 @@ class ToastManager { #controller = null; + #boundHide = null; + constructor(elem, duration) { this.#toastElement = elem; this.#duration = duration; } show(action, type) { + if (this.#timeoutID) { + this.#finalizeTimeout(); + } + if (this.#controller) { + this.#finalizeController(); + } this.#toastElement.setAttribute("data-l10n-args", JSON.stringify({ type })); this.#toastElement.removeAttribute("hidden"); - this.#timeoutID = setTimeout(() => { - this.#hide(); - }, this.#duration); + this.#boundHide = this.#hide.bind(this); + this.#timeoutID = setTimeout(this.#boundHide, this.#duration); this.#controller = new AbortController(); console.log(this.#toastElement, this.#toastElement.getElementById); this.#toastElement @@ -32,21 +54,26 @@ class ToastManager { ); this.#toastElement .querySelector("#annotationRemovedCloseButton") - .addEventListener( - "click", - () => { - this.#hide(); - }, - { signal: this.#controller.signal } - ); + .addEventListener("click", this.#boundHide, { + signal: this.#controller.signal, + }); } - #hide() { - this.#toastElement.setAttribute("hidden", ""); + #finalizeTimeout() { clearTimeout(this.#timeoutID); + this.#timeoutID = null; + } + + #finalizeController() { this.#controller.abort(); this.#controller = null; } + + #hide() { + this.#toastElement.setAttribute("hidden", ""); + this.#finalizeTimeout(); + this.#finalizeController(); + } } export { ToastManager };