PluginProbe
MxChat – AI Chatbot & Content Generation for WordPress / 2.0.1
MxChat – AI Chatbot & Content Generation for WordPress v2.0.1
3.2.21 3.2.20 3.2.19 3.2.18 3.2.17 3.2.16 3.2.15 3.2.14 3.2.12 3.2.13 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 3.2.6 3.2.5 3.2.4 3.2.3 3.2.2 3.2.1 2.0.3 2.0.4 2.0.5 2.0.6 All 152 releases
← All changes | js/mxchat-admin.js +38 -54 2.0.62.0.1 View file →
@@ -169,9 +169,9 @@
169 169
170 170 // Initialize color pickers with debouncing
171 171 $autosaveSections.find('.my-color-field').each(function() {
172 172 const $colorField = $(this);
173 -
173 +
174 174 $(this).wpColorPicker({
175 175 change: useDebounce(function(event, ui) {
176 176 // Safety check - ensure we have a valid field and value
177 177 if (!$colorField || !$colorField.val()) {
@@ -251,16 +251,16 @@
251 251 // Initialize tabs system
252 252 function initTabs() {
253 253 // Remove any existing handlers first
254 254 $('.mxchat-nav-tab').off('click.mxchat');
255 -
255 +
256 256 // Add new click handlers
257 257 $('.mxchat-nav-tab').on('click.mxchat', function(e) {
258 258 e.preventDefault();
259 259 e.stopPropagation();
260 -
260 +
261 261 var $this = $(this);
262 -
262 +
263 263 // Get tab ID - try href first, fallback to data-tab, then to default
264 264 var tabId = $this.attr('href');
265 265 if (tabId) {
266 266 tabId = tabId.replace('#', '');
@@ -266,25 +266,25 @@
266 266 tabId = tabId.replace('#', '');
267 267 } else {
268 268 tabId = $this.data('tab') || 'chatbot';
269 269 }
270 -
270 +
271 271 // Safety check for empty tabId
272 272 if (!tabId) {
273 273 console.warn('No tab identifier found');
274 274 return;
275 275 }
276 -
276 +
277 277 // Update tabs
278 278 $('.mxchat-nav-tab').removeClass('mxchat-nav-tab-active');
279 279 $this.addClass('mxchat-nav-tab-active');
280 -
280 +
281 281 // Update content areas - with safety check
282 282 $('.mxchat-tab-content').removeClass('active').hide();
283 283 var $targetTab = $('#' + tabId);
284 284 if ($targetTab.length) {
285 285 $targetTab.addClass('active').show();
286 -
286 +
287 287 // Store active tab
288 288 try {
289 289 localStorage.setItem('mxchat_active_tab', tabId);
290 290 } catch (e) {
@@ -294,13 +294,13 @@
294 294 console.warn('Tab content #' + tabId + ' not found');
295 295 }
296 296 });
297 297 }
298 -
298 +
299 299 // Initialize tabs and handle events
300 300 initTabs();
301 301 $(document).on('widget-added widget-updated postbox-toggled', initTabs);
302 -
302 +
303 303 // Activate initial tab
304 304 try {
305 305 var savedTab = localStorage.getItem('mxchat_active_tab');
306 306 if (savedTab && $('#' + savedTab).length > 0) {
@@ -310,9 +310,9 @@
310 310 }
311 311 } catch (e) {
312 312 $('.mxchat-nav-tab').first().trigger('click.mxchat');
313 313 }
314 -
314 +
315 315 // Attach edit modal event handler
316 316 $(document).on('click', '.mxchat-edit-button', function() {
317 317 const intentId = $(this).data('intent-id');
318 318 const phrases = $(this).data('phrases');
@@ -317,9 +317,9 @@
317 317 const intentId = $(this).data('intent-id');
318 318 const phrases = $(this).data('phrases');
319 319 mxchatOpenEditModal(intentId, phrases);
320 320 });
321 -
321 +
322 322 // Toggle visibility handlers
323 323 function toggleVisibility(selector) {
324 324 $(selector).on('click', function() {
325 325 var inputField = $(this).prev('input');
@@ -331,14 +331,13 @@
331 331 $(this).text('Show');
332 332 }
333 333 });
334 334 }
335 -
335 +
336 336 // Initialize all toggle visibility buttons
337 337 [
338 338 '#toggleApiKeyVisibility',
339 339 '#toggleWooCommerceSecretVisibility',
340 - '#toggleVoyageAPIKeyVisibility',
341 340 '#toggleLoopsApiKeyVisibility',
342 341 '#toggleXaiApiKeyVisibility',
343 342 '#toggleClaudeApiKeyVisibility',
344 343 '#toggleBraveApiKeyVisibility',
@@ -346,9 +345,9 @@
346 345 '#toggleSecretKeyVisibility',
347 346 '#toggleBotTokenVisibility',
348 347 '#toggleDeepSeekApiKeyVisibility'
349 348 ].forEach(toggleVisibility);
350 -
349 +
351 350 // Add Intent Form Submission
352 351 $('#mxchat-add-intent-form').on('submit', function(event) {
353 352 $('#mxchat-intent-loading').show();
354 353 $('#mxchat-intent-loading-text').show();
@@ -353,9 +352,9 @@
353 352 $('#mxchat-intent-loading').show();
354 353 $('#mxchat-intent-loading-text').show();
355 354 $(this).find('button[type="submit"]').hide();
356 355 });
357 -
356 +
358 357 // Inline Edit Functionality
359 358 $('.edit-button').on('click', function() {
360 359 var row = $(this).closest('tr');
361 360 row.find('.content-view, .url-view').hide();
@@ -362,9 +361,9 @@
362 361 row.find('.content-edit, .url-edit').show();
363 362 row.find('.edit-button').hide();
364 363 row.find('.save-button').show();
365 364 });
366 -
365 +
367 366 // Save button handler
368 367 $('.save-button').on('click', function() {
369 368 var button = $(this);
370 369 var row = button.closest('tr');
@@ -370,12 +369,12 @@
370 369 var row = button.closest('tr');
371 370 var id = button.data('id');
372 371 var newContent = row.find('.content-edit').val();
373 372 var newUrl = row.find('.url-edit').val();
374 -
373 +
375 374 button.prop('disabled', true);
376 375 button.text('Saving...');
377 -
376 +
378 377 $.ajax({
379 378 url: mxchatAdmin.ajax_url,
380 379 type: 'POST',
381 380 data: {
@@ -387,9 +386,9 @@
387 386 },
388 387 success: function(response) {
389 388 button.prop('disabled', false);
390 389 button.text('Save');
391 -
390 +
392 391 if (response.success) {
393 392 row.find('.content-view').html(newContent.replace(/\n/g, "<br>"));
394 393 if (newUrl) {
395 394 row.find('.url-view').html('<a href="' + newUrl + '" target="_blank">' + newUrl + '</a>');
@@ -395,9 +394,9 @@
395 394 row.find('.url-view').html('<a href="' + newUrl + '" target="_blank">' + newUrl + '</a>');
396 395 } else {
397 396 row.find('.url-view').html('N/A');
398 397 }
399 -
398 +
400 399 row.find('.content-edit, .url-edit').hide();
401 400 row.find('.content-view, .url-view').show();
402 401 row.find('.save-button').hide();
403 402 row.find('.edit-button').show();
@@ -411,15 +410,15 @@
411 410 alert('An error occurred while saving.');
412 411 }
413 412 });
414 413 });
415 -
414 +
416 415 // Activation handling
417 416 const form = $('#mxchat-activation-form');
418 417 const spinner = $('#mxchat-activation-spinner');
419 418 const submitButton = $('#activate_license_button');
420 419 const licenseStatus = $('#mxchat-license-status');
421 -
420 +
422 421 if (form.length && licenseStatus.length && submitButton.length) {
423 422 function handleActivationResponse(response) {
424 423 spinner.hide();
425 424 if (response.success) {
@@ -431,14 +430,14 @@
431 430 alert(response.data || 'Activation failed. Please check your input.');
432 431 submitButton.prop('disabled', false);
433 432 }
434 433 }
435 -
434 +
436 435 form.on('submit', function(event) {
437 436 event.preventDefault();
438 437 spinner.show();
439 438 submitButton.prop('disabled', true);
440 -
439 +
441 440 var formData = {
442 441 action: 'mxchat_activate_license',
443 442 mxchat_pro_email: $('#mxchat_pro_email').val(),
444 443 mxchat_activation_key: $('#mxchat_activation_key').val(),
@@ -443,9 +442,9 @@
443 442 mxchat_pro_email: $('#mxchat_pro_email').val(),
444 443 mxchat_activation_key: $('#mxchat_activation_key').val(),
445 444 security: mxchatAdmin.license_nonce
446 445 };
447 -
446 +
448 447 $.post(mxchatAdmin.ajax_url, formData, function(response) {
449 448 handleActivationResponse(response);
450 449 }).fail(function() {
451 450 alert('Server error. Please try again.');
@@ -453,15 +452,15 @@
453 452 submitButton.prop('disabled', false);
454 453 });
455 454 });
456 455 }
457 -
456 +
458 457 // Questions handling
459 458 $('.mxchat-add-question').on('click', function () {
460 459 const container = $('#mxchat-additional-questions-container');
461 460 const questionCount = container.find('.mxchat-question-row').length + 4;
462 461 const questionIndex = container.find('.mxchat-question-row').length;
463 -
462 +
464 463 const newQuestion = `
465 464 <div class="mxchat-question-row">
466 465 <input type="text"
467 466 name="additional_popular_questions[]"
@@ -473,18 +472,18 @@
473 472 </div>
474 473 `;
475 474 container.append(newQuestion);
476 475 });
477 -
476 +
478 477 $(document).on('click', '.mxchat-remove-question', function () {
479 478 $(this).closest('.mxchat-question-row').remove();
480 479 saveQuestions();
481 480 });
482 -
481 +
483 482 $(document).on('change', '.mxchat-question-input', function() {
484 483 saveQuestions();
485 484 });
486 -
485 +
487 486 function saveQuestions() {
488 487 const questions = [];
489 488 $('.mxchat-question-input').each(function() {
490 489 const value = $(this).val().trim();
@@ -491,17 +490,17 @@
491 490 if (value) {
492 491 questions.push(value);
493 492 }
494 493 });
495 -
494 +
496 495 const feedbackContainer = $('<div class="feedback-container"></div>');
497 496 const spinner = $('<div class="saving-spinner"></div>');
498 497 const successIcon = $('<div class="success-icon">✔</div>');
499 -
498 +
500 499 // Append feedback after the add button
501 500 $('.mxchat-add-question').after(feedbackContainer);
502 501 feedbackContainer.append(spinner);
503 -
502 +
504 503 // Save via AJAX
505 504 $.ajax({
506 505 url: mxchatAdmin.ajax_url,
507 506 type: 'POST',
@@ -529,9 +528,9 @@
529 528 feedbackContainer.remove();
530 529 }
531 530 });
532 531 }
533 -
532 +
534 533 // Live agent status handler
535 534 const statusToggle = document.getElementById('live_agent_status');
536 535 const statusText = statusToggle?.parentElement.nextElementSibling?.querySelector('.status-text');
537 536 if (statusToggle && statusText) {
@@ -537,9 +536,9 @@
537 536 if (statusToggle && statusText) {
538 537 statusToggle.addEventListener('change', function() {
539 538 // Update display text
540 539 statusText.textContent = this.checked ? 'Online' : 'Offline';
541 -
540 +
542 541 // Send the correct on/off value to the server
543 542 if (window.mxchatSaveSetting) {
544 543 window.mxchatSaveSetting('live_agent_status', this.checked ? 'on' : 'off');
545 544 }
@@ -544,25 +543,10 @@
544 543 window.mxchatSaveSetting('live_agent_status', this.checked ? 'on' : 'off');
545 544 }
546 545 });
547 546 }
547 +
548 +
549 +});
548 550
549 - // Function to adjust the textarea height to content
550 - function adjustTextareaHeight() {
551 - this.style.height = 'auto'; // Reset to auto to calculate scrollHeight
552 - this.style.height = this.scrollHeight + 'px'; // Expand to content height
553 - }
554 551
555 - // Function to reset the textarea height to initial
556 - function resetTextareaHeight() {
557 - this.style.height = ''; // Remove inline height, reverting to CSS default
558 - }
559 552
560 - // Target the specific textarea by ID
561 - var $textarea = $('#system_prompt_instructions');
562 -
563 - // Bind events
564 - $textarea.on('focus input', adjustTextareaHeight) // Expand on focus and input
565 - .on('blur', resetTextareaHeight); // Reset on blur
566 -
567 -
568 -});