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

Image Optimization: Mark Optimized Images #40

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
File renamed without changes.
11 changes: 11 additions & 0 deletions assets/image-optimized-marker/image-optimized-marker.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* image-optimized-marker.css */
.nfd-performance-image-optimized-marker {
position: absolute;
top: 8px;
right: 8px;
background: #007cba;
color: #fff;
padding: 2px 6px;
border-radius: 4px;
font-size: 12px;
}
37 changes: 37 additions & 0 deletions assets/image-optimized-marker/image-optimized-marker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import './image-optimized-marker.css';

import { __ } from '@wordpress/i18n';

document.addEventListener( 'DOMContentLoaded', () => {
/**
* Adds a marker to optimized images in the media library
*/
const markOptimizedImages = () => {
document.querySelectorAll( '.attachment' ).forEach( ( attachment ) => {
// Get media library data
const mediaId = attachment.getAttribute( 'data-id' );
const mediaData = wp.media.attachment( mediaId ).attributes;

// Check if the image is optimized
if (
mediaData.nfdPerformanceImageOptimized &&
! attachment.querySelector(
'.nfd-performance-image-optimized-marker'
)
) {
const marker = document.createElement( 'span' );
marker.textContent = __( 'Optimized', 'wp-module-performance' );
marker.className = 'nfd-performance-image-optimized-marker';

attachment.querySelector( '.thumbnail' )?.appendChild( marker );
}
} );
};

// Monitor for changes in the media library
const observer = new MutationObserver( markOptimizedImages );
observer.observe( document.body, { childList: true, subtree: true } );

// Initial run
markOptimizedImages();
} );
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion build/bulk-optimizer.min.asset.php

This file was deleted.

2 changes: 1 addition & 1 deletion build/bulk-optimizer.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading