PluginProbe
Image Optimizer – Compress Images and Convert to WebP or AVIF / 1.7.7
Image Optimizer – Compress Images and Convert to WebP or AVIF v1.7.7
1.7.7 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 All 33 releases
image-optimization / modules / optimization / assets / js / templates / list-view / index.js

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

99 lines 2.8 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 { getErrorButton } from '../common';
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, errorType, allowRetry } ) => {
44 return `
45 <span class="image-optimization-control__error-message">${ escapeHTML( message ) }</span>
46
47 ${ getErrorButton( { imagesLeft, errorType, allowRetry } ) }
48 `;
49 };
50
51 const optimizedTemplate = ( data ) => {
52 const absoluteValue = formatFileSize( data?.saved?.absolute, 1 );
53
54 return `
55 <p class="image-optimization-control__property">
56 ${ __( 'Image sizes optimized', 'image-optimization' ) }:
57
58 <span>
59 ${ data?.sizesOptimized }/${ data?.sizesTotal }
60
61 <button type="button"
62 class="image-optimization-control__details-button"
63 aria-label="${ __( 'Open optimization details', 'image-optimization' ) }">
64 (+)
65 </button>
66 </span>
67 </p>
68
69 <p class="image-optimization-control__property">
70 ${ data?.saved?.absolute !== 0
71 ? `${ __( 'Overall saving', 'image-optimization' ) }: <span>${ data?.saved?.relative }% (${ absoluteValue })</span>`
72 : `<span>${ __( 'Image is fully optimized', 'image-optimization' ) }</span>` }
73 </p>
74
75 <div class="image-optimization-control__buttons-wrapper">
76 ${ data?.canBeRestored ? `
77 <button type="button"
78 class="button button-secondary image-optimization-control__button image-optimization-control__button--restore-original">
79 ${ __( 'Restore original', 'image-optimization' ) }
80 </button>
81 ` : '' }
82
83 <button type="button"
84 class="button button-secondary image-optimization-control__button image-optimization-control__button--reoptimize">
85 ${ __( 'Reoptimize', 'image-optimization' ) }
86 </button>
87 </div>
88 `;
89 };
90
91 const listViewTemplates = Object.freeze( {
92 notOptimizedTemplate,
93 loadingTemplate,
94 errorTemplate,
95 optimizedTemplate,
96 } );
97
98 export default listViewTemplates;
99