Question 1
I'm conditionally displaying a customizer notification on a control depending on the value of another control. When the notification is visible I'd like to be able to disable (not deactivate) the control too so users can still see it but not interact with it.
Is this possible?
// JavaScript that runs on the customizer panel
( function( $, api ) {
'use strict';
api.control( 'sidebar_width', function(control) {
var showSidebarWidthNotification = function() {
var iFrameWidth = parseInt($('#customize-preview').width());
var responsiveWidth = api( 'sidebar_width' )._value);
var code = 'test_responsive_width';
/* show notification under the primary sidebar width slider if the site is in responsive mode as changing the sliders won't have any effect */
if( iFrameWidth <= responsiveWidth ) {
control.setting.notifications.add( code, new wp.customize.Notification(
code,
{
type: 'info',
message: 'Sidebar sliders won\'t have any visual effect when responsive layout is active.'
}
));
} else {
control.setting.notifications.remove( code );
}
};
// events to listen for (and run on customizer load)
showSidebarWidthNotification();
api( 'responsive_width' ).bind( function() {
showSidebarWidthNotification();
});
$(window).resize(function() {
showSidebarWidthNotification();
});
});
}( jQuery, wp.customize ) );
Question 2
When deactivating a control is it possible to still show a notification for it? e.g. "The [name] control is hidden as it doesn't apply to archive pages."
The code below shows how I'm hiding controls but I'd also like to be able to show a notification for hidden controls to explain why they are no longer visible.
( function( $, api ) {
'use strict';
// display sidebar width controls depending on current column layout
api( 'column_layout', function( setting ) {
api.control( 'sidebar_width', function(control) {
var displaySidebarWidth = function() {
var columnLayout = setting.get();
return columnLayout > 1 ? true : false;
}
var setActiveState = function() {
control.active.set( displaySidebarWidthr );
}
control.active.validate = displaySidebarWidth;
setActiveState();
setting.bind( setActiveState );
};
});
}( jQuery, wp.customize ) );
I know I could get round this by creating a 'dummy' control that renders no UI directly and only acts as a hook to display notifications but it's a bit of a hack.
Question 3
Finally, is it possible to alter the rendering location of a notification? By default it's rendered directly underneath a controls label. It would be more flexible if you could choose to render a notification before/after the control UI too.