1/** 2 * Articles archive: progressive reveal (load more). 3 */ 4(function () { 5 'use strict'; 6 7 var MOBILE_MQ = window.matchMedia('(max-width: 767px)'); 8 9 function getLimit(list) { 10 var desktop = parseInt(list.getAttribute('data-desktop-limit'), 10) || 12; 11 var mobile = parseInt(list.getAttribute('data-mobile-limit'), 10) || 8; 12 13 return MOBILE_MQ.matches ? mobile : desktop; 14 } 15 16 function getArticles(list) { 17 return Array.prototype.slice.call(list.querySelectorAll('.articles__element')); 18 } 19 20 function sync(list, button, visible) { 21 var limit = getLimit(list); 22 var articles = getArticles(list); 23 var articleCount = 0; 24 25 if (visible < limit) { 26 visible = limit; 27 } 28 29 Array.prototype.forEach.call(list.children, function (child) { 30 if (child.classList.contains('articles__element')) { 31 articleCount += 1; 32 33 if (articleCount > visible) { 34 child.classList.add('is-hidden'); 35 } else { 36 child.classList.remove('is-hidden'); 37 } 38 39 return; 40 } 41 42 if (child.classList.contains('articles__inline-form')) { 43 if (articleCount > 0 && articleCount <= visible) { 44 child.classList.remove('is-hidden'); 45 } else { 46 child.classList.add('is-hidden'); 47 } 48 } 49 }); 50 51 if (button) { 52 button.hidden = visible >= articles.length; 53 } 54 55 list.setAttribute('data-visible', String(visible)); 56 } 57 58 function getVisible(list) { 59 var raw = parseInt(list.getAttribute('data-visible'), 10); 60 return raw > 0 ? raw : getLimit(list); 61 } 62 63 function initList(list) { 64 var wrap = list.parentElement; 65 var button = wrap 66 ? wrap.querySelector('[data-articles-load-more-btn]') 67 : null; 68 69 sync(list, button, getLimit(list)); 70 71 if (button) { 72 button.addEventListener('click', function (event) { 73 event.preventDefault(); 74 sync(list, button, getVisible(list) + getLimit(list)); 75 }); 76 } 77 78 var onChange = function () { 79 sync(list, button, getVisible(list)); 80 }; 81 82 if (typeof MOBILE_MQ.addEventListener === 'function') { 83 MOBILE_MQ.addEventListener('change', onChange); 84 } else if (typeof MOBILE_MQ.addListener === 'function') { 85 MOBILE_MQ.addListener(onChange); 86 } 87 } 88 89 function initAll() { 90 document.querySelectorAll('[data-articles-load-more]').forEach(initList); 91 } 92 93 if (document.readyState === 'loading') { 94 document.addEventListener('DOMContentLoaded', initAll); 95 } else { 96 initAll(); 97 } 98})();
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.