| 1 |
<?php |
| 2 |
|
| 3 |
namespace Wdk\Includes\Controls; |
| 4 |
|
| 5 |
use Elementor\Control_Select2; |
| 6 |
|
| 7 |
if (! defined('ABSPATH')) { |
| 8 |
exit(); |
| 9 |
} |
| 10 |
|
| 11 |
class Wdk_Field_Selector extends Control_Select2 |
| 12 |
{ |
| 13 |
|
| 14 |
const INIT = 'wdk-fields-selector'; |
| 15 |
|
| 16 |
public function get_type() |
| 17 |
{ |
| 18 |
return self::INIT; |
| 19 |
} |
| 20 |
|
| 21 |
|
| 22 |
public function content_template() { |
| 23 |
?> |
| 24 |
|
| 25 |
<# |
| 26 |
if(data.controlValue && data.controlValue.indexOf('__') !==-1){ |
| 27 |
data.controlValue=data.controlValue.split('__')[1]; |
| 28 |
} |
| 29 |
#> |
| 30 |
|
| 31 |
<div class="elementor-control-field"> |
| 32 |
<# if ( data.label ) {#> |
| 33 |
<label for="<?php $this->print_control_uid(); ?>" class="elementor-control-title">{{{ data.label }}}</label> |
| 34 |
<# } #> |
| 35 |
<div class="elementor-control-input-wrapper elementor-control-unit-5"> |
| 36 |
<# var multiple = ( data.multiple ) ? 'multiple' : ''; #> |
| 37 |
<select id="<?php $this->print_control_uid(); ?>" class="elementor-select2 el-wdk-selector-field" type="select2" {{ multiple }} data-setting="{{ data.name }}"> |
| 38 |
<# if ( data.raw_options ) { #> |
| 39 |
<# _.each( data.raw_options, function( item ){ #> |
| 40 |
<option value="{{ _.escape(item.value) }}" |
| 41 |
<# if ( data.controlValue==item.value ) { #> |
| 42 |
selected="selected" |
| 43 |
<# } #> |
| 44 |
>{{{ _.escape(item.label) }}} |
| 45 |
</option> |
| 46 |
<# } ); #> |
| 47 |
<# } else { #> |
| 48 |
<# _.each( data.options, function( label, value ) { |
| 49 |
|
| 50 |
if ( typeof data.controlValue == 'string' ) { |
| 51 |
var selected = ( value === data.controlValue ) ? 'selected' : ''; |
| 52 |
} else if ( null !== data.controlValue ) { |
| 53 |
var selected = ( -1 !== data.controlValue.indexOf( value ) ) ? 'selected' : ''; |
| 54 |
} |
| 55 |
|
| 56 |
#> |
| 57 |
<option {{ selected }} value="{{ _.escape(value) }}">{{{ _.escape(label)}}}</option> |
| 58 |
<# } ); #> |
| 59 |
<# } #> |
| 60 |
</select> |
| 61 |
</div> |
| 62 |
</div> |
| 63 |
<# if ( data.description ) { #> |
| 64 |
<div class="elementor-control-field-description">{{{ data.description }}}</div> |
| 65 |
<# } #> |
| 66 |
<?php |
| 67 |
} |
| 68 |
|
| 69 |
} |
| 70 |
|