Last active
January 5, 2024 07:21
-
-
Save wpeasy/1bc8aae4b9f4841d164a0e543aef8f4b to your computer and use it in GitHub Desktop.
Bricks Default Colors to a List
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
<?php | |
add_action('get_footer', function(){ | |
if (!class_exists('Bricks\Capabilities')) { | |
return; | |
} | |
if( !bricks_is_builder() ) return; | |
?> | |
<script> | |
;(()=>{ | |
function maybeSetColorsToList(element) { | |
const trigger = element.querySelector('ul'); | |
const isTarget = trigger.classList.contains("color-palette") && trigger.classList.contains("grid"); | |
if(!isTarget){ return } | |
/* Is in Grid mode click the switch */ | |
const mode_switch = element.querySelector('.label-actions > *:last-child'); | |
mode_switch.click(); | |
} | |
window.addEventListener('load', ()=>{ | |
const targetElement = document.querySelector('.bricks-panel'); | |
const observer = new MutationObserver((mutationsList, observer) => { | |
/*console.log(mutationsList);*/ | |
for (const mutation of mutationsList) { | |
if (mutation.type === 'childList') { | |
for (const addedNode of mutation.addedNodes) { | |
if (addedNode.classList && addedNode.classList.contains('bricks-control-popup')) { | |
maybeSetColorsToList(addedNode); | |
} | |
} | |
} | |
} | |
}); | |
if(targetElement){ | |
observer.observe(targetElement, { attributes: true, childList: true, subtree: true }); | |
} | |
}) | |
})(); | |
</script> | |
<?php | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment