mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-09 04:11:10 +01:00
967d29d83d
In addition to syncing the latest changes, this change also merges the theme’s `.scss` files and other related build tool configurations required to compile the theme’s CSS.
This will allow development of the theme to continue on Trac after 5.6 is released and the GitHub repository is archived.
For a full list of changes since [], see e7d5991...aa284fd
.
Props poena, luminuu kjellr, aristath, justinahinon.
See #51526.
Built from https://develop.svn.wordpress.org/trunk@49574
git-svn-id: http://core.svn.wordpress.org/trunk@49312 1a063a9b-81f0-0310-95a4-ce76da25c4cd
59 lines
2.3 KiB
JavaScript
59 lines
2.3 KiB
JavaScript
/* global twentytwentyoneGetHexLum, jQuery */
|
|
( function() {
|
|
// Add listener for the "background_color" control.
|
|
wp.customize( 'background_color', function( value ) {
|
|
value.bind( function( to ) {
|
|
var lum = twentytwentyoneGetHexLum( to ),
|
|
isDark = 127 > lum,
|
|
textColor = ! isDark ? 'var(--global--color-dark-gray)' : 'var(--global--color-light-gray)',
|
|
tableColor = ! isDark ? 'var(--global--color-light-gray)' : 'var(--global--color-dark-gray)',
|
|
stylesheetID = 'twentytwentyone-customizer-inline-styles',
|
|
stylesheet,
|
|
styles;
|
|
|
|
// Modify the html & body classes depending on whether this is a dark background or not.
|
|
if ( isDark ) {
|
|
document.body.classList.add( 'is-dark-theme' );
|
|
document.documentElement.classList.add( 'is-dark-theme' );
|
|
document.documentElement.classList.remove( 'respect-color-scheme-preference' );
|
|
} else {
|
|
document.body.classList.remove( 'is-dark-theme' );
|
|
document.documentElement.classList.remove( 'is-dark-theme' );
|
|
if ( wp.customize( 'respect_user_color_preference' ).get() ) {
|
|
document.documentElement.classList.add( 'respect-color-scheme-preference' );
|
|
}
|
|
}
|
|
|
|
// Toggle the white background class.
|
|
if ( '#ffffff' === to.toLowerCase() ) {
|
|
document.body.classList.add( 'has-background-white' );
|
|
} else {
|
|
document.body.classList.remove( 'has-background-white' );
|
|
}
|
|
|
|
stylesheet = jQuery( '#' + stylesheetID );
|
|
styles = '';
|
|
// If the stylesheet doesn't exist, create it and append it to <head>.
|
|
if ( ! stylesheet.length ) {
|
|
jQuery( '#twenty-twenty-one-style-inline-css' ).after( '<style id="' + stylesheetID + '"></style>' );
|
|
stylesheet = jQuery( '#' + stylesheetID );
|
|
}
|
|
|
|
// Generate the styles.
|
|
styles += '--global--color-primary:' + textColor + ';';
|
|
styles += '--global--color-secondary:' + textColor + ';';
|
|
styles += '--global--color-background:' + to + ';';
|
|
|
|
styles += '--button--color-background:' + textColor + ';';
|
|
styles += '--button--color-text:' + to + ';';
|
|
styles += '--button--color-text-hover:' + textColor + ';';
|
|
|
|
styles += '--table--stripes-border-color:' + tableColor + ';';
|
|
styles += '--table--stripes-background-color:' + tableColor + ';';
|
|
|
|
// Add the styles.
|
|
stylesheet.html( ':root{' + styles + '}' );
|
|
} );
|
|
} );
|
|
}() );
|