@internetarchive/ia-topnav 1.3.6 → 1.3.7-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc +16 -16
- package/LICENSE +661 -661
- package/README.md +147 -147
- package/index.d.ts +109 -109
- package/index.js +3 -3
- package/package.json +61 -61
- package/src/assets/img/hamburger.js +38 -38
- package/src/assets/img/ia-icon.js +33 -33
- package/src/assets/img/icon-audio.js +23 -23
- package/src/assets/img/icon-close.js +16 -16
- package/src/assets/img/icon-donate-unpadded.js +16 -16
- package/src/assets/img/icon-donate.js +15 -15
- package/src/assets/img/icon-ellipses.js +15 -15
- package/src/assets/img/icon-ia-logo.js +22 -22
- package/src/assets/img/icon-images.js +15 -15
- package/src/assets/img/icon-search.js +15 -15
- package/src/assets/img/icon-software.js +15 -15
- package/src/assets/img/icon-texts.js +15 -15
- package/src/assets/img/icon-upload-unpadded.js +14 -14
- package/src/assets/img/icon-upload.js +15 -15
- package/src/assets/img/icon-user.js +15 -15
- package/src/assets/img/icon-video.js +15 -15
- package/src/assets/img/icon-web.js +15 -15
- package/src/assets/img/icon.js +18 -18
- package/src/assets/img/icons.js +33 -33
- package/src/assets/img/wordmark-stacked.js +13 -13
- package/src/data/menus.js +646 -646
- package/src/desktop-subnav.js +45 -45
- package/src/dropdown-menu.js +110 -109
- package/src/ia-topnav.js +324 -314
- package/src/lib/formatUrl.js +1 -1
- package/src/lib/keyboard-navigation.js +128 -0
- package/src/lib/location-handler.js +5 -5
- package/src/lib/query-handler.js +7 -7
- package/src/lib/toSentenceCase.js +8 -8
- package/src/login-button.js +79 -79
- package/src/media-button.js +113 -113
- package/src/media-menu.js +154 -133
- package/src/media-slider.js +118 -104
- package/src/media-subnav.js +112 -112
- package/src/more-slider.js +33 -33
- package/src/nav-search.js +111 -117
- package/src/primary-nav.js +258 -224
- package/src/save-page-form.js +59 -59
- package/src/search-menu.js +145 -115
- package/src/signed-out-dropdown.js +10 -10
- package/src/styles/base.js +48 -48
- package/src/styles/desktop-subnav.js +37 -37
- package/src/styles/dropdown-menu.js +168 -166
- package/src/styles/ia-topnav.js +87 -87
- package/src/styles/login-button.js +82 -79
- package/src/styles/media-button.js +156 -156
- package/src/styles/media-menu.js +66 -70
- package/src/styles/media-slider.js +81 -81
- package/src/styles/media-subnav.js +156 -156
- package/src/styles/more-slider.js +15 -15
- package/src/styles/nav-search.js +136 -136
- package/src/styles/primary-nav.js +311 -300
- package/src/styles/save-page-form.js +54 -54
- package/src/styles/search-menu.js +105 -99
- package/src/styles/signed-out-dropdown.js +31 -31
- package/src/styles/user-menu.js +31 -31
- package/src/styles/wayback-search.js +48 -48
- package/src/styles/wayback-slider.js +30 -30
- package/src/tracked-element.js +29 -27
- package/src/user-menu.js +56 -42
- package/src/wayback-search.js +18 -18
- package/src/wayback-slider.js +87 -87
- package/test/assets/img/hamburger.test.js +15 -15
- package/test/assets/img/user.test.js +15 -15
- package/test/data/menus.test.js +19 -19
- package/test/dropdown-menu.test.js +25 -25
- package/test/ia-icon.test.js +13 -13
- package/test/ia-topnav.test.js +273 -273
- package/test/login-button.test.js +15 -15
- package/test/media-button.test.js +19 -19
- package/test/media-menu.test.js +40 -40
- package/test/media-slider.test.js +57 -57
- package/test/more-slider.test.js +13 -13
- package/test/nav-search.test.js +61 -61
- package/test/primary-nav.test.js +82 -82
- package/test/save-page-form.test.js +35 -35
- package/test/search-menu.test.js +49 -49
- package/test/user-menu.test.js +33 -33
- package/test/wayback-slider.test.js +80 -80
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
export default class KeyboardNavigation {
|
|
2
|
+
/**
|
|
3
|
+
* Constructor for the KeyboardNavigation class.
|
|
4
|
+
* @param {HTMLElement} elementsContainer - The container element that holds the focusable elements.
|
|
5
|
+
* @param {string} menuOption - The type of menu option ('web' or 'usermenu').
|
|
6
|
+
*/
|
|
7
|
+
constructor(elementsContainer, menuOption) {
|
|
8
|
+
this.elementsContainer = elementsContainer;
|
|
9
|
+
this.menuOption = menuOption;
|
|
10
|
+
this.focusableElements = this.getFocusableElements();
|
|
11
|
+
this.focusedIndex = this.getInitialFocusedIndex();
|
|
12
|
+
|
|
13
|
+
this.focusableElements[this.focusedIndex]?.focus();
|
|
14
|
+
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the initial focused index based on the menu option.
|
|
19
|
+
* @returns {number} The initial focused index (0 for 'web', 1 for 'usermenu').
|
|
20
|
+
*/
|
|
21
|
+
getInitialFocusedIndex() {
|
|
22
|
+
return this.menuOption === 'usermenu' ? 1 : 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Gets an array of focusable elements within the container.
|
|
27
|
+
* @returns {HTMLElement[]} An array of focusable elements.
|
|
28
|
+
*/
|
|
29
|
+
getFocusableElements() {
|
|
30
|
+
const focusableTagSelectors = 'a[href], button, input, [tabindex]:not([tabindex="-1"])';
|
|
31
|
+
const isDisabledOrHidden = el => !el.hasAttribute('disabled') && !el.getAttribute('aria-hidden');
|
|
32
|
+
|
|
33
|
+
let elements;
|
|
34
|
+
if (this.menuOption === 'web') {
|
|
35
|
+
// wayback focusable elements
|
|
36
|
+
const waybackSlider = this.elementsContainer.querySelector('wayback-slider').shadowRoot;
|
|
37
|
+
const waybackSearch = waybackSlider.querySelector('wayback-search');
|
|
38
|
+
const waybackSearchElements = Array.from(waybackSearch.shadowRoot.querySelectorAll(focusableTagSelectors));
|
|
39
|
+
|
|
40
|
+
const normalElements = Array.from(waybackSlider.querySelectorAll(focusableTagSelectors));
|
|
41
|
+
|
|
42
|
+
// wayback save-form focusable elements
|
|
43
|
+
const savePageForm = waybackSlider.querySelector('save-page-form');
|
|
44
|
+
const savePageFormElements = Array.from(savePageForm.shadowRoot.querySelectorAll(focusableTagSelectors));
|
|
45
|
+
|
|
46
|
+
elements = [...waybackSearchElements, ...normalElements, ...savePageFormElements];
|
|
47
|
+
} else {
|
|
48
|
+
elements = this.elementsContainer.querySelectorAll(focusableTagSelectors);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return Array.from(elements).filter(isDisabledOrHidden);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Handles keyboard events and focuses the appropriate element.
|
|
56
|
+
* @param {KeyboardEvent} event - The keyboard event object.
|
|
57
|
+
*/
|
|
58
|
+
handleKeyDown(event) {
|
|
59
|
+
const { key } = event;
|
|
60
|
+
const isArrowKey = ['ArrowDown', 'ArrowRight', 'ArrowUp', 'ArrowLeft'].includes(key);
|
|
61
|
+
const isTabKey = key === 'Tab';
|
|
62
|
+
|
|
63
|
+
if (isArrowKey) {
|
|
64
|
+
this.handleArrowKey(key);
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
} else if (isTabKey) {
|
|
67
|
+
this.handleTabKey(event);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Handles arrow key events and focuses the next or previous element for topnav sub-nav and usermenu
|
|
73
|
+
* @param {string} key - The key that was pressed ('ArrowDown', 'ArrowRight', 'ArrowUp', or 'ArrowLeft').
|
|
74
|
+
*/
|
|
75
|
+
handleArrowKey(key) {
|
|
76
|
+
const isDownOrRight = ['ArrowDown', 'ArrowRight'].includes(key);
|
|
77
|
+
isDownOrRight ? this.focusNext() : this.focusPrevious();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Focuses the previous focusable element in the container.
|
|
82
|
+
*/
|
|
83
|
+
focusPrevious() {
|
|
84
|
+
if (this.focusableElements.length === 0) return;
|
|
85
|
+
this.focusedIndex = (this.focusedIndex - 1 + this.focusableElements.length) % this.focusableElements.length;
|
|
86
|
+
this.focusableElements[this.focusedIndex]?.focus();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Focuses the next focusable element in the container.
|
|
91
|
+
*/
|
|
92
|
+
focusNext() {
|
|
93
|
+
if (this.focusableElements.length === 0) return;
|
|
94
|
+
this.focusedIndex = (this.focusedIndex + 1) % this.focusableElements.length;
|
|
95
|
+
this.focusableElements[this.focusedIndex]?.focus();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Handles the Tab key event and focuses the next or previous menu item.
|
|
100
|
+
* @param {KeyboardEvent} event - The keyboard event object.
|
|
101
|
+
*/
|
|
102
|
+
handleTabKey(event) {
|
|
103
|
+
if (this.menuOption) {
|
|
104
|
+
const isShiftPressed = event.shiftKey;
|
|
105
|
+
this.focusToOtherMenuItems(isShiftPressed);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
this.focusableElements[this.focusedIndex]?.blur();
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Focuses the other parent menu items based on the provided flag.
|
|
114
|
+
* @param {boolean} isPrevious - A flag indicating whether to focus the previous menu item.
|
|
115
|
+
*/
|
|
116
|
+
focusToOtherMenuItems(isPrevious = false) {
|
|
117
|
+
this.elementsContainer.dispatchEvent(
|
|
118
|
+
new CustomEvent('focusToOtherMenuItem', {
|
|
119
|
+
bubbles: true,
|
|
120
|
+
composed: true,
|
|
121
|
+
detail: {
|
|
122
|
+
mediatype: this.menuOption,
|
|
123
|
+
moveTo: isPrevious ? 'prev' : 'next',
|
|
124
|
+
},
|
|
125
|
+
})
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
|
|
3
|
-
export default function (url) {
|
|
4
|
-
window.location = url;
|
|
5
|
-
}
|
|
1
|
+
/* istanbul ignore file */
|
|
2
|
+
|
|
3
|
+
export default function (url) {
|
|
4
|
+
window.location = url;
|
|
5
|
+
}
|
package/src/lib/query-handler.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/* istanbul ignore file */
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
performQuery(query) {
|
|
5
|
-
window.location = `https://web.archive.org/web/*/${query}`;
|
|
6
|
-
}
|
|
7
|
-
};
|
|
1
|
+
/* istanbul ignore file */
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
performQuery(query) {
|
|
5
|
+
window.location = `https://web.archive.org/web/*/${query}`;
|
|
6
|
+
}
|
|
7
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const toSentenceCase = (phrase) => {
|
|
2
|
-
const words = phrase.split(' ');
|
|
3
|
-
const lastWord = words.pop();
|
|
4
|
-
const capitalizedWord = `${lastWord.substr(0, 1).toUpperCase()}${lastWord.substr(1)}`;
|
|
5
|
-
return words.length ? toSentenceCase(`${words.join(' ')}${capitalizedWord}`) : capitalizedWord;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export default toSentenceCase;
|
|
1
|
+
const toSentenceCase = (phrase) => {
|
|
2
|
+
const words = phrase.split(' ');
|
|
3
|
+
const lastWord = words.pop();
|
|
4
|
+
const capitalizedWord = `${lastWord.substr(0, 1).toUpperCase()}${lastWord.substr(1)}`;
|
|
5
|
+
return words.length ? toSentenceCase(`${words.join(' ')}${capitalizedWord}`) : capitalizedWord;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export default toSentenceCase;
|
package/src/login-button.js
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import { html } from 'https://offshoot.prod.archive.org/lit.js';
|
|
2
|
-
import TrackedElement from './tracked-element.js';
|
|
3
|
-
import icons from './assets/img/icons.js';
|
|
4
|
-
import loginButtonCSS from './styles/login-button.js';
|
|
5
|
-
import formatUrl from './lib/formatUrl.js';
|
|
6
|
-
|
|
7
|
-
class LoginButton extends TrackedElement {
|
|
8
|
-
static get styles() {
|
|
9
|
-
return loginButtonCSS;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static get properties() {
|
|
13
|
-
return {
|
|
14
|
-
baseHost: { type: String },
|
|
15
|
-
config: { type: Object },
|
|
16
|
-
openMenu: { type: String },
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
super();
|
|
22
|
-
this.config = {};
|
|
23
|
-
this.openMenu = '';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get signupPath() {
|
|
27
|
-
return formatUrl('/account/signup', this.baseHost);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get loginPath() {
|
|
31
|
-
return formatUrl('/account/login', this.baseHost);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get analyticsEvent() {
|
|
35
|
-
return `${this.config.eventCategory}|NavLoginIcon`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
get menuOpened() {
|
|
39
|
-
return this.openMenu === 'login';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
get avatarClass() {
|
|
43
|
-
return `dropdown-toggle${this.menuOpened ? ' active' : ''}`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
toggleDropdown(e) {
|
|
47
|
-
e.preventDefault();
|
|
48
|
-
this.trackClick(e);
|
|
49
|
-
this.dropdownTabIndex = this.menuOpened ? '' : '-1';
|
|
50
|
-
this.dispatchEvent(new CustomEvent('menuToggled', {
|
|
51
|
-
bubbles: true,
|
|
52
|
-
composed: true,
|
|
53
|
-
detail: {
|
|
54
|
-
menuName: 'login'
|
|
55
|
-
}
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
render() {
|
|
60
|
-
return html`
|
|
61
|
-
<div class="logged-out-toolbar">
|
|
62
|
-
<a
|
|
63
|
-
class="${this.avatarClass}"
|
|
64
|
-
@click=${this.toggleDropdown}
|
|
65
|
-
data-event-click-tracking="${this.analyticsEvent}"
|
|
66
|
-
>
|
|
67
|
-
${icons.user}
|
|
68
|
-
</a>
|
|
69
|
-
<span>
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
</span>
|
|
74
|
-
</div>
|
|
75
|
-
`;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
customElements.define('login-button', LoginButton);
|
|
1
|
+
import { html } from 'https://offshoot.prod.archive.org/lit.js';
|
|
2
|
+
import TrackedElement from './tracked-element.js';
|
|
3
|
+
import icons from './assets/img/icons.js';
|
|
4
|
+
import loginButtonCSS from './styles/login-button.js';
|
|
5
|
+
import formatUrl from './lib/formatUrl.js';
|
|
6
|
+
|
|
7
|
+
class LoginButton extends TrackedElement {
|
|
8
|
+
static get styles() {
|
|
9
|
+
return loginButtonCSS;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static get properties() {
|
|
13
|
+
return {
|
|
14
|
+
baseHost: { type: String },
|
|
15
|
+
config: { type: Object },
|
|
16
|
+
openMenu: { type: String },
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
super();
|
|
22
|
+
this.config = {};
|
|
23
|
+
this.openMenu = '';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get signupPath() {
|
|
27
|
+
return formatUrl('/account/signup', this.baseHost);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get loginPath() {
|
|
31
|
+
return formatUrl('/account/login', this.baseHost);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get analyticsEvent() {
|
|
35
|
+
return `${this.config.eventCategory}|NavLoginIcon`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get menuOpened() {
|
|
39
|
+
return this.openMenu === 'login';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get avatarClass() {
|
|
43
|
+
return `dropdown-toggle${this.menuOpened ? ' active' : ''}`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
toggleDropdown(e) {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
this.trackClick(e);
|
|
49
|
+
this.dropdownTabIndex = this.menuOpened ? '' : '-1';
|
|
50
|
+
this.dispatchEvent(new CustomEvent('menuToggled', {
|
|
51
|
+
bubbles: true,
|
|
52
|
+
composed: true,
|
|
53
|
+
detail: {
|
|
54
|
+
menuName: 'login'
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
render() {
|
|
60
|
+
return html`
|
|
61
|
+
<div class="logged-out-toolbar">
|
|
62
|
+
<a
|
|
63
|
+
class="${this.avatarClass}"
|
|
64
|
+
@click=${this.toggleDropdown}
|
|
65
|
+
data-event-click-tracking="${this.analyticsEvent}"
|
|
66
|
+
>
|
|
67
|
+
${icons.user}
|
|
68
|
+
</a>
|
|
69
|
+
<span>
|
|
70
|
+
<a href="${this.signupPath}">Sign up</a>
|
|
71
|
+
|
|
|
72
|
+
<a href="${this.loginPath}">Log in</a>
|
|
73
|
+
</span>
|
|
74
|
+
</div>
|
|
75
|
+
`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
customElements.define('login-button', LoginButton);
|
package/src/media-button.js
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
import { html } from 'https://offshoot.prod.archive.org/lit.js';
|
|
2
|
-
import TrackedElement from './tracked-element.js';
|
|
3
|
-
import icons from './assets/img/icons.js';
|
|
4
|
-
import toSentenceCase from './lib/toSentenceCase.js';
|
|
5
|
-
import mediaButtonCSS from './styles/media-button.js';
|
|
6
|
-
|
|
7
|
-
class MediaButton extends TrackedElement {
|
|
8
|
-
static get styles() {
|
|
9
|
-
return mediaButtonCSS;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
static get properties() {
|
|
13
|
-
return {
|
|
14
|
-
config: { type: Object },
|
|
15
|
-
icon: { type: String },
|
|
16
|
-
href: { type: String },
|
|
17
|
-
label: { type: String },
|
|
18
|
-
mediatype: { type: String },
|
|
19
|
-
openMenu: { type: String },
|
|
20
|
-
selected: { type: Boolean },
|
|
21
|
-
followable: { type: Boolean },
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
static get icons() {
|
|
26
|
-
return icons;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
constructor() {
|
|
30
|
-
super();
|
|
31
|
-
this.config = {};
|
|
32
|
-
this.icon = '';
|
|
33
|
-
this.href = '';
|
|
34
|
-
this.label = '';
|
|
35
|
-
this.mediatype = '';
|
|
36
|
-
this.openMenu = '';
|
|
37
|
-
this.selected = false;
|
|
38
|
-
this.followable = false;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
onClick(e) {
|
|
42
|
-
this.trackClick(e);
|
|
43
|
-
e.preventDefault();
|
|
44
|
-
// On desktop viewport widths, the media subnav is always visible. To
|
|
45
|
-
// ensure the media subnav is open on mobile if the viewport is
|
|
46
|
-
// resized, the openMenu needs to be set to 'media'.
|
|
47
|
-
if (this.openMenu !== 'media') {
|
|
48
|
-
this.dispatchMenuToggledEvent();
|
|
49
|
-
}
|
|
50
|
-
this.dispatchMediaTypeSelectedEvent();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
dispatchMenuToggledEvent() {
|
|
54
|
-
this.dispatchEvent(new CustomEvent('menuToggled', {
|
|
55
|
-
bubbles: true,
|
|
56
|
-
composed: true,
|
|
57
|
-
detail: {
|
|
58
|
-
menuName: 'media'
|
|
59
|
-
}
|
|
60
|
-
}));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
dispatchMediaTypeSelectedEvent() {
|
|
64
|
-
this.dispatchEvent(new CustomEvent('mediaTypeSelected', {
|
|
65
|
-
bubbles: true,
|
|
66
|
-
composed: true,
|
|
67
|
-
detail: {
|
|
68
|
-
mediatype: this.mediatype
|
|
69
|
-
}
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
get buttonClass() {
|
|
74
|
-
return this.selected ? 'selected' : '';
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
get tooltipPrefix() {
|
|
78
|
-
return this.selected ? 'Collapse' : 'Expand';
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
get iconClass() {
|
|
82
|
-
return this.selected ? 'active' : '';
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
get analyticsEvent() {
|
|
86
|
-
return `${this.config.eventCategory}|NavMenu${toSentenceCase(this.mediatype)}`;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get menuItem() {
|
|
90
|
-
return html`
|
|
91
|
-
<span class="icon ${this.iconClass}">
|
|
92
|
-
${MediaButton.icons[this.icon]}
|
|
93
|
-
</span>
|
|
94
|
-
<span class="label">${this.label}</span>
|
|
95
|
-
`;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
render() {
|
|
99
|
-
return html`
|
|
100
|
-
<a
|
|
101
|
-
href="${this.href}"
|
|
102
|
-
class="menu-item ${this.mediatype} ${this.buttonClass}"
|
|
103
|
-
@click=${this.followable ? this.trackClick : this.onClick}
|
|
104
|
-
data-event-click-tracking="${this.analyticsEvent}"
|
|
105
|
-
title="${this.tooltipPrefix} ${this.mediatype} menu"
|
|
106
|
-
>
|
|
107
|
-
${this.menuItem}
|
|
108
|
-
</a>
|
|
109
|
-
`;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
customElements.define('media-button', MediaButton);
|
|
1
|
+
import { html } from 'https://offshoot.prod.archive.org/lit.js';
|
|
2
|
+
import TrackedElement from './tracked-element.js';
|
|
3
|
+
import icons from './assets/img/icons.js';
|
|
4
|
+
import toSentenceCase from './lib/toSentenceCase.js';
|
|
5
|
+
import mediaButtonCSS from './styles/media-button.js';
|
|
6
|
+
|
|
7
|
+
class MediaButton extends TrackedElement {
|
|
8
|
+
static get styles() {
|
|
9
|
+
return mediaButtonCSS;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static get properties() {
|
|
13
|
+
return {
|
|
14
|
+
config: { type: Object },
|
|
15
|
+
icon: { type: String },
|
|
16
|
+
href: { type: String },
|
|
17
|
+
label: { type: String },
|
|
18
|
+
mediatype: { type: String },
|
|
19
|
+
openMenu: { type: String },
|
|
20
|
+
selected: { type: Boolean },
|
|
21
|
+
followable: { type: Boolean },
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static get icons() {
|
|
26
|
+
return icons;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor() {
|
|
30
|
+
super();
|
|
31
|
+
this.config = {};
|
|
32
|
+
this.icon = '';
|
|
33
|
+
this.href = '';
|
|
34
|
+
this.label = '';
|
|
35
|
+
this.mediatype = '';
|
|
36
|
+
this.openMenu = '';
|
|
37
|
+
this.selected = false;
|
|
38
|
+
this.followable = false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onClick(e) {
|
|
42
|
+
this.trackClick(e);
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
// On desktop viewport widths, the media subnav is always visible. To
|
|
45
|
+
// ensure the media subnav is open on mobile if the viewport is
|
|
46
|
+
// resized, the openMenu needs to be set to 'media'.
|
|
47
|
+
if (this.openMenu !== 'media') {
|
|
48
|
+
this.dispatchMenuToggledEvent();
|
|
49
|
+
}
|
|
50
|
+
this.dispatchMediaTypeSelectedEvent();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
dispatchMenuToggledEvent() {
|
|
54
|
+
this.dispatchEvent(new CustomEvent('menuToggled', {
|
|
55
|
+
bubbles: true,
|
|
56
|
+
composed: true,
|
|
57
|
+
detail: {
|
|
58
|
+
menuName: 'media'
|
|
59
|
+
}
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
dispatchMediaTypeSelectedEvent() {
|
|
64
|
+
this.dispatchEvent(new CustomEvent('mediaTypeSelected', {
|
|
65
|
+
bubbles: true,
|
|
66
|
+
composed: true,
|
|
67
|
+
detail: {
|
|
68
|
+
mediatype: this.mediatype
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get buttonClass() {
|
|
74
|
+
return this.selected ? 'selected' : '';
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get tooltipPrefix() {
|
|
78
|
+
return this.selected ? 'Collapse' : 'Expand';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get iconClass() {
|
|
82
|
+
return this.selected ? 'active' : '';
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
get analyticsEvent() {
|
|
86
|
+
return `${this.config.eventCategory}|NavMenu${toSentenceCase(this.mediatype)}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get menuItem() {
|
|
90
|
+
return html`
|
|
91
|
+
<span class="icon ${this.iconClass}">
|
|
92
|
+
${MediaButton.icons[this.icon]}
|
|
93
|
+
</span>
|
|
94
|
+
<span class="label">${this.label}</span>
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
render() {
|
|
99
|
+
return html`
|
|
100
|
+
<a
|
|
101
|
+
href="${this.href}"
|
|
102
|
+
class="menu-item ${this.mediatype} ${this.buttonClass}"
|
|
103
|
+
@click=${this.followable ? this.trackClick : this.onClick}
|
|
104
|
+
data-event-click-tracking="${this.analyticsEvent}"
|
|
105
|
+
title="${this.tooltipPrefix} ${this.mediatype} menu"
|
|
106
|
+
>
|
|
107
|
+
${this.menuItem}
|
|
108
|
+
</a>
|
|
109
|
+
`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
customElements.define('media-button', MediaButton);
|