/** * WC Licensed Product - Frontend Scripts * * @package Jeremias\WcLicensedProduct */ (function($) { 'use strict'; var WCLicensedProductFrontend = { $modal: null, $form: null, /** * Sanitize a value for safe use in jQuery selectors * License IDs should be numeric only */ sanitizeForSelector: function(value) { return String(value).replace(/[^\d]/g, ''); }, init: function() { this.$modal = $('#wclp-transfer-modal'); this.$form = $('#wclp-transfer-form'); this.bindEvents(); }, bindEvents: function() { $(document).on('click', '.copy-license-btn', this.copyLicenseKey); $(document).on('click', '.copy-secret-btn', this.copySecret); // Transfer modal events $(document).on('click', '.wclp-transfer-btn', this.openTransferModal.bind(this)); $(document).on('click', '.wclp-modal-close, .wclp-modal-cancel, .wclp-modal-overlay', this.closeTransferModal.bind(this)); $(document).on('submit', '#wclp-transfer-form', this.submitTransfer.bind(this)); // Older versions toggle $(document).on('click', '.older-versions-toggle', this.toggleOlderVersions); // Secret toggle $(document).on('click', '.secret-toggle', this.toggleSecret); // Close modal on escape key $(document).on('keyup', function(e) { if (e.key === 'Escape') { WCLicensedProductFrontend.closeTransferModal(); } }); }, /** * Toggle older versions visibility */ toggleOlderVersions: function(e) { e.preventDefault(); var $btn = $(this); var $list = $btn.siblings('.older-versions-list'); var isExpanded = $btn.attr('aria-expanded') === 'true'; $btn.attr('aria-expanded', !isExpanded); $list.slideToggle(200); }, /** * Toggle secret visibility */ toggleSecret: function(e) { e.preventDefault(); var $btn = $(this); var $content = $btn.siblings('.secret-content'); var isExpanded = $btn.attr('aria-expanded') === 'true'; $btn.attr('aria-expanded', !isExpanded); $content.slideToggle(200); }, /** * Copy secret to clipboard */ copySecret: function(e) { e.preventDefault(); var $btn = $(this); var secret = $btn.data('secret'); if (!secret) { return; } // Use modern clipboard API if available if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(secret) .then(function() { WCLicensedProductFrontend.showCopyFeedback($btn, true); }) .catch(function() { WCLicensedProductFrontend.fallbackCopy(secret, $btn); }); } else { WCLicensedProductFrontend.fallbackCopy(secret, $btn); } }, /** * Copy license key to clipboard */ copyLicenseKey: function(e) { e.preventDefault(); var $btn = $(this); var licenseKey = $btn.data('license-key'); if (!licenseKey) { return; } // Use modern clipboard API if available if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(licenseKey) .then(function() { WCLicensedProductFrontend.showCopyFeedback($btn, true); }) .catch(function() { WCLicensedProductFrontend.fallbackCopy(licenseKey, $btn); }); } else { WCLicensedProductFrontend.fallbackCopy(licenseKey, $btn); } }, /** * Fallback copy method for older browsers */ fallbackCopy: function(text, $btn) { var $temp = $('