|
29 | 29 | let authService = AuthService.Instance;
|
30 | 30 |
|
31 | 31 | let shlStore: Writable<SHLAdminParams[]> = getContext('shlStore');
|
32 |
| -
|
33 |
| - let shlClient: SHLClient = getContext('shlClient'); |
34 | 32 |
|
35 | 33 | let isOpen: Writable<boolean> = getContext('isOpen');
|
36 | 34 |
|
|
56 | 54 | }
|
57 | 55 |
|
58 | 56 | onMount(async () => {
|
59 |
| - window.onscroll = function() {scrollFunction()}; |
60 |
| - scrollFunction(); |
61 | 57 | $isOpen = false;
|
| 58 | + setTimeout(() => { |
| 59 | + if (window.innerWidth < 800) { |
| 60 | + shrinkNav(); |
| 61 | + } |
| 62 | + }, 10); |
62 | 63 |
|
63 | 64 | window.addEventListener('userFound', handleAuthenticationEvent);
|
| 65 | + addDynamicNavbarListeners(); |
64 | 66 | });
|
65 | 67 | onDestroy(() => {
|
66 | 68 | window.removeEventListener('userFound', handleAuthenticationEvent);
|
| 69 | + removeDynamicNavbarListeners(); |
67 | 70 | });
|
68 | 71 |
|
69 |
| - function scrollFunction() { |
70 |
| - if (window.scrollY > 40) { |
71 |
| - let links = document.getElementsByClassName("nav-link"); |
72 |
| - if (links.length == 0) return; |
73 |
| - for(let i = 0; i < links.length; i++) { |
74 |
| - links[i].classList.add("scrolling"); |
75 |
| - } |
76 |
| - document.getElementById("nav-image")?.classList.add("scrolling"); |
77 |
| - document.getElementsByClassName("navbar")?.[0]?.classList.add("scrolling"); |
78 |
| - let es = document.getElementsByClassName("nav-text"); |
79 |
| - if (es.length == 0) return; |
80 |
| - for(let i = 0; i < es.length; i++) { |
81 |
| - es[i].classList.add("scrolling"); |
82 |
| - } |
83 |
| - } else if (window.scrollY == 0) { |
84 |
| - let links = document.getElementsByClassName("nav-link"); |
85 |
| - if (links.length == 0) return; |
86 |
| - for(let i = 0; i < links.length; i++) { |
87 |
| - links[i].classList.remove("scrolling"); |
88 |
| - } |
89 |
| - document.getElementById("nav-image")?.classList.remove("scrolling"); |
90 |
| - document.getElementsByClassName("navbar")?.[0]?.classList.remove("scrolling"); |
91 |
| - let es = document.getElementsByClassName("nav-text"); |
92 |
| - if (es.length == 0) return; |
93 |
| - for(let i = 0; i < es.length; i++) { |
94 |
| - es[i].classList.remove("scrolling"); |
95 |
| - } |
96 |
| - } |
97 |
| - } |
98 |
| -
|
99 | 72 | function closeNav() {
|
100 | 73 | $isOpen = false;
|
101 | 74 | }
|
102 | 75 |
|
103 |
| - let navOpening = false; |
104 |
| - document.addEventListener('click', (event) => { |
105 |
| - // Ignore clicks on the navbar toggler |
106 |
| - if (event.target?.className?.includes('navbar-toggler')) return; |
107 |
| - // Ignore clicks on the dropdown toggle menu items |
108 |
| - if (event.target?.className?.includes('nav-link') && event.target?.className?.includes('dropdown-toggle')) { |
109 |
| - navOpening = true; |
110 |
| - setTimeout(() => { |
111 |
| - navOpening = false; |
112 |
| - }, 100); |
113 |
| - return; |
| 76 | + function shrinkNav() { |
| 77 | + let links = document.getElementsByClassName("nav-link"); |
| 78 | + if (links.length == 0) return; |
| 79 | + for(let i = 0; i < links.length; i++) { |
| 80 | + links[i].classList.add("scrolling"); |
114 | 81 | }
|
115 |
| - closeNav(); |
116 |
| - }); |
117 |
| - document.addEventListener('keydown', (event) => { |
118 |
| - closeNav(); |
119 |
| - }); |
| 82 | + document.getElementById("nav-image")?.classList.add("scrolling"); |
| 83 | + document.getElementsByClassName("navbar")?.[0]?.classList.add("scrolling"); |
| 84 | + let es = document.getElementsByClassName("nav-text"); |
| 85 | + if (es.length == 0) return; |
| 86 | + for(let i = 0; i < es.length; i++) { |
| 87 | + es[i].classList.add("scrolling"); |
| 88 | + } |
| 89 | + } |
120 | 90 |
|
121 |
| - window.addEventListener('scroll', (event) => { |
122 |
| - if (document.querySelector('.navbar-dropdown.show')?.matches(':hover')) return; |
123 |
| - if (document.getElementsByClassName('navbar-collapse collapsing')?.length > 0) return; |
124 |
| - if (navOpening) return; |
125 |
| - closeNav(); |
126 |
| - }); |
| 91 | + function growNav() { |
| 92 | + let links = document.getElementsByClassName("nav-link"); |
| 93 | + if (links.length == 0) return; |
| 94 | + for(let i = 0; i < links.length; i++) { |
| 95 | + links[i].classList.remove("scrolling"); |
| 96 | + } |
| 97 | + document.getElementById("nav-image")?.classList.remove("scrolling"); |
| 98 | + document.getElementsByClassName("navbar")?.[0]?.classList.remove("scrolling"); |
| 99 | + let es = document.getElementsByClassName("nav-text"); |
| 100 | + if (es.length == 0) return; |
| 101 | + for(let i = 0; i < es.length; i++) { |
| 102 | + es[i].classList.remove("scrolling"); |
| 103 | + } |
| 104 | + } |
| 105 | + function removeDynamicNavbarListeners() { |
| 106 | + window.removeEventListener('page-sm', shrinkNav); |
| 107 | + window.removeEventListener('page-md', growNav); |
| 108 | + } |
| 109 | +
|
| 110 | + let navOpening = false; |
| 111 | + function addDynamicNavbarListeners() { |
| 112 | + window.addEventListener('page-sm', shrinkNav); |
| 113 | + window.addEventListener('page-md', growNav); |
| 114 | + document.addEventListener('click', (event) => { |
| 115 | + // Ignore clicks on the navbar toggler |
| 116 | + if (event.target?.className?.includes('navbar-toggler')) return; |
| 117 | + // Ignore clicks on the dropdown toggle menu items |
| 118 | + if (event.target?.className?.includes('nav-link') && event.target?.className?.includes('dropdown-toggle')) { |
| 119 | + navOpening = true; |
| 120 | + setTimeout(() => { |
| 121 | + navOpening = false; |
| 122 | + }, 100); |
| 123 | + return; |
| 124 | + } |
| 125 | + closeNav(); |
| 126 | + }); |
| 127 | + document.addEventListener('keydown', (event) => { |
| 128 | + closeNav(); |
| 129 | + }); |
| 130 | + } |
127 | 131 |
|
128 | 132 | function handleUpdate(event: any) {
|
129 | 133 | $isOpen = event.detail.isOpen;
|
130 | 134 | }
|
131 | 135 | </script>
|
132 |
| - |
133 |
| -<Navbar sticky="top"color="light" light expand="md" style="border-bottom: 1px solid rgb(204, 204, 204);"> |
134 |
| - <NavbarBrand href="https://doh.wa.gov/" target="_blank"> |
135 |
| - <Row> |
136 |
| - <Col> |
137 |
| - <Image id="nav-image" alt="Washington State Department of Health Logo" src="/img/doh_logo_doh-black.png"/> |
138 |
| - </Col> |
139 |
| - </Row> |
140 |
| - </NavbarBrand> |
141 |
| - <NavbarToggler on:click={() => ($isOpen = !$isOpen)} /> |
142 |
| - <Collapse class="flex-column" isOpen={$isOpen} navbar expand="md" on:update={handleUpdate}> |
143 |
| - <Nav class="ms-auto" navbar> |
144 |
| - <LanguageMenu /> |
145 |
| - </Nav> |
146 |
| - <Nav class="ms-auto" navbar> |
147 |
| - <NavItem> |
148 |
| - <NavLink href={"/"} active={ activeItem === "home" }>Home</NavLink> |
149 |
| - </NavItem> |
150 |
| - {#if haveUser} |
151 |
| - {#await authService.getProfile() then profile} |
152 |
| - {#if profile} |
153 |
| - <NavItem> |
154 |
| - <NavLink href="/home" active={ activeItem === "summaries" }>Summaries</NavLink> |
155 |
| - </NavItem> |
156 |
| - <NavItem> |
157 |
| - <NavLink href="/create" active={ activeItem === "create" }>Create</NavLink> |
158 |
| - </NavItem> |
159 |
| - <Dropdown nav inNavbar class="navbar-dropdown" size="sm" direction="down"> |
160 |
| - <DropdownToggle color="primary" nav caret><Icon name="person-circle"/> Account</DropdownToggle> |
161 |
| - <DropdownMenu end style="max-height: 500px; overflow:auto"> |
162 |
| - <DropdownItem header>Welcome, {profile.given_name ?? profile.preferred_username}</DropdownItem> |
163 |
| - <DropdownItem |
164 |
| - on:click={() => { |
165 |
| - authService.logout(); |
166 |
| - }}><Icon name="box-arrow-right"/> Sign Out</DropdownItem> |
167 |
| - <DropdownItem divider /> |
168 |
| - <DropdownItem header>Demo Options</DropdownItem> |
169 |
| - <DropdownItem |
170 |
| - on:click={() => { |
171 |
| - $mode = ($mode === 'advanced' ? 'normal' : 'advanced'); |
172 |
| - }}> |
173 |
| - <Row class="mr-0" style="min-width:240px"> |
174 |
| - <Col class="d-flex justify-content-start align-items-center pe-0"> |
175 |
| - Show Advanced Features |
176 |
| - </Col> |
177 |
| - <Col class="d-flex justify-content-end ps-0"> |
178 |
| - {#if $mode == 'advanced'} |
179 |
| - <Icon class="text-primary" name="toggle-on"></Icon> |
180 |
| - {:else} |
181 |
| - <Icon class="text-secondary" name="toggle-off"></Icon> |
182 |
| - {/if} |
183 |
| - </Col> |
184 |
| - </Row> |
185 |
| - </DropdownItem> |
186 |
| - <DropdownItem divider /> |
187 |
| - <DropdownItem header>Your Summaries</DropdownItem> |
188 |
| - <DropdownItem on:click={() => { goto("/create") }}> |
189 |
| - <Icon name="plus-lg" /> Create New Summary |
190 |
| - </DropdownItem> |
191 |
| - {#if $shlStore.length > 0} |
192 |
| - {#each $shlStore as shl, i} |
| 136 | +<Row> |
| 137 | + <Navbar sticky="top"color="light" light expand="sm" style="border-bottom: 1px solid rgb(204, 204, 204);"> |
| 138 | + <NavbarBrand href="https://doh.wa.gov/" target="_blank"> |
| 139 | + <Row> |
| 140 | + <Col> |
| 141 | + <Image id="nav-image" alt="Washington State Department of Health Logo" src="/img/doh_logo_doh-black.png"/> |
| 142 | + </Col> |
| 143 | + </Row> |
| 144 | + </NavbarBrand> |
| 145 | + <NavbarToggler class="me-2" on:click={() => ($isOpen = !$isOpen)} /> |
| 146 | + <Collapse class="flex-column ms-2" isOpen={$isOpen} navbar expand="sm" on:update={handleUpdate}> |
| 147 | + <Nav class="ms-auto" navbar> |
| 148 | + <LanguageMenu /> |
| 149 | + </Nav> |
| 150 | + <Nav class="ms-auto" navbar> |
| 151 | + <NavItem> |
| 152 | + <NavLink href={"/"} active={ activeItem === "home" }>Home</NavLink> |
| 153 | + </NavItem> |
| 154 | + {#if haveUser} |
| 155 | + {#await authService.getProfile() then profile} |
| 156 | + {#if profile} |
| 157 | + <NavItem> |
| 158 | + <NavLink href="/home" active={ activeItem === "summaries" }>Summaries</NavLink> |
| 159 | + </NavItem> |
| 160 | + <NavItem> |
| 161 | + <NavLink href="/create" active={ activeItem === "create" }>Create</NavLink> |
| 162 | + </NavItem> |
| 163 | + <Dropdown nav inNavbar class="navbar-dropdown" size="sm" direction="down"> |
| 164 | + <DropdownToggle color="primary" nav caret><Icon name="person-circle"/> Account</DropdownToggle> |
| 165 | + <DropdownMenu end style="max-height: 500px; overflow:auto"> |
| 166 | + <DropdownItem header>Welcome, {profile.given_name ?? profile.preferred_username}</DropdownItem> |
| 167 | + <DropdownItem |
| 168 | + on:click={() => { |
| 169 | + authService.logout(); |
| 170 | + }}><Icon name="box-arrow-right"/> Sign Out</DropdownItem> |
| 171 | + <DropdownItem divider /> |
| 172 | + <DropdownItem header>Demo Options</DropdownItem> |
193 | 173 | <DropdownItem
|
194 | 174 | on:click={() => {
|
195 |
| - goto('/view/' + shl.id); |
196 |
| - }}>{shl.label || `Summary ${i + 1}`}</DropdownItem> |
197 |
| - {/each} |
198 |
| - {/if} |
199 |
| - </DropdownMenu> |
200 |
| - </Dropdown> |
| 175 | + $mode = ($mode === 'advanced' ? 'normal' : 'advanced'); |
| 176 | + }}> |
| 177 | + <Row class="mr-0" style="min-width:240px"> |
| 178 | + <Col class="d-flex justify-content-start align-items-center pe-0"> |
| 179 | + Show Advanced Features |
| 180 | + </Col> |
| 181 | + <Col class="d-flex justify-content-end ps-0"> |
| 182 | + {#if $mode == 'advanced'} |
| 183 | + <Icon class="text-primary" name="toggle-on"></Icon> |
| 184 | + {:else} |
| 185 | + <Icon class="text-secondary" name="toggle-off"></Icon> |
| 186 | + {/if} |
| 187 | + </Col> |
| 188 | + </Row> |
| 189 | + </DropdownItem> |
| 190 | + <DropdownItem divider /> |
| 191 | + <DropdownItem header>Your Summaries</DropdownItem> |
| 192 | + <DropdownItem on:click={() => { goto("/create") }}> |
| 193 | + <Icon name="plus-lg" /> Create New Summary |
| 194 | + </DropdownItem> |
| 195 | + {#if $shlStore.length > 0} |
| 196 | + {#each $shlStore as shl, i} |
| 197 | + <DropdownItem |
| 198 | + on:click={() => { |
| 199 | + goto('/view/' + shl.id); |
| 200 | + }}>{shl.label || `Summary ${i + 1}`}</DropdownItem> |
| 201 | + {/each} |
| 202 | + {/if} |
| 203 | + </DropdownMenu> |
| 204 | + </Dropdown> |
| 205 | + {:else} |
| 206 | + <NavItem> |
| 207 | + <NavLink on:click={() => authService.login()}><Icon name="person-circle"/> Sign In</NavLink> |
| 208 | + </NavItem> |
| 209 | + {/if} |
| 210 | + {/await} |
201 | 211 | {:else}
|
202 |
| - <NavItem> |
203 |
| - <NavLink on:click={() => authService.login()}><Icon name="person-circle"/> Sign In</NavLink> |
204 |
| - </NavItem> |
205 |
| - {/if} |
206 |
| - {/await} |
207 |
| - {:else} |
208 |
| - <NavItem> |
209 |
| - <NavLink on:click={() => authService.login()}><Icon name="person-circle"/> Sign In</NavLink> |
210 |
| - </NavItem> |
211 |
| - {/if} |
212 |
| - </Nav> |
213 |
| - </Collapse> |
214 |
| -</Navbar> |
215 |
| -<Banner title="International Patient Summary Prototype"/> |
216 |
| - |
| 212 | + <NavItem> |
| 213 | + <NavLink on:click={() => authService.login()}><Icon name="person-circle"/> Sign In</NavLink> |
| 214 | + </NavItem> |
| 215 | + {/if} |
| 216 | + </Nav> |
| 217 | + </Collapse> |
| 218 | + </Navbar> |
| 219 | + <Banner title="International Patient Summary Prototype"/> |
| 220 | +</Row> |
217 | 221 | <style>
|
| 222 | + :global(#nav-image) { |
| 223 | + width: 240px; |
| 224 | + -webkit-transition: all 0.06s linear; |
| 225 | + -moz-transition: all 0.06s linear; |
| 226 | + -o-transition: all 0.06s linear; |
| 227 | + transition: all 0.06s linear; |
| 228 | + } |
| 229 | + :global(.nav-text) { |
| 230 | + font-size:medium; |
| 231 | + -webkit-transition: all 0.06s linear; |
| 232 | + -moz-transition: all 0.06s linear; |
| 233 | + -o-transition: all 0.06s linear; |
| 234 | + transition: all 0.06s linear; |
| 235 | + } |
| 236 | + :global(.nav-link.scrolling) { |
| 237 | + padding-top: 0rem !important; |
| 238 | + padding-bottom: 0.25rem !important; |
| 239 | + } |
| 240 | + :global(#nav-image.scrolling) { |
| 241 | + width: 160px !important; |
| 242 | + margin-left: 10px; |
| 243 | + } |
| 244 | + :global(.nav-text.scrolling) { |
| 245 | + font-size: xx-small; |
| 246 | + color: #000; /* Fallback for older browsers */ |
| 247 | + color: rgba(0, 0, 0, 0.0); |
| 248 | + } |
| 249 | + :global(.navbar.scrolling) { |
| 250 | + padding: 0px !important; |
| 251 | + } |
218 | 252 | :global(.nav-link) {
|
219 | 253 | position: relative;
|
220 | 254 | }
|
|
0 commit comments