| 1 |
jQuery(function($){ |
| 2 |
/* |
| 3 |
* Create a new Imagify account |
| 4 |
*/ |
| 5 |
$('#imagify-signup').click( function(e){ |
| 6 |
e.preventDefault(); |
| 7 |
|
| 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(); |
| 46 |
|
| 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 |
}); |
| 100 |
|
| 101 |
|
| 102 |
/* |
| 103 |
* Imagify Light modal |
| 104 |
*/ |
| 105 |
|
| 106 |
if ( $('.imagify-modal-trigger').length > 0 ) { |
| 107 |
|
| 108 |
// accessibility |
| 109 |
$('.imagify-modal').attr('aria-hidden', 'true'); |
| 110 |
|
| 111 |
// on click on modal trigger |
| 112 |
$('.imagify-modal-trigger').on('click', function(){ |
| 113 |
var the_target = $(this).attr('href') || $(this).data('target'); |
| 114 |
|
| 115 |
$( the_target ).css('display', 'flex').hide().fadeIn(400).attr('aria-hidden', 'false').attr('tabindex', '0').focus().removeAttr('tabindex').addClass('modal-is-open'); |
| 116 |
|
| 117 |
return false; |
| 118 |
}); |
| 119 |
|
| 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 |
}); |
| 130 |
|
| 131 |
// `Esc` key binding |
| 132 |
$(window).on('keydown', function(e){ |
| 133 |
if ( e.keyCode == 27 && $('.imagify-modal.modal-is-open').length > 0 ) { |
| 134 |
|
| 135 |
e.preventDefault(); |
| 136 |
|
| 137 |
// trigger the event |
| 138 |
$('.imagify-modal.modal-is-open').find('.close-btn').trigger('click'); |
| 139 |
|
| 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 |
}); |