Skip to content

Commit b1d93d0

Browse files
committed
Hide the new badge while a page is selected (bug 2026564)
1 parent 777251d commit b1d93d0

3 files changed

Lines changed: 97 additions & 0 deletions

File tree

test/integration/reorganize_pages_spec.mjs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,4 +2819,93 @@ describe("Reorganize Pages View", () => {
28192819
);
28202820
});
28212821
});
2822+
2823+
describe("New badge (bug 2026564)", () => {
2824+
let pages;
2825+
2826+
beforeEach(async () => {
2827+
pages = await loadAndWait(
2828+
"page_with_number.pdf",
2829+
"#viewsManagerToggleButton",
2830+
"page-fit",
2831+
null,
2832+
{ enableSplitMerge: true, enableNewBadge: true }
2833+
);
2834+
});
2835+
2836+
afterEach(async () => {
2837+
await closePages(pages);
2838+
});
2839+
2840+
it("should hide the new badge when a page is selected and show it again when deselected", async () => {
2841+
await Promise.all(
2842+
pages.map(async ([browserName, page]) => {
2843+
await waitForThumbnailVisible(page, 1);
2844+
2845+
// The badge must be visible initially.
2846+
await page.waitForSelector(".newBadge", { visible: true });
2847+
2848+
// Select page 1 via its checkbox.
2849+
await waitAndClick(
2850+
page,
2851+
`.thumbnail:has(${getThumbnailSelector(1)}) input`
2852+
);
2853+
2854+
// The badge must be hidden after selection.
2855+
await page.waitForSelector(".newBadge", { hidden: true });
2856+
2857+
// Deselect page 1.
2858+
await waitAndClick(
2859+
page,
2860+
`.thumbnail:has(${getThumbnailSelector(1)}) input`
2861+
);
2862+
2863+
// The badge must be visible again after deselection.
2864+
await page.waitForSelector(".newBadge", { visible: true });
2865+
})
2866+
);
2867+
});
2868+
2869+
it("should hide the new badge when dragging an unselected page and restore it after", async () => {
2870+
await Promise.all(
2871+
pages.map(async ([browserName, page]) => {
2872+
await waitForThumbnailVisible(page, 1);
2873+
2874+
// The badge must be visible initially.
2875+
await page.waitForSelector(".newBadge", { visible: true });
2876+
2877+
// Watch for the badge being hidden during the drag.
2878+
const handleBadgeHidden = await createPromise(page, resolve => {
2879+
const observer = new MutationObserver(() => {
2880+
const badge = document.querySelector(".newBadge");
2881+
if (badge?.classList.contains("hidden")) {
2882+
observer.disconnect();
2883+
resolve();
2884+
}
2885+
});
2886+
observer.observe(document.querySelector(".newBadge"), {
2887+
attributes: true,
2888+
attributeFilter: ["class"],
2889+
});
2890+
});
2891+
2892+
const rect1 = await getRect(page, getThumbnailSelector(1));
2893+
const rect2 = await getRect(page, getThumbnailSelector(2));
2894+
2895+
await dragAndDrop(
2896+
page,
2897+
getThumbnailSelector(1),
2898+
[[0, rect2.y - rect1.y + rect2.height / 2]],
2899+
10
2900+
);
2901+
2902+
// The badge must have been hidden at some point during the drag.
2903+
await awaitPromise(handleBadgeHidden);
2904+
2905+
// The badge must be visible again after the drag ends.
2906+
await page.waitForSelector(".newBadge", { visible: true });
2907+
})
2908+
);
2909+
});
2910+
});
28222911
});

web/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ const PDFViewerApplication = {
373373
enableComment: x => x === "true",
374374
enableFakeMLManager: x => x === "true",
375375
enableGuessAltText: x => x === "true",
376+
enableNewBadge: x => x === "true",
376377
enablePermissions: x => x === "true",
377378
enableSplitMerge: x => x === "true",
378379
enableUpdatedAddImage: x => x === "true",

web/pdf_thumbnail_viewer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ class PDFThumbnailViewer {
161161

162162
#hasUndoBarVisible = false;
163163

164+
#newBadge = null;
165+
164166
/**
165167
* @param {PDFThumbnailViewerOptions} options
166168
*/
@@ -216,6 +218,7 @@ class PDFThumbnailViewer {
216218
newSpan.setAttribute("data-l10n-id", "pdfjs-new-badge-content");
217219
newSpan.classList.add("newBadge");
218220
button.parentElement.before(newSpan);
221+
this.#newBadge = newSpan;
219222
}
220223

221224
this.eventBus.on(
@@ -601,6 +604,7 @@ class PDFThumbnailViewer {
601604
this.#currentScrollTop + this.scrollableContainer.clientHeight;
602605
this.#dragAC = new AbortController();
603606
this.container.classList.add("isDragging");
607+
this.#newBadge?.classList.add("hidden");
604608
const startPageNumber = parseInt(
605609
draggedThumbnail.getAttribute("page-number"),
606610
10
@@ -658,6 +662,7 @@ class PDFThumbnailViewer {
658662
this.#dragMarker = null;
659663
this.#dragAC.abort();
660664
this.#dragAC = null;
665+
this.#newBadge?.classList.remove("hidden");
661666

662667
this.container.classList.remove("isDragging");
663668
for (const selected of this.#selectedPages) {
@@ -976,12 +981,14 @@ class PDFThumbnailViewer {
976981
: "pdfjs-views-manager-pages-status-none-action-label"
977982
);
978983
if (count) {
984+
this.#newBadge?.classList.add("hidden");
979985
this.#statusLabel.setAttribute(
980986
"data-l10n-args",
981987
JSON.stringify({ count })
982988
);
983989
this.#deselectButton.classList.toggle("hidden", false);
984990
} else {
991+
this.#newBadge?.classList.remove("hidden");
985992
this.#statusLabel.removeAttribute("data-l10n-args");
986993
this.#deselectButton.classList.toggle("hidden", true);
987994
}

0 commit comments

Comments
 (0)