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
← All changes | assets/js/admin.js +80 -154 1.3.6.1 → trunk View file →
@@ -1,166 +1,92 @@
1 -jQuery(function($){
2 - /*
3 - * Create a new Imagify account
4 - */
5 - $('#imagify-signup').click( function(e){
6 - e.preventDefault();
1 +window.imagify = window.imagify || {};
7 2
8 - // Display the sign up form
9 - swal({
10 - title: imagify.signupTitle,
11 - text: imagify.signupText,
12 - confirmButtonText: imagify.signupConfirmButtonText,
13 - type: "input",
14 - closeOnConfirm: false,
15 - allowOutsideClick: true,
16 - showLoaderOnConfirm: true,
17 - customClass: "imagify-sweet-alert imagify-sweet-alert-signup"
18 - },
19 - function(inputValue){
20 - if ($.trim(inputValue) == "" || ! inputValue) {
21 - swal.showInputError(imagify.signupErrorEmptyEmail);
22 - return false;
23 - }
24 -
25 - $.get(ajaxurl + "?action=imagify_signup&email=" +inputValue + "&imagifysignupnonce="+ $('#imagifysignupnonce').val())
26 - .done(function(response){
27 - if( !response.success ) {
28 - swal.showInputError(response.data);
29 - } else {
30 - swal({
31 - title:imagify.signupSuccessTitle,
32 - text: imagify.signupSuccessText,
33 - type: "success",
34 - customClass: "imagify-sweet-alert"
35 - });
36 - }
37 - });
38 - });
39 - });
40 -
41 - /*
42 - * Check and save the Imagify API Key
43 - */
44 - $('#imagify-save-api-key').click( function(e){
45 - e.preventDefault();
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 );
46 18
47 - // Display the sign up form
48 - swal({
49 - title: imagify.saveApiKeyTitle,
50 - text: imagify.saveApiKeyText,
51 - confirmButtonText: imagify.saveApiKeyConfirmButtonText,
52 - type: "input",
53 - closeOnConfirm: false,
54 - allowOutsideClick: true,
55 - showLoaderOnConfirm: true,
56 - customClass: "imagify-sweet-alert imagify-sweet-alert-signup"
57 - },
58 - function(inputValue){
59 - if ($.trim(inputValue) == "" || ! inputValue) {
60 - swal.showInputError(imagify.signupErrorEmptyEmail);
61 - return false;
62 - }
63 -
64 - $.get(ajaxurl + "?action=imagify_check_api_key_validity&api_key=" +inputValue + "&imagifycheckapikeynonce="+ $('#imagifycheckapikeynonce').val())
65 - .done(function(response){
66 - if( !response.success ) {
67 - swal.showInputError(response.data);
68 - } else {
69 - swal({
70 - title:imagify.ApiKeyCheckSuccessTitle,
71 - text: imagify.ApiKeyCheckSuccessText,
72 - type: "success",
73 - customClass: "imagify-sweet-alert"
74 - });
75 - }
76 - });
77 - });
78 - });
79 -
80 - /*
81 - * Toggle an Imagify notice
82 - */
83 - $('.imagify-notice-dismiss').click( function( e ) {
84 - e.preventDefault();
85 -
86 - var obj = $(this),
87 - parent = obj.parents('.imagify-welcome, .imagify-notice'),
88 - href = obj.attr('href');
89 -
90 - // Hide the notice
91 - parent.fadeTo( 100 , 0, function() {
92 - $(this).slideUp( 100, function() {
93 - $(this).remove();
94 - });
95 - });
96 -
97 - // Save the dismiss notice
98 - $.get( href.replace( 'admin-post.php', 'admin-ajax.php' ) );
99 - });
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' );
100 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 + }
101 31
102 - /*
103 - * Imagify Light modal
104 - */
105 -
106 - if ( $('.imagify-modal-trigger').length > 0 ) {
107 -
108 - // accessibility
109 - $('.imagify-modal').attr('aria-hidden', 'true');
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 + };
110 40
111 - // on click on modal trigger
112 - $('.imagify-modal-trigger').on('click', function(){
113 - var the_target = $(this).attr('href') || $(this).data('target');
41 + return function() {
42 + compiled = compiled || _.template( jQuery( '#tmpl-' + id ).html(), null, options );
43 + data = data || {};
44 + return compiled( data );
45 + };
46 + } );
47 + }
48 +} );
114 49
115 - $( the_target ).css('display', 'flex').hide().fadeIn(400).attr('aria-hidden', 'false').attr('tabindex', '0').focus().removeAttr('tabindex').addClass('modal-is-open');
116 50
117 - return false;
118 - });
51 +// Imagify light modal =============================================================================
52 +(function($, d, w, undefined) { // eslint-disable-line no-unused-vars, no-shadow, no-shadow-restricted-names
119 53
120 - // on click on close button
121 - $('.imagify-modal').find('.close-btn').on('click', function(){
122 - $(this).closest('.imagify-modal').fadeOut(400).attr('aria-hidden', 'true').removeClass('modal-is-open');
123 - })
124 - .on('blur', function(){
125 - var $modal = $(this).closest('.imagify-modal');
126 - if ( $modal.attr('aria-hidden') === 'false' ) {
127 - $modal.attr('tabindex', '0').focus().removeAttr('tabindex');
128 - }
129 - });
54 + // Accessibility.
55 + $( '.imagify-modal' ).attr( 'aria-hidden', 'true' );
130 56
131 - // `Esc` key binding
132 - $(window).on('keydown', function(e){
133 - if ( e.keyCode == 27 && $('.imagify-modal.modal-is-open').length > 0 ) {
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' );
134 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 ) {
135 86 e.preventDefault();
136 -
137 - // trigger the event
138 - $('.imagify-modal.modal-is-open').find('.close-btn').trigger('click');
87 + // Trigger the event.
88 + $( '.imagify-modal.modal-is-open' ).find( '.close-btn' ).trigger( 'click.imagify' );
89 + }
90 + } );
139 91
140 - return false;
141 - }
142 - });
143 - }
144 -
145 - var busy = false,
146 - xhr = false;
147 -
148 - $('#wp-admin-bar-imagify').hover( function() {
149 - if ( true === busy ) {
150 - xhr.abort();
151 - }
152 -
153 - busy = true;
154 -
155 - var $adminBarProfile = $('#wp-admin-bar-imagify-profile-content');
156 -
157 - if( $adminBarProfile.is(':empty') ) {
158 - xhr = $.get(ajaxurl + "?action=imagify_get_admin_bar_profile&imagifygetadminbarprofilenonce="+ $('#imagifygetadminbarprofilenonce').val())
159 - .done(function(response){
160 - $adminBarProfile.html(response.data);
161 - $('#wp-admin-bar-imagify-profile-loading').remove();
162 - busy = false;
163 - });
164 - }
165 - });
166 -});
92 +} )(jQuery, document, window);