Skip to content

Commit

Permalink
Merge pull request #40 from newfold-labs/enhance/PRESS7-131-annotate-…
Browse files Browse the repository at this point in the history
…opt-images

Image Optimization: Mark Optimized Images
  • Loading branch information
arunshenoy99 authored Dec 23, 2024
2 parents 2a09574 + d5fa3c8 commit c00555b
Show file tree
Hide file tree
Showing 24 changed files with 3,935 additions and 1,086 deletions.
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

0 comments on commit c00555b

Please sign in to comment.