(function () { 'use strict'; function normalizeText(value) { return (value || '') .normalize('NFD') .replace(/[\u0300-\u036f]/g, '') .replace(/đ/g, 'd') .replace(/Đ/g, 'D') .replace(/\s+/g, ' ') .trim() .toUpperCase(); } function initSearchCommand() { var search = document.getElementById('s'); if (!search) { return; } document.addEventListener('keydown', function (event) { var target = event.target; var isTyping = target && /INPUT|TEXTAREA|SELECT/.test(target.tagName); if (event.key === '/' && !isTyping && !event.metaKey && !event.ctrlKey && !event.altKey) { event.preventDefault(); search.focus(); } if (event.key === 'Escape' && document.activeElement === search) { search.blur(); } }); } function enhanceScienceLibrary() { var body = document.body; if (!body.classList.contains('rensei-science-hub-page')) { return; } var content = document.querySelector('.rensei-inner-main .entry-content'); if (!content) { return; } var links = Array.prototype.filter.call(content.querySelectorAll('a[href]'), function (link) { return link.textContent.trim().length > 0; }); if (!links.length) { return; } var isLibrary = body.classList.contains('page-id-19863'); var grid = document.createElement('div'); grid.className = 'rensei-science-grid ' + (isLibrary ? 'rensei-science-grid--grades' : 'rensei-science-grid--topics'); links.forEach(function (source, index) { var card = document.createElement('a'); var label = source.textContent.trim(); var cardIndex = document.createElement('span'); var icon = document.createElement('span'); var iconGlyph = document.createElement('i'); var copy = document.createElement('span'); var type = document.createElement('small'); var title = document.createElement('strong'); var hint = document.createElement('em'); var arrow = document.createElement('span'); var arrowGlyph = document.createElement('i'); card.className = 'rensei-science-card'; card.href = source.href; cardIndex.className = 'rensei-science-card__index'; cardIndex.textContent = String(index + 1).padStart(2, '0'); icon.className = 'rensei-science-card__icon'; iconGlyph.className = 'fa ' + (isLibrary ? 'fa-cubes' : 'fa-flask'); iconGlyph.setAttribute('aria-hidden', 'true'); icon.appendChild(iconGlyph); copy.className = 'rensei-science-card__copy'; type.textContent = isLibrary ? 'GRADE MISSION' : 'SCIENCE MISSION'; title.textContent = label; hint.textContent = isLibrary ? 'Mở thư viện chủ đề' : 'Bắt đầu khám phá'; copy.append(type, title, hint); arrow.className = 'rensei-science-card__arrow'; arrowGlyph.className = 'fa fa-arrow-right'; arrowGlyph.setAttribute('aria-hidden', 'true'); arrow.appendChild(arrowGlyph); card.append(cardIndex, icon, copy, arrow); grid.appendChild(card); }); content.replaceChildren(grid); content.classList.add('is-enhanced'); } function enhanceLegacyContent() { document.querySelectorAll('.rensei-about-page .entry-content').forEach(function (content) { Array.prototype.forEach.call(content.children, function (child) { if (/^(P|DIV)$/.test(child.tagName) && child.textContent.trim().length > 30) { child.classList.add('rensei-content-block'); } }); content.querySelectorAll('table').forEach(function (table) { if (table.parentElement && table.parentElement.classList.contains('rensei-table-scroll')) { return; } var wrapper = document.createElement('div'); wrapper.className = 'rensei-table-scroll'; table.parentNode.insertBefore(wrapper, table); wrapper.appendChild(table); }); }); if (document.body.classList.contains('page-id-17')) { document.querySelectorAll('.entry-content h4').forEach(function (heading) { if (normalizeText(heading.textContent).indexOf('VI SAO NEN HOC TAI RENSEI') !== -1) { var row = heading.closest('.vc_row'); if (row) { row.classList.add('rensei-legacy-reasons'); } } }); } } function enhanceScienceTopic() { if (!document.body.classList.contains('rensei-science-topic')) { return; } var copy = document.querySelector('.rensei-article-copy'); if (!copy) { return; } var firstHeading = copy.querySelector('h1:first-child'); if (firstHeading) { firstHeading.classList.add('rensei-duplicate-topic-title'); } copy.classList.add('rensei-science-notebook'); } function enhanceCareerPages() { if (!document.body.classList.contains('rensei-career-page')) { return; } document.querySelectorAll('.entry-content').forEach(function (content) { content.querySelectorAll('p, h2, h3, h4').forEach(function (element) { var text = normalizeText(element.textContent); if (/^(I|II|III|IV|V|VI)\.?\s/.test(text) || text.indexOf('YEU CAU HO SO') !== -1) { element.classList.add('rensei-career-heading'); } if (text.indexOf('CV GUI VE EMAIL') !== -1 || text.indexOf('NOP HO SO') !== -1) { element.classList.add('rensei-career-apply'); } }); content.querySelectorAll('a[href^="mailto:"]').forEach(function (link) { link.classList.add('rensei-career-email'); }); }); } function enhanceHomeModules() { if (!document.body.classList.contains('home')) { return; } var modules = [ { match: 'CAC MON HOC TAI RENSEI', label: 'LEARNING MISSIONS', className: 'rensei-module--courses' }, { match: 'KHOANH KHAC RENSEI', label: 'RENSEI MOMENTS', className: 'rensei-module--moments' }, { match: 'TIN TUC & SU KIEN', label: 'NEWSROOM SIGNAL', className: 'rensei-module--news' }, { match: 'THU VIEN HINH ANH', label: 'VISUAL DISCOVERY LAB', className: 'rensei-module--gallery' } ]; document.querySelectorAll('.entry-content h2.vc_custom_heading').forEach(function (heading) { var text = normalizeText(heading.textContent); modules.forEach(function (module) { if (text.indexOf(module.match) === -1) { return; } heading.setAttribute('data-rensei-module-label', module.label); var row = heading.closest('.vc_row'); if (row) { row.classList.add('rensei-home-module', module.className); } }); }); document.querySelectorAll('.home .vc_btn3').forEach(function (button) { button.classList.add('rensei-module-button'); if (!button.querySelector('.fa-arrow-right')) { var icon = document.createElement('i'); icon.className = 'fa fa-arrow-right'; icon.setAttribute('aria-hidden', 'true'); button.appendChild(icon); } }); document.querySelectorAll('.home .course-carousel').forEach(function (carousel) { if (carousel.querySelectorAll('.course--item').length <= 2) { carousel.classList.add('is-underfilled'); } }); } function initEnrollmentForm() { var form = document.getElementById('rensei-enrollment-form'); if (!form) { return; } form.addEventListener('submit', function () { if (!form.checkValidity()) { return; } var button = form.querySelector('.rensei-enrollment-submit'); if (button) { button.disabled = true; button.classList.add('is-loading'); button.querySelector('span').textContent = 'Đang gửi hồ sơ…'; } }); } function initReveal() { var items = document.querySelectorAll('.rensei-inner-intro, .rensei-reason-card, .rensei-why-us, .rensei-science-card, .rensei-enrollment'); if (!items.length || !('IntersectionObserver' in window) || window.matchMedia('(prefers-reduced-motion: reduce)').matches) { items.forEach(function (item) { item.classList.add('is-visible'); }); return; } var observer = new IntersectionObserver(function (entries) { entries.forEach(function (entry) { if (entry.isIntersecting) { entry.target.classList.add('is-visible'); observer.unobserve(entry.target); } }); }, { threshold: 0.12 }); items.forEach(function (item) { observer.observe(item); }); } document.addEventListener('DOMContentLoaded', function () { initSearchCommand(); enhanceScienceLibrary(); enhanceLegacyContent(); enhanceScienceTopic(); enhanceCareerPages(); enhanceHomeModules(); initEnrollmentForm(); initReveal(); }); })();