if (!window.Giftify) { window.Giftify = { checkoutButton: false, validationErrors: {}, init: function() { this.reset(); this.insertStyle(); this.initiateButton(); }, reset: function() { var xhr = new XMLHttpRequest; xhr.open('POST', window.Shopify.routes.root + 'cart/update.js'); xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8'); xhr.send(JSON.stringify({ attributes: { 'Giftify • To': '', 'Giftify • From': '', 'Giftify • Message': '' } })); }, insertStyle: function() { var head = document.head || document.getElementsByTagName('head')[0], style = document.createElement('style'); style.type = 'text/css'; var validationCSS = '.giftify-popup__field--error input, .giftify-popup__field--error textarea { border-color: #dc3545; } .giftify-popup__error { color: #dc3545; font-size: 12px; margin-top: 4px; display: none; } .giftify-popup__field--error .giftify-popup__error { display: block; }'; style.appendChild(document.createTextNode(' .giftify-wrapper { width: 100% } .giftify-button { margin: 25px 0px 5px 0px; display: inline-block; transition: all .2s ease; text-decoration: none!important; } .giftify-button span { background: #ffffff; color: #000000; border-radius: 50px; border: 2px solid #ffffff; padding: 5px 5px 5px 5px; display: flex; white-space: nowrap; transition: all .2s ease; align-items: center; justify-content: center; } .giftify-button svg { fill: #000000; display: inline-block; margin-right: 5px; width: 24px; height: 24px; transition: all .2s ease; } .giftify-button:hover span { background: #ffffff; color: #000000; border-color: #000000; } .giftify-button:hover svg { fill: #000000; } .giftify-popup { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 999; opacity: 0; visibility: hidden; pointer-events: none; transition: all .5s ease; } .giftify-popup.giftify-popup--loading { pointer-events: none; } .giftify-popup.giftify-popup--active { opacity: 1; visibility: visible; pointer-events: all; } .giftify-popup.giftify-popup--active .giftify-popup__inside { transition-delay: .3s; opacity: 1; margin-top: 0; } .giftify-popup__bg { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,.6); z-index: 1; display: block!important; } .giftify-popup__inside { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background: #fff; width: 90%; max-width: 460px; display: flex; align-items: stretch; z-index: 2; transition: margin .5s Cubic-bezier(0.3, 0, 0.3, 1), opacity .3s ease; margin-top: 50px; opacity: 0; } .giftify-popup__close { position: absolute; top: 0; right: 0; width: 48px; height: 48px; z-index: 3; display: flex; align-items: center; justify-content: center; } .giftify-popup__close svg { fill: #191919; width: 24px; } .giftify-popup__grid { display: flex; width: 100%; } .giftify-popup__right { width: 50%; display: block!important; background-size: cover; background-position: center; background-repeat: no-repeat; } .giftify-popup__left { width: 100%; padding: 50px 50px 75px; position: relative; } .giftify-popup__header { text-align: center; } .giftify-popup__header img { max-height: 50px; } .giftify-popup__title { color: #191919; font-size: 32px; margin: 20px 0; } .giftify-popup__steps + div { font-size: 13px; position: absolute; left: 0; width: 100%; bottom: 10px; text-align: center; } .giftify-popup__steps + div a { color: #191919; border-bottom: 1px solid transparent; } .giftify-popup__steps + div a:hover { border-bottom-color: #191919; } .giftify-popup__step { display: none; } .giftify-popup__step--active { display: block; } .giftify-popup__action { margin-top: 20px; display: flex; align-items: center; justify-content: center; } .giftify-popup__button { margin: 5px; display: inline-block; transition: all .2s ease; padding: 0; border: 0; border-radius: 0!important; background: none!important; cursor: pointer; } .giftify-popup__button span { border-radius: 50px; padding: 15px 20px 15px 20px; display: flex; white-space: nowrap; transition: all .2s ease; position: relative; } .giftify-popup__next span { background: #000000; color: #ffffff; border: 2px solid #000000; position: relative; } .giftify-popup__next:hover span { background: #ffffff; color: #000000; border-color: #000000; } .giftify-popup__prev span { background: #000000; color: #ffffff; border: 2px solid #000000; } .giftify-popup__prev:hover span { background: #ffffff; color: #000000; border-color: #000000; } .giftify-popup__next span::after { content: ""; position: absolute; top: 50%; left: 50%; width: 20px; height: 20px; border: 3px solid #ffffff; border-top: 3px solid transparent!important; border-radius: 50%; margin-left: -10px; margin-top: -10px; opacity: 0; -webkit-animation: giftify_spin .7s linear infinite; animation: giftify_spin .7s linear infinite; } @-webkit-keyframes giftify_spin { 100% { -webkit-transform: rotate(360deg); } } @keyframes giftify_spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } } .giftify-popup__step ol { counter-reset: giftify; list-style: none; padding: 0; } .giftify-popup__step li { color: #191919; font-size: 16px; counter-increment: giftify; position: relative; padding-left: 30px; display: block; } .giftify-popup__step li + li { margin-top: 5px; } .giftify-popup__step li::before { content: counter(giftify)"."; font-weight: bold; top: 0; left: 0; position: absolute; } .giftify-popup__label { font-weight: bold; text-align: center; } .giftify-popup__field { margin: 5px 0 10px; } .giftify-popup__grid > .giftify-popup__field { width: 50%; padding-right: 2px; } .giftify-popup__grid > .giftify-popup__field + .giftify-popup__field { padding-left: 2px; } .giftify-popup__field > * { width: 100%; } .giftify-popup__field input, .giftify-popup__field textarea { padding: 10px; border: 1px solid #d2d2d2; } .giftify-popup--loading .giftify-popup__next span { color: transparent!important; } .giftify-popup--loading .giftify-popup__next span::after { opacity: 1; } ' + validationCSS)); head.appendChild(style); }, validateEmail: function(email) { const trimmedEmail = email.trim(); const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$/; if (!emailRegex.test(trimmedEmail)) { return false; } if (trimmedEmail.endsWith('.')) { return false; } const parts = trimmedEmail.split('@'); if (parts.length !== 2) { return false; } const domain = parts[1]; const domainParts = domain.split('.'); if (domainParts.length < 2) { return false; } const tld = domainParts[domainParts.length - 1]; if (tld.length < 2 || !/^[a-zA-Z]+$/.test(tld)) { return false; } if (domainParts.some(part => part.length === 0)) { return false; } return true; }, validateField: function(field) { const fieldWrapper = field.closest('.giftify-popup__field'); const fieldName = field.name; const fieldValue = field.value.trim(); let isValid = true; let errorMessage = ''; fieldWrapper.classList.remove('giftify-popup__field--error'); this.validationErrors[fieldName] = null; if (!fieldValue && field.hasAttribute('required')) { isValid = false; errorMessage = 'This field is required'; } else if (field.type === 'email' && fieldValue && !this.validateEmail(fieldValue)) { isValid = false; errorMessage = 'Please enter a valid email address'; } if (!isValid) { fieldWrapper.classList.add('giftify-popup__field--error'); this.validationErrors[fieldName] = errorMessage; this.showFieldError(fieldWrapper, errorMessage); } else { this.hideFieldError(fieldWrapper); } return isValid; }, showFieldError: function(fieldWrapper, message) { let errorEl = fieldWrapper.querySelector('.giftify-popup__error'); if (!errorEl) { errorEl = document.createElement('div'); errorEl.className = 'giftify-popup__error'; fieldWrapper.appendChild(errorEl); } errorEl.textContent = message; }, hideFieldError: function(fieldWrapper) { const errorEl = fieldWrapper.querySelector('.giftify-popup__error'); if (errorEl) { errorEl.remove(); } }, validateForm: function(form) { const fields = form.querySelectorAll('input[required], input[type="email"], textarea[required]'); let isFormValid = true; fields.forEach(field => { if (!this.validateField(field)) { isFormValid = false; } }); return isFormValid; }, initiateButton: function() { var wrappers = document.querySelectorAll('.giftify-wrapper'), checkoutButtons = document.querySelectorAll('[name="checkout"]'); if (wrappers.length) { this.renderButton(); } else if (checkoutButtons.length) { this.checkoutButton = checkoutButtons[0]; checkoutButtons.forEach(function(checkoutButton) { var el = document.createElement('div'); el.classList.add('giftify-wrapper'); checkoutButton.parentNode.insertAfter(el, checkoutButton); }); this.renderButton(); } }, renderButton: function(wrappers = null) { if (!wrappers) { wrappers = document.querySelectorAll('.giftify-wrapper'); } if (wrappers && wrappers.length) { wrappers.forEach(function(wrapper) { if (!wrapper.querySelector('a')) { buttonEl = document.createElement('a'); buttonEl.href = '#'; buttonEl.innerHTML = ` I want to send this as a gift`; buttonEl.classList.add('giftify-button'); buttonEl.addEventListener('click', window.Giftify.openPopup); wrapper.appendChild(buttonEl); } }); if (!document.querySelector('.giftify-popup')) { var saved = { to: { name: '', email: '' }, from: { name: '', email: '' }, message: '' }; if (localStorage.getItem('giftify')) { saved = JSON.parse(localStorage.getItem('giftify')); } var popupHTML = '
SENDING A GIFT IS EASY!
  1. First, add your recipient’s information.
  2. Then complete purchase using the recipient’s address.
  3. Within 24 hours, they will receive an email with your gift message.
  4. And you'll receive order confirmation email for your files.
To
From
Message
Powered by Giftify
'; popupHTML = popupHTML.replace('{saved.to.name}', saved.to.name); popupHTML = popupHTML.replace('{saved.to.email}', saved.to.email); popupHTML = popupHTML.replace('{saved.from.name}', saved.from.name); popupHTML = popupHTML.replace('{saved.from.email}', saved.from.email); popupHTML = popupHTML.replace('{saved.message}', saved.message); var popupEl = document.createElement('div'); popupEl.classList.add('giftify-popup'); popupEl.innerHTML = popupHTML; document.body.appendChild(popupEl); this.initiatePopupListeners(); } } }, initiatePopupListeners: function() { document.querySelector('.giftify-popup__bg').addEventListener('click', this.closePopup); document.querySelector('.giftify-popup__close').addEventListener('click', this.closePopup); document.querySelector('.giftify-popup__step[data-step="1"] .giftify-popup__next').addEventListener('click', this.buttonNext); document.querySelector('.giftify-popup__step[data-step="2"] .giftify-popup__prev').addEventListener('click', this.buttonPrev); document.querySelector('.giftify-popup__step[data-step="2"] form').addEventListener('submit', this.submitGift); const form = document.querySelector('.giftify-popup__step[data-step="2"] form'); const fields = form.querySelectorAll('input[required], input[type="email"], textarea[required]'); fields.forEach(field => { field.addEventListener('blur', () => { this.validateField(field); }); field.addEventListener('input', () => { const fieldWrapper = field.closest('.giftify-popup__field'); if (fieldWrapper.classList.contains('giftify-popup__field--error')) { fieldWrapper.classList.remove('giftify-popup__field--error'); this.hideFieldError(fieldWrapper); this.validationErrors[field.name] = null; } }); }); }, openPopup: function(e) { e.preventDefault(); var popup = document.querySelector('.giftify-popup'); if (popup) { popup.classList.add('giftify-popup--active'); } }, closePopup: function(e) { e.preventDefault(); var popup = document.querySelector('.giftify-popup'); if (popup) { popup.classList.remove('giftify-popup--active'); window.Giftify.validationErrors = {}; popup.querySelectorAll('.giftify-popup__field--error').forEach(field => { field.classList.remove('giftify-popup__field--error'); }); popup.querySelectorAll('.giftify-popup__error').forEach(error => { error.remove(); }); } }, buttonNext: function(e) { e.preventDefault(); var step = document.querySelector('.giftify-popup__step[data-step="1"]'); step.classList.remove('giftify-popup__step--active'); step.nextElementSibling.classList.add('giftify-popup__step--active'); }, buttonPrev: function(e) { e.preventDefault(); var step = document.querySelector('.giftify-popup__step[data-step="2"]'); step.classList.remove('giftify-popup__step--active'); step.previousElementSibling.classList.add('giftify-popup__step--active'); }, submitGift: function(e) { e.preventDefault(); var form = e.target; if (!window.Giftify..(form)) { const firstError = form.querySelector('.giftify-popup__field--error input, .giftify-popup__field--error textarea'); if (firstError) { firstError.focus(); } return; } var attrs = { to: { name: form.rname.value.trim(), email: form.remail.value.trim() }, from: { name: form.yname.value.trim(), email: form.yemail.value.trim() }, message: form.ymessage.value.trim() }; localStorage.setItem('giftify', JSON.stringify(attrs)); document.querySelector('.giftify-popup').classList.add('giftify-popup--loading'); var xhr = new XMLHttpRequest; xhr.open('POST', window.Shopify.routes.root + 'cart/update.js'); xhr.onload = function() { if (window.Giftify.checkoutButton) { window.Giftify.checkoutButton.click(); } else { location.href = '/checkout'; } }; xhr.onerror = function() { document.querySelector('.giftify-popup').classList.remove('giftify-popup--loading'); alert('An error occurred. Please try again.'); }; xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8'); xhr.send(JSON.stringify({ attributes: { 'Giftify • To': attrs.to.name + ' (' + attrs.to.email + ')', 'Giftify • From': attrs.from.name + ' (' + attrs.from.email + ')', 'Giftify • Message': (attrs.message ? attrs.message : '-') } })); } }; window.Giftify.init(); }