| 1 |
<?php |
| 2 |
/** |
| 3 |
* Main Elementor Select2AjaxControl Class |
| 4 |
* |
| 5 |
* The main class that initiates and runs the plugin. |
| 6 |
* |
| 7 |
* @package RadiusTheme\SB |
| 8 |
* @since 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace RadiusTheme\SB\Elementor\Controls; |
| 12 |
|
| 13 |
use Elementor\Base_Data_Control; |
| 14 |
|
| 15 |
// Do not allow directly accessing this file. |
| 16 |
if ( ! defined( 'ABSPATH' ) ) { |
| 17 |
exit( 'This script cannot be accessed directly.' ); |
| 18 |
} |
| 19 |
|
| 20 |
class Select2AjaxControl extends Base_Data_Control { |
| 21 |
|
| 22 |
/** |
| 23 |
* Set control name. |
| 24 |
* |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
public static $controlName = 'rt-select2'; |
| 28 |
|
| 29 |
public function get_type() { |
| 30 |
return self::$controlName; |
| 31 |
} |
| 32 |
|
| 33 |
public function enqueue() { |
| 34 |
wp_enqueue_script( 'rtsb-editor-script' ); |
| 35 |
wp_localize_script( |
| 36 |
'rtsb-editor-script', |
| 37 |
'rtSelect2Obj', |
| 38 |
[ |
| 39 |
'ajaxurl' => esc_url( admin_url( 'admin-ajax.php' ) ), |
| 40 |
'search_text' => esc_html__( 'Please Select', 'shopbuilder' ), |
| 41 |
'nonceId' => rtsb()->nonceId, |
| 42 |
rtsb()->nonceId => wp_create_nonce( rtsb()->nonceText ), |
| 43 |
] |
| 44 |
); |
| 45 |
?> |
| 46 |
<style> |
| 47 |
.rt-select2-main-wrapper ul.select2-selection__rendered li:last-child { |
| 48 |
pointer-events: none; |
| 49 |
} |
| 50 |
|
| 51 |
.rt-select2-main-wrapper ul.select2-selection__rendered li:last-child::before { |
| 52 |
background: var(--e-a-btn-bg); |
| 53 |
content: '+'; |
| 54 |
padding: 1px 5px; |
| 55 |
position: relative; |
| 56 |
top: 1px; |
| 57 |
margin-right: 5px; |
| 58 |
color: #fff; |
| 59 |
} |
| 60 |
|
| 61 |
.rt-select2-main-wrapper ul.select2-selection__rendered li[title=search] { |
| 62 |
display: none; |
| 63 |
} |
| 64 |
</style> |
| 65 |
<?php |
| 66 |
} |
| 67 |
|
| 68 |
protected function get_default_settings() { |
| 69 |
return [ |
| 70 |
'multiple' => false, |
| 71 |
'label_block' => true, |
| 72 |
'source_name' => 'post_type', |
| 73 |
'source_type' => 'post', |
| 74 |
'minimum_input_length' => 3, |
| 75 |
'maximum_selection_length' => - 1, |
| 76 |
]; |
| 77 |
} |
| 78 |
|
| 79 |
public function content_template() { |
| 80 |
$control_uid = $this->get_control_uid(); |
| 81 |
?> |
| 82 |
|
| 83 |
<# var controlUID = '<?php echo esc_html( $control_uid ); ?>'; #> |
| 84 |
<# var currentID = elementor.panel.currentView.currentPageView.model.attributes.settings.attributes[data.name]; #> |
| 85 |
<# var maxSelection = (data.maximum_selection_length > 0) ? 'max-select'+data.maximum_selection_length : 'unlimited-select' #> |
| 86 |
<div class="elementor-control-field rt-select2-main-wrapper {{maxSelection}}"> |
| 87 |
<# if ( data.label ) { #> |
| 88 |
<label for="<?php echo esc_attr( $control_uid ); ?>" class="elementor-control-title">{{{data.label }}}</label> |
| 89 |
<# } #> |
| 90 |
<div class="elementor-control-input-wrapper elementor-control-unit-5"> |
| 91 |
<# var multiple = ( data.multiple ) ? 'multiple' : ''; #> |
| 92 |
<select id="<?php echo esc_attr( $control_uid ); ?>" {{ multiple }} class="rt-select2" data-setting="{{ data.name }}"></select> |
| 93 |
</div> |
| 94 |
<# if ( data.description ) { #> |
| 95 |
<div class="elementor-control-field-description rtsb-description">{{{ data.description }}}</div> |
| 96 |
<# } #> |
| 97 |
</div> |
| 98 |
<# |
| 99 |
( function( $ ) { |
| 100 |
$( document.body ).trigger( 'rt_select2_event',{currentID:data.controlValue,data:data,controlUID:controlUID,multiple:data.multiple} ); |
| 101 |
}( jQuery ) ); |
| 102 |
#> |
| 103 |
<?php |
| 104 |
} |
| 105 |
} |
| 106 |
|