-
Notifications
You must be signed in to change notification settings - Fork 934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add global variable to USWDS package for the polling to recognize the… #3867
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… load of JS on uswds-ste
thisisdano
approved these changes
Dec 3, 2020
…li entry points to create bableified version of the detector script
…s/uswds into js-uswds-global-js-variable
Also, don't require `no-js`
2 tasks
2 tasks
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a small (under 1 KB minified) initialization script (
uswds-init.min.js) to the package. When included in the<head>— either by reference or inline — this script prevents the banner from flashing its content on page load and shifting content (#3092).Note: This only prevents flashing when you use CSS generated from USWDS 2.10.0 or later.
What it does
Simply:
.usa-js-loadingclass to the<html>element as the USWDS JS library is loading.In more detail:
.usa-js-loadingclass to the<html>element before thebodyrenders..usa-js-loadingclass..usa-js-loadingclass.Since USWDS components are meant to make their content available even if our JS does not load, their visibility of any toggle-able content defaults to visible and the JS is responsible for hiding it. This resulted in a flash of "hidden" content between when the page renders and the JS loads.
This initialization script allows us to visually hide "hidden" content at page render by hooking those styles to the
.usa-js-loadingclass. When the USWDS JS loads, the JavaScript is responsible for hiding/showing interactive content as usual and the class hook is removed. If the USWDS JS does not load,uswds-initremoves the.usa-ls-loadingclass and the content will revert to visible. If there is no JS present at all,uswds-initwill not load and the content will be visible at page render.Using the initializer
uswds-init-min.jsout of the USWDS package an into your project directory.<head>or include the entire script inline.Include by reference
Include inline
Other changes
snykas a dependency for more reliable local testsnpm startThis initialization script is based on techniques found in https://www.filamentgroup.com/lab/enhancing-optimistically.html