| 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 |
var imagify_open_modal = function( $the_link ){ |
| 109 |
|
| 110 |
var the_target = $the_link.data('target') || $the_link.attr('href'); |
| 111 |
|
| 112 |
$( the_target ).css('display', 'flex').hide().fadeIn(400).attr('aria-hidden', 'false').attr('tabindex', '0').focus().removeAttr('tabindex').addClass('modal-is-open'); |
| 113 |
$('body').addClass('imagify-modal-is-open'); |
| 114 |
|
| 115 |
}; |
| 116 |
|
| 117 |
// accessibility |
| 118 |
$('.imagify-modal').attr('aria-hidden', 'true'); |
| 119 |
|
| 120 |
// on click on modal trigger |
| 121 |
$('.imagify-modal-trigger').on('click', function(){ |
| 122 |
|
| 123 |
imagify_open_modal( $(this) ); |
| 124 |
|
| 125 |
return false; |
| 126 |
}); |
| 127 |
|
| 128 |
// on click on close button |
| 129 |
$(document).on('click', '.imagify-modal .close-btn', function(){ |
| 130 |
$(this).closest('.imagify-modal').fadeOut(400).attr('aria-hidden', 'true').removeClass('modal-is-open'); |
| 131 |
$('body').removeClass('imagify-modal-is-open'); |
| 132 |
}) |
| 133 |
.on('blur', '.imagify-modal .close-btn', function(){ |
| 134 |
var $modal = $(this).closest('.imagify-modal'); |
| 135 |
if ( $modal.attr('aria-hidden') === 'false' ) { |
| 136 |
$modal.attr('tabindex', '0').focus().removeAttr('tabindex'); |
| 137 |
} |
| 138 |
}); |
| 139 |
|
| 140 |
// `Esc` key binding |
| 141 |
$(window).on('keydown', function(e){ |
| 142 |
if ( e.keyCode == 27 && $('.imagify-modal.modal-is-open').length > 0 ) { |
| 143 |
|
| 144 |
e.preventDefault(); |
| 145 |
|
| 146 |
// trigger the event |
| 147 |
$('.imagify-modal.modal-is-open').find('.close-btn').trigger('click'); |
| 148 |
|
| 149 |
return false; |
| 150 |
} |
| 151 |
}); |
| 152 |
|
| 153 |
var busy = false, |
| 154 |
xhr = false; |
| 155 |
|
| 156 |
$('#wp-admin-bar-imagify').hover( function() { |
| 157 |
if ( true === busy ) { |
| 158 |
xhr.abort(); |
| 159 |
} |
| 160 |
|
| 161 |
busy = true; |
| 162 |
|
| 163 |
var $adminBarProfile = $('#wp-admin-bar-imagify-profile-content'); |
| 164 |
|
| 165 |
if( $adminBarProfile.is(':empty') ) { |
| 166 |
xhr = $.get(ajaxurl + concat + "action=imagify_get_admin_bar_profile&imagifygetadminbarprofilenonce="+ $('#imagifygetadminbarprofilenonce').val()) |
| 167 |
.done(function(response){ |
| 168 |
$adminBarProfile.html(response.data); |
| 169 |
$('#wp-admin-bar-imagify-profile-loading').remove(); |
| 170 |
busy = false; |
| 171 |
}); |
| 172 |
} |
| 173 |
}); |
| 174 |
}); |