(function ($){
'use strict';
var VT=window.VT||{};
var doc=document;
var reduce=window.matchMedia&&window.matchMedia('(prefers-reduced-motion: reduce)').matches;
function url(endpoint){
return (VT.ajax||'/?wc-ajax=%%endpoint%%').replace('%%endpoint%%', endpoint);
}
function post(endpoint, data){
var body=new URLSearchParams();
Object.keys(data||{}).forEach(function (k){ body.append(k, data[k]); });
return fetch(url(endpoint), {
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' },
body: body.toString()
}).then(function (r){ return r.json(); });
}
function text(html){
var d=new DOMParser().parseFromString(html||'', 'text/html');
return (d.body.textContent||'').replace(/\s+/g, ' ').trim();
}
function applyFragments(res){
if(!res||!res.fragments) return;
Object.keys(res.fragments).forEach(function (sel){
var html=res.fragments[sel];
try {
doc.querySelectorAll(sel).forEach(function (el){ el.outerHTML=html; });
} catch (e){  }});
var p=window.wc_cart_fragments_params;
if(p&&res.cart_hash!==undefined){
try {
sessionStorage.setItem(p.fragment_name, JSON.stringify(res.fragments));
localStorage.setItem(p.cart_hash_key, res.cart_hash);
sessionStorage.setItem(p.cart_hash_key, res.cart_hash);
} catch (e){  }}
if($) $(doc.body).trigger('wc_fragments_loaded');
}
var mini=doc.getElementById('vt-mini');
var lastFocus=null;
var closeTimer=null;
function panel(){ return mini&&mini.querySelector('.vt-mini__panel'); }
function openMini(){
if(!mini) return false;
clearTimeout(closeTimer);
lastFocus=doc.activeElement;
mini.hidden=false;
doc.documentElement.classList.add('vt-mini-open');
void mini.offsetWidth;
mini.classList.add('is-open');
var p=panel();
if(p){
p.style.removeProperty('--vt-drag');
setTimeout(function (){ p.focus({ preventScroll: true });}, reduce ? 0:60);
}
if(window.matchMedia('(max-width: 767px)').matches) doc.documentElement.style.overflow='hidden';
return true;
}
function closeMini(){
if(!mini||mini.hidden) return;
mini.classList.remove('is-open');
doc.documentElement.classList.remove('vt-mini-open');
doc.documentElement.style.overflow='';
closeTimer=setTimeout(function (){ mini.hidden=true; }, reduce ? 0:380);
if(lastFocus&&lastFocus.focus) lastFocus.focus({ preventScroll: true });
}
function status(msg){
var s=mini&&mini.querySelector('[data-vt-status]');
if(s) s.textContent=msg||'';
}
if(mini){
doc.addEventListener('click', function (e){
var trigger=e.target.closest('#cv-header .cv-cart, [data-vt-cart-open]');
if(!trigger||e.metaKey||e.ctrlKey||e.shiftKey) return;
e.preventDefault();
mini.hidden||!mini.classList.contains('is-open') ? openMini():closeMini();
});
mini.addEventListener('click', function (e){
if(e.target.closest('[data-vt-close]')){ closeMini(); return; }
var step=e.target.closest('[data-vt-step]');
var rm=e.target.closest('[data-vt-remove]');
if(!step&&!rm) return;
var item=e.target.closest('[data-key]');
if(!item) return;
var cur=parseInt((item.querySelector('.vt-qty__val')||{}).textContent, 10)||1;
var qty=rm ? 0:cur + parseInt(step.getAttribute('data-vt-step'), 10);
if(!rm&&qty < 1) return;
mini.classList.add('is-busy');
post('vt_qty', { key: item.getAttribute('data-key'), qty: qty })
.then(function (res){
applyFragments(res);
status(res.error||res.message||'');
if(rm&&$) $(doc.body).trigger('removed_from_cart', [res.fragments, res.cart_hash, $()]);
})
.catch(function (){ status('No pudimos actualizar tu carrito. Inténtalo de nuevo.'); })
.finally(function (){
mini.classList.remove('is-busy');
var focusTo=mini.querySelector('[data-key="' + item.getAttribute('data-key') + '"] [data-vt-step="' + (step ? step.getAttribute('data-vt-step'):'1') + '"]');
(focusTo&&!focusTo.disabled ? focusTo:panel()).focus({ preventScroll: true });
});
});
doc.addEventListener('keydown', function (e){
if(mini.hidden) return;
if(e.key==='Escape'){ closeMini(); return; }
if(e.key!=='Tab') return;
var f=Array.prototype.filter.call(panel().querySelectorAll('a[href], button:not([disabled]), input, [tabindex]:not([tabindex="-1"])'),
function (el){ return el.offsetParent!==null; }
);
if(!f.length) return;
var p=panel();
if(e.shiftKey&&(doc.activeElement===f[0]||doc.activeElement===p)){ e.preventDefault(); f[f.length - 1].focus(); }
else if(!e.shiftKey&&doc.activeElement===f[f.length - 1]){ e.preventDefault(); f[0].focus(); }
else if(!p.contains(doc.activeElement)){ e.preventDefault(); f[0].focus(); }});
var dragY=null;
mini.addEventListener('touchstart', function (e){
if(!e.target.closest('.vt-mini__grip, .vt-mini__head')) return;
dragY=e.touches[0].clientY;
}, { passive: true });
mini.addEventListener('touchmove', function (e){
if(dragY===null) return;
var d=Math.max(0, e.touches[0].clientY - dragY);
panel().style.transition='none';
panel().style.setProperty('--vt-drag', d + 'px');
}, { passive: true });
mini.addEventListener('touchend', function (e){
if(dragY===null) return;
var d=e.changedTouches[0].clientY - dragY;
dragY=null;
panel().style.transition='';
panel().style.removeProperty('--vt-drag');
if(d > 90) closeMini();
});
if($){
$(doc.body).on('added_to_cart', function (){
setTimeout(openMini, 120);
});
}}
function clampStepper(box){
var input=box.querySelector('input.vt-qty__val');
if(!input) return;
var max=parseInt(box.getAttribute('data-max'), 10);
var v=parseInt(input.value, 10)||1;
var minus=box.querySelector('[data-vt-step="-1"]');
var plus=box.querySelector('[data-vt-step="1"]');
if(minus) minus.disabled=v <=1;
if(plus&&!input.readOnly) plus.disabled=max > 0&&v >=max;
}
var cartTimer=null;
doc.addEventListener('click', function (e){
var btn=e.target.closest('.vt-qty [data-vt-step]');
if(!btn||btn.closest('#vt-mini')) return;
var box=btn.closest('.vt-qty');
var input=box.querySelector('input.vt-qty__val');
if(!input||input.readOnly) return;
var max=parseInt(box.getAttribute('data-max'), 10);
var v=(parseInt(input.value, 10)||1) + parseInt(btn.getAttribute('data-vt-step'), 10);
if(v < 1||(max > 0&&v > max)) return;
input.value=v;
clampStepper(box);
input.dispatchEvent(new Event('change', { bubbles: true }));
if($) $(input).trigger('change');
var form=box.closest('.woocommerce-cart-form');
if(form) queueCartUpdate(form);
});
doc.querySelectorAll('.vt-qty').forEach(clampStepper);
function queueCartUpdate(form){
clearTimeout(cartTimer);
cartTimer=setTimeout(function (){
var up=form.querySelector('[name="update_cart"]');
if(up){ up.disabled=false; up.click(); }}, 450);
}
doc.addEventListener('change', function (e){
var input=e.target.closest('.woocommerce-cart-form input.vt-qty__val');
if(!input||!e.isTrusted) return;
var box=input.closest('.vt-qty');
var max=parseInt(box.getAttribute('data-max'), 10);
var v=Math.max(1, parseInt(input.value, 10)||1);
if(max > 0&&v > max) v=max;
input.value=v;
clampStepper(box);
queueCartUpdate(input.closest('form'));
});
var lastSubmit=null;
doc.addEventListener('click', function (e){
var b=e.target.closest('form[data-vt-buy] button[type="submit"]');
if(b) lastSubmit=b;
}, true);
doc.addEventListener('submit', function (e){
var form=e.target.closest('form[data-vt-buy]');
if(!form||!window.fetch) return;
e.preventDefault();
var sub=e.submitter||(lastSubmit&&form.contains(lastSubmit) ? lastSubmit:null);
lastSubmit=null;
var buyNow = !!(sub&&sub.hasAttribute('data-vt-buynow'));
var btn=buyNow ? form.querySelector('[data-vt-buynow]'):form.querySelector('[data-vt-add]');
var msg=form.querySelector('[data-vt-msg]');
var qty=form.querySelector('input[name="quantity"]');
msg.textContent='';
msg.classList.remove('is-ok');
btn.classList.add('is-busy');
btn.setAttribute('aria-busy', 'true');
post('vt_add', { product_id: form.getAttribute('data-product'), quantity: qty ? qty.value:1 })
.then(function (res){
if(buyNow&&(res.ok||res.in_cart)){
window.location.href=VT.checkout;
return;
}
applyFragments(res);
if(res.ok){
if($) $(doc.body).trigger('added_to_cart', [res.fragments, res.cart_hash, $(btn)]);
else openMini();
msg.textContent='Añadido a tu carrito.';
msg.classList.add('is-ok');
if(mini) msg.classList.add('vt-sr');
}else{
msg.classList.remove('vt-sr');
msg.textContent=res.error||'No pudimos añadir esta pieza.';
if(res.in_cart&&mini) setTimeout(openMini, 400);
}})
.catch(function (){
if(buyNow){
var h=doc.createElement('input');
h.type='hidden'; h.name='vt_buy_now'; h.value='1';
form.appendChild(h);
}
form.submit();
})
.finally(function (){
btn.classList.remove('is-busy');
btn.removeAttribute('aria-busy');
});
});
doc.querySelectorAll('[data-vt-gallery]').forEach(function (g){
var track=g.querySelector('[data-vt-track]');
var slides=g.querySelectorAll('.vt-gallery__slide');
var thumbs=g.querySelectorAll('[data-vt-thumb]');
var idx=0;
function go(i){
idx=Math.max(0, Math.min(slides.length - 1, i));
track.scrollTo({ left: slides[idx].offsetLeft, behavior: reduce ? 'auto':'smooth' });
mark();
}
function mark(){
thumbs.forEach(function (t, n){
t.classList.toggle('is-active', n===idx);
n===idx ? t.setAttribute('aria-current', 'true'):t.removeAttribute('aria-current');
});
}
var st=null;
track.addEventListener('scroll', function (){
clearTimeout(st);
st=setTimeout(function (){
idx=Math.round(track.scrollLeft / Math.max(1, track.clientWidth));
mark();
}, 80);
}, { passive: true });
track.addEventListener('keydown', function (e){
if(e.key==='ArrowRight'){ e.preventDefault(); go(idx + 1); }
if(e.key==='ArrowLeft'){ e.preventDefault(); go(idx - 1); }});
thumbs.forEach(function (t){
t.addEventListener('click', function (){ go(parseInt(t.getAttribute('data-vt-thumb'), 10)); });
});
g.querySelectorAll('[data-vt-nav]').forEach(function (b){
b.addEventListener('click', function (){
var n=idx + parseInt(b.getAttribute('data-vt-nav'), 10);
go(n < 0 ? slides.length - 1:n >=slides.length ? 0:n);
});
});
var box=doc.querySelector('[data-vt-lightbox]');
if(!box) return;
var img=box.querySelector('[data-vt-lightbox-img]');
var opener=null;
function openBox(){
var s=slides[idx];
var src=s&&(s.getAttribute('data-full')||(s.querySelector('img')||{}).currentSrc);
if(!src) return;
opener=doc.activeElement;
img.src=src;
img.alt=(s.querySelector('img')||{}).alt||'';
box.hidden=false;
doc.documentElement.style.overflow='hidden';
box.querySelector('[data-vt-lightbox-close]').focus();
}
function closeBox(){
box.hidden=true;
doc.documentElement.style.overflow='';
if(opener) opener.focus();
}
var zoom=g.querySelector('[data-vt-zoom]');
if(zoom) zoom.addEventListener('click', openBox);
slides.forEach(function (s){ s.addEventListener('click', openBox); });
box.addEventListener('click', function (e){ if(e.target===box||e.target.closest('[data-vt-lightbox-close]')||e.target===img) closeBox(); });
doc.addEventListener('keydown', function (e){ if(e.key==='Escape'&&!box.hidden) closeBox(); });
});
doc.addEventListener('click', function (e){
var more=e.target.closest('[data-vt-more]');
if(!more||!window.fetch||!window.DOMParser) return;
e.preventDefault();
var grid=doc.querySelector('[data-vt-grid]');
if(!grid||more.classList.contains('is-busy')) return;
more.classList.add('is-busy');
more.setAttribute('aria-busy', 'true');
fetch(more.href, { credentials: 'same-origin' })
.then(function (r){ return r.text(); })
.then(function (html){
var d=new DOMParser().parseFromString(html, 'text/html');
var cards=d.querySelectorAll('[data-vt-grid] > .vt-card');
var first=null;
cards.forEach(function (c){
var n=doc.importNode(c, true);
if(!reduce){ n.style.opacity='0'; n.style.transform='translateY(16px)'; }
grid.appendChild(n);
first=first||n;
});
if(!reduce){
requestAnimationFrame(function (){
grid.querySelectorAll('.vt-card[style]').forEach(function (n, i){
n.style.transition='opacity .5s ease ' + (i * 40) + 'ms, transform .6s cubic-bezier(.22,.8,.24,1) ' + (i * 40) + 'ms';
n.style.opacity=''; n.style.transform='';
setTimeout(function (){ n.removeAttribute('style'); }, 900 + i * 40);
});
});
}
var next=d.querySelector('[data-vt-more]');
if(next) more.href=next.href;
else more.closest('.vt-more').remove();
if(first){
var a=first.querySelector('.vt-card__title a');
if(a) a.focus({ preventScroll: true });
}})
.catch(function (){ window.location.href=more.href; })
.finally(function (){
more.classList.remove('is-busy');
more.removeAttribute('aria-busy');
});
});
var couponState=null;
function couponMsg(box, ok, msg){
var p=box.querySelector('[data-vt-coupon-msg]');
box.classList.toggle('is-error', !ok);
p.className='vt-coupon__msg ' + (ok ? 'is-ok':'is-error');
p.innerHTML='';
if(!ok){
var i=doc.createElement('span');
i.innerHTML='<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 7.5v5.5M12 16.5h.01"/></svg>';
p.appendChild(i.firstChild);
}
p.appendChild(doc.createTextNode(msg));
}
function applyCoupon(box){
var input=box.querySelector('input');
var code=(input.value||'').trim();
if(!code){ input.focus(); return; }
var onCheckout = !!doc.querySelector('form.woocommerce-checkout');
var params=onCheckout ? window.wc_checkout_params:window.wc_cart_params;
if(!params) return;
var btn=box.querySelector('[data-vt-coupon-apply]');
btn.classList.add('is-busy');
var body=new URLSearchParams({ security: params.apply_coupon_nonce, coupon_code: code });
fetch(url('apply_coupon'), { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }, body: body.toString() })
.then(function (r){ return r.text(); })
.then(function (html){
var bad=/woocommerce-error|is-error/.test(html);
var msg=text(html);
if(bad&&(/no existe|does not exist/i.test(msg)||!msg)) msg='Este cupón no es válido. Revisa el código e inténtalo de nuevo.';
if(!bad) msg='Cupón aplicado.';
couponState={ ok: !bad, msg: msg, code: bad ? code:'' };
couponMsg(box, !bad, msg);
if(!bad){
input.value='';
if($) $(doc.body).trigger(onCheckout ? 'update_checkout':'wc_update_cart', [true]);
}else{
input.focus();
input.select();
}})
.catch(function (){ couponMsg(box, false, 'No pudimos revisar el cupón. Inténtalo de nuevo.'); })
.finally(function (){ btn.classList.remove('is-busy'); });
}
doc.addEventListener('click', function (e){
var b=e.target.closest('[data-vt-coupon-apply]');
if(!b) return;
e.preventDefault();
e.stopPropagation();
applyCoupon(b.closest('[data-vt-coupon]'));
}, true);
doc.addEventListener('keydown', function (e){
if(e.key!=='Enter'||!e.target.closest('[data-vt-coupon] input')) return;
e.preventDefault();
e.stopPropagation();
applyCoupon(e.target.closest('[data-vt-coupon]'));
}, true);
if($){
$(doc.body).on('updated_wc_div updated_cart_totals', function (){
var form=doc.querySelector('.woocommerce-cart-form');
var count=doc.querySelector('[data-vt-count]');
if(form&&count&&form.getAttribute('data-count')) count.textContent=form.getAttribute('data-count');
doc.querySelectorAll('.vt-qty').forEach(clampStepper);
var box=doc.querySelector('.woocommerce-cart-form [data-vt-coupon]');
if(box&&couponState){
couponMsg(box, couponState.ok, couponState.msg);
if(couponState.code) box.querySelector('input').value=couponState.code;
couponState=null;
}
doc.querySelectorAll('.woocommerce-notices-wrapper .woocommerce-message').forEach(function (n){
if(/cup[oó]n/i.test(n.textContent)) n.remove();
});
});
}
doc.documentElement.classList.add('vt-js');
doc.querySelectorAll('[data-vt-tilt]').forEach(function (box){
if(reduce) return;
var img=box.querySelector('img');
var zone=box.closest('.vt-stone')||box;
if(!img) return;
var tx=0, ty=0, cx=0, cy=0, sy=0, raf=null;
function frame(){
raf=null;
cx +=(tx - cx) * 0.12;
cy +=(ty - cy) * 0.12;
img.style.setProperty('--vt-px', (cx * 10).toFixed(2) + 'px');
img.style.setProperty('--vt-py', (cy * 8).toFixed(2) + 'px');
img.style.setProperty('--vt-ry', (cx * 12).toFixed(2) + 'deg');
img.style.setProperty('--vt-rx', (-cy * 9).toFixed(2) + 'deg');
img.style.setProperty('--vt-sy', sy.toFixed(1) + 'px');
if(Math.abs(tx - cx) > 0.002||Math.abs(ty - cy) > 0.002) raf=requestAnimationFrame(frame);
}
function kick(){ if(!raf) raf=requestAnimationFrame(frame); }
if(window.matchMedia('(hover: hover) and (pointer: fine)').matches){
img.style.transition='none';
zone.addEventListener('pointermove', function (e){
var r=box.getBoundingClientRect();
tx=Math.max(-1, Math.min(1, (e.clientX - (r.left + r.width / 2)) / (r.width * 1.2)));
ty=Math.max(-1, Math.min(1, (e.clientY - (r.top + r.height / 2)) / (r.height * 1.2)));
kick();
});
zone.addEventListener('pointerleave', function (){ tx=0; ty=0; kick(); });
}
window.addEventListener('scroll', function (){
var y=window.scrollY;
if(y > zone.offsetTop + zone.offsetHeight) return;
sy=Math.min(60, y * 0.14);
kick();
}, { passive: true });
});
function revealCards(root){
if(reduce||!('IntersectionObserver' in window)) return;
var io=new IntersectionObserver(function (entries){
var n=0;
entries.forEach(function (en){
if(!en.isIntersecting) return;
en.target.style.setProperty('--vt-d', (n++ * 0.07) + 's');
en.target.classList.add('is-in');
io.unobserve(en.target);
});
}, { rootMargin: '0px 0px -8% 0px' });
(root||doc).querySelectorAll('.vt-card:not(.vt-reveal)').forEach(function (c){
if(c.getBoundingClientRect().top < window.innerHeight) return;
c.classList.add('vt-reveal');
io.observe(c);
});
}
revealCards();
var CHECK='<svg class="vt-i vt-check-i" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg>';
function confirmAdded(btn){
if(!btn||!btn.classList) return;
if(!btn.querySelector('.vt-check-i')) btn.insertAdjacentHTML('afterbegin', CHECK);
btn.classList.add('is-added');
clearTimeout(btn._vtAdded);
btn._vtAdded=setTimeout(function (){ btn.classList.remove('is-added'); }, 1800);
}
function bumpCount(){
setTimeout(function (){
doc.querySelectorAll('#cv-header .cv-count').forEach(function (c){
c.classList.remove('vt-bump');
void c.offsetWidth;
c.classList.add('vt-bump');
});
}, 60);
}
if($){
$(doc.body).on('added_to_cart', function (e, fragments, hash, $btn){
if($btn&&$btn[0]) confirmAdded($btn[0]);
bumpCount();
});
}
(function (){
var els=doc.querySelectorAll('.vt-reveal-up');
if(!els.length) return;
if(reduce||!('IntersectionObserver' in window)){ els.forEach(function (e){ e.classList.add('is-in'); });return; }
var io=new IntersectionObserver(function (entries){
entries.forEach(function (en){ if(en.isIntersecting){ en.target.classList.add('is-in'); io.unobserve(en.target); }});
}, { rootMargin: '0px 0px -10% 0px' });
els.forEach(function (e){ io.observe(e); });
})();
doc.querySelectorAll('[data-vt-rail]').forEach(function (rail){
var sec=rail.closest('section')||doc;
var pos=sec.querySelector('[data-vt-rail-pos]');
var items=rail.children;
function step(){ return items.length ? items[0].getBoundingClientRect().width + 8:240; }
sec.querySelectorAll('[data-vt-rail-nav]').forEach(function (b){
b.addEventListener('click', function (){
var per=Math.max(1, Math.floor(rail.clientWidth / step()) - 1);
rail.scrollBy({ left: parseInt(b.getAttribute('data-vt-rail-nav'), 10) * per * step(), behavior: reduce ? 'auto':'smooth' });
});
});
var t=null;
rail.addEventListener('scroll', function (){
clearTimeout(t);
t=setTimeout(function (){
if(!pos) return;
var n=Math.min(items.length, Math.round(rail.scrollLeft / step()) + 1);
pos.textContent=String(n).padStart(2, '0');
}, 60);
}, { passive: true });
});
(function (){
var img=doc.querySelector('[data-vt-parallax]');
if(!img||reduce) return;
var box=img.parentElement, raf=null;
function run(){
raf=null;
var r=box.getBoundingClientRect();
if(r.bottom < 0||r.top > window.innerHeight) return;
var p=(r.top + r.height / 2 - window.innerHeight / 2) / window.innerHeight;
img.style.setProperty('--vt-par', (-p * 60 - 40).toFixed(1) + 'px');
}
window.addEventListener('scroll', function (){ if(!raf) raf=requestAnimationFrame(run); }, { passive: true });
run();
})();
(function (){
var v=doc.querySelector('[data-vt-hero-video]');
if(!v) return;
if(reduce){ v.removeAttribute('autoplay'); v.pause(); return; }
if('IntersectionObserver' in window){
new IntersectionObserver(function (en){ en[0].isIntersecting ? v.play().catch(function (){}):v.pause(); }).observe(v);
}})();
(function (){
var links=Array.prototype.slice.call(doc.querySelectorAll('[data-vt-lb]'));
var box=doc.querySelector('[data-vt-lightbox]');
if(!links.length||!box) return;
var img=box.querySelector('[data-vt-lightbox-img]');
var idx=0, opener=null;
function show(i){ idx=(i + links.length) % links.length; img.src=links[idx].href; }
function close(){ box.hidden=true; doc.documentElement.style.overflow=''; if(opener) opener.focus(); }
links.forEach(function (a, i){
a.addEventListener('click', function (e){
e.preventDefault(); opener=a; show(i);
box.hidden=false; doc.documentElement.style.overflow='hidden';
box.querySelector('[data-vt-lightbox-close]').focus();
});
});
box.addEventListener('click', function (e){ if(e.target===box||e.target.closest('[data-vt-lightbox-close]')) close(); else if(e.target===img) show(idx + 1); });
doc.addEventListener('keydown', function (e){
if(box.hidden) return;
if(e.key==='Escape') close();
if(e.key==='ArrowRight') show(idx + 1);
if(e.key==='ArrowLeft') show(idx - 1);
});
})();
var noteTimer=null;
var noteSent=null;
function saveNote(t, leaving){
clearTimeout(noteTimer);
if(t.value===noteSent) return;
noteSent=t.value;
var body=new URLSearchParams({ note: t.value });
if(leaving&&navigator.sendBeacon){
navigator.sendBeacon(url('vt_note'), body);
return;
}
fetch(url('vt_note'), { method: 'POST', credentials: 'same-origin', keepalive: true, body: body }).catch(function (){ noteSent=null; });
}
doc.addEventListener('input', function (e){
var t=e.target.closest('[data-vt-note]');
if(!t) return;
clearTimeout(noteTimer);
noteTimer=setTimeout(function (){ saveNote(t); }, 600);
});
doc.addEventListener('change', function (e){
var t=e.target.closest('[data-vt-note]');
if(t) saveNote(t);
});
window.addEventListener('pagehide', function (){
var t=doc.querySelector('[data-vt-note]');
if(t) saveNote(t, true);
});
})(window.jQuery);