education-header.jsp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <%@ page pageEncoding="UTF-8"%>
  2. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  3. <c:set var="educationSiteTitle" value="${empty website.seoTitle ? website.name : website.seoTitle}"/>
  4. <c:set var="educationLogo" value="${empty website.logo ? '/main/ffkj-portal/education/education-logo.png' : website.logo}"/>
  5. <header class="edu-topbar" id="top">
  6. <div class="edu-wrap edu-topbar-inner">
  7. <a class="edu-brand" href="/" aria-label="${educationSiteTitle}首页">
  8. <img class="edu-brand-logo" src="${educationLogo}" alt="${educationSiteTitle}">
  9. </a>
  10. <div class="edu-top-tools">
  11. <nav class="edu-top-links" aria-label="快捷入口">
  12. <c:set var="educationSchoolHomeFound" value="${false}" scope="request"/>
  13. <c:forEach items="${educationTopLinksNmv.articleList}" var="item">
  14. <c:if test="${item.title eq '学校首页'}"><c:set var="educationSchoolHomeFound" value="${true}" scope="request"/></c:if>
  15. <a href="${item.url}" target="${item.target}" rel="noopener">${item.title}</a>
  16. </c:forEach>
  17. <c:if test="${not educationSchoolHomeFound}">
  18. <a href="${empty educationSchoolHomeUrl ? 'https://www.gzhxtc.edu.cn/' : educationSchoolHomeUrl}">${empty educationSchoolHomeName ? '学校首页' : educationSchoolHomeName}</a>
  19. </c:if>
  20. <c:if test="${empty educationTopLinksNmv.articleList}"><a href="/">本站首页</a></c:if>
  21. </nav>
  22. <form class="edu-top-search" action="/search" method="get" role="search">
  23. <label class="edu-sr-only" for="edu-top-search-input">搜索本站内容</label>
  24. <input id="edu-top-search-input" name="str" type="search" value="${str}" placeholder="搜索文章、通知、专业…" autocomplete="off">
  25. <button type="submit" aria-label="搜索">
  26. <svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="10.7" cy="10.7" r="6.5"></circle><path d="m15.5 15.5 5 5"></path></svg>
  27. </button>
  28. </form>
  29. <button class="edu-nav-toggle" type="button" aria-label="打开导航" aria-expanded="false" aria-controls="education-main-nav"><span></span><span></span><span></span></button>
  30. </div>
  31. </div>
  32. </header>
  33. <nav class="edu-nav" id="education-main-nav" aria-label="${educationSiteTitle}主导航">
  34. <div class="edu-wrap edu-nav-inner">
  35. <div class="edu-nav-item">
  36. <a class="edu-nav-link ${empty navigation ? 'is-active' : ''}" href="/">首页</a>
  37. </div>
  38. <c:forEach items="${navList}" var="item">
  39. <c:if test="${item.name ne '首页' and item.name ne '首页子栏目'}">
  40. <div class="edu-nav-item ${not empty item.children ? 'has-children' : ''}">
  41. <a class="edu-nav-link ${item.navigationid eq navigation.navigationid or item.navigationid eq navigation.parentNid ? 'is-active' : ''}" href="${item.href}" target="${item.target}" rel="noopener" data-edu-subnav-toggle="${item.navigationid}">${item.name}</a>
  42. <c:if test="${not empty item.children}">
  43. <div class="edu-subnav" id="education-subnav-${item.navigationid}">
  44. <c:forEach items="${item.children}" var="child"><a href="${child.href}" target="${child.target}" rel="noopener">${child.name}</a></c:forEach>
  45. </div>
  46. </c:if>
  47. </div>
  48. </c:if>
  49. </c:forEach>
  50. </div>
  51. </nav>
  52. <div class="edu-menu-mask" aria-hidden="true"></div>
  53. <script>
  54. (function () {
  55. var toggle = document.querySelector('.edu-nav-toggle');
  56. var nav = document.querySelector('.edu-nav');
  57. var mask = document.querySelector('.edu-menu-mask');
  58. if (!toggle || !nav || !mask) return;
  59. var mobileBreakpoint = 1120;
  60. var backgroundNodes = [
  61. document.querySelector('.edu-brand'),
  62. document.querySelector('.edu-top-links'),
  63. document.querySelector('.edu-top-search'),
  64. document.querySelector('main'),
  65. document.querySelector('.edu-footer'),
  66. document.querySelector('.edu-back-top')
  67. ].filter(Boolean);
  68. function setBackgroundInert(inert) {
  69. backgroundNodes.forEach(function (node) { node.inert = inert; });
  70. }
  71. function syncState() {
  72. var mobile = window.innerWidth <= mobileBreakpoint;
  73. if (!mobile) {
  74. nav.classList.remove('is-open');
  75. mask.classList.remove('is-open');
  76. toggle.classList.remove('is-open');
  77. toggle.setAttribute('aria-expanded', 'false');
  78. toggle.setAttribute('aria-label', '打开导航');
  79. document.documentElement.style.overflow = '';
  80. Array.prototype.forEach.call(nav.querySelectorAll('.edu-nav-item.has-children.is-open'), function (item) {
  81. item.classList.remove('is-open');
  82. var itemLink = item.querySelector('.edu-nav-link');
  83. if (itemLink) itemLink.setAttribute('aria-expanded', 'false');
  84. });
  85. }
  86. var offscreen = mobile && !nav.classList.contains('is-open');
  87. nav.inert = offscreen;
  88. if (mobile) nav.setAttribute('aria-hidden', offscreen ? 'true' : 'false');
  89. else nav.removeAttribute('aria-hidden');
  90. setBackgroundInert(mobile && nav.classList.contains('is-open'));
  91. }
  92. function setOpen(open) {
  93. nav.classList.toggle('is-open', open);
  94. mask.classList.toggle('is-open', open);
  95. toggle.classList.toggle('is-open', open);
  96. toggle.setAttribute('aria-expanded', open ? 'true' : 'false');
  97. toggle.setAttribute('aria-label', open ? '关闭导航' : '打开导航');
  98. document.documentElement.style.overflow = open ? 'hidden' : '';
  99. setBackgroundInert(open && window.innerWidth <= mobileBreakpoint);
  100. syncState();
  101. }
  102. toggle.addEventListener('click', function () { setOpen(!nav.classList.contains('is-open')); });
  103. mask.addEventListener('click', function () { setOpen(false); });
  104. Array.prototype.forEach.call(nav.querySelectorAll('.edu-nav-item.has-children > .edu-nav-link'), function (link) {
  105. var submenu = link.parentNode.querySelector('.edu-subnav');
  106. if (submenu) {
  107. link.setAttribute('aria-controls', submenu.id);
  108. link.setAttribute('aria-expanded', 'false');
  109. }
  110. link.addEventListener('click', function (event) {
  111. if (window.innerWidth <= mobileBreakpoint) {
  112. event.preventDefault();
  113. var open = !link.parentNode.classList.contains('is-open');
  114. Array.prototype.forEach.call(nav.querySelectorAll('.edu-nav-item.has-children.is-open'), function (item) {
  115. item.classList.remove('is-open');
  116. var itemLink = item.querySelector('.edu-nav-link');
  117. if (itemLink) itemLink.setAttribute('aria-expanded', 'false');
  118. });
  119. link.parentNode.classList.toggle('is-open', open);
  120. link.setAttribute('aria-expanded', open ? 'true' : 'false');
  121. }
  122. });
  123. });
  124. Array.prototype.forEach.call(nav.querySelectorAll('.edu-subnav a'), function (link) {
  125. link.addEventListener('click', function () { if (window.innerWidth <= mobileBreakpoint) setOpen(false); });
  126. });
  127. document.addEventListener('keydown', function (event) { if (event.key === 'Escape') setOpen(false); });
  128. window.addEventListener('resize', syncState);
  129. syncState();
  130. })();
  131. </script>