-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from newfold-labs/enhance/PRESS7-131-annotate-…
…opt-images Image Optimization: Mark Optimized Images
- Loading branch information
Showing
24 changed files
with
3,935 additions
and
1,086 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.