1/** 2 * Load More Auto Initialization 3 * 4 * data屿§ãã¼ã¹ã§èªåçã«LoadMoreãåæåãã¾ã 5 * 6 * ä½¿ç¨æ¹æ³: 7 * <div data-load-more 8 * data-load-more-api="/wp-json/madamefigaro/v1/tag-posts/fashion" 9 * data-load-more-template="post-item-template" 10 * data-load-more-offset="12" 11 * data-load-more-count="12" 12 * data-load-more-tag-count="2"> 13 * <!-- åææç¨¿ --> 14 * </div> 15 * 16 * <div class="c-btn-more"> 17 * <p class="c-btn-more__link">View More</p> 18 * </div> 19 * 20 * <script id="post-item-template" type="x-tmpl-mustache"> 21 * <!-- Mustacheãã³ãã¬ã¼ã --> 22 * </script> 23 * 24 * @package madameFIGARO.jp 25 */ 26 27document.addEventListener('DOMContentLoaded', function() { 28 // å¿ é ã©ã¤ãã©ãªã®ãã§ã㯠29 if (typeof Mustache === 'undefined' || typeof LoadMore === 'undefined') { 30 console.warn('LoadMore auto initialization: Mustache or LoadMore class not found'); 31 return; 32 } 33 34 // data-load-more屿§ãæã¤ãã¹ã¦ã®è¦ç´ ãåå¾ 35 const containers = document.querySelectorAll('[data-load-more]'); 36 37 containers.forEach(function(container) { 38 // data屿§ããè¨å®ãåå¾ 39 const apiUrl = container.getAttribute('data-load-more-api'); 40 const templateId = container.getAttribute('data-load-more-template'); 41 const offset = parseInt(container.getAttribute('data-load-more-offset'), 10) || 0; 42 const count = parseInt(container.getAttribute('data-load-more-count'), 10) || 12; 43 const tagCountAttr = container.getAttribute('data-load-more-tag-count'); 44 const tagCount = tagCountAttr !== null ? parseInt(tagCountAttr, 10) : 2; 45 const excludeTagsAttr = container.getAttribute('data-load-more-exclude-tags'); 46 const excludeTags = excludeTagsAttr ? excludeTagsAttr.split(',').map(s => s.trim()).filter(Boolean) : []; 47 const buttonSelector = container.getAttribute('data-load-more-button'); 48 49 // å¿ é ãã©ã¡ã¼ã¿ã®ãã§ã㯠50 if (!apiUrl || !templateId) { 51 console.warn('LoadMore auto initialization: Missing required data attributes (api or template)', container); 52 return; 53 } 54 55 // ãã¿ã³è¦ç´ ãåå¾ 56 let button; 57 if (buttonSelector) { 58 button = document.querySelector(buttonSelector); 59 } else { 60 // ããã©ã«ã: ã³ã³ããã®è¦ªè¦ç´ å ã§.c-btn-more__linkãæ¢ã 61 const parentSection = container.closest('.section') || container.closest('.author-posts') || container.parentElement; 62 if (parentSection) { 63 button = parentSection.querySelector('.c-btn-more__link, .load-more-button'); 64 } 65 } 66 67 if (!button) { 68 console.warn('LoadMore auto initialization: Button not found', container); 69 return; 70 } 71 72 // Mustacheãã³ãã¬ã¼ããåå¾ 73 const templateElement = document.getElementById(templateId); 74 if (!templateElement) { 75 console.warn('LoadMore auto initialization: Template not found', templateId); 76 return; 77 } 78 79 const template = templateElement.innerHTML; 80 81 // createItemHTML颿°ãçæ 82 function createItemHTML(post) { 83 // 対象ã¿ã°ãé¤å¤ãã¦ããã¿ã°è¡¨ç¤ºæ°ã§å¶é 84 let filteredTags = post.tags || []; 85 if (excludeTags.length > 0) { 86 filteredTags = filteredTags.filter(tag => !excludeTags.includes(tag.slug)); 87 } 88 const postData = { 89 ...post, 90 tags: (tagCount > 0 && filteredTags.length > 0) ? filteredTags.slice(0, tagCount) : [] 91 }; 92 93 return Mustache.render(template, postData); 94 } 95 96 // LoadMoreã¯ã©ã¹ãåæå 97 try { 98 new LoadMore({ 99 container: container, 100 button: button, 101 apiUrl: apiUrl, 102 createItemHTML: createItemHTML, 103 offset: offset, 104 perPage: count 105 }); 106 } catch (error) { 107 console.error('LoadMore initialization failed:', error); 108 } 109 }); 110});
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.