Basically what this code does is to trigger clicks on Advanced Themer’s Elements Shortcuts and drastically speeds up your workflow.
Limitations
It doesn’t work when you have an empty page, where there is no elements on structure panel (i didn’t bother to figure out why) so you can add a section the old way and then start using the shortcuts.
Made some modifications to avoid JS errors on pages outside Bricks builder:
document.addEventListener('keydown', function(event) {
// Check if Shift key is pressed
if (getUrlParameter('bricks') === 'run') {
if (event.shiftKey && !event.ctrlKey) {
// Check which key is pressed
switch(event.key) {
case 'S':
triggerClickAction('section');
break;
case 'B':
triggerClickAction('button');
break;
case 'D':
triggerClickAction('block');
break;
case 'H':
triggerClickAction('heading');
break;
case 'T':
triggerClickAction('text-basic');
break;
case 'I':
triggerClickAction('image');
break;
case 'K':
triggerClickAction('code');
break;
default:
//console.log("No action defined for Shift + " + event.key);
}
}
}
});
function triggerClickAction(dataName) {
// Select the element
var element = document.querySelector('.brxc-right-sidebar-shortcuts[data-name="' + dataName + '"]');
// Check if the element exists
if (element) {
// Trigger click action
element.click();
} else {
console.error("Element with data-name='" + dataName + "' not found");
}
}
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};
Yes. Well, it’s not something special that Hydrogen does. It’s the way Oxygen works. New elements automatically become active.
Still drives me mad that the newly added element is not active by default in Bricks. The native way of doing this by holding Shift down when an element is added.
In AT, holding shift + clicking the element icon on the right will set the newly created element as active. You can leverage that function in your JS code.
Yes, gave it a try. Couldn’t get the JS working. This is mainly for others who don’t use my custom Keyboard Maestro setup. Didn’t try harder and left it at that.