CoreFiles by mySites.guru
customize.js60 lines, 2,455 bytes, from wordpress-5.6-beta1.zip
Raw History Compare with 5.5-beta4
md5
6b5c4b70360284efc77eb68d0f872d0a
sha1
93b15000327400531306b0d14adba00ec13d74a6
sha256
f0a47904125e0f9b2edff96e5532c8ec7258d26839aea161091e89e8569d5900
/* global twentytwentyoneGetHexLum, backgroundColorNotice */

( function() {
	// Wait until the customizer has finished loading.
	wp.customize.bind( 'ready', function() {
		var supportsDarkMode = ( 127 <= twentytwentyoneGetHexLum( wp.customize( 'background_color' ).get() ) && wp.customize( 'respect_user_color_preference' ).get() );

		// Hide the "respect_user_color_preference" setting if the background-color is dark.
		if ( 127 > twentytwentyoneGetHexLum( wp.customize( 'background_color' ).get() ) ) {
			wp.customize.control( 'respect_user_color_preference' ).deactivate();
		}

		// Add notice on init if needed.
		if ( window.matchMedia( '(prefers-color-scheme: dark)' ).matches && wp.customize( 'respect_user_color_preference' ) ) {
			if ( supportsDarkMode ) {
				wp.customize( 'background_color' ).notifications.add( 'backgroundColorNotice', new wp.customize.Notification( 'backgroundColorNotice', {
					type: 'info',
					message: backgroundColorNotice.message
				} ) );
			}

			// Remove notice when the value changes.
			wp.customize( 'background_color', function( setting ) {
				setting.bind( function() {
					setting.notifications.remove( 'backgroundColorNotice' );
				} );
			} );
		}

		// Handle changes to the background-color.
		wp.customize( 'background_color', function( setting ) {
			setting.bind( function( value ) {
				if ( 127 > twentytwentyoneGetHexLum( value ) ) {
					wp.customize.control( 'respect_user_color_preference' ).deactivate();
					supportsDarkMode = false;
				} else {
					wp.customize.control( 'respect_user_color_preference' ).activate();
					supportsDarkMode = wp.customize( 'respect_user_color_preference' ).get();
				}
			} );
		} );

		// Handle changes to the "respect_user_color_preference" setting.
		wp.customize( 'respect_user_color_preference', function( setting ) {
			setting.bind( function( value ) {
				supportsDarkMode = value && 127 < twentytwentyoneGetHexLum( wp.customize( 'background_color' ).get() );
				if ( window.matchMedia( '(prefers-color-scheme: dark)' ).matches ) {
					if ( ! supportsDarkMode ) {
						wp.customize( 'background_color' ).notifications.remove( 'backgroundColorNotice' );
					} else {
						wp.customize( 'background_color' ).notifications.add( 'backgroundColorNotice', new wp.customize.Notification( 'backgroundColorNotice', {
							type: 'info',
							message: backgroundColorNotice.message
						} ) );
					}
				}
			} );
		} );
	} );
}() );

No other release has this exact content. See every version of this file.