/* Trang Bảng xếp hạng nạp (/topnap) — trước đây là script nhúng cuối topnap.php. * Chạy qua WGNav.page nên tự gỡ sự kiện, đồng hồ đếm ngược và tooltip khi rời trang. */ WGNav.page('topnap', function (root, ctx) { var $ = window.jQuery; /* ----- Tab BXH tuần / tháng ----- */ ctx.on(root, 'click', '.btn_tabs', function (ev, btn) { $(root).find('.btn_tabs').removeClass('active'); $(btn).addClass('active'); var tabType = $(btn).data('tab'); var show = tabType === 'week' ? '.tab_week' : tabType === 'month' ? '.tab_month' : null; var hide = tabType === 'week' ? '.tab_month' : '.tab_week'; if (!show) return; $(root).find(show).removeClass('isHidden').addClass('activeShow'); $(root).find(hide).addClass('isHidden').removeClass('activeShow'); }); /* ----- Số coin dạng con lăn ----- */ ctx.load('https://cdnjs.cloudflare.com/ajax/libs/gsap/3.11.1/gsap.min.js').then(function () { $(root).find('.rollerBlock').each(function () { var targetValue = $(this).find('.copyable').text().trim(); if (!isNaN(targetValue)) { window.gsap.to($(this), { duration: 0.1, top: '-' + targetValue + '00%', ease: 'power2.inOut' }); } }); }, function () {}); /* ----- Tooltip số tiền đầy đủ ----- */ var $tips = $(root).find('[data-toggle="tooltip"]'); if ($.fn.tooltip) { $tips.tooltip(); ctx.cleanup(function () { $tips.tooltip('destroy'); }); } /* ----- Đồng hồ đếm ngược tới cuối tuần / cuối tháng ----- */ function getEndOfWeek() { var now = new Date(); var endOfWeek = new Date(); if (now.getDay() !== 0) endOfWeek.setDate(now.getDate() + (7 - now.getDay())); endOfWeek.setHours(23, 59, 59, 999); return endOfWeek; } function getEndOfMonth() { var now = new Date(); var endOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0); endOfMonth.setHours(23, 59, 59, 999); return endOfMonth; } function padNumber(n) { return n < 10 ? '0' + n : n; } function paint(sel, distance, days) { var $c = $(root).find(sel); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); $c.find('.item:nth-child(1) .item-time').text(padNumber(days)); $c.find('.item:nth-child(3) .item-time').text(padNumber(hours)); $c.find('.item:nth-child(5) .item-time').text(padNumber(minutes)); $c.find('.item:nth-child(7) .item-time').text(padNumber(seconds)); } /* Như bản cũ: đồng hồ tuần ghi vào mọi .rank_clock_time, đồng hồ tháng ghi đè ô tháng */ function updateCountdown() { var now = new Date(); var distance = getEndOfWeek() - now; var days = now.getDay() === 0 ? 0 : Math.floor(distance / (1000 * 60 * 60 * 24)); paint('.rank_clock_time', distance, days); } function updateCountdownMonth() { var distance = getEndOfMonth() - new Date(); paint('.tab_month .rank_clock_time', distance, Math.floor(distance / (1000 * 60 * 60 * 24))); } function tick() { updateCountdown(); updateCountdownMonth(); } tick(); ctx.interval(tick, 1000); });