Skip to content

Commit

Permalink
Address few review comments
Browse files Browse the repository at this point in the history
This is a temporary commit on this branch that aims to address some of the review comments from the PR at mozilla#18900.
  • Loading branch information
ryzokuken committed Oct 14, 2024
1 parent ae79bee commit 67822c9
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
2 changes: 1 addition & 1 deletion l10n/en-US/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
pdfjs-editor-messagebar-annotation-close-button = Close
4 changes: 2 additions & 2 deletions src/display/editor/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 15 additions & 0 deletions web/message_bar.css
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
2 changes: 1 addition & 1 deletion web/pdf_viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
51 changes: 39 additions & 12 deletions web/toast_manager.js
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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
Expand All @@ -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 };

0 comments on commit 67822c9

Please sign in to comment.