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

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