/** * WC Licensed Product - Frontend Scripts * * @package Jeremias\WcLicensedProduct */ (function($) { 'use strict'; var WCLicensedProductFrontend = { $modal: null, $form: null, init: function() { this.$modal = $('#wclp-transfer-modal'); this.$form = $('#wclp-transfer-form'); this.bindEvents(); }, bindEvents: function() { $(document).on('click', '.copy-license-btn', this.copyLicenseKey); // 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); // 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); }, /** * 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 = $('