|
1714 | 1714 | */
|
1715 | 1715 | class Page {
|
1716 | 1716 |
|
1717 |
| - // The immediate following can be set in subclasses. |
1718 |
| - |
1719 |
| - /** |
1720 |
| - * @type {string|RegExp} - What pathname part of the URL this page should |
1721 |
| - * handle. The special case of null is used by the {@link SPA} class to |
1722 |
| - * represent global keys. |
1723 |
| - */ |
1724 |
| - _pathname; |
1725 |
| - |
1726 | 1717 | #pageReadySelector
|
1727 | 1718 |
|
1728 |
| - // Private members. |
1729 |
| - |
1730 | 1719 | /** @type {SPA} - SPA instance managing this instance. */
|
1731 | 1720 | #spa;
|
1732 | 1721 |
|
|
1750 | 1739 | condition: '!inputFocus && !inDialog',
|
1751 | 1740 | };
|
1752 | 1741 |
|
| 1742 | + /** |
| 1743 | + * Turn a pathname into a RegExp. |
| 1744 | + * @param {string|RegExp} pathname - A pathname to convert. |
| 1745 | + * @returns {RegExp} - A converted pathname. |
| 1746 | + */ |
| 1747 | + #computePathname = (pathname) => { |
| 1748 | + const me = 'computePath'; |
| 1749 | + this.logger.entered(me, pathname); |
| 1750 | + let pathnameRE = /.*/u; |
| 1751 | + if (pathname instanceof RegExp) { |
| 1752 | + pathnameRE = pathname; |
| 1753 | + } else if (pathname) { |
| 1754 | + pathnameRE = RegExp(`^${pathname}$`, 'u'); |
| 1755 | + } |
| 1756 | + this.logger.leaving(me, pathnameRE); |
| 1757 | + return pathnameRE; |
| 1758 | + } |
| 1759 | + |
1753 | 1760 | /**
|
1754 | 1761 | * @typedef {object} PageDetails
|
1755 |
| - * @property {string|RegExp} [pathname=RegExp] - Pathname portion of the |
1756 |
| - * URL this page should handle. |
| 1762 | + * @property {string|RegExp} [pathname=RegExp(.*)] - Pathname portion of |
| 1763 | + * the URL this page should handle. |
1757 | 1764 | * @property {string} [pageReadySelector='body'] - CSS selector that is
|
1758 | 1765 | * used to detect that the page is loaded enough to activate.
|
1759 | 1766 | */
|
|
1763 | 1770 | if (new.target === Page) {
|
1764 | 1771 | throw new TypeError('Abstract class; do not instantiate directly.');
|
1765 | 1772 | }
|
1766 |
| - if (details.pathname) { |
1767 |
| - if (details.pathname instanceof RegExp) { |
1768 |
| - this.#pathnameRE = details.pathname; |
1769 |
| - } else { |
1770 |
| - this.#pathnameRE = RegExp(`^${details.pathname}$`, 'u'); |
1771 |
| - } |
1772 |
| - } |
| 1773 | + this.#logger = new Logger(this.constructor.name); |
| 1774 | + this.#pathnameRE = this.#computePathname(details.pathname); |
1773 | 1775 | ({
|
1774 | 1776 | pageReadySelector: this.#pageReadySelector = 'body',
|
1775 | 1777 | } = details);
|
1776 |
| - this.#logger = new Logger(this.constructor.name); |
1777 | 1778 | this.#logger.log('Base page constructed', this);
|
1778 | 1779 | }
|
1779 | 1780 |
|
|
1826 | 1827 |
|
1827 | 1828 | /** @type {RegExp} */
|
1828 | 1829 | get pathname() {
|
1829 |
| - if (!this.#pathnameRE) { |
1830 |
| - if (this._pathname instanceof RegExp) { |
1831 |
| - this.#pathnameRE = this._pathname; |
1832 |
| - } else if (this._pathname) { |
1833 |
| - this.#pathnameRE = RegExp(`^${this._pathname}$`, 'u'); |
1834 |
| - } else { |
1835 |
| - // New global |
1836 |
| - this.#pathnameRE = /.*/u; |
1837 |
| - } |
1838 |
| - } |
1839 | 1830 | return this.#pathnameRE;
|
1840 | 1831 | }
|
1841 | 1832 |
|
|
1941 | 1932 | */
|
1942 | 1933 | class Global extends Page {
|
1943 | 1934 |
|
1944 |
| - _pathname = null; |
1945 |
| - |
1946 | 1935 | /**
|
1947 | 1936 | * Click on the requested link in the global nav bar.
|
1948 | 1937 | * @param {string} item - Portion of the link to match.
|
|
2023 | 2012 | /** Class for handling the Posts feed. */
|
2024 | 2013 | class Feed extends Page {
|
2025 | 2014 |
|
2026 |
| - _pathname = '/feed/'; |
2027 |
| - |
2028 | 2015 | #tabSnippet = SPA._parseSeq2('tab'); // eslint-disable-line no-use-before-define
|
2029 | 2016 |
|
2030 | 2017 | #postScroller = null;
|
|
2438 | 2425 | */
|
2439 | 2426 | class MyNetwork extends Page {
|
2440 | 2427 |
|
2441 |
| - _pathname = '/mynetwork/'; |
2442 |
| - |
2443 | 2428 | #sectionScroller
|
2444 | 2429 | #cardScroller
|
2445 | 2430 | #currentSectionText
|
|
2697 | 2682 | /** Class for handling the Invitation manager page. */
|
2698 | 2683 | class InvitationManager extends Page {
|
2699 | 2684 |
|
2700 |
| - _pathname = '/mynetwork/invitation-manager/'; |
2701 |
| - |
2702 | 2685 | #inviteScroller
|
2703 | 2686 | #currentInviteText
|
2704 | 2687 |
|
|
2882 | 2865 | */
|
2883 | 2866 | class Jobs extends Page {
|
2884 | 2867 |
|
2885 |
| - _pathname = '/jobs/'; |
2886 |
| - |
2887 | 2868 | #sectionScroller = null;
|
2888 | 2869 | #jobScroller = null;
|
2889 | 2870 |
|
|
3306 | 3287 | /** Class for handling Job collections. */
|
3307 | 3288 | class JobCollections extends Page {
|
3308 | 3289 |
|
3309 |
| - // eslint-disable-next-line prefer-regex-literals |
3310 |
| - _pathname = RegExp('^/jobs/(?:collections|search)/.*', 'u'); |
3311 |
| - |
3312 | 3290 | #lastScroller
|
3313 | 3291 |
|
3314 | 3292 | #jobScroller = null;
|
|
3467 | 3445 | /** Class for handling the Notifications page. */
|
3468 | 3446 | class Notifications extends Page {
|
3469 | 3447 |
|
3470 |
| - _pathname = '/notifications/'; |
3471 |
| - |
3472 | 3448 | #notificationScroller = null;
|
3473 | 3449 |
|
3474 | 3450 | /** @type {Scroller~What} */
|
|
0 commit comments