PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
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 trunk, at assets/js/admin.js

93 lines 2.9 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 $target = jQuery( target );
18
19 $target.css( 'display', 'flex' ).hide().fadeIn( 400 ).attr( {
20 'aria-hidden': 'false',
21 'tabindex': '0'
22 } ).trigger('focus').removeAttr( 'tabindex' ).addClass( 'modal-is-open' );
23
24 jQuery( 'body' ).addClass( 'imagify-modal-is-open' );
25 },
26 template: function( id ) {
27 if ( undefined === _ ) {
28 // No need to load underscore everywhere if we don't use it.
29 return '';
30 }
31
32 return _.memoize( function( data ) {
33 var compiled,
34 options = {
35 evaluate: /<#([\s\S]+?)#>/g,
36 interpolate: /\{\{\{([\s\S]+?)\}\}\}/g,
37 escape: /\{\{([^}]+?)\}\}(?!\})/g,
38 variable: 'data'
39 };
40
41 return function() {
42 compiled = compiled || _.template( jQuery( '#tmpl-' + id ).html(), null, options );
43 data = data || {};
44 return compiled( data );
45 };
46 } );
47 }
48 } );
49
50
51 // Imagify light modal =============================================================================
52 (function($, d, w, undefined) { // eslint-disable-line no-unused-vars, no-shadow, no-shadow-restricted-names
53
54 // Accessibility.
55 $( '.imagify-modal' ).attr( 'aria-hidden', 'true' );
56
57 $( d )
58 // On click on modal trigger, open modal.
59 .on( 'click.imagify', '.imagify-modal-trigger', function( e ) {
60 e.preventDefault();
61 w.imagify.openModal( $( this ) );
62 } )
63 // On click on close button, close modal.
64 .on( 'click.imagify', '.imagify-modal .close-btn', function() {
65 var $modal = $( this ).closest( '.imagify-modal' );
66
67 $modal.fadeOut( 400 ).attr( 'aria-hidden', 'true' ).removeClass( 'modal-is-open' ).trigger( 'modalClosed.imagify' );
68
69 $( 'body' ).removeClass( 'imagify-modal-is-open' );
70 } )
71 // On close button blur, improve accessibility.
72 .on( 'blur.imagify', '.imagify-modal .close-btn', function() {
73 var $modal = $( this ).closest( '.imagify-modal' );
74
75 if ( $modal.attr( 'aria-hidden' ) === 'false' ) {
76 $modal.attr( 'tabindex', '0' ).trigger('focus').removeAttr( 'tabindex' );
77 }
78 } )
79 // On click on dropped layer of modal, close modal.
80 .on( 'click.imagify', '.imagify-modal', function( e ) {
81 $( e.target ).filter( '.modal-is-open' ).find( '.close-btn' ).trigger( 'click.imagify' );
82 } )
83 // `Esc` key binding, close modal.
84 .on( 'keydown.imagify', function( e ) {
85 if ( 27 === e.keyCode && $( '.imagify-modal.modal-is-open' ).length > 0 ) {
86 e.preventDefault();
87 // Trigger the event.
88 $( '.imagify-modal.modal-is-open' ).find( '.close-btn' ).trigger( 'click.imagify' );
89 }
90 } );
91
92 } )(jQuery, document, window);
93