assets
1 year ago
ajax-select2.php
1 year ago
control-manager.php
1 year ago
image-choose.php
4 years ago
init.php
3 years ago
ajax-select2.php
91 lines
| 1 | <?php |
| 2 | namespace ShopEngine\Core\Elementor_Controls; |
| 3 | |
| 4 | defined( 'ABSPATH' ) || exit; |
| 5 | |
| 6 | class Ajax_Select2 extends \Elementor\Base_Data_Control { |
| 7 | |
| 8 | public function get_api_url(){ |
| 9 | return get_rest_url() . 'shopengine-builder/v1'; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Get select2 control type. |
| 14 | * |
| 15 | * Retrieve the control type, in this case `select2`. |
| 16 | * |
| 17 | * @since 1.0.0 |
| 18 | * @access public |
| 19 | * |
| 20 | * @return string Control type. |
| 21 | */ |
| 22 | public function get_type() { |
| 23 | return 'shopengine_ajaxselect2'; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Enqueue ontrol scripts and styles. |
| 28 | * |
| 29 | * @since 1.0.0 |
| 30 | * @access public |
| 31 | */ |
| 32 | public function enqueue() { |
| 33 | // script |
| 34 | wp_register_script( 'shopengine-js-ajaxchoose-control', Init::get_url() . 'assets/js/ajaxchoose.js' ); |
| 35 | wp_enqueue_script( 'shopengine-js-ajaxchoose-control' ); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Get select2 control default settings. |
| 40 | * |
| 41 | * Retrieve the default settings of the select2 control. Used to return the |
| 42 | * default settings while initializing the select2 control. |
| 43 | * |
| 44 | * @since 1.8.0 |
| 45 | * @access protected |
| 46 | * |
| 47 | * @return array Control default settings. |
| 48 | */ |
| 49 | protected function get_default_settings() { |
| 50 | return [ |
| 51 | 'options' => [], |
| 52 | 'multiple' => false, |
| 53 | 'select2options' => [], |
| 54 | ]; |
| 55 | } |
| 56 | |
| 57 | |
| 58 | /** |
| 59 | * Render select2 control output in the editor. |
| 60 | * |
| 61 | * Used to generate the control HTML in the editor using Underscore JS |
| 62 | * template. The variables for the class are available using `data` JS |
| 63 | * object. |
| 64 | * |
| 65 | * @since 1.0.0 |
| 66 | * @access public |
| 67 | */ |
| 68 | public function content_template() { |
| 69 | $control_uid = $this->get_control_uid(); |
| 70 | ?> |
| 71 | <div class="elementor-control-field"> |
| 72 | <label for="<?php echo esc_attr($control_uid); ?>" class="elementor-control-title">{{{ data.label }}}</label> |
| 73 | <div class="elementor-control-input-wrapper"> |
| 74 | <# var multiple = ( data.multiple ) ? 'multiple' : ''; #> |
| 75 | <select |
| 76 | id="<?php echo esc_attr($control_uid); ?>" |
| 77 | class="elementor-megamenushopengine_ajaxselect2" |
| 78 | type="megamenushopengine_ajaxselect2" {{ multiple }} |
| 79 | data-setting="{{ data.name }}" |
| 80 | data-ajax-url="<?php echo esc_attr($this->get_api_url() . '/{{data.options}}/'); ?>" |
| 81 | > |
| 82 | </select> |
| 83 | </div> |
| 84 | </div> |
| 85 | <# if ( data.description ) { #> |
| 86 | <div class="elementor-control-field-description">{{{ data.description }}}</div> |
| 87 | <# } #> |
| 88 | <?php |
| 89 | } |
| 90 | } |
| 91 |