From 9478d1feb9309e680b39e613e78964c5d773d68b Mon Sep 17 00:00:00 2001 From: IA Jim Date: Wed, 18 Dec 2024 15:26:16 -0800 Subject: [PATCH] Switch to new page number display format - Split desktop and mobile page number displays - CSS: Move 'hide' to .controls - Add/split tests for desktop and mobile page number displays --- src/BookReader/Navbar/Navbar.js | 58 ++++++++++++++++++--- src/css/_BRnav.scss | 3 -- src/css/_controls.scss | 4 ++ tests/jest/BookReader/Navbar/Navbar.test.js | 25 ++++++--- 4 files changed, 73 insertions(+), 17 deletions(-) diff --git a/src/BookReader/Navbar/Navbar.js b/src/BookReader/Navbar/Navbar.js index aa01faa23..d490c32fa 100644 --- a/src/BookReader/Navbar/Navbar.js +++ b/src/BookReader/Navbar/Navbar.js @@ -142,12 +142,36 @@ export class Navbar { if (this.br.options.bookType !== 'linerNotes') { if (this.br.refs.$brContainer.prop('clientWidth') < 640) { this.showMinimumNavbarControls(); + this.showMinimumNavPageNum(); } else { this.showMaximumNavbarControls(); + this.showMaximumNavPageNum(); } } } + /** + * Switch Book Nav page number display to minimum/mobile + */ + showMinimumNavPageNum() { + const minelement = document.querySelector(`.BRcurrentpage.BRmin`); + const maxelement = document.querySelector(`.BRcurrentpage.BRmax`); + + if (minelement) minelement.classList.remove('hide'); + if (maxelement) maxelement.classList.add('hide'); + } + + /** + * Switch Book Nav page number display to maximum/desktop + */ + showMaximumNavPageNum() { + const minelement = document.querySelector(`.BRcurrentpage.BRmin`); + const maxelement = document.querySelector(`.BRcurrentpage.BRmax`); + + if (minelement) minelement.classList.add('hide'); + if (maxelement) maxelement.classList.remove('hide'); + } + /** * Switch Book Navbar controls to minimised * NOTE: only `this.minimumControls` and `this.maximumControls` switch on resize @@ -203,7 +227,10 @@ export class Navbar {
-

+

+ + +

${this._renderControls()} @@ -246,9 +273,10 @@ export class Navbar { /** * Returns the textual representation of the current page for the navbar * @param {number} index + * @param {"max"|"min"} size * @return {string} */ - getNavPageNumString(index) { + getNavPageNumString(index, size) { const { br } = this; // Accessible index starts at 0 (alas) so we add 1 to make human const pageNum = br.book.getPageNum(index); @@ -268,7 +296,8 @@ export class Navbar { this.maxPageNum = maxPageNum; } - return getNavPageNumHtml(index, numLeafs, pageNum, pageType, this.maxPageNum); + return getNavPageNumHtml(index, numLeafs, pageNum, pageType, this.maxPageNum, size); + } /** @@ -276,7 +305,8 @@ export class Navbar { * @param {number} index */ updateNavPageNum(index) { - this.$root.find('.BRcurrentpage').html(this.getNavPageNumString(index)); + this.$root.find('.BRcurrentpage.BRmax').html(this.getNavPageNumString(index,'max')); + this.$root.find('.BRcurrentpage.BRmin').html(this.getNavPageNumString(index,'min')); } /** @@ -298,16 +328,28 @@ export class Navbar { * @param {number|string} pageNum * @param {*} pageType - Deprecated * @param {number} maxPageNum + * @param {"max"|"min"} size * @return {string} */ -export function getNavPageNumHtml(index, numLeafs, pageNum, pageType, maxPageNum) { +export function getNavPageNumHtml(index, numLeafs, pageNum, pageType, maxPageNum, size) { const pageIsAsserted = pageNum[0] != 'n'; + const pageIndex = index + 1; if (!pageIsAsserted) { - const pageIndex = index + 1; - return `(${pageIndex} of ${numLeafs})`; // Page (8 of 10) + pageNum = `—`; + } + + if (size === "max") { + return `Page ${pageNum} (${pageIndex}/${numLeafs})`; } const bookLengthLabel = (maxPageNum && parseFloat(pageNum)) ? ` of ${maxPageNum}` : ''; - return `${pageNum}${bookLengthLabel}`; + + if (size === "min" && !pageIsAsserted) { + return `(${pageIndex} of ${numLeafs})`; + } + + if (size === "min" && pageIsAsserted) { + return `${pageNum}${bookLengthLabel}`; + } } diff --git a/src/css/_BRnav.scss b/src/css/_BRnav.scss index ccb428745..8ae28f402 100644 --- a/src/css/_BRnav.scss +++ b/src/css/_BRnav.scss @@ -110,9 +110,6 @@ display: block; } } - &.hide { - display: none; - } } } diff --git a/src/css/_controls.scss b/src/css/_controls.scss index 7b16504f1..f152b9431 100644 --- a/src/css/_controls.scss +++ b/src/css/_controls.scss @@ -81,6 +81,10 @@ height: 30px; } + .controls .hide { + display: none; + } + @keyframes slideUp { from { opacity: 0; diff --git a/tests/jest/BookReader/Navbar/Navbar.test.js b/tests/jest/BookReader/Navbar/Navbar.test.js index 84a3c117a..c87c57499 100644 --- a/tests/jest/BookReader/Navbar/Navbar.test.js +++ b/tests/jest/BookReader/Navbar/Navbar.test.js @@ -4,16 +4,29 @@ import BookReader from '@/src/BookReader.js'; describe('getNavPageNumHtml', () => { const f = getNavPageNumHtml; - test('handle n-prefixed page numbers', () => { - expect(f(3, 40, 'n3', '', 40)).toBe('(4 of 40)'); + + test('handle n-prefixed page numbers-min format', () => { + expect(f(3, 40, 'n3', '', 40, 'min')).toBe('(4 of 40)'); + }); + + test('handle regular page numbers-min format', () => { + expect(f(3, 40, '14', '', 40, 'min')).toBe('14 of 40'); + }); + + test('handle no max page-min format', () => { + expect(f(3, 40, '14', '', null, 'min')).toBe('14'); + }); + + test('handle n-prefixed page numbers-max format', () => { + expect(f(3, 40, 'n3', '', 40, 'max')).toBe('Page — (4/40)'); }); - test('handle regular page numbers', () => { - expect(f(3, 40, '14', '', 40)).toBe('14 of 40'); + test('handle regular page numbers-max format', () => { + expect(f(3, 40, '14', '', 40, 'max')).toBe('Page 14 (4/40)'); }); - test('handle no max page', () => { - expect(f(3, 40, '14', '', null)).toBe('14'); + test('handle no max page-max format', () => { + expect(f(3, 40, '14', '', null, 'max')).toBe('Page 14 (4/40)'); }); });