Created
October 25, 2023 10:30
-
-
Save davidpmccormick/bb91d4ca72912674dfa9e836e55ab148 to your computer and use it in GitHub Desktop.
Wraps the items from a Prismic repeating group field in a details/summary for easier re-ordering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let widgetGroups = document.querySelectorAll('.widget-Group'); | |
[...widgetGroups].forEach(widgetGroup => { | |
let groupWrapper = widgetGroup.querySelector('.group-wrapper'); | |
let standaloneTitle = groupWrapper.querySelector('[data-widget-key="standaloneTitle"] .ProseMirror').textContent; | |
let title = groupWrapper.querySelector('[data-widget-key="title"] .ProseMirror').textContent; | |
let tools = widgetGroup.querySelector('.tools'); | |
tools.style.top = "0"; | |
let detailsNode = document.createElement('details'); | |
detailsNode.style.padding = "20px 0"; | |
let summaryNode = document.createElement('summary'); | |
summaryNode.innerHTML = standaloneTitle || title; | |
detailsNode.appendChild(summaryNode); | |
groupWrapper.parentNode.insertBefore(detailsNode, groupWrapper); | |
detailsNode.appendChild(groupWrapper); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment