education-header.jsp 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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:forEach items="${educationTopLinksNmv.articleList}" var="item">
  13. <a href="${item.url}" target="${item.target}" rel="noopener">${item.title}</a>
  14. </c:forEach>
  15. <c:if test="${empty educationTopLinksNmv.articleList}">
  16. <a href="${empty educationSchoolHomeUrl ? 'http://ffkj-school.localhost:4188/' : educationSchoolHomeUrl}">${empty educationSchoolHomeName ? '学校首页' : educationSchoolHomeName}</a>
  17. <a href="/">本站首页</a>
  18. </c:if>
  19. </nav>
  20. <form class="edu-top-search" action="/search" method="get" role="search">
  21. <label class="edu-sr-only" for="edu-top-search-input">搜索本站内容</label>
  22. <input id="edu-top-search-input" name="str" type="search" value="${str}" placeholder="搜索文章、通知、专业…" autocomplete="off">
  23. <button type="submit" aria-label="搜索">
  24. <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>
  25. </button>
  26. </form>
  27. <button class="edu-nav-toggle" type="button" aria-label="打开导航" aria-expanded="false" aria-controls="education-main-nav"><span></span><span></span><span></span></button>
  28. </div>
  29. </div>
  30. </header>
  31. <nav class="edu-nav" id="education-main-nav" aria-label="${educationSiteTitle}主导航">
  32. <div class="edu-wrap edu-nav-inner">
  33. <div class="edu-nav-item">
  34. <a class="edu-nav-link ${empty navigation ? 'is-active' : ''}" href="/">首页</a>
  35. </div>
  36. <c:forEach items="${navList}" var="item">
  37. <c:if test="${item.name ne '首页' and item.name ne '首页子栏目'}">
  38. <div class="edu-nav-item ${not empty item.children ? 'has-children' : ''}">
  39. <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>
  40. <c:if test="${not empty item.children}">
  41. <div class="edu-subnav" id="education-subnav-${item.navigationid}">
  42. <c:forEach items="${item.children}" var="child"><a href="${child.href}" target="${child.target}" rel="noopener">${child.name}</a></c:forEach>
  43. </div>
  44. </c:if>
  45. </div>
  46. </c:if>
  47. </c:forEach>
  48. </div>
  49. </nav>
  50. <div class="edu-menu-mask" aria-hidden="true"></div>
  51. <script>
  52. (function () {
  53. var toggle = document.querySelector('.edu-nav-toggle');
  54. var nav = document.querySelector('.edu-nav');
  55. var mask = document.querySelector('.edu-menu-mask');
  56. if (!toggle || !nav || !mask) return;
  57. var mobileBreakpoint = 1120;
  58. var backgroundNodes = [
  59. document.querySelector('.edu-brand'),
  60. document.querySelector('.edu-top-links'),
  61. document.querySelector('.edu-top-search'),
  62. document.querySelector('main'),
  63. document.querySelector('.edu-footer'),
  64. document.querySelector('.edu-back-top')
  65. ].filter(Boolean);
  66. function setBackgroundInert(inert) {
  67. backgroundNodes.forEach(function (node) { node.inert = inert; });
  68. }
  69. function syncState() {
  70. var mobile = window.innerWidth <= mobileBreakpoint;
  71. if (!mobile) {
  72. nav.classList.remove('is-open');
  73. mask.classList.remove('is-open');
  74. toggle.classList.remove('is-open');
  75. toggle.setAttribute('aria-expanded', 'false');
  76. toggle.setAttribute('aria-label', '打开导航');
  77. document.documentElement.style.overflow = '';
  78. Array.prototype.forEach.call(nav.querySelectorAll('.edu-nav-item.has-children.is-open'), function (item) {
  79. item.classList.remove('is-open');
  80. var itemLink = item.querySelector('.edu-nav-link');
  81. if (itemLink) itemLink.setAttribute('aria-expanded', 'false');
  82. });
  83. }
  84. var offscreen = mobile && !nav.classList.contains('is-open');
  85. nav.inert = offscreen;
  86. if (mobile) nav.setAttribute('aria-hidden', offscreen ? 'true' : 'false');
  87. else nav.removeAttribute('aria-hidden');
  88. setBackgroundInert(mobile && nav.classList.contains('is-open'));
  89. }
  90. function setOpen(open) {
  91. nav.classList.toggle('is-open', open);
  92. mask.classList.toggle('is-open', open);
  93. toggle.classList.toggle('is-open', open);
  94. toggle.setAttribute('aria-expanded', open ? 'true' : 'false');
  95. toggle.setAttribute('aria-label', open ? '关闭导航' : '打开导航');
  96. document.documentElement.style.overflow = open ? 'hidden' : '';
  97. setBackgroundInert(open && window.innerWidth <= mobileBreakpoint);
  98. syncState();
  99. }
  100. toggle.addEventListener('click', function () { setOpen(!nav.classList.contains('is-open')); });
  101. mask.addEventListener('click', function () { setOpen(false); });
  102. Array.prototype.forEach.call(nav.querySelectorAll('.edu-nav-item.has-children > .edu-nav-link'), function (link) {
  103. var submenu = link.parentNode.querySelector('.edu-subnav');
  104. if (submenu) {
  105. link.setAttribute('aria-controls', submenu.id);
  106. link.setAttribute('aria-expanded', 'false');
  107. }
  108. link.addEventListener('click', function (event) {
  109. if (window.innerWidth <= mobileBreakpoint) {
  110. event.preventDefault();
  111. var open = !link.parentNode.classList.contains('is-open');
  112. Array.prototype.forEach.call(nav.querySelectorAll('.edu-nav-item.has-children.is-open'), function (item) {
  113. item.classList.remove('is-open');
  114. var itemLink = item.querySelector('.edu-nav-link');
  115. if (itemLink) itemLink.setAttribute('aria-expanded', 'false');
  116. });
  117. link.parentNode.classList.toggle('is-open', open);
  118. link.setAttribute('aria-expanded', open ? 'true' : 'false');
  119. }
  120. });
  121. });
  122. Array.prototype.forEach.call(nav.querySelectorAll('.edu-subnav a'), function (link) {
  123. link.addEventListener('click', function () { if (window.innerWidth <= mobileBreakpoint) setOpen(false); });
  124. });
  125. document.addEventListener('keydown', function (event) { if (event.key === 'Escape') setOpen(false); });
  126. window.addEventListener('resize', syncState);
  127. syncState();
  128. })();
  129. </script>