Parts for Sliding Gate Openers
// Create popup HTML
function createPopupHTML() {
var html = '';
html += '';
html += 'Coupon copied!
';
return html;
}
// Initialize popup
function initPopup() {
if (!shouldShowPopup()) return;
var container = document.createElement('div');
container.innerHTML = createPopupHTML();
document.body.appendChild(container);
setTimeout(function() {
var overlay = document.getElementById('alekoPopupOverlay');
if (overlay) overlay.classList.add('show');
}, POPUP_CONFIG.showDelay);
// Event listeners
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' || e.keyCode === 27) alekoClosePopup();
});
var overlay = document.getElementById('alekoPopupOverlay');
if (overlay) {
overlay.addEventListener('click', function(e) {
if (e.target === this) alekoClosePopup();
});
}
}
// Global functions
window.alekoClosePopup = function() {
var overlay = document.getElementById('alekoPopupOverlay');
if (overlay) {
overlay.style.animation = 'alekoFadeOut 0.3s ease-out forwards';
setTimeout(function() {
if (overlay.parentNode) overlay.parentNode.removeChild(overlay);
}, 300);
setCookie(POPUP_CONFIG.cookieName, 'true', POPUP_CONFIG.cookieExpireDays);
}
};
window.alekoCopyCoupon = function() {
var couponCode = document.getElementById('alekoCouponCode').textContent;
var copyButton = document.querySelector('.aleko-copy-button');
var copyIcon = document.getElementById('alekoCopyIcon');
var copyText = document.getElementById('alekoCopyText');
var successMsg = document.getElementById('alekoSuccessMessage');
function showSuccess() {
if (copyButton) {
copyButton.classList.add('copied');
copyButton.style.background = '#48bb78';
copyButton.style.color = 'white';
}
if (copyIcon) copyIcon.textContent = '✓';
if (copyText) copyText.textContent = 'Copied!';
if (successMsg) successMsg.classList.add('show');
setTimeout(function() {
if (copyButton) {
copyButton.classList.remove('copied');
copyButton.style.background = '';
copyButton.style.color = '';
}
if (copyIcon) copyIcon.textContent = '';
if (copyText) copyText.textContent = 'Copy Again';
if (successMsg) successMsg.classList.remove('show');
}, 2000);
}
// Modern clipboard API
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(couponCode).then(showSuccess).catch(function() {
// Fallback method
var textArea = document.createElement('textarea');
textArea.value = couponCode;
textArea.style.position = 'fixed';
textArea.style.left = '-9999px';
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand('copy');
showSuccess();
} catch (err) {
console.log('Copy failed');
}
document.body.removeChild(textArea);
});
} else {
// Fallback for older browsers
var textArea = document.createElement('textarea');
textArea.value = couponCode;
textArea.style.position = 'fixed';
textArea.style.left = '-9999px';
document.body.appendChild(textArea);
textArea.select();
try {
document.execCommand('copy');
showSuccess();
} catch (err) {
console.log('Copy failed');
}
document.body.removeChild(textArea);
}
};
window.alekoTrackClick = function() {
// Add analytics tracking here if needed
alekoClosePopup();
};
// Initialize when ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initPopup);
} else {
initPopup();
}
})();