1// Thay thế toà n bá» ná»i dung file article-image.js bằng Äoạn nà y (Version 10) 2 3(function($) { 4 5 // Äảm bảo mã chá» chạy khi DOM Äã sẵn sà ng (jQuery ready) 6 $(document).ready(function () { 7 8 // --- BƯá»C 0: KIá»M TRA FANCYBOX Äà TẢI CHƯA --- 9 if (typeof Fancybox === 'undefined' || typeof Fancybox.show !== 'function') { 10 console.error("Lá»i: Fancybox V4 chưa ÄÆ°á»£c tải hoặc không ÄÆ°á»£c Äá»nh nghÄ©a khi DOM Äã sẵn sà ng. Vui lòng kiá»m tra lại thứ tá»± tải file fancybox.umd.js."); 11 return; 12 } 13 14 const imageBlockSelector = '.news-details__content table.center'; 15 16 // --- BƯá»C 1: Thu tháºp dữ liá»u Gallery và gắn data-index --- 17 const galleryData = []; 18 const imageBlocks = document.querySelectorAll(imageBlockSelector); 19 20 imageBlocks.forEach(function(table, index) { 21 const img = table.querySelector('img'); 22 const captionElement = table.querySelector(".image_desc p"); 23 24 if (img) { 25 const imageUrl = img.src; 26 const captionText = captionElement ? captionElement.textContent.trim() : ''; 27 28 // Thêm dữ liá»u và o mảng cho FancyBox.show() 29 galleryData.push({ 30 src: imageUrl, 31 caption: captionText 32 }); 33 34 // Gán data-index và o TABLE 35 table.setAttribute('data-index', index); 36 } 37 }); 38 39 // --- BƯá»C 2: Gán sá»± kiá»n click --- 40 41 // Loại bá» tất cả các sá»± kiá»n click FancyBox hoặc click cÅ© trên các phần tá» nà y 42 $(imageBlockSelector).off('click.fancybox').off('click').find('img').off('click.fancybox').off('click'); 43 44 // Gắn sá»± kiá»n click má»i và o tất cả các bảng ảnh 45 $(imageBlockSelector).on('click', function(e) { 46 47 // NgÄn chặn hà nh vi mặc Äá»nh và lan truyá»n sá»± kiá»n 48 e.preventDefault(); 49 e.stopPropagation(); 50 51 // Lấy ra phần tá» bảng (table) gần nhất Äã ÄÆ°á»£c gán data-index 52 const clickedTable = $(e.currentTarget).closest(imageBlockSelector + '[data-index]'); 53 54 if (clickedTable.length) { 55 const clickedIndex = parseInt(clickedTable.attr('data-index')); 56 57 // Má» FancyBox V4 bằng API Fancybox.show() 58 Fancybox.show(galleryData, { 59 startIndex: clickedIndex, // Má» Äúng ảnh ÄÆ°á»£c click 60 groupAll: true, 61 hash: false, 62 selector: false 63 }); 64 } 65 }); 66 67 console.log(`[article-image.js Fix V10] Äã thiết láºp lại FancyBox cho ${galleryData.length} ảnh.`) 68 }); 69 70})(jQuery);
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.