-
Notifications
You must be signed in to change notification settings - Fork 0
/
urlexpander-plugin.js
32 lines (29 loc) · 1.28 KB
/
urlexpander-plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
jQuery(document).ready(function($) {
$('#urlexpander-expand-btn').on('click', function(e) {
e.preventDefault();
var shortUrl = $('#urlexpander-input').val();
$.ajax({
type: 'POST',
url: urlexpander_vars.ajax_url,
data: {
action: 'urlexpander',
nonce: urlexpander_vars.nonce,
short_url: shortUrl
},
beforeSend: function() {
$('#urlexpander-result').html('Expanding URL...');
},
success: function(response) {
if (response.success && response.data) {
// $('#urlexpander-result').html(response.data.expanded_url); // Adjust depending on actual API response structure
var expandedUrl = response.data.expanded_url;
var formattedResponse = '<p style="font-weight: bold; font-size: 14px; text-decoration: underline;">Here is your full URL:</p>';
formattedResponse += '<a href="' + expandedUrl + '" target="_blank">' + expandedUrl + '</a>';
$('#urlexpander-result').html(formattedResponse);
} else {
$('#urlexpander-result').html('Failed to expand URL');
}
}
});
});
});