Я создаю динамический блок (просмотр с помощью PHP). Мне нужен атрибут data-align. Чтобы получить атрибут выравнивания данных в PHP, я создаю атрибут…
function capacity_after_setup_theme() {
add_theme_support( 'align-wide' );
}
add_action( 'after_setup_theme', 'capacity_after_setup_theme' );
supports: {
align: ["full"]
},
blockWith() {
var wrap = document.querySelector(
'[data-type="capacity/employee-skills"]'
);
if (
wrap.getAttribute("data-align") != "full" &&
this.props.attributes.isFullWidth
)
wrap.setAttribute("data-align", "full");
var config = { attributes: true, childList: false };
var callback = function(mutationsList) {
for (var mutation of mutationsList) {
if (
mutation.type == "attributes" &&
mutation.attributeName == "data-align"
) {
if (wrap.hasAttribute("data-align"))
this.props.setAttributes({ isFullWidth: true });
else this.props.setAttributes({ isFullWidth: true });
}
}
};
var observer = new MutationObserver(callback);
observer.observe(wrap, config);
}
разве нет более чистого способа сделать это?