| 1 |
|
| 2 |
/** |
| 3 |
* Function that initializes select2 on fields |
| 4 |
* |
| 5 |
* @since v.3.3.4 |
| 6 |
*/ |
| 7 |
function wppb_select2_initialize() { |
| 8 |
jQuery ( '.custom_field_select2' ).each( function(){ |
| 9 |
var selectElement = jQuery( this ); |
| 10 |
var select2Arguments = selectElement.attr( 'data-wppb-select2-arguments' ); |
| 11 |
|
| 12 |
if ( select2Arguments ) { |
| 13 |
select2Arguments = JSON.parse( select2Arguments ); |
| 14 |
} else { |
| 15 |
select2Arguments = {}; |
| 16 |
} |
| 17 |
|
| 18 |
select2Arguments = wp.hooks.applyFilters( 'wppb_select2_initialize_arguments', select2Arguments, selectElement ); |
| 19 |
|
| 20 |
if ( !( 'placeholder' in select2Arguments ) || select2Arguments.placeholder === '' ) { |
| 21 |
select2Arguments.placeholder = jQuery('label[for="' + selectElement.attr('id') + '"]').text(); |
| 22 |
} |
| 23 |
|
| 24 |
selectElement.select2( select2Arguments ).on('select2:open', function(){ |
| 25 |
// compatibility with Divi Overlay |
| 26 |
if( jQuery(selectElement).parents( '.overlay-container' ).length ){ |
| 27 |
jQuery(selectElement).data('select2').dropdown.$dropdownContainer.css( 'z-index', '99999999' ); |
| 28 |
} |
| 29 |
}); |
| 30 |
}); |
| 31 |
} |
| 32 |
|
| 33 |
jQuery( document ).ready(function() { |
| 34 |
wppb_select2_initialize(); |
| 35 |
}); |