CoreFiles by mySites.guru
customize.js61 lines, 2,223 bytes, from wordpress-5.6-beta3.zip
Raw History Compare with 5.6-beta2
md5
9c2f77d9471118a0478cca6ba98029fc
sha1
1cf6205b332ccd1c3d06aecb4802dfac905bb74b
sha256
2aa2ec48a9bc731465eb09fb8c8da7a71634b34bc92fd4630a06fa6245d2c99c
/* global twentytwentyoneGetHexLum, backgroundColorNotice */

( function() {
	/**
	 * Add/remove the notice.
	 *
	 * @param {boolean} enable - Whether we want to enable or disable the notice.
	 *
	 * @return {void}
	 */
	function twentytwentyoneBackgroundColorNotice( enable ) {
		if ( enable ) {
			wp.customize( 'background_color' ).notifications.add( 'backgroundColorNotice', new wp.customize.Notification( 'backgroundColorNotice', {
				type: 'info',
				message: backgroundColorNotice.message
			} ) );
		} else {
			wp.customize( 'background_color' ).notifications.remove( 'backgroundColorNotice' );
		}
	}

	// 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 ( wp.customize( 'respect_user_color_preference' ) ) {
			twentytwentyoneBackgroundColorNotice( true );
		}

		// 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 ( ! supportsDarkMode ) {
					twentytwentyoneBackgroundColorNotice( false );
				} else {
					twentytwentyoneBackgroundColorNotice( true );
				}
			} );
		} );
	} );
}() );

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