theme-customizer-controls.js
13.1 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
(function($){
$( document ).ready( function() {
var ET_Select_Image = function(element, options){
this.element = element;
this.custom_select_link = null;
this.custom_dropdown = null;
this.frontend_customizer = $('body').hasClass( 'et_frontend_customizer' ) ? true : false;
this.options = jQuery.extend({}, this.defaults, options);
this.create_dropdown();
}
if ( typeof window.location.search !== 'undefined' && window.location.search.search( 'et_customizer_option_set=module' ) !== -1 ) {
$( 'body' ).addClass( 'et_modules_customizer_option_set' );
} else {
$( 'body' ).addClass( 'et_theme_customizer_option_set' );
}
ET_Select_Image.prototype = {
defaults: {
apply_value_to : 'body'
},
create_dropdown: function(){
var $et_select_image_main_select = this.element,
et_filter_options_html = '',
$selected_option,
$dropdown_selected_option,
self = this;
if ( $et_select_image_main_select.length ) {
$et_select_image_main_select.hide().addClass( 'et_select_image_main_select' );
$et_select_image_main_select.change( $.proxy( self.change_option, self ) );
$et_select_image_main_select.find( 'option' ).each( function() {
var $this_option = $(this),
selected = $(this).is( ':selected' ) ? ' class="et_select_image_active"' : '',
option_class = 0 === $this_option.attr( 'value' ).indexOf( '_' ) ? $this_option.attr( 'value' ) : '_' + $this_option.attr( 'value' );
et_filter_options_html += '<li class="et_si' + option_class + '_column" data-value="' + $this_option.attr( 'value' ) + '"' + selected +'>' + $this_option.text() + '</li>';
} );
$et_select_image_main_select.after( '<a href="#" class="et_select_image_custom_select">' + '<span class="et_filter_text"></span>' + '</a>' + '<ul class="et_select_image_options '+ self.esc_classname( $et_select_image_main_select.attr('data-customize-setting-link') ) +'">' + et_filter_options_html + '</ul>' );
}
this.custom_select_link = $et_select_image_main_select.next( '.et_select_image_custom_select' );
this.custom_dropdown = this.custom_select_link.next('.et_select_image_options');
$selected_option = $et_select_image_main_select.find( ':selected' );
if ( $selected_option.length ) {
var selected_option_class = 0 === $selected_option.attr( 'value' ).indexOf( '_' ) ? $selected_option.attr( 'value' ) : '_' + $selected_option.attr( 'value' );
this.custom_select_link.find('.et_filter_text').text( $selected_option.text() ).addClass( 'et_si' + selected_option_class + '_column' );
$dropdown_selected_option = ( $selected_option.val() == 'none' ) ? this.custom_dropdown.find('li').eq(0) : this.custom_dropdown.find('li[data-value="' + $selected_option.text() + '"]');
this.custom_select_link.find('.et_filter_text').addClass( $dropdown_selected_option.attr('class') ).attr( 'data-si-class', $dropdown_selected_option.attr('class') );
$dropdown_selected_option.addClass( 'et_select_image_active' );
}
this.custom_select_link.click( $.proxy( self.open_dropdown, self ) );
this.custom_dropdown.find('li').click( $.proxy( self.select_option, self ) );
},
open_dropdown: function(event) {
var self = this,
$this_link = $(event.target);
if ( self.custom_dropdown.hasClass( 'et_select_image_open' ) ) return false;
self.custom_dropdown.show().addClass( 'et_select_image_open' );
$this_link.hide();
return false;
},
select_option: function(event) {
var self = this,
$this_option = $(event.target),
this_option_value = $this_option.attr('data-value'),
$main_text = self.custom_select_link.find( '.et_filter_text' ),
$main_select_active_element = self.element.find( 'option[value="' + this_option_value + '"]' );
if ( $this_option.hasClass( 'et_select_image_active' ) ) {
self.close_dropdown();
return false;
}
$this_option.siblings().removeClass( 'et_select_image_active' );
$main_text.removeClass(function(index, css){
return (css.match(/\bet_si_\S+/g) || []).join(' ')
});
$main_text.addClass( $this_option.attr( 'class' ) ).attr( 'data-si-class', $this_option.attr( 'class' ) );
$this_option.addClass('et_select_image_active');
self.close_dropdown();
if ( ! $main_select_active_element.length )
self.element.val( 'none' ).trigger( 'change' );
else
self.element.val( this_option_value ).trigger( 'change' );
return false;
},
close_dropdown: function() {
this.custom_select_link.find( '.et_filter_text' ).show();
this.custom_dropdown.hide().removeClass( 'et_select_image_open' );
},
change_option: function() {
var self = this,
$active_option = self.element.find('option:selected'),
active_option_value = $active_option.val(),
$this_option = this.custom_dropdown.find('li[data-value="' + active_option_value + '"]'),
$main_text = self.custom_select_link.find( '.et_filter_text' ),
main_text_si_class = $main_text.attr( 'data-si-class' );
// set correct custom dropdown values on first load
if ( this.custom_dropdown.find('li.et_select_image_active').data( 'value' ) !== active_option_value ) {
this.custom_dropdown.find('li').removeClass( 'et_select_image_active' );
$main_text.removeClass( main_text_si_class ).addClass( $this_option.attr( 'class' ) ).attr( 'data-si-class', $this_option.attr( 'class' ) );
$this_option.addClass('et_select_image_active');
}
},
esc_classname: function( option_value ) {
return 'et_si_' + option_value.replace(/[ +\/\[\]]/g,'_').toLowerCase();
}
}
$.fn.et_select_image = function(options){
new ET_Select_Image(this, options)
return this;
};
$('select[data-customize-setting-link="et_divi[footer_columns]"]').et_select_image({ apply_value_to: 'body' });
$( '.et_divi_reset_slider' ).click( function () {
var $this_input = $( this ).closest( 'label' ).find( 'input' ),
input_name = $this_input.data( 'customize-setting-link' ),
input_default = $this_input.data( 'reset_value' );
$this_input.val( input_default );
$this_input.change();
});
$( '#accordion-section-et_divi_mobile_tablet h3, #accordion-panel-et_divi_mobile h3' ).click( function () {
var $iframe_preview = $( '#customize-preview' );
$iframe_preview.removeClass( 'et_divi_phone et_divi_tablet' );
$iframe_preview.addClass( 'et_divi_tablet' );
});
$( '#accordion-section-et_divi_mobile_phone h3, #accordion-section-et_divi_mobile_menu h3' ).click( function () {
var $iframe_preview = $( '#customize-preview' );
$iframe_preview.removeClass( 'et_divi_phone et_divi_tablet' );
$iframe_preview.addClass( 'et_divi_phone' );
});
$( '.control-panel-back, .customize-panel-back' ).click( function () {
var $iframe_preview = $( '#customize-preview' );
$iframe_preview.removeClass( 'et_divi_phone et_divi_tablet' );
});
$( 'input[type=range]' ).on( 'mousedown', function() {
$( '.et_pb_range_tooltip' ).remove();
value = $( this ).attr( 'value' );
$( this ).parent().append( '<div class="et_pb_range_tooltip">' + value + '</div> ' );
$( this ).mousemove(function() {
value = $( this ).attr( 'value' );
$( '.et_pb_range_tooltip' ).text( value );
});
$( this ).mouseup(function() {
$( '.et_pb_range_tooltip' ).fadeOut( 'fast' );
});
$( this ).mousedown(function() {
$( '.et_pb_range_tooltip' ).fadeIn( 'fast' );
});
});
$('input.et_font_style_checkbox[type=checkbox]').live('change', function(){
var $this_el = $(this),
$main_option = $this_el.closest( 'span' ).siblings( 'input.et_font_styles' ),
value = $this_el.val(),
current_value = $main_option.val(),
values = ( current_value != 'false' ) ? current_value.split( '|' ) : [],
query = $.inArray( value, values ),
result = '';
if ( $this_el.prop('checked' ) == true ) {
if ( current_value.length ) {
if ( query < 0 ) {
values.push( value );
result = values.join( '|' );
}
} else {
result = value;
}
} else {
if ( current_value.length !== 0 ) {
if ( query >= 0 ) {
values.splice( query, 1 );
result = values.join( '|' );
} else {
result = current_value;
}
}
}
$main_option.val( result ).trigger( 'change' );
});
$( 'span.et_font_style' ).click( function() {
var style_checkbox = $( this ).find( 'input' );
$( this ).toggleClass( 'et_font_style_checked' );
if ( style_checkbox.is( ':checked' ) ) {
style_checkbox.prop( 'checked', false );
} else {
style_checkbox.prop( 'checked', true );
}
style_checkbox.change();
});
var $vertical_nav_input = $( '#customize-control-et_divi-vertical_nav input[type=checkbox]' ),
$nav_fullwidth_control = $( '#customize-control-et_divi-nav_fullwidth' ),
$hide_navigation_until_scroll_control = $('#customize-control-et_divi-hide_nav');
if ( $vertical_nav_input.is( ':checked') ) {
$nav_fullwidth_control.hide();
$hide_navigation_until_scroll_control.hide();
} else {
$nav_fullwidth_control.show();
$hide_navigation_until_scroll_control.show();
}
$('#customize-theme-controls').on( 'change', '#customize-control-et_divi-vertical_nav input[type=checkbox]', function(){
$input = $(this);
if ( $input.is(':checked') ) {
$nav_fullwidth_control.hide();
$hide_navigation_until_scroll_control.hide();
} else {
$nav_fullwidth_control.show();
$hide_navigation_until_scroll_control.show();
}
});
function toggle_sidebar_width_control() {
$checkbox = $('#customize-control-et_divi-use_sidebar_width input[type="checkbox"]'),
$sidebar_width_control = $( '#customize-control-et_divi-sidebar_width' );
if ( $checkbox.is( ':checked' ) ) {
$sidebar_width_control.fadeIn();
} else {
$sidebar_width_control.fadeOut();
}
}
toggle_sidebar_width_control();
$('#customize-theme-controls').on( 'change', '#customize-control-et_divi-use_sidebar_width input[type=checkbox]', function(){
toggle_sidebar_width_control();
});
});
var api = wp.customize;
api.ET_ColorAlphaControl = api.Control.extend({
ready: function() {
var control = this,
picker = control.container.find('.color-picker-hex');
picker.val( control.setting() ).wpColorPicker({
change: function() {
control.setting.set( picker.wpColorPicker('color') );
},
clear: function() {
control.setting.set( false );
}
});
control.setting.bind( function( value ) {
picker.val( value );
picker.wpColorPicker( 'color', value );
});
/**
* Adding following event whenever footer_menu_text_color is changed, due to its relationship with footer_menu_active_link_color.
*/
if ( 'et_divi[footer_menu_text_color]' === this.id ) {
// Whenever user change footer_menu_text_color, do the following
this.setting.bind( 'change', function( value ){
// Set footer_menu_active_link_color equal to the newly changed footer_menu_text_color
api( 'et_divi[footer_menu_active_link_color]' ).set( value );
// Update default color of footer_menu_active_link_color equal to the newly changed footer_menu_text_color.
// If afterward user change the color and not happy with it, they can click reset and back to footer_menu_text_color color
api.control( 'et_divi[footer_menu_active_link_color]' ).container.find( '.color-picker-hex' )
.data( 'data-default-color', value )
.wpColorPicker({ 'defaultColor' : value, 'color' : value });
});
}
}
});
$( 'body' ).on( 'click', '.et_font_icon li', function() {
var $this_el = $( this ),
$this_input;
if ( ! $this_el.hasClass( 'active' ) ) {
$( '.et_font_icon li' ).removeClass( 'et_active' );
$this_el.addClass( 'et_active' );
$this_input = $this_el.closest( 'label' ).find( '.et_selected_icon' );
$this_input.val( $this_el.data( 'icon' ) );
$this_input.change();
}
});
api.controlConstructor['et_coloralpha'] = api.ET_ColorAlphaControl;
$( window ).load( function() {
if ( $( '#accordion-section-et_divi_buttons' ).length ) {
var $icon_options_trigger = $( '#customize-control-et_divi-all_buttons_icon select' ),
icon_options_trigger_val = $icon_options_trigger.val();
trigger_button_options( icon_options_trigger_val );
$icon_options_trigger.change( function() {
icon_options_trigger_val = $( this ).val();
trigger_button_options( icon_options_trigger_val );
});
}
function trigger_button_options( trigger_val ) {
var icon_options_set = [ 'all_buttons_icon_color', 'all_buttons_icon_placement', 'all_buttons_icon_hover', 'all_buttons_selected_icon' ];
$.each( icon_options_set, function( i, option_name ) {
if ( 'yes' === trigger_val ) {
$( '#customize-control-et_divi-' + option_name ).show();
} else {
$( '#customize-control-et_divi-' + option_name ).hide();
}
} );
}
if ( $( '.et_font_icon' ).length ) {
$( '.et_font_icon' ).each( function(){
var $this_el = $( this ),
this_input_val = $this_el.closest( 'label' ).find( '.et_selected_icon' ).val();
$this_el.find( 'li[data-icon="' + this_input_val + '"]').addClass( 'et_active' );
});
}
} );
})(jQuery)