PluginProbe
Easy Elements for Elementor – Addons & Website Templates / trunk
Easy Elements for Elementor – Addons & Website Templates vtrunk
1.5.3 1.5.2 1.5.1 1.5.0 1.4.9 1.4.6 1.4.7 1.4.8 1.4.5 1.4.4 1.4.3 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 All 47 releases
easy-elements / includes / Utils / SearchSelect2.php

SearchSelect2.php in Easy Elements for Elementor – Addons & Website Templates trunk, at includes/Utils/SearchSelect2.php

111 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Easyel\EasyElements\Utils;
3 /**
4 * Elementor autocomplete controls
5 */
6 use Elementor\Base_Data_Control;
7 use Elementor\Plugin;
8
9 if ( ! defined( 'ABSPATH' ) ) exit;
10
11 /**
12 * Elementor easyel_autocomplete control.
13 *
14 * @since 1.0.0
15 */
16 class SearchSelect2 extends Base_Data_Control {
17 /**
18 * Get easyel_autocomplete control type.
19 *
20 * Retrieve the control type, in this case `easyel_autocomplete`.
21 *
22 * @since 1.0.0
23 * @access public
24 *
25 * @return string Control type.
26 */
27 public function get_type() {
28 return 'easyel_autocomplete';
29 }
30
31 /**
32 * Get easyel_autocomplete control default settings.
33 *
34 * Retrieve the default settings of the easyel_autocomplete control. Used to return the
35 * default settings while initializing the easyel_autocomplete control.
36 *
37 * @since 1.0.0
38 * @access protected
39 *
40 * @return array Control default settings.
41 */
42 protected function get_default_settings() {
43 return [
44 'label_block' => true,
45 'multiple' => false,
46 'taxonomy' => false,
47 'post_type' => false,
48 'security' => wp_create_nonce( 'easyel_autocomplete_nonce' ),
49 'options' => [],
50 'callback' => '',
51 ];
52 }
53
54 /**
55 * Enqueue control scripts and styles.
56 *
57 * @since 1.0.0
58 * @access public
59 */
60 public function enqueue() {
61 wp_enqueue_script( 'easyel-autocomplete-control', EASYELEMENTS_ASSETS_URL . 'js/easyel-autocomplete.js', [ 'jquery' ], EASYELEMENTS_VER, false );
62
63 wp_localize_script(
64 'easyel-autocomplete-control',
65 'easyel_custom_select_obj',
66 [
67 'security' => wp_create_nonce('easyel_autocomplete_nonce'),
68 'ajax_url' => admin_url('admin-ajax.php'),
69 ]
70 );
71 }
72
73 /**
74 * Render easyel_autocomplete control output in the editor.
75 *
76 * Used to generate the control HTML in the editor using Underscore JS
77 * template. The variables for the class are available using `data` JS
78 * object.
79 *
80 * @since 1.0.0
81 * @access public
82 */
83 public function content_template() {
84 $control_uid = $this->get_control_uid();
85 ?>
86 <div class="elementor-control-field">
87 <label for="<?php echo esc_attr( $control_uid ); ?>" class="elementor-control-title">{{{ data.label
88 }}}</label>
89 <div class="elementor-control-input-wrapper">
90 <# var multiple = ( data.multiple ) ? 'multiple' : ''; #>
91 <select id="<?php echo esc_attr( $control_uid ); ?>" class="elementor-select2" type="select2" {{ multiple }} data-setting="{{ data.name }}" data-post-type="{{ data.post_type }}" data-taxonomy="{{ data.taxonomy }}" data-placeholder="<?php echo esc_attr__( 'Search', 'easy-elements' ); ?>">
92 <# _.each( data.options, function( option_title, option_value ) {
93 var value = data.controlValue;
94 if ( typeof value == 'string' ) {
95 var selected = ( option_value === value ) ? 'selected' : '';
96 } else if ( null !== value ) {
97 var value = _.values( value );
98 var selected = ( -1 !== value.indexOf( option_value ) ) ? 'selected' : '';
99 }
100 #>
101 <option {{ selected }} value="{{ option_value }}">{{{ option_title }}}</option>
102 <# } ); #>
103 </select>
104 </div>
105 </div>
106 <# if ( data.description ) { #>
107 <div class="elementor-control-field-description">{{{ data.description }}}</div>
108 <# } #>
109 <?php
110 }
111 }