I had a project that relied heavily on the spacing options of areas, columns, and blocks and got tired of clicking through to see what was set on one column in order to set the same on another. So I made a little JS that runs when the page is in edit mode that shows the applied margins and padding, custom layout classes, and custom block classes above or below the particular area. Mine is super hacky (it will only work on an area name ‘Sections’). Is there a better way to do this (of course there is)? Can this be something to include on a future core release?
// JavaScript Document
$(document).ready(function(){
setTimeout(function(){
var cscontainers = $("[class*='ccm-custom-style-sections']");
var $toAppendBlockStyles;
var $toAppendLayoutStyles;
var $toAppendColumnStyles;
var $toAppendWrapperStyles;
var $toAppendCustomBlockClasses;
var $toAppendCustomLayoutClasses;
var $toAppendCustomColumnClasses;
var $toAppendCustomWrapperClasses;
var $toAppendCustomBlockTemplate;
var thisThing;
cscontainers.each(function() {
var el = $(this);
var classString = el.attr('class');
var classList = classString.split(/\s+/);
if( el.parent().hasClass('ccm-block-edit')) {
thisThing = 'block';
} else if ( el.parent().data('container') == 'block') {
thisThing = 'layout';
} else if ( el.data('area-handle').length > 8 ) {
thisThing = 'column';
console.log(el.data('area-handle').length)
} else if ( el.data('area-handle') == 'Sections' ) {
thisThing = 'wrapper';
}
$toAppendBlockStyles = '';
$toAppendLayoutStyles = '';
$toAppendColumnStyles = '';
$toAppendWrapperStyles = '';
$toAppendCustomBlockClasses = '';
$toAppendCustomLayoutClasses = '';
$toAppendCustomColumnClasses = '';
$toAppendCustomWrapperClasses = '';
$toAppendCustomBlockTemplate = '';
var cc = '';
var cbt = '';
classList.forEach(function(e){ //Loop Through Classes
if (!e.includes('ccm-custom-style-container') && !e.includes('container') && !e.includes('ccm-area') && !e.includes('ccm-layout-area') && !e.includes('ccm-parent-menu-item-hover') ) {
if (e.includes('ccm-custom-style-sections')) {
var mt,mr,mb,ml,pt,pr,pb,pl,bw,bs,bc;
var sp = '';
var customEl;
if (el.hasClass('ccm-custom-style-container')) {
customEl = '.ccm-custom-style-container.' + e;
} else {
customEl = '.' + e;
}
const styles = {};
for (let i = 0; i < document.styleSheets.length; i++) {
const sheet = document.styleSheets[i];
try { // Handle cross-origin stylesheet access issues
const rules = sheet.cssRules || sheet.rules;
if (rules) {
for (let j = 0; j < rules.length; j++) {
const rule = rules[j];
//if (rule.selectorText && rule.selectorText.includes(customEl)) {
if (rule.selectorText && rule.selectorText === customEl) {
// Extract relevant styles from the rule
// This example extracts all properties, you might want to filter
for (let k = 0; k < rule.style.length; k++) {
const propName = rule.style[k];
styles[propName] = rule.style.getPropertyValue(propName);
}
}
}
}
} catch (e) {
// console.warn("Cannot access stylesheet:", sheet.href, e);
}
}
if(styles['margin-top'] != undefined || styles['margin-right'] != undefined || styles['margin-bottom'] != undefined || styles['margin-left'] != undefined) {
mt = styles['margin-top'] == undefined ? '0px' : styles['margin-top'];
mr = styles['margin-right'] == undefined ? '0px' : styles['margin-right'];
mb = styles['margin-bottom'] == undefined ? '0px' : styles['margin-bottom'];
ml = styles['margin-left'] == undefined ? '0px' : styles['margin-left'];
sp += 'margin: ' + mt + ' ' + mr + ' ' + mb + ' ' + ml + '; ';
}
if(styles['padding-top'] != undefined || styles['padding-right'] != undefined || styles['padding-bottom'] != undefined || styles['padding-left'] != undefined) {
pt = styles['padding-top'] == undefined ? '0px' : styles['padding-top'];
pr = styles['padding-right'] == undefined ? '0px' : styles['padding-right'];
pb = styles['padding-bottom'] == undefined ? '0px' : styles['padding-bottom'];
pl = styles['padding-left'] == undefined ? '0px' : styles['padding-left'];
sp += 'padding: ' + pt + ' ' + pr + ' ' + pb + ' ' + pl + '; ';
}
if(styles['transform'] != undefined) {
sp += 'transform: ' + styles['transform'] + '; ';
}
if(styles['box-shadow'] != undefined) {
sp += 'box-shadow: ' + styles['box-shadow'] + '; ';
}
if(styles['border-top-width'] != undefined) {
bw = styles['border-top-width'];
bs = styles['border-top-style'];
bc = styles['border-top-color'];
sp += 'border: ' + bw + ' ' + bs + ' ' + bc + '; ';
}
if(styles['border-top-left-radius'] != undefined) {
sp += 'border-radius: ' + styles['border-top-left-radius'] + '; ';
}
} else {
if(e.includes('ccm-block-custom-template-')) {
cbt += e.replace('ccm-block-custom-template-', "") + ' ';
} else {
cc += e + ' ';
}
}
if (sp != undefined) {
if(thisThing == 'block') {
$toAppendBlockStyles += sp
} else if(thisThing == 'layout') {
$toAppendLayoutStyles += sp;
} else if(thisThing == 'column') {
$toAppendColumnStyles += sp;
} else if(thisThing == 'wrapper') {
$toAppendWrapperStyles += sp;
}
}
if (cc != undefined) {
if(thisThing == 'block') {
$toAppendCustomBlockClasses = cc
} else if(thisThing == 'layout') {
$toAppendCustomLayoutClasses = cc;
} else if(thisThing == 'column') {
$toAppendCustomColumnClasses = cc;
} else if(thisThing == 'wrapper') {
$toAppendCustomWrapperClasses = cc;
}
}
if (cbt != undefined) {
if(thisThing == 'block') {
$toAppendCustomBlockTemplate = cbt
}
}
}
});
if ($toAppendBlockStyles != '') {
el.after('<div class="hint-blockstyle">Block Styles: ' + $toAppendBlockStyles + '</div>');
}
if ($toAppendLayoutStyles != '') {
el.find('> div:first-child').after('<div class="hint-layoutstyle">Layout Styles: ' + $toAppendLayoutStyles + '</div>');
}
if ($toAppendColumnStyles != '') {
el.find('> .ccm-area-footer').prepend('<div class="hint-columnstyle">Column Styles: ' + $toAppendColumnStyles + '</div>');
}
if ($toAppendWrapperStyles != '') {
el.find('> .ccm-area-footer').prepend('<div class="hint-wrapperstyle">Wrapper Styles: ' + $toAppendWrapperStyles + '</div>');
}
if ($toAppendCustomBlockClasses != '') {
el.after('<div class="hint-customblockclasses">Custom Block Classes: ' + $toAppendCustomBlockClasses + '</div>');
}
if ($toAppendCustomLayoutClasses != '') {
el.find('> div:first-child').after('<div class="hint-customlayoutclasses">Custom Layout Classes: ' + $toAppendCustomLayoutClasses + '</div>');
}
if ($toAppendCustomColumnClasses != '') {
el.find('> .ccm-area-footer').prepend('<div class="hint-customcolumnclasses">Custom Column Classes: ' + $toAppendCustomColumnClasses + '</div>');
}
if ($toAppendCustomWrapperClasses != '') {
el.find('> .ccm-area-footer').prepend('<div class="hint-customwrapperclasses">Custom Wrapper Classes: ' + $toAppendCustomWrapperClasses + '</div>');
}
if ($toAppendCustomBlockTemplate != '') {
el.after('<div class="hint-customblocktemplate">Custom Block Template: ' + $toAppendCustomBlockTemplate + '</div>');
}
})
},300)
})


