@internetarchive/ia-topnav 1.3.5-alpha6 → 1.3.6-alpha.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.
Files changed (84) hide show
  1. package/.eslintrc +16 -16
  2. package/LICENSE +661 -661
  3. package/README.md +147 -147
  4. package/index.d.ts +109 -109
  5. package/index.js +3 -3
  6. package/package.json +61 -61
  7. package/src/assets/img/hamburger.js +38 -38
  8. package/src/assets/img/ia-icon.js +33 -33
  9. package/src/assets/img/icon-audio.js +23 -23
  10. package/src/assets/img/icon-close.js +16 -16
  11. package/src/assets/img/icon-donate-unpadded.js +16 -16
  12. package/src/assets/img/icon-donate.js +15 -15
  13. package/src/assets/img/icon-ellipses.js +15 -15
  14. package/src/assets/img/icon-ia-logo.js +22 -22
  15. package/src/assets/img/icon-images.js +15 -15
  16. package/src/assets/img/icon-search.js +15 -15
  17. package/src/assets/img/icon-software.js +15 -15
  18. package/src/assets/img/icon-texts.js +15 -15
  19. package/src/assets/img/icon-upload-unpadded.js +14 -14
  20. package/src/assets/img/icon-upload.js +15 -15
  21. package/src/assets/img/icon-user.js +15 -15
  22. package/src/assets/img/icon-video.js +15 -15
  23. package/src/assets/img/icon-web.js +15 -15
  24. package/src/assets/img/icon.js +18 -18
  25. package/src/assets/img/icons.js +33 -33
  26. package/src/assets/img/wordmark-stacked.js +13 -13
  27. package/src/data/menus.js +670 -670
  28. package/src/desktop-subnav.js +45 -45
  29. package/src/dropdown-menu.js +109 -109
  30. package/src/ia-topnav.js +314 -315
  31. package/src/lib/formatUrl.js +1 -1
  32. package/src/lib/location-handler.js +5 -5
  33. package/src/lib/query-handler.js +7 -7
  34. package/src/lib/toSentenceCase.js +8 -8
  35. package/src/login-button.js +79 -79
  36. package/src/media-button.js +113 -113
  37. package/src/media-menu.js +133 -133
  38. package/src/media-slider.js +104 -104
  39. package/src/media-subnav.js +112 -112
  40. package/src/more-slider.js +33 -33
  41. package/src/nav-search.js +117 -120
  42. package/src/primary-nav.js +224 -232
  43. package/src/save-page-form.js +59 -59
  44. package/src/search-menu.js +115 -146
  45. package/src/signed-out-dropdown.js +10 -10
  46. package/src/styles/base.js +48 -48
  47. package/src/styles/desktop-subnav.js +37 -37
  48. package/src/styles/dropdown-menu.js +166 -166
  49. package/src/styles/ia-topnav.js +87 -87
  50. package/src/styles/login-button.js +79 -79
  51. package/src/styles/media-button.js +156 -156
  52. package/src/styles/media-menu.js +70 -70
  53. package/src/styles/media-slider.js +81 -81
  54. package/src/styles/media-subnav.js +156 -156
  55. package/src/styles/more-slider.js +15 -15
  56. package/src/styles/nav-search.js +136 -136
  57. package/src/styles/primary-nav.js +300 -300
  58. package/src/styles/save-page-form.js +54 -54
  59. package/src/styles/search-menu.js +99 -102
  60. package/src/styles/signed-out-dropdown.js +31 -31
  61. package/src/styles/user-menu.js +31 -31
  62. package/src/styles/wayback-search.js +48 -48
  63. package/src/styles/wayback-slider.js +30 -30
  64. package/src/tracked-element.js +27 -27
  65. package/src/user-menu.js +42 -42
  66. package/src/wayback-search.js +18 -18
  67. package/src/wayback-slider.js +87 -87
  68. package/test/assets/img/hamburger.test.js +15 -15
  69. package/test/assets/img/user.test.js +15 -15
  70. package/test/data/menus.test.js +19 -19
  71. package/test/dropdown-menu.test.js +25 -25
  72. package/test/ia-icon.test.js +13 -13
  73. package/test/ia-topnav.test.js +273 -273
  74. package/test/login-button.test.js +15 -15
  75. package/test/media-button.test.js +19 -19
  76. package/test/media-menu.test.js +40 -40
  77. package/test/media-slider.test.js +57 -57
  78. package/test/more-slider.test.js +13 -13
  79. package/test/nav-search.test.js +61 -61
  80. package/test/primary-nav.test.js +82 -82
  81. package/test/save-page-form.test.js +35 -35
  82. package/test/search-menu.test.js +49 -49
  83. package/test/user-menu.test.js +33 -33
  84. package/test/wayback-slider.test.js +80 -80
