| 1 |
// All notices ===================================================================================== |
| 2 |
(function($, d, w, undefined) { // eslint-disable-line no-unused-vars, no-shadow, no-shadow-restricted-names |
| 3 |
|
| 4 |
/** |
| 5 |
* Close an Imagify notice. |
| 6 |
*/ |
| 7 |
$( '.imagify-notice-dismiss' ).on( 'click.imagify', function( e ) { |
| 8 |
var $this = $( this ), |
| 9 |
$parent = $this.parents( '.imagify-welcome, .imagify-notice, .imagify-rkt-notice' ), |
| 10 |
href = $this.attr( 'href' ); |
| 11 |
|
| 12 |
e.preventDefault(); |
| 13 |
|
| 14 |
// Hide the notice. |
| 15 |
$parent.fadeTo( 100 , 0, function() { |
| 16 |
$( this ).slideUp( 100, function() { |
| 17 |
$( this ).remove(); |
| 18 |
} ); |
| 19 |
} ); |
| 20 |
|
| 21 |
// Save the dismiss notice. |
| 22 |
$.get( href.replace( 'admin-post.php', 'admin-ajax.php' ) ); |
| 23 |
} ); |
| 24 |
|
| 25 |
} )(jQuery, document, window); |
| 26 |
|
| 27 |
|
| 28 |
// The "welcome steps" notice + "wrong API key" notice ============================================= |
| 29 |
(function($, d, w, undefined) { // eslint-disable-line no-unused-vars, no-shadow, no-shadow-restricted-names |
| 30 |
|
| 31 |
/** |
| 32 |
* 1. Create a new Imagify account. |
| 33 |
*/ |
| 34 |
$( '#imagify-signup' ).on( 'click.imagify', function( e ) { |
| 35 |
e.preventDefault(); |
| 36 |
|
| 37 |
// Display the sign up form. |
| 38 |
swal( { |
| 39 |
title: imagifyNotices.labels.signupTitle, |
| 40 |
html: imagifyNotices.labels.signupText, |
| 41 |
confirmButtonText: imagifyNotices.labels.signupConfirmButtonText, |
| 42 |
input: 'email', |
| 43 |
padding: 0, |
| 44 |
showLoaderOnConfirm: true, |
| 45 |
customClass: 'imagify-sweet-alert imagify-sweet-alert-signup', |
| 46 |
inputValidator: function( inputValue ) { |
| 47 |
return new Promise( function( resolve, reject ) { |
| 48 |
if ( $.trim( inputValue ) === '' || ! inputValue ) { |
| 49 |
reject( imagifyNotices.labels.signupErrorEmptyEmail ); |
| 50 |
} else { |
| 51 |
resolve(); |
| 52 |
} |
| 53 |
} ); |
| 54 |
}, |
| 55 |
preConfirm: function( inputValue ) { |
| 56 |
return new Promise( function( resolve, reject ) { |
| 57 |
setTimeout( function() { |
| 58 |
$.get( ajaxurl + w.imagify.concat + 'action=imagify_signup&email=' + inputValue + '&imagifysignupnonce=' + $( '#imagifysignupnonce' ).val() ) |
| 59 |
.done( function( response ) { |
| 60 |
if ( ! response.success ) { |
| 61 |
reject( response.data ); |
| 62 |
} else { |
| 63 |
resolve(); |
| 64 |
} |
| 65 |
} ); |
| 66 |
}, 2000 ); |
| 67 |
} ); |
| 68 |
}, |
| 69 |
} ).then( function() { |
| 70 |
swal( { |
| 71 |
title: imagifyNotices.labels.signupSuccessTitle, |
| 72 |
html: imagifyNotices.labels.signupSuccessText, |
| 73 |
type: 'success', |
| 74 |
padding: 0, |
| 75 |
customClass: 'imagify-sweet-alert' |
| 76 |
} ); |
| 77 |
} ); |
| 78 |
} ); |
| 79 |
|
| 80 |
/** |
| 81 |
* 2. Check and save the Imagify API Key. |
| 82 |
*/ |
| 83 |
$( '#imagify-save-api-key' ).on( 'click.imagify', function( e ) { |
| 84 |
e.preventDefault(); |
| 85 |
|
| 86 |
// Display the API key form. |
| 87 |
swal( { |
| 88 |
title: imagifyNotices.labels.saveApiKeyTitle, |
| 89 |
html: imagifyNotices.labels.saveApiKeyText, |
| 90 |
confirmButtonText: imagifyNotices.labels.saveApiKeyConfirmButtonText, |
| 91 |
input: 'text', |
| 92 |
padding: 0, |
| 93 |
showLoaderOnConfirm: true, |
| 94 |
customClass: 'imagify-sweet-alert imagify-sweet-alert-signup', |
| 95 |
inputValidator: function( inputValue ) { |
| 96 |
return new Promise( function( resolve, reject ) { |
| 97 |
if ( $.trim( inputValue ) === '' || ! inputValue ) { |
| 98 |
reject( imagifyNotices.labels.ApiKeyErrorEmpty ); |
| 99 |
} else { |
| 100 |
resolve(); |
| 101 |
} |
| 102 |
} ); |
| 103 |
}, |
| 104 |
preConfirm: function( inputValue ) { |
| 105 |
return new Promise( function( resolve, reject ) { |
| 106 |
$.get( ajaxurl + w.imagify.concat + 'action=imagify_check_api_key_validity&api_key=' + inputValue + '&imagifycheckapikeynonce=' + $( '#imagifycheckapikeynonce' ).val() ) |
| 107 |
.done( function( response ) { |
| 108 |
if ( ! response.success ) { |
| 109 |
reject( response.data ); |
| 110 |
} else { |
| 111 |
resolve(); |
| 112 |
} |
| 113 |
} ); |
| 114 |
} ); |
| 115 |
}, |
| 116 |
} ).then( function() { |
| 117 |
swal( { |
| 118 |
title: imagifyNotices.labels.ApiKeyCheckSuccessTitle, |
| 119 |
html: imagifyNotices.labels.ApiKeyCheckSuccessText, |
| 120 |
type: 'success', |
| 121 |
padding: 0, |
| 122 |
customClass: 'imagify-sweet-alert' |
| 123 |
} ); |
| 124 |
} ); |
| 125 |
} ); |
| 126 |
|
| 127 |
} )(jQuery, document, window); |
| 128 |
|