Skip to content
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

Site Editor: Add skip link to block templates #30336

Merged
merged 31 commits into from
Apr 21, 2021
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f4a33e0
Add skip-link to FSE themes
aristath Feb 11, 2021
f7f16b5
Add check for null selectors
aristath Feb 11, 2021
b2f8cdd
Allow opt-in to auto-css for the skip-link
aristath Feb 11, 2021
22c03e1
Escape things where needed
aristath Feb 11, 2021
c859129
Add inline comment
aristath Feb 11, 2021
199651b
This MUST NOT be escaped
aristath Feb 11, 2021
f16dad4
Use wp_json_encode
aristath Feb 12, 2021
540a5cd
Don't use an anonymous function
aristath Feb 12, 2021
f113ed4
Allow multiple skip-links
aristath Feb 12, 2021
8d24431
Update lib/class-wp-theme-json.php
aristath Feb 12, 2021
9b3b0cc
Merge remote-tracking branch 'origin/add/skip-link' into add/skip-link
aristath Feb 12, 2021
37ca703
fix should_add_skip_link_styles check after the refactor
aristath Feb 12, 2021
afad710
Merge branch 'master' into add/skip-link
aristath Feb 12, 2021
e359454
make css opt-out
aristath Feb 12, 2021
05607a7
classList.add can add multiple classes at once
aristath Feb 12, 2021
6134c79
Merge branch 'trunk' into add/skip-link
aristath Mar 12, 2021
56d0a5a
Add docs
aristath Mar 12, 2021
82ea31a
Merge branch 'trunk' into add/skip-link
aristath Mar 29, 2021
b5214e8
fix merge conflicts
aristath Mar 29, 2021
8d0f990
attempt to simplify previous implementation
aristath Mar 29, 2021
9c8be3d
more merge-conflicts
aristath Mar 29, 2021
0526415
Merge branch 'add/skip-link' into add/skip-link-simplified
aristath Mar 29, 2021
15a8543
No docs tweaks needed
aristath Mar 29, 2021
39f867a
fix link label
aristath Mar 29, 2021
dcbb027
This file is irrelevant to this PR
aristath Mar 29, 2021
368b96c
add missing textdomain
aristath Apr 1, 2021
527f049
Merge branch 'trunk' into add/skip-link-simplified
aristath Apr 13, 2021
9ca5a52
Merge branch 'trunk' into add/skip-link-simplified
aristath Apr 21, 2021
a6947c4
Update list of elements to check for
aristath Apr 21, 2021
da262fc
Use gutenberg_supports_block_templates()
aristath Apr 21, 2021
dfe3818
Revert "Update list of elements to check for"
aristath Apr 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions lib/full-site-editing/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,94 @@ function set_unique_slug_on_create_template( $post_id ) {
}
}
add_action( 'save_post_wp_template', 'set_unique_slug_on_create_template' );

/**
* Print the skip-link script & styles.
*
* @return void
*/
function gutenberg_the_skip_link() {

// Early exit if not an FSE theme.
if ( ! gutenberg_supports_block_templates() ) {
return;
}
?>

<?php
/**
* Print the skip-link styles.
*/
?>
<style id="skip-link-styles">
.skip-link.screen-reader-text {
border: 0;
clip: rect(1px,1px,1px,1px);
clip-path: inset(50%);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute !important;
width: 1px;
word-wrap: normal !important;
}

.skip-link.screen-reader-text:focus {
background-color: #eee;
clip: auto !important;
clip-path: none;
color: #444;
display: block;
font-size: 1em;
height: auto;
left: 5px;
line-height: normal;
padding: 15px 23px 14px;
text-decoration: none;
top: 5px;
width: auto;
z-index: 100000;
}
</style>
<?php
/**
* Print the skip-link script.
*/
?>
<script>
( function() {
var skipLinkTarget = document.querySelector( 'main' ),
parentEl,
skipLinkTargetID,
skipLink;

// Early exit if a skip-link target can't be located.
if ( ! skipLinkTarget ) {
return;
}

// Get the site wrapper.
// The skip-link will be injected in the beginning of it.
parentEl = document.querySelector( '.wp-site-blocks' ) || document.body,

// Get the skip-link target's ID, and generate one if it doesn't exist.
skipLinkTargetID = skipLinkTarget.id;
if ( ! skipLinkTargetID ) {
skipLinkTargetID = 'wp--skip-link--target';
skipLinkTarget.id = skipLinkTargetID;
}

// Create the skip link.
skipLink = document.createElement( 'a' );
skipLink.classList.add( 'skip-link', 'screen-reader-text' );
skipLink.href = '#' + skipLinkTargetID;
skipLink.innerHTML = '<?php esc_html_e( 'Skip to content', 'gutenberg' ); ?>';

// Inject the skip link.
parentEl.insertAdjacentElement( 'afterbegin', skipLink );
}() );
</script>
<?php
}
add_action( 'wp_footer', 'gutenberg_the_skip_link' );