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8B,EAAgBF,EAAkB7B,cAAc,iCAAiCN,aAAa,SACpGiB,EAAKE,OAAO,gBAAiBkB,GAE7BhB,MAAMP,EAAK,CACVQ,OAAQ,OACRC,KAAMN,IAELO,MAAMC,IACN,GAAIA,EAASC,GACZ,OAAOD,EAASa,OAEhB,MAAM,IAAIV,MAAM,8BACjB,IAEAJ,MAAMe,IACNH,EAAiBI,mBAAmB,cAAeD,EAAK,IAExDE,OAAOC,IACPC,QAAQD,MAAMA,EAAM,IAEpBE,SAAQ,KACRvC,EAAkBG,SAASC,IAC1BA,EAAMC,UAAUmC,IAAI,kBAAkB,GACrC,GAEL,CA7CCC,CAAYf,EAAOC,GAEnB,MACMe,EADc7C,SAAS8B,EAAOhC,aAAa,sBACZ+B,EAAMiB,OAC3ChB,EAAOiB,aAAa,oBAAqBF,EAC1C,CA1CKG,CAAYzB,EAASM,MAAOnC,EAC7B,IAEA6C,OAAOC,IACPC,QAAQD,MAAMA,EAAM,KAGtBrC,EAAkBG,SAASC,IAC1BA,EAAME,QAAQ,IAEff,EAAOuD,UAAYpC,QAAQqC,YAE7B,CAyEAC,SAASC,iBAAiB,oBAAoB,KAGrBC,MAAMC,KAAKH,SAASI,uBAAuB,0BAGnDjD,SAASwB,GAAWA,EAAOsB,iBAAiB,QAAS7D,IAAiB,G","sources":["webpack://modularity/./source/php/Module/Curator/assets/mod-curator-load-more.js"],"sourcesContent":["function loadMoreHandler(event) {\n\tevent.preventDefault();\n\n\tconst parent = event.target.closest('.mod-curator-load-more');\n\n\tconst embedCode = parent.getAttribute('data-code');\n\tconst itemCount = parseInt(parent.getAttribute('data-item-count'));\n\tconst itemsPerPage = parseInt(parent.getAttribute('data-items-per-page'));\n\tlet itemsLoaded = parseInt(parent.getAttribute('data-items-loaded'));\n\n\tconst grandParent = parent.closest('.modularity-socialmedia-container');\n\tconst socialMediaBlocks = grandParent.querySelector('.modularity-socialmedia__content');\n\tconst placeholderBlocks = socialMediaBlocks.querySelectorAll('.modularity-socialmedia__item--placeholder');\n\n\tplaceholderBlocks.forEach((block) => {\n\t\tblock.classList.remove('u-display--none');\n\t});\n\tif (itemsLoaded < itemCount) {\n\t\tgetFeed(embedCode, itemsPerPage, itemsLoaded)\n\t\t\t.then((response) => {\n\t\t\t\tif (response.success && response.posts) {\n\t\t\t\t\tupdateItems(response.posts, parent);\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch((error) => {\n\t\t\t\tconsole.error(error);\n\t\t\t});\n\t} else {\n\t\tplaceholderBlocks.forEach((block) => {\n\t\t\tblock.remove();\n\t\t});\n\t\tparent.innerHTML = curator.noMoreItems;\n\t}\n}\n\nfunction getFeed(embedCode, limit, offset) {\n\tconst url = curator.ajaxurl;\n\tconst data = new FormData();\n\n\tdata.append('action', 'mod_curator_get_feed');\n\tdata.append('nonce', curator.nonce);\n\tdata.append('embed-code', embedCode);\n\tdata.append('limit', limit);\n\tdata.append('offset', offset);\n\n\treturn fetch(url, {\n\t\tmethod: 'POST',\n\t\tbody: data,\n\t}).then((response) => {\n\t\tif (response.ok) {\n\t\t\treturn response.json();\n\t\t} else {\n\t\t\tthrow new Error('Network response was not ok');\n\t\t}\n\t});\n}\n\nfunction updateItems(posts, button) {\n\trenderPosts(posts, button);\n\n\tconst itemsLoaded = parseInt(button.getAttribute('data-items-loaded'));\n\tconst newItemsLoaded = itemsLoaded + posts.length;\n\tbutton.setAttribute('data-items-loaded', newItemsLoaded);\n}\n\nfunction renderPosts(posts, button) {\n\tconst url = curator.ajaxurl;\n\tconst data = new FormData();\n\n\tdata.append('action', 'mod_curator_load_more');\n\tdata.append('nonce', curator.nonce);\n\tdata.append('layout', button.getAttribute('data-layout'));\n\tdata.append('posts', JSON.stringify(posts));\n\n\tconst closestParent = button.closest('.modularity-socialmedia-container');\n\tconst socialMediaBlocks = closestParent.querySelector('.modularity-socialmedia__content');\n\tconst placeholderBlock = socialMediaBlocks.querySelector('.modularity-socialmedia__item--placeholder');\n\tconst placeholderBlocks = socialMediaBlocks.querySelectorAll('.modularity-socialmedia__item--placeholder');\n\tconst columnClasses = socialMediaBlocks.querySelector('.modularity-socialmedia__item').getAttribute('class');\n\tdata.append('columnClasses', columnClasses);\n\n\tfetch(url, {\n\t\tmethod: 'POST',\n\t\tbody: data,\n\t})\n\t\t.then((response) => {\n\t\t\tif (response.ok) {\n\t\t\t\treturn response.text();\n\t\t\t} else {\n\t\t\t\tthrow new Error('Network response was not ok');\n\t\t\t}\n\t\t})\n\t\t.then((html) => {\n\t\t\tplaceholderBlock.insertAdjacentHTML('beforebegin', html);\n\t\t})\n\t\t.catch((error) => {\n\t\t\tconsole.error(error);\n\t\t})\n\t\t.finally(() => {\n\t\t\tplaceholderBlocks.forEach((block) => {\n\t\t\t\tblock.classList.add('u-display--none');\n\t\t\t});\n\t\t});\n}\n\n\ndocument.addEventListener('DOMContentLoaded', () => {\n\n\t// Select all elements with class 'mod-curator-load-more' and convert the result to an array\n\tconst loadMoreButtons = Array.from(document.getElementsByClassName('mod-curator-load-more'));\n\n\t// Add the event listener to each button in the array\n\tloadMoreButtons.forEach((button) => button.addEventListener('click', loadMoreHandler));\n\n}); "],"names":["loadMoreHandler","event","preventDefault","parent","target","closest","embedCode","getAttribute","itemCount","parseInt","itemsPerPage","itemsLoaded","placeholderBlocks","querySelector","querySelectorAll","forEach","block","classList","remove","limit","offset","url","curator","ajaxurl","data","FormData","append","nonce","fetch","method","body","then","response","ok","json","Error","getFeed","success","posts","button","JSON","stringify","socialMediaBlocks","placeholderBlock","columnClasses","text","html","insertAdjacentHTML","catch","error","console","finally","add","renderPosts","newItemsLoaded","length","setAttribute","updateItems","innerHTML","noMoreItems","document","addEventListener","Array","from","getElementsByClassName"],"sourceRoot":""}