You've already forked wc-licensed-product
Implement version 0.0.3 features
- Add file attachment support for product versions (Media Library) - Add version auto-detection from uploaded filenames - Implement secure customer downloads with hash verification - Add license key copy-to-clipboard functionality - Redesign customer licenses page with card-based UI - Fix product versions meta box visibility for non-licensed types - Add DownloadController for secure file delivery - Update CLAUDE.md roadmap and session history Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
90
assets/js/frontend.js
Normal file
90
assets/js/frontend.js
Normal file
@@ -0,0 +1,90 @@
|
||||
/**
|
||||
* WC Licensed Product - Frontend Scripts
|
||||
*
|
||||
* @package Jeremias\WcLicensedProduct
|
||||
*/
|
||||
|
||||
(function($) {
|
||||
'use strict';
|
||||
|
||||
var WCLicensedProductFrontend = {
|
||||
init: function() {
|
||||
this.bindEvents();
|
||||
},
|
||||
|
||||
bindEvents: function() {
|
||||
$(document).on('click', '.copy-license-btn', this.copyLicenseKey);
|
||||
},
|
||||
|
||||
/**
|
||||
* 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 = $('<textarea>');
|
||||
$('body').append($temp);
|
||||
$temp.val(text).select();
|
||||
|
||||
try {
|
||||
var success = document.execCommand('copy');
|
||||
WCLicensedProductFrontend.showCopyFeedback($btn, success);
|
||||
} catch (err) {
|
||||
WCLicensedProductFrontend.showCopyFeedback($btn, false);
|
||||
}
|
||||
|
||||
$temp.remove();
|
||||
},
|
||||
|
||||
/**
|
||||
* Show feedback after copy attempt
|
||||
*/
|
||||
showCopyFeedback: function($btn, success) {
|
||||
var message = success
|
||||
? wcLicensedProduct.strings.copied
|
||||
: wcLicensedProduct.strings.copyFailed;
|
||||
|
||||
var $feedback = $('<span class="copy-feedback"></span>')
|
||||
.text(message)
|
||||
.addClass(success ? 'success' : 'error');
|
||||
|
||||
$btn.after($feedback);
|
||||
|
||||
setTimeout(function() {
|
||||
$feedback.fadeOut(300, function() {
|
||||
$(this).remove();
|
||||
});
|
||||
}, 1500);
|
||||
}
|
||||
};
|
||||
|
||||
$(document).ready(function() {
|
||||
WCLicensedProductFrontend.init();
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
Reference in New Issue
Block a user