PluginProbe
Image Optimization – Compress Images and Convert to WebP or AVIF / 1.6.6
Image Optimization – Compress Images and Convert to WebP or AVIF v1.6.6
1.7.6 1.7.5 1.7.4 trunk 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 All 32 releases
image-optimization / modules / optimization / assets / js / templates / list-view / index.js

index.js in Image Optimization – Compress Images and Convert to WebP or AVIF 1.6.6, at modules/optimization/assets/js/templates/list-view/index.js

109 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { __ } from '@wordpress/i18n';
2 import { escapeHTML } from '@wordpress/escape-html';
3 import { formatFileSize } from '../../utils';
4 import { UPGRADE_LINK } from '../../constants';
5
6 const notOptimizedTemplate = () => {
7 return `
8 <button type="button"
9 class="button button-primary image-optimization-control__button image-optimization-control__button--optimize">
10 ${ __( 'Optimize now', 'image-optimization' ) }
11 </button>
12 `;
13 };
14
15 const loadingTemplate = ( action ) => {
16 let buttonText;
17
18 switch ( action ) {
19 case 'restore':
20 buttonText = __( 'Restoring…', 'image-optimization' );
21 break;
22
23 case 'optimize':
24 buttonText = __( 'Optimizing…', 'image-optimization' );
25 break;
26
27 case 'reoptimize':
28 buttonText = __( 'Reoptimizing…', 'image-optimization' );
29 break;
30
31 default:
32 buttonText = __( 'Loading…', 'image-optimization' );
33 }
34
35 return `
36 <button class="button button-secondary image-optimization-control__button image-optimization-control__button--optimize"
37 disabled="">
38 <span class="spinner is-active"></span> ${ buttonText }
39 </button>
40 `;
41 };
42
43 const errorTemplate = ( message, imagesLeft ) => {
44 return `
45 <span class="image-optimization-control__error-message">${ escapeHTML( message ) }</span>
46
47 ${ imagesLeft === 0
48 ? `<a class="button button-secondary button-large image-optimization-control__button"
49 href="${ UPGRADE_LINK }"
50 target="_blank" rel="noopener noreferrer">
51 ${ __( 'Upgrade', 'image-optimization' ) }
52 </a>
53 ` : `
54 <button class="button button-secondary button-large button-link-delete image-optimization-control__button image-optimization-control__button--try-again"
55 type="button">
56 ${ __( 'Try again', 'image-optimization' ) }
57 </button>` }
58 `;
59 };
60
61 const optimizedTemplate = ( data ) => {
62 const absoluteValue = formatFileSize( data?.saved?.absolute, 1 );
63
64 return `
65 <p class="image-optimization-control__property">
66 ${ __( 'Image sizes optimized', 'image-optimization' ) }:
67
68 <span>
69 ${ data?.sizesOptimized }/${ data?.sizesTotal }
70
71 <button type="button"
72 class="image-optimization-control__details-button"
73 aria-label="${ __( 'Open optimization details', 'image-optimization' ) }">
74 (+)
75 </button>
76 </span>
77 </p>
78
79 <p class="image-optimization-control__property">
80 ${ data?.saved?.absolute !== 0
81 ? `${ __( 'Overall saving', 'image-optimization' ) }: <span>${ data?.saved?.relative }% (${ absoluteValue })</span>`
82 : `<span>${ __( 'Image is fully optimized', 'image-optimization' ) }</span>` }
83 </p>
84
85 <div class="image-optimization-control__buttons-wrapper">
86 ${ data?.canBeRestored ? `
87 <button type="button"
88 class="button button-secondary image-optimization-control__button image-optimization-control__button--restore-original">
89 ${ __( 'Restore original', 'image-optimization' ) }
90 </button>
91 ` : '' }
92
93 <button type="button"
94 class="button button-secondary image-optimization-control__button image-optimization-control__button--reoptimize">
95 ${ __( 'Reoptimize', 'image-optimization' ) }
96 </button>
97 </div>
98 `;
99 };
100
101 const listViewTemplates = Object.freeze( {
102 notOptimizedTemplate,
103 loadingTemplate,
104 errorTemplate,
105 optimizedTemplate,
106 } );
107
108 export default listViewTemplates;
109