PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 1.9.8
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v1.9.8
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / assets / js / admin.js

admin.js in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 1.9.8, at assets/js/admin.js

104 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 window.imagify = window.imagify || {};
2
3 jQuery.extend( window.imagify, {
4 concat: ajaxurl.indexOf( '?' ) > 0 ? '&' : '?',
5 log: function( content ) {
6 if ( undefined !== console ) {
7 console.log( content ); // eslint-disable-line no-console
8 }
9 },
10 info: function( content ) {
11 if ( undefined !== console ) {
12 console.info( content ); // eslint-disable-line no-console
13 }
14 },
15 openModal: function( $link ) {
16 var target = $link.data( 'target' ) || $link.attr( 'href' );
17
18 jQuery( target ).css( 'display', 'flex' ).hide().fadeIn( 400 ).attr( {
19 'aria-hidden': 'false',
20 'tabindex': '0'
21 } ).focus().removeAttr( 'tabindex' ).addClass( 'modal-is-open' );
22
23 jQuery( 'body' ).addClass( 'imagify-modal-is-open' );
24 },
25 template: function( id ) {
26 if ( undefined === _ ) {
27 // No need to load underscore everywhere if we don't use it.
28 return '';
29 }
30
31 return _.memoize( function( data ) {
32 var compiled,
33 options = {
34 evaluate: /<#([\s\S]+?)#>/g,
35 interpolate: /\{\{\{([\s\S]+?)\}\}\}/g,
36 escape: /\{\{([^}]+?)\}\}(?!\})/g,
37 variable: 'data'
38 };
39
40 return function() {
41 compiled = compiled || _.template( jQuery( '#tmpl-' + id ).html(), null, options );
42 data = data || {};
43 return compiled( data );
44 };
45 } );
46 },
47 humanSize: function( bytes ) {
48 var sizes = ['B', 'kB', 'MB'],
49 i;
50
51 if ( 0 === bytes ) {
52 return '0\xA0kB';
53 }
54
55 i = parseInt( Math.floor( Math.log( bytes ) / Math.log( 1024 ) ), 10 );
56
57 return ( bytes / Math.pow( 1024, i ) ).toFixed( 2 ) + '\xA0' + sizes[ i ];
58 }
59 } );
60
61
62 // Imagify light modal =============================================================================
63 (function($, d, w, undefined) { // eslint-disable-line no-unused-vars, no-shadow, no-shadow-restricted-names
64
65 // Accessibility.
66 $( '.imagify-modal' ).attr( 'aria-hidden', 'true' );
67
68 $( d )
69 // On click on modal trigger, open modal.
70 .on( 'click.imagify', '.imagify-modal-trigger', function( e ) {
71 e.preventDefault();
72 w.imagify.openModal( $( this ) );
73 } )
74 // On click on close button, close modal.
75 .on( 'click.imagify', '.imagify-modal .close-btn', function() {
76 var $modal = $( this ).closest( '.imagify-modal' );
77
78 $modal.fadeOut( 400 ).attr( 'aria-hidden', 'true' ).removeClass( 'modal-is-open' ).trigger( 'modalClosed.imagify' );
79
80 $( 'body' ).removeClass( 'imagify-modal-is-open' );
81 } )
82 // On close button blur, improve accessibility.
83 .on( 'blur.imagify', '.imagify-modal .close-btn', function() {
84 var $modal = $( this ).closest( '.imagify-modal' );
85
86 if ( $modal.attr( 'aria-hidden' ) === 'false' ) {
87 $modal.attr( 'tabindex', '0' ).focus().removeAttr( 'tabindex' );
88 }
89 } )
90 // On click on dropped layer of modal, close modal.
91 .on( 'click.imagify', '.imagify-modal', function( e ) {
92 $( e.target ).filter( '.modal-is-open' ).find( '.close-btn' ).trigger( 'click.imagify' );
93 } )
94 // `Esc` key binding, close modal.
95 .on( 'keydown.imagify', function( e ) {
96 if ( 27 === e.keyCode && $( '.imagify-modal.modal-is-open' ).length > 0 ) {
97 e.preventDefault();
98 // Trigger the event.
99 $( '.imagify-modal.modal-is-open' ).find( '.close-btn' ).trigger( 'click.imagify' );
100 }
101 } );
102
103 } )(jQuery, document, window);
104