admin管理员组文章数量:1130349
I am trying to send data from customize control to customize previewer. The scripts work fine until the customize previewer is refresh. The problem is only the previewer is refresh, the customize control won't send the data again, so there is no data for previewer to get and perform actions. Is there a way for customize control to send data again every time the previewer has been refresh? Here are my scripts: customize-preview.js
(function ($) {
wp.customize.bind('preview-ready', function () {
console.log('Previewer is ready');
wp.customize.preview.bind('widget-show-name', function (data) {
showWidgetName(data);
showWidgetOutline(data);
});
function showWidgetName(widgetId) {
//Find the widget span
let $widget = $('body').find('[data-customize-partial-id="widget[' + widgetId + ']"]');
//Get its name
let name = $widget.data('customize-widget-name');
//Show the name
if (name && !$widget.find('.widget__text').length) {
$widget.prepend('<span class="widget__text"><strong>Editing</strong>: ' + name + '</span>');
}
}
function showWidgetOutline(widgetId) {
//Find the widget area
let $widget = $('body').find('#' + widgetId);
//Highlight it when mouse enters and remove when mouse leaves
$($widget).on({
mouseenter: function () {
$widget.addClass('widget-customizer-highlighted-widget');
},
mouseleave: function () {
$widget.removeClass('widget-customizer-highlighted-widget');
}
})
}
});})(jQuery);
customize-controls.js
(function ($) {
wp.customize.bind('ready', function () {
console.log('Control is ready.');
wp.customize.control.bind('change', function (widget) {
let widgetIdArray = widget.selector.split('_');
widgetIdArray.splice(0, 1);
let widgetId = widgetIdArray.join('_');
wp.customize.previewer.send('widget-show-name', widgetId);
});
});})(jQuery);
I am trying to send data from customize control to customize previewer. The scripts work fine until the customize previewer is refresh. The problem is only the previewer is refresh, the customize control won't send the data again, so there is no data for previewer to get and perform actions. Is there a way for customize control to send data again every time the previewer has been refresh? Here are my scripts: customize-preview.js
(function ($) {
wp.customize.bind('preview-ready', function () {
console.log('Previewer is ready');
wp.customize.preview.bind('widget-show-name', function (data) {
showWidgetName(data);
showWidgetOutline(data);
});
function showWidgetName(widgetId) {
//Find the widget span
let $widget = $('body').find('[data-customize-partial-id="widget[' + widgetId + ']"]');
//Get its name
let name = $widget.data('customize-widget-name');
//Show the name
if (name && !$widget.find('.widget__text').length) {
$widget.prepend('<span class="widget__text"><strong>Editing</strong>: ' + name + '</span>');
}
}
function showWidgetOutline(widgetId) {
//Find the widget area
let $widget = $('body').find('#' + widgetId);
//Highlight it when mouse enters and remove when mouse leaves
$($widget).on({
mouseenter: function () {
$widget.addClass('widget-customizer-highlighted-widget');
},
mouseleave: function () {
$widget.removeClass('widget-customizer-highlighted-widget');
}
})
}
});})(jQuery);
customize-controls.js
(function ($) {
wp.customize.bind('ready', function () {
console.log('Control is ready.');
wp.customize.control.bind('change', function (widget) {
let widgetIdArray = widget.selector.split('_');
widgetIdArray.splice(0, 1);
let widgetId = widgetIdArray.join('_');
wp.customize.previewer.send('widget-show-name', widgetId);
});
});})(jQuery);
本文标签: javascriptHow to check if customize previewer is refreshing
版权声明:本文标题:javascript - How to check if customize previewer is refreshing? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749085523a2313710.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论