1(function() { 2 'use strict'; 3 4 // ç¥æ¥å¤å®ç¨ã®ç°¡æå®è£ ï¼ä¸»è¦ãªç¥æ¥ã®ã¿ï¼ 5 const isHoliday = function(date) { 6 const year = date.getFullYear(); 7 const month = date.getMonth() + 1; 8 const day = date.getDate(); 9 const dayOfWeek = date.getDay(); 10 11 // åºå®ç¥æ¥ 12 const fixedHolidays = [ 13 [1, 1], // å æ¥ 14 [2, 11], // 建å½è¨å¿µã®æ¥ 15 [4, 29], // æåã®æ¥ 16 [5, 3], // æ²æ³è¨å¿µæ¥ 17 [5, 4], // ã¿ã©ãã®æ¥ 18 [5, 5], // ãã©ãã®æ¥ 19 [8, 11], // å±±ã®æ¥ 20 [11, 3], // æåã®æ¥ 21 [11, 23], // å¤å´æè¬ã®æ¥ 22 [12, 23], // 天çèªçæ¥ 23 ]; 24 25 // åºå®ç¥æ¥ã®ãã§ã㯠26 for (let i = 0; i < fixedHolidays.length; i++) { 27 if (fixedHolidays[i][0] === month && fixedHolidays[i][1] === day) { 28 return true; 29 } 30 } 31 32 // æ¥åã®æ¥ã»ç§åã®æ¥ã¯ç°¡æçã«è¨ç®ï¼å®å ¨ã§ã¯ãªãï¼ 33 // å®éã®ããã¸ã§ã¯ãã§ã¯ãããæ£ç¢ºãªè¨ç®ãAPIã使ç¨ãããã¨ãæ¨å¥¨ 34 35 return false; 36 }; 37 38 // æ¥ä»ãã©ã¼ããã颿° 39 const getDayOfWeek = function(dateStr) { 40 const dateOnly = dateStr.replace(/-/g, ''); 41 if (dateOnly.length !== 8) { 42 return { day: '', isHoliday: false, className: '' }; 43 } 44 45 const year = parseInt(dateOnly.substring(0, 4), 10);
46 const month = parseInt(dateOnly.substring(4, 6), 10) - 1; 47 const day = parseInt(dateOnly.substring(6, 8), 10); 48 const date = new Date(year, month, day); 49 const dayOfWeekIndex = date.getDay(); 50 const dayOfWeekChars = ['æ¥', 'æ', 'ç«', 'æ°´', 'æ¨', 'é', 'å']; 51 const dayOfWeek = dayOfWeekChars[dayOfWeekIndex]; 52 const holiday = isHoliday(date); 53 const dayDisplay = holiday ? dayOfWeek + 'ã»ç¥' : dayOfWeek; 54 55 let className = 'p-home-event__card__date__day-of-week'; 56 // ç¥æ¥ã®å ´åã¯å ã®ææ¥ã«é¢ä¿ãªãæ¥æã¯ã©ã¹ãé©ç¨ 57 if (holiday) { 58 className += ' p-home-event__card__date__day-of-week--sunday'; 59 } else if (dayOfWeekIndex === 0) { 60 // æ¥ææ¥ 61 className += ' p-home-event__card__date__day-of-week--sunday'; 62 } else if (dayOfWeekIndex === 6) { 63 // åææ¥ 64 className += ' p-home-event__card__date__day-of-week--saturday'; 65 } 66 67 return { day: dayDisplay, isHoliday: holiday, className: className }; 68 }; 69 70 const formatDateRange = function(startDate, endDate) { 71 const startDateOnly = startDate.replace(/-/g, ''); 72 73 if (startDateOnly.length !== 8) { 74 return { year: '', dates: [] }; 75 } 76 77 const year = startDateOnly.substring(0, 4); 78 const startMonth = startDateOnly.substring(4, 6); 79 const startDay = startDateOnly.substring(6, 8); 80 const startDateFormatted = startMonth + '/' + startDay; 81 82 const startDateWithHyphen = year + '-' + startMonth + '-' + startDay; 83 const startDayInfo = getDayOfWeek(startDateWithHyphen); 84 85 const dates = [ 86 { date: startDateFormatted, day: startDayInfo.day, className: startDayInfo.className } 87 ]; 88 89 if (endDate) { 90 const endDateOnly = endDate.replace(/-/g, ''); 91 92 if (endDateOnly.length === 8) { 93 const endYear = endDateOnly.substring(0, 4); 94 const endMonth = endDateOnly.substring(4, 6); 95 const endDay = endDateOnly.substring(6, 8); 96 const endDateFormatted = endMonth + '/' + endDay; 97 98 const endDateWithHyphen = endYear + '-' + endMonth + '-' + endDay; 99 const endDayInfo = getDayOfWeek(endDateWithHyphen); 100 101 dates.push({ date: endDateFormatted, day: endDayInfo.day, className: endDayInfo.className }); 102 } 103 } 104 105 return { year: year, dates: dates }; 106 }; 107 108 // create-slug.ts ã¨åããã¸ãã¯ï¼public é ä¸ã®ãã import ä¸å¯ï¼ 109 function removeDateHyphen(dateStr) { 110 return (dateStr || '').replace(/-/g, ''); 111 } 112 function createSlug(item) { 113 return item.slug || (removeDateHyphen(item.ymd) + '-' + item.topics_id); 114 } 115 116 // text-to-html.ts ã¨åããã¸ãã¯ï¼public é ä¸ã®ãã import ä¸å¯ï¼ 117 function textToHtml(text) { 118 return text.replace(/<br\s*\/?>/gi, '\n'); 119 } 120 121 // DOMçæé¢æ° 122 const createEventCard = function(event) { 123 const li = document.createElement('li'); 124 li.className = 'p-home-event__card'; 125 126 const link = document.createElement('a'); 127 const slug = createSlug(event); 128 link.href = '/calendar/' + slug + '/'; 129 link.className = 'p-home-event__card__link'; 130 131 // æ¥ä»ã»ã¯ã·ã§ã³ï¼date-format.tsxããçæãããHTMLã使ç¨ï¼ 132 const dateDiv = document.createElement('div'); 133 dateDiv.className = 'p-home-event__card__date'; 134 135 if (event.dateHtml) { 136 // dateHtmlãåå¨ããå ´åã¯ãããä½¿ç¨ 137 dateDiv.innerHTML = event.dateHtml; 138 139 // ç¥æ¥å¤å®ãè¡ã£ã¦ã¯ã©ã¹åãä¿®æ£ 140 const dayOfWeekElements = dateDiv.querySelectorAll('.p-home-event__card__date__day-of-week'); 141 dayOfWeekElements.forEach(function(element) { 142 // ããã¹ãã«ãã»ç¥ããå«ã¾ãã¦ããå ´åã¯ç¥æ¥ã¨ãã¦æ¥æã¯ã©ã¹ãé©ç¨ 143 const isHolidayText = element.textContent.indexOf('ã»ç¥') !== -1; 144 if (isHolidayText) { 145 element.className = 'p-home-event__card__date__day-of-week p-home-event__card__date__day-of-week--sunday'; 146 } 147 }); 148 } else { 149 // ãã©ã¼ã«ããã¯: æ¢åã®ãã¸ãã¯ãä½¿ç¨ 150 const { year, dates } = formatDateRange(event.date.start_date, event.date.end_date); 151 152 const yearP = document.createElement('p'); 153 yearP.className = 'p-home-event__card__date__year';
154 yearP.textContent = year; 155 dateDiv.appendChild(yearP); 156 157 const datesDiv = document.createElement('div'); 158 datesDiv.className = 'p-home-event__card__date__dates'; 159 160 dates.forEach(function(dateInfo, index) { 161 const dateItem = document.createElement('div'); 162 dateItem.className = 'p-home-event__card__date__date-item'; 163 164 const dateNumber = document.createElement('span'); 165 dateNumber.className = 'p-home-event__card__date__date-number'; 166 dateNumber.textContent = dateInfo.date; 167 dateItem.appendChild(dateNumber); 168 169 const dayOfWeek = document.createElement('span'); 170 dayOfWeek.className = dateInfo.className; 171 dayOfWeek.textContent = dateInfo.day; 172 dateItem.appendChild(dayOfWeek); 173 174 datesDiv.appendChild(dateItem); 175 176 if (index < dates.length - 1) { 177 const hyphen = document.createElement('span'); 178 hyphen.className = 'p-home-event__card__date__hyphen'; 179 datesDiv.appendChild(hyphen); 180 } 181 }); 182 183 dateDiv.appendChild(datesDiv); 184 } 185 186 link.appendChild(dateDiv); 187 188 // ç»åã»ã¯ã·ã§ã³ï¼ImageFilterã¨åãæ§é ï¼ 189 const figure = document.createElement('figure'); 190 figure.className = 'c-image-filter'; 191 192 const cloneImg = document.createElement('img'); 193 cloneImg.src = event.image.url; 194 cloneImg.alt = event.image.desc; 195 cloneImg.className = 'c-image-filter__clone'; 196 figure.appendChild(cloneImg); 197 198 const mainImg = document.createElement('img'); 199 mainImg.src = event.image.url; 200 mainImg.alt = event.image.desc; 201 mainImg.className = 'c-image-filter__main'; 202 figure.appendChild(mainImg); 203 204 link.appendChild(figure); 205 206 // ã³ã³ãã³ãã»ã¯ã·ã§ã³ 207 const contentDiv = document.createElement('div'); 208 contentDiv.className = 'p-home-event__card__content'; 209 210 const categoryDiv = document.createElement('div'); 211 categoryDiv.className = 'p-home-event__card__category'; 212 213 const iconSpan = document.createElement('span'); 214 iconSpan.className = 'p-home-event__card__category__icon p-home-event__card__category__icon--' + event.contents_type_slug; 215 categoryDiv.appendChild(iconSpan); 216 217 const textSpan = document.createElement('span'); 218 textSpan.className = 'p-home-event__card__category__text'; 219 textSpan.textContent = event.contents_type; 220 categoryDiv.appendChild(textSpan); 221 222 contentDiv.appendChild(categoryDiv); 223 224 const divider = document.createElement('div'); 225 divider.className = 'p-home-event__card__divider'; 226 contentDiv.appendChild(divider); 227 228 const titleP = document.createElement('p'); 229 titleP.className = 'p-home-event__card__title'; 230 titleP.textContent = textToHtml(event.subject); 231 contentDiv.appendChild(titleP); 232 233 link.appendChild(contentDiv); 234 li.appendChild(link); 235 236 return li; 237 }; 238 239 // æ¥ä»ã»ã¯ã·ã§ã³ã®é«ããæãã颿° 240 const alignDateHeights = function(container) { 241 // ã³ã³ããå ã®ãã¹ã¦ã®æ¥ä»ã»ã¯ã·ã§ã³ãåå¾ 242 const dateSections = container.querySelectorAll('.p-home-event__card__date'); 243 if (dateSections.length === 0) { 244 return; 245 } 246 247 // æå¤§ã®é«ããè¨ç® 248 let maxHeight = 0; 249 dateSections.forEach(function(section) { 250 // 䏿çã«é«ãããªã»ãããã¦å®éã®é«ããæ¸¬å® 251 const originalHeight = section.style.height; 252 section.style.height = 'auto'; 253 const height = section.offsetHeight; 254 section.style.height = originalHeight; 255 if (height > maxHeight) { 256 maxHeight = height; 257 } 258 }); 259 260 // ãã¹ã¦ã®æ¥ä»ã»ã¯ã·ã§ã³ã«æå¤§é«ããé©ç¨ 261 if (maxHeight > 0) { 262 dateSections.forEach(function(section) { 263 section.style.height = maxHeight + 'px'; 264 }); 265 } 266 }; 267 268 // æ¥æ¬æå»ï¼JSTï¼ã§ã仿¥ãã® 0:00 ã®ã¿ã¤ã ã¹ã¿ã³ããåå¾ 269 const getTodayJSTMs = function() { 270 const jstDateStr = new Date().toLocaleDateString('en-CA', { timeZone: 'Asia/Tokyo' }); 271 return new Date(jstDateStr + 'T00:00:00+09:00').getTime(); 272 }; 273
274 // æ¥ä»æååãæ¥æ¬æå»ã® 0:00 ã®ã¿ã¤ã ã¹ã¿ã³ãã«å¤æï¼YYYY-MM-DD ã¾ã㯠ISO å½¢å¼ï¼ 275 const getDateJSTMs = function(dateStr) { 276 var dateOnly = (dateStr || '').substring(0, 10); 277 if (dateOnly.length !== 10) return 0; 278 return new Date(dateOnly + 'T00:00:00+09:00').getTime(); 279 }; 280 281 // ã¤ãã³ãã®åºæºæ¥ï¼end_date ãããã° end_dateããªããã° start_dateï¼ãæ¥æ¬æå»ã®ã¿ã¤ã ã¹ã¿ã³ãã§è¿ã 282 const getEventReferenceDateJSTMs = function(event) { 283 var dateStr = event.date.end_date !== undefined && event.date.end_date !== '' 284 ? event.date.end_date 285 : event.date.start_date; 286 return getDateJSTMs(dateStr); 287 }; 288 289 // æªæ¥ï¼ä»æ¥ä»¥éï¼ã®ã¤ãã³ãã®ã¿æ½åºï¼æ¥æ¬æå»ã§ãã£ã«ã¿ãåºæºæ¥ã¯ end_date â start_dateï¼ 290 const getFilteredEventList = function() { 291 if (!window.eventListData || !Array.isArray(window.eventListData)) { 292 return []; 293 } 294 const todayJSTMs = getTodayJSTMs(); 295 return window.eventListData 296 .filter(function(event) { 297 const refJSTMs = getEventReferenceDateJSTMs(event); 298 return refJSTMs >= todayJSTMs; 299 }) 300 .sort(function(a, b) { 301 return getDateJSTMs(a.date.start_date) - getDateJSTMs(b.date.start_date); 302 }); 303 }; 304 305 // åæå颿° 306 const initEventList = function() { 307 const container = document.getElementById('event-list-container'); 308 if (!container || !window.eventListData) { 309 return; 310 } 311 312 var displayList = getFilteredEventList().slice(0, 4); 313 314 // æ¢åã®ã³ã³ãã³ããã¯ãªã¢ 315 container.innerHTML = ''; 316 317 // ã¤ãã³ãã«ã¼ããçæï¼ä»æ¥ä»¥éã®ã¤ãã³ãã®ã¿ï¼ 318 displayList.forEach(function(event) { 319 const card = createEventCard(event); 320 container.appendChild(card); 321 }); 322 323 // æ¥ä»ã»ã¯ã·ã§ã³ã®é«ããæããï¼PCæã®ã¿ï¼ 324 const isSP = window.innerWidth < 960; 325 if (!isSP) { 326 // å°ãé å»¶ããã¦ã¬ã³ããªã³ã°å¾ã«å®è¡ 327 setTimeout(function() { 328 alignDateHeights(container); 329 }, 100); 330 } 331 332 // SPæã«Splideã¹ã©ã¤ãã¼ãé©ç¨ 333 const checkAndInitSplide = function() { 334 const isSP = window.innerWidth < 960; 335 if (isSP && typeof Splide !== 'undefined') { 336 // æ¢ã«Splideãåæåããã¦ããå ´åã¯ã¹ããã 337 if (container.querySelector('.splide')) { 338 return; 339 } 340 341 // çæãããã«ã¼ããåå¾ 342 const cards = container.querySelectorAll('.p-home-event__card'); 343 if (cards.length === 0) { 344 return; 345 } 346 347 // Splideãèªã¿è¾¼ã¾ãã¦ããå ´å 348 const splideContainer = document.createElement('div'); 349 splideContainer.className = 'splide'; 350 splideContainer.id = 'event-splide'; 351 352 const splideTrack = document.createElement('div'); 353 splideTrack.className = 'splide__track'; 354 355 const splideList = document.createElement('ul'); 356 splideList.className = 'splide__list'; 357 358 // æ¢åã®ã«ã¼ããSplideã®æ§é ã«ç§»å 359 cards.forEach(function(card) { 360 const slide = document.createElement('li'); 361 slide.className = 'splide__slide'; 362 slide.appendChild(card.cloneNode(true)); 363 splideList.appendChild(slide); 364 }); 365 366 splideTrack.appendChild(splideList); 367 splideContainer.appendChild(splideTrack); 368 369 // å ã®ã³ã³ããã®å 容ãSplideã³ã³ããã«ç½®ãæã 370 container.innerHTML = ''; 371 container.appendChild(splideContainer); 372 373 // ããã°ã¬ã¹ãã¼ã¨ç¢å°ãã¿ã³ã®è¦ç´ ãåå¾ 374 const progressBarElement = document.getElementById('event-progress-bar'); 375 const prevArrow = document.getElementById('event-arrow-prev'); 376 const nextArrow = document.getElementById('event-arrow-next'); 377 378 // Splideãåæå 379 const splide = new Splide('#event-splide', { 380 type: 'slide', 381 perPage: 1, 382 perMove: 1, 383 gap: '2.5rem', 384 pagination: '#event-pagination',
385 arrows: false, 386 fixedWidth: '27rem', 387 focus: 'center', 388 }); 389 390 // ç¢å°ãã¿ã³ã®ã¯ãªãã¯ã¤ãã³ã 391 if (prevArrow) { 392 prevArrow.addEventListener('click', function() { 393 splide.go('<'); 394 }); 395 } 396 397 if (nextArrow) { 398 nextArrow.addEventListener('click', function() { 399 splide.go('>'); 400 }); 401 } 402 403 // ç¢å°ãã¿ã³ã®ç¡å¹åç¶æ ãæ´æ°ãã颿° 404 const updateArrows = function() { 405 if (prevArrow) { 406 prevArrow.disabled = splide.index === 0; 407 } 408 if (nextArrow) { 409 nextArrow.disabled = splide.index === splide.length - 1; 410 } 411 }; 412 413 splide.on('moved', function(newIndex) { 414 // ããã°ã¬ã¹ãã¼ãæ´æ° 415 if (progressBarElement) { 416 const total = splide.length; 417 const progress = ((newIndex + 1) / total) * 100; 418 progressBarElement.style.width = progress + '%'; 419 } 420 // ç¢å°ãã¿ã³ã®ç¶æ ãæ´æ° 421 updateArrows(); 422 }); 423 424 splide.mount(); 425 426 // åæããã°ã¬ã¹ãã¼ã®ä½ç½®ãè¨å® 427 if (progressBarElement) { 428 const total = splide.length; 429 const initialProgress = (1 / total) * 100; 430 progressBarElement.style.width = initialProgress + '%'; 431 } 432 433 // åæã®ç¢å°ãã¿ã³ã®ç¶æ ãè¨å® 434 updateArrows(); 435 } else { 436 // PCæ: æ¥ä»ã»ã¯ã·ã§ã³ã®é«ããæãã 437 setTimeout(function() { 438 alignDateHeights(container); 439 }, 100); 440 } 441 }; 442 443 // Splideãèªã¿è¾¼ã¾ããã¾ã§å¾ æ© 444 if (typeof Splide === 'undefined') { 445 // Splideãã¾ã èªã¿è¾¼ã¾ãã¦ããªãå ´åãèªã¿è¾¼ã¿ãå¾ ã¤ 446 const checkSplide = setInterval(function() { 447 if (typeof Splide !== 'undefined') { 448 clearInterval(checkSplide); 449 checkAndInitSplide(); 450 } 451 }, 100); 452 453 // ã¿ã¤ã ã¢ã¦ãï¼5ç§å¾ï¼ 454 setTimeout(function() { 455 clearInterval(checkSplide); 456 }, 5000); 457 } else { 458 checkAndInitSplide(); 459 } 460 }; 461 462 // DOMContentLoadedã¾ãã¯æ¢ã«èªã¿è¾¼ã¿æ¸ã¿ã®å ´å 463 if (document.readyState === 'loading') { 464 document.addEventListener('DOMContentLoaded', initEventList); 465 } else { 466 initEventList(); 467 } 468 469 // ãªãµã¤ãºæã®å¦ç 470 let resizeTimer; 471 window.addEventListener('resize', function() { 472 clearTimeout(resizeTimer); 473 resizeTimer = setTimeout(function() { 474 const container = document.getElementById('event-list-container'); 475 if (container && window.eventListData) { 476 const isSP = window.innerWidth < 960; 477 const existingSplide = container.querySelector('.splide'); 478 479 if (isSP) { 480 // SPæ: Splideãæ¢ã«åæåããã¦ããå ´åã¯ç ´æ£ãã¦ååæå 481 if (existingSplide) { 482 const splideInstance = existingSplide.splide; 483 if (splideInstance) { 484 splideInstance.destroy(); 485 } 486 } 487 // ååæå 488 initEventList(); 489 } else { 490 // PCæ: Splideãåæåããã¦ããå ´åã¯ç ´æ£ãã¦å ã®æ§é ã«æ»ã 491 if (existingSplide) { 492 const splideInstance = existingSplide.splide; 493 if (splideInstance) { 494 splideInstance.destroy(); 495 } 496 // å ã®ã«ã¼ãæ§é ã«åçæï¼PCæã¯4ä»¶ã«å¶éï¼ 497 container.innerHTML = ''; 498 getFilteredEventList().slice(0, 4).forEach(function(event) { 499 const card = createEventCard(event); 500 container.appendChild(card); 501 }); 502 // æ¥ä»ã»ã¯ã·ã§ã³ã®é«ããæãã 503 setTimeout(function() { 504 alignDateHeights(container); 505 }, 100); 506 } else { 507 // Splideãåæåããã¦ããªãå ´åãé«ããæãã 508 setTimeout(function() { 509 alignDateHeights(container); 510 }, 100); 511 } 512 } 513 } 514 }, 250); 515 }); 516})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.