1/** 2 * ã¬ãã£ã°ã«ã¼ãã«ã«ã¼ã»ã«ã® Swiper åæå + destroy 管ç 3 * 4 * å 㯠resources/views/components/gacha-group-carousel.blade.php L53-131 ã® @once scriptã 5 * å·®åãªãã¼ã (fragment swap) ã§æ°è¦ã«ã«ã¼ã»ã«ã® init + æ§ã«ã«ã¼ã»ã«ã® destroy ãè¡ããã 6 * å¤é¨ JS åãSwiper ã¤ã³ã¹ã¿ã³ã¹ leak (spec-reviewer [é大] #2) ã®è§£æ¶ã 7 * 8 * å ¬é API: 9 * - window.GachaGroupCarousel.initAll(root?) â root ã¹ã³ã¼ãå ã®æª init ã«ã«ã¼ã»ã«ã init 10 * - window.GachaGroupCarousel.destroyRemoved(root?) â root ã¹ã³ã¼ãå ã® disconnected 㪠11 * Swiper ã¤ã³ã¹ã¿ã³ã¹ã destroy ã㦠Map ããåé¤ 12 * 13 * åªçå: 14 * - window.__GACHA_GROUP_CAROUSEL_LOADED__ ã¬ã¼ãã§ module äºéãã¼ã鲿¢ 15 * - åè¦ç´ ã« data-swiperInitialized="1" ãã¼ã«ã¼ + Map<Element, Swiper> ã§ã¤ã³ã¹ã¿ã³ã¹ç®¡ç 16 * 17 * ã¤ãã³ã: 18 * - top:gacha-list-will-swap â swap å hook: æ¶ããäºå®ã® Swiper ã¤ã³ã¹ã¿ã³ã¹ã destroy 19 * - top:gacha-list-updated â swap å¾ hook: æ°è¦ã«ã«ã¼ã»ã«ã init 20 * 21 * Spec: docs/features/top-main-gacha-partial-reload/spec.md §3.D-2 22 */ 23(function () { 24 if (window.__GACHA_GROUP_CAROUSEL_LOADED__) return; 25 window.__GACHA_GROUP_CAROUSEL_LOADED__ = true; 26 27 // Swiper ã¤ã³ã¹ã¿ã³ã¹ç®¡ç: DOM element â Swiper instance 28 // swap åã« destroy(true, true) ãå¼ã¶ããã« instance ãä¿æãã 29 var instances = new Map(); 30 31 function setupSwipeHint(el, swiper) { 32 if (swiper.slides.length < 2) { 33 return; 34 } 35 el.classList.add('swipe-hint-active'); 36 var stopHint = function () { 37 el.classList.remove('swipe-hint-active'); 38 }; 39 swiper.once('touchStart', stopHint); 40 swiper.once('slideChange', stopHint); 41 } 42 43 function initOne(el) { 44 if (el.dataset.swiperInitialized === '1') { 45 return; 46 } 47 el.dataset.swiperInitialized = '1'; 48 49 try { 50 var wrapper = el.closest('.gacha-group-carousel'); 51 var params = { 52 centeredSlides: true, 53 slidesPerView: 1.05, 54 spaceBetween: 12, 55 loop: false 56 }; 57 58 var paginationEl = wrapper ? wrapper.querySelector('.gacha-group-carousel-pagination') : null; 59 if (paginationEl) { 60 params.pagination = { 61 el: paginationEl, 62 clickable: true 63 }; 64 } 65 66 var nextEl = el.querySelector('.swiper-button-next'); 67 var prevEl = el.querySelector('.swiper-button-prev'); 68 if (nextEl && prevEl) { 69 params.navigation = { 70 nextEl: nextEl, 71 prevEl: prevEl 72 }; 73 } 74 75 var swiper = new Swiper(el, params); 76 instances.set(el, swiper); 77 78 setupSwipeHint(el, swiper); 79 } catch (e) { 80 // 1 ä»¶ã® init 失æãä»ã®ã«ã«ã¼ã»ã«ã® init ãå·»ãè¾¼ã¾ãªãããã«ãã 81 } 82 } 83 84 function initAll(root) { 85 if (typeof Swiper === 'undefined') { 86 // Swiper JS ãèªã¿è¾¼ããªãã£ãå ´å㯠CSS ãã©ã¼ã«ããã¯ï¼æ¨ªã¹ã¯ãã¼ã«ï¼ã«ä»»ãã 87 return; 88 } 89 var scope = root || document; 90 scope.querySelectorAll('.gacha-group-carousel-swiper').forEach(initOne); 91 } 92 93 function destroyOne(el) { 94 var swiper = instances.get(el); 95 if (swiper && typeof swiper.destroy === 'function') { 96 try { 97 swiper.destroy(true, true); 98 } catch (e) { 99 // destroy 失æãã¦ã Map ããåé¤ã¯è¡ã (leak 鲿¢) 100 } 101 } 102 instances.delete(el); 103 } 104 105 function destroyRemoved(root) { 106 // root é ä¸ (== ãããã swap ã§æ¶ãã container) å ã® Swiper ã¤ã³ã¹ã¿ã³ã¹ãå ¨ã¦ destroy 107 // container.innerHTML = '' ã®åã«å¼ã¶ãã¨ã§ DOM åç §ãçãã¦ãããã¡ã« destroy ã§ãã 108 var scope = root || document; 109 scope.querySelectorAll('.gacha-group-carousel-swiper').forEach(destroyOne); 110 } 111 112 // å ¬é API 113 window.GachaGroupCarousel = { 114 initAll: initAll, 115 destroyRemoved: destroyRemoved, 116 }; 117 118 // åæãã¼ãæã®èªå init (å ã® script ã window load ãå¾ ã£ã¦ããã®ã§åã¿ã¤ãã³ã°ã§å®è¡) 119 if (document.readyState === 'complete') { 120 initAll(); 121 } else { 122 window.addEventListener('load', function () { initAll(); }, { once: true }); 123 } 124 125 // swap å hook: æ¶ãã container å ã® Swiper ã¤ã³ã¹ã¿ã³ã¹ã de
125stroy 126 document.addEventListener('top:gacha-list-will-swap', function (e) { 127 var root = (e && e.detail && e.detail.container) ? e.detail.container : null; 128 if (root) destroyRemoved(root); 129 }); 130 131 // swap å¾ hook: æ°è¦ã«ã«ã¼ã»ã«ã init 132 document.addEventListener('top:gacha-list-updated', function (e) { 133 var root = (e && e.detail && e.detail.container) ? e.detail.container : document; 134 initAll(root); 135 }); 136})();
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.