PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / 2.0.7
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF v2.0.7
2.0.7 2.0.6 2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / admin / assets / js / wrio-license-manager.js
robin-image-optimizer / admin / assets / js Last commit date
Chart.min.js 7 months ago bulk-conversion.js 7 months ago bulk-optimization.js 7 months ago calculate-attachments.js 1 year ago index.php 3 years ago meta-migrations.js 3 years ago modals.js 7 months ago notices.js 4 months ago restore-backup.js 7 months ago settings-premium.js 7 months ago single-optimization.js 7 months ago statistic.js 7 months ago sweetalert2.js 3 years ago wrio-license-manager.js 7 months ago
wrio-license-manager.js
149 lines
1 /**
2 * License Manager JavaScript
3 *
4 * Handles license activation, deactivation, sync, and unsubscribe actions.
5 * This is a lightweight replacement for clearfy-license-manager.js
6 *
7 * @package Robin_Image_Optimizer
8 */
9
10 jQuery(function($) {
11 'use strict';
12
13 /**
14 * Handle license action button clicks
15 */
16 $(document).on('click', '.wrio-license-btn', function(e) {
17 e.preventDefault();
18
19 // Remove any existing notices when user tries again
20 $('.wrio-license-notice').remove();
21
22 var $button = $(this),
23 $wrapper = $('#wrio-license-wrapper'),
24 action = $button.data('action'),
25 nonce = $wrapper.data('nonce'),
26 loaderUrl = $wrapper.data('loader');
27
28 // Disable all buttons and show loader inside the clicked button
29 $('.wrio-license-btn').prop('disabled', true);
30 $button.prepend('<img class="wrio-loader" src="' + loaderUrl + '" alt="Loading..." style="height: 16px; vertical-align: middle; margin-right: 8px;">');
31
32 // Build request data
33 var data = {
34 action: 'wrio_license_action',
35 _wpnonce: nonce,
36 license_action: action,
37 licensekey: ''
38 };
39
40 // Include license key for activation
41 if (action === 'activate') {
42 data.licensekey = $('#license-key').val().trim();
43
44 if (!data.licensekey) {
45 showNotice('Please enter a license key.', 'error');
46 resetButtons();
47 return;
48 }
49 }
50
51 // Send AJAX request
52 $.ajax({
53 url: ajaxurl,
54 type: 'POST',
55 dataType: 'json',
56 data: data,
57 success: function(response) {
58 if (response && response.success) {
59 showNotice(response.data.message, 'success');
60 // Reload page to show updated license state
61 setTimeout(function() {
62 window.location.reload();
63 }, 1000);
64 } else {
65 var errorMsg = response && response.data && response.data.message
66 ? response.data.message
67 : 'An error occurred. Please try again.';
68 showNotice(errorMsg, 'error');
69 resetButtons();
70 }
71 },
72 error: function(xhr, status, error) {
73 console.error('WRIO License AJAX Error:', {
74 status: xhr.status,
75 statusText: xhr.statusText,
76 responseText: xhr.responseText,
77 error: error
78 });
79
80 var errorMsg = 'Connection error. Please check your internet connection and try again.';
81 if (xhr.responseText) {
82 try {
83 var response = JSON.parse(xhr.responseText);
84 if (response.data && response.data.message) {
85 errorMsg = response.data.message;
86 }
87 } catch (e) {
88 // Response wasn't JSON
89 }
90 }
91
92 showNotice(errorMsg, 'error');
93 resetButtons();
94 }
95 });
96 });
97
98 /**
99 * Reset buttons to their original state
100 */
101 function resetButtons() {
102 $('.wrio-loader').remove();
103 $('.wrio-license-btn').prop('disabled', false);
104 }
105
106 /**
107 * Show a notice message
108 *
109 * @param {string} message The message to display
110 * @param {string} type Notice type: 'success' or 'error'
111 */
112 function showNotice(message, type) {
113 // Remove any existing notices
114 $('.wrio-license-notice').remove();
115
116 var typeClass = type === 'success' ? 'wrio-license-notice--success' : 'wrio-license-notice--error';
117 var $notice = $('<div class="wrio-license-notice ' + typeClass + '"><p>' + escapeHtml(message) + '</p></div>');
118
119 // Insert into the error container
120 $('#license-form-error-container').html($notice);
121
122 // Auto-dismiss after 5 seconds for success messages
123 if (type === 'success') {
124 setTimeout(function() {
125 $notice.fadeOut(function() {
126 $(this).remove();
127 });
128 }, 5000);
129 }
130 }
131
132 /**
133 * Escape HTML entities
134 *
135 * @param {string} text Text to escape
136 * @return {string} Escaped text
137 */
138 function escapeHtml(text) {
139 var map = {
140 '&': '&amp;',
141 '<': '&lt;',
142 '>': '&gt;',
143 '"': '&quot;',
144 "'": '&#039;'
145 };
146 return String(text).replace(/[&<>"']/g, function(m) { return map[m]; });
147 }
148 });
149