package/src/nav-search.js CHANGED
@@ -1,120 +1,117 @@
1
- import { nothing, html } from 'https://offshoot.prod.archive.org/lit.js';
2
-
3
- import TrackedElement from './tracked-element.js';
4
- import navSearchCSS from './styles/nav-search.js';
5
- import icons from './assets/img/icons.js';
6
- import formatUrl from './lib/formatUrl.js';
7
-
8
- class NavSearch extends TrackedElement {
9
- static get styles() {
10
- return navSearchCSS;
11
- }
12
-
13
- static get properties() {
14
- return {
15
- baseHost: { type: String },
16
- config: { type: Object },
17
- locationHandler: { type: Object },
18
- open: { type: Boolean },
19
- openMenu: { type: String },
20
- searchIn: { type: String },
21
- searchQuery: { type: String },
22
- };
23
- }
24
-
25
- constructor() {
26
- super();
27
- this.config = {};
28
- this.locationHandler = () => {};
29
- this.open = false;
30
- this.openMenu = '';
31
- this.searchIn = '';
32
- this.inSearchBeta = false;
33
-
34
- this.initSearchBetaOptIn();
35
- }
36
-
37
- initSearchBetaOptIn() {
38
- this.inSearchBeta = !!window.localStorage?.getItem('SearchBeta-opt-in') ||
39
- !!window.localStorage?.getItem('SearchBeta-launched');
40
- }
41
-
42
- search(e) {
43
- const query = this.shadowRoot.querySelector('[name=query]').value;
44
-
45
- if (!query) {
46
- e.preventDefault();
47
- return false;
48
- }
49
-
50
- // TV search points to a detail page with a q param instead
51
- if (this.searchIn === 'TV') {
52
- this.locationHandler(formatUrl(`/details/tv?q=${query}`, this.baseHost));
53
- e.preventDefault();
54
- return false;
55
- }
56
-
57
- this.trackSubmit(e);
58
- return true;
59
- }
60
-
61
- toggleSearchMenu() {
62
- if (this.openMenu === 'search') {
63
- return;
64
- }
65
- this.dispatchEvent(new CustomEvent('menuToggled', {
66
- detail: {
67
- menuName: 'search'
68
- },
69
- composed: true,
70
- bubbles: true,
71
- }));
72
- }
73
-
74
- get searchInsideInput() {
75
- return this.searchIn ? html`<input type='hidden' name='sin' value='${this.searchIn}' />` : nothing;
76
- }
77
-
78
- get searchEndpoint() {
79
- return this.inSearchBeta ? '/search' : '/search.php';
80
- }
81
-
82
- render() {
83
- const searchMenuClass = this.open ? 'flex' : 'search-inactive';
84
-
85
- return html`
86
- <div class="search-activated fade-in ${searchMenuClass}">
87
- <form
88
- id="nav-search"
89
- class="highlight"
90
- action=${formatUrl(this.searchEndpoint, this.baseHost)}
91
- method="get"
92
- @submit=${this.search}
93
- data-event-submit-tracking="${this.config.eventCategory}|NavSearchSubmit"
94
- >
95
- <input
96
- type="text"
97
- name="query"
98
- class="search-field"
99
- placeholder="Search"
100
- autocomplete="off"
101
- tabindex="2"
102
- value=${this.searchQuery || ''}
103
- @focus=${this.toggleSearchMenu}
104
- />
105
- ${this.searchInsideInput}
106
- <button
107
- type="submit"
108
- class="search"
109
- tabindex="-1"
110
- data-event-click-tracking="${this.config.eventCategory}|NavSearchClose"
111
- >
112
- ${icons.search}
113
- </button>
114
- </form>
115
- </div>
116
- `;
117
- }
118
- }
119
-
120
- customElements.define('nav-search', NavSearch);
1
+ import { nothing, html } from 'https://offshoot.prod.archive.org/lit.js';
2
+
3
+ import TrackedElement from './tracked-element.js';
4
+ import navSearchCSS from './styles/nav-search.js';
5
+ import icons from './assets/img/icons.js';
6
+ import formatUrl from './lib/formatUrl.js';
7
+
8
+ class NavSearch extends TrackedElement {
9
+ static get styles() {
10
+ return navSearchCSS;
11
+ }
12
+
13
+ static get properties() {
14
+ return {
15
+ baseHost: { type: String },
16
+ config: { type: Object },
17
+ locationHandler: { type: Object },
18
+ open: { type: Boolean },
19
+ openMenu: { type: String },
20
+ searchIn: { type: String },
21
+ searchQuery: { type: String },
22
+ };
23
+ }
24
+
25
+ constructor() {
26
+ super();
27
+ this.config = {};
28
+ this.locationHandler = () => {};
29
+ this.open = false;
30
+ this.openMenu = '';
31
+ this.searchIn = '';
32
+ }
33
+
34
+ updated() {
35
+ if (this.open) {
36
+ this.shadowRoot.querySelector('[name=query]').focus();
37
+ }
38
+ return true;
39
+ }
40
+
41
+ search(e) {
42
+ const query = this.shadowRoot.querySelector('[name=query]').value;
43
+
44
+ if (!query) {
45
+ e.preventDefault();
46
+ return false;
47
+ }
48
+
49
+ // TV search points to a detail page with a q param instead
50
+ if (this.searchIn === 'TV') {
51
+ this.locationHandler(formatUrl(`/details/tv?q=${query}`, this.baseHost));
52
+ e.preventDefault();
53
+ return false;
54
+ }
55
+
56
+ this.trackSubmit(e);
57
+ return true;
58
+ }
59
+
60
+ toggleSearchMenu() {
61
+ if (this.openMenu === 'search') {
62
+ return;
63
+ }
64
+ this.dispatchEvent(new CustomEvent('menuToggled', {
65
+ detail: {
66
+ menuName: 'search'
67
+ },
68
+ composed: true,
69
+ bubbles: true,
70
+ }));
71
+ }
72
+
73
+ get searchInsideInput() {
74
+ return this.searchIn ? html`<input type='hidden' name='sin' value='${this.searchIn}' />` : nothing;
75
+ }
76
+
77
+ get searchEndpoint() {
78
+ return '/search';
79
+ }
80
+
81
+ render() {
82
+ const searchMenuClass = this.open ? 'flex' : 'search-inactive';
83
+
84
+ return html`
85
+ <div class="search-activated fade-in ${searchMenuClass}">
86
+ <form
87
+ id="nav-search"
88
+ class="highlight"
89
+ action=${formatUrl(this.searchEndpoint, this.baseHost)}
90
+ method="get"
91
+ @submit=${this.search}
92
+ data-event-submit-tracking="${this.config.eventCategory}|NavSearchSubmit"
93
+ >
94
+ <input
95
+ type="text"
96
+ name="query"
97
+ class="search-field"
98
+ placeholder="Search"
99
+ autocomplete="off"
100
+ @focus=${this.toggleSearchMenu}
101
+ value=${this.searchQuery || ''}
102
+ />
103
+ ${this.searchInsideInput}
104
+ <button
105
+ type="submit"
106
+ class="search"
107
+ data-event-click-tracking="${this.config.eventCategory}|NavSearchClose"
108
+ >
109
+ ${icons.search}
110
+ </button>
111
+ </form>
112
+ </div>
113
+ `;
114
+ }
115
+ }
116
+
117
+ customElements.define('nav-search', NavSearch);