/* help.js — contextual "?" tooltips. Usage: add data-help="key" to any element. Hover on desktop, tap on mobile. */ (function () { 'use strict'; var HELP = { zscore: "How far the current price is from its 20-day average. Negative = below average.", rsi: "0–100 momentum gauge. Under 30 = oversold, over 70 = overbought.", atr: "How far TP/SL are placed from price. 2× = moderate, 3× = wider targets.", basis: "Difference between futures and spot price. Positive = contango, negative = backwardation.", signal: "Buy signal fires when Z-Score, momentum, volatility, and RSI all pass criteria.", tp: "Take Profit. Price target for automatic sell at a gain.", sl: "Stop Loss. Price at which the position closes to limit losses.", momentum: "7-day price change as a percentage.", volatility: "Standard deviation of daily returns over 20 days. Lower = calmer.", score: "Composite score combining Z-Score, momentum, volatility, and RSI.", invest: "Total USDT to spread across your selected coins.", contango: "Futures trade above spot. Market expects higher prices; longs pay shorts.", backwardation: "Futures trade below spot. Signals tight supply or bearish sentiment.", conservative: "Scans top 20 by market cap with tight stops.", risk: "Includes lower-liquidity, high-volatility coins with wider stops." }; var activeTip = null; function buildIcon(key) { var span = document.createElement('span'); span.className = 'help-icon'; span.setAttribute('data-help-key', key); span.textContent = '?'; return span; } function showTip(target, key) { hideTip(); var text = HELP[key] || 'Info'; var tip = document.createElement('div'); tip.className = 'help-tip'; tip.textContent = text; document.body.appendChild(tip); var rect = target.getBoundingClientRect(); var tipRect = tip.getBoundingClientRect(); var scrollY = window.scrollY || window.pageYOffset; var scrollX = window.scrollX || window.pageXOffset; // Position: prefer below, flip above if no room var top, left; left = rect.left + scrollX + (rect.width / 2) - (tipRect.width / 2); // Clamp to viewport if (left < 8) left = 8; if (left + tipRect.width > window.innerWidth - 8) { left = window.innerWidth - tipRect.width - 8; } var spaceBelow = window.innerHeight - rect.bottom; if (spaceBelow < tipRect.height + 12) { top = rect.top + scrollY - tipRect.height - 8; } else { top = rect.bottom + scrollY + 8; } tip.style.top = top + 'px'; tip.style.left = left + 'px'; tip.style.opacity = '1'; activeTip = tip; } function hideTip() { if (activeTip) { activeTip.remove(); activeTip = null; } } function attach() { var nodes = document.querySelectorAll('[data-help]'); nodes.forEach(function (el) { if (el.querySelector(':scope > .help-icon')) return; var key = el.getAttribute('data-help'); var icon = buildIcon(key); el.appendChild(icon); icon.addEventListener('mouseenter', function () { showTip(icon, key); }); icon.addEventListener('mouseleave', function () { hideTip(); }); icon.addEventListener('click', function (e) { e.stopPropagation(); e.preventDefault(); if (activeTip && activeTip.getAttribute('data-tip-key') === key) { hideTip(); } else { showTip(icon, key); if (activeTip) activeTip.setAttribute('data-tip-key', key); } }); }); } document.addEventListener('click', function (e) { if (!e.target.classList || !e.target.classList.contains('help-icon')) { hideTip(); } }); window.HelpTips = { attach: attach, HELP: HELP }; if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', attach); } else { attach(); } })();