-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcustomizer-toggle-control.js
More file actions
38 lines (32 loc) · 1.25 KB
/
customizer-toggle-control.js
File metadata and controls
38 lines (32 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
* Script run inside a Customizer control sidebar
*
* Enable / disable the control title by toggeling its .disabled-control-title style class on or off.
*/
( function( $ ) {
wp.customize.bind( 'ready', function() { // Ready?
var customize = this; // Customize object alias.
//get the toggle controls
var toggleControls = $('.customize-toogle-label').parent();
var toggleControlIds = [];
//Segment in the id of the control that is added by wordpress, but not needed for our purpose
var idSegment = "customize-control-";
//fill the id array
for (var control of toggleControls){
//remove the segment from the control id
var controlId = control.id.substring(idSegment.length, control.id.length);
toggleControlIds.push(controlId);
}
$.each( toggleControlIds, function( index, control_name ) {
customize( control_name, function( value ) {
var controlTitle = customize.control( control_name ).container.find( '.customize-control-title' ); // Get control title.
// 1. On loading.
controlTitle.toggleClass('disabled-control-title', !value.get() );
// 2. Binding to value change.
value.bind( function( to ) {
controlTitle.toggleClass( 'disabled-control-title', !value.get() );
} );
} );
} );
} );
} )( jQuery );