groups
1 year ago
alert.php
2 years ago
animation.php
1 year ago
base-data.php
3 years ago
base-icon-font.php
3 years ago
base-multiple.php
3 years ago
base-ui.php
3 years ago
base-units.php
2 years ago
base.php
3 years ago
box-shadow.php
3 years ago
button.php
3 years ago
choose.php
3 years ago
code.php
3 years ago
color.php
3 years ago
date-time.php
3 years ago
deprecated-notice.php
3 years ago
dimensions.php
3 years ago
divider.php
2 years ago
exit-animation.php
1 year ago
font.php
3 years ago
gallery.php
1 year ago
gaps.php
2 years ago
heading.php
3 years ago
hidden.php
3 years ago
hover-animation.php
1 year ago
icon.php
2 years ago
icons.php
2 years ago
image-dimensions.php
3 years ago
media.php
1 year ago
notice.php
1 year ago
number.php
3 years ago
popover-toggle.php
3 years ago
raw-html.php
3 years ago
repeater.php
1 year ago
section.php
2 years ago
select.php
3 years ago
select2.php
2 years ago
slider.php
3 years ago
structure.php
2 years ago
switcher.php
3 years ago
tab.php
2 years ago
tabs.php
2 years ago
text-shadow.php
3 years ago
text.php
3 years ago
textarea.php
3 years ago
url.php
1 year ago
wp-widget.php
3 years ago
wysiwyg.php
3 years ago
select2.php
95 lines
| 1 | <?php |
| 2 | namespace Elementor; |
| 3 | |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | exit; // Exit if accessed directly. |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * Elementor select2 control. |
| 10 | * |
| 11 | * A base control for creating select2 control. Displays a select box control |
| 12 | * based on select2 jQuery plugin @see https://select2.github.io/ . |
| 13 | * It accepts an array in which the `key` is the value and the `value` is the |
| 14 | * option name. Set `multiple` to `true` to allow multiple value selection. |
| 15 | * |
| 16 | * @since 1.0.0 |
| 17 | */ |
| 18 | class Control_Select2 extends Base_Data_Control { |
| 19 | |
| 20 | /** |
| 21 | * Get select2 control type. |
| 22 | * |
| 23 | * Retrieve the control type, in this case `select2`. |
| 24 | * |
| 25 | * @since 1.0.0 |
| 26 | * @access public |
| 27 | * |
| 28 | * @return string Control type. |
| 29 | */ |
| 30 | public function get_type() { |
| 31 | return 'select2'; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Get select2 control default settings. |
| 36 | * |
| 37 | * Retrieve the default settings of the select2 control. Used to return the |
| 38 | * default settings while initializing the select2 control. |
| 39 | * |
| 40 | * @since 1.8.0 |
| 41 | * @access protected |
| 42 | * |
| 43 | * @return array Control default settings. |
| 44 | */ |
| 45 | protected function get_default_settings() { |
| 46 | return [ |
| 47 | 'options' => [], |
| 48 | 'multiple' => false, |
| 49 | // Select2 library options |
| 50 | 'select2options' => [], |
| 51 | // the lockedOptions array can be passed option keys. The passed option keys will be non-deletable. |
| 52 | 'lockedOptions' => [], |
| 53 | ]; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Render select2 control output in the editor. |
| 58 | * |
| 59 | * Used to generate the control HTML in the editor using Underscore JS |
| 60 | * template. The variables for the class are available using `data` JS |
| 61 | * object. |
| 62 | * |
| 63 | * @since 1.0.0 |
| 64 | * @access public |
| 65 | */ |
| 66 | public function content_template() { |
| 67 | ?> |
| 68 | <div class="elementor-control-field"> |
| 69 | <# if ( data.label ) {#> |
| 70 | <label for="<?php $this->print_control_uid(); ?>" class="elementor-control-title">{{{ data.label }}}</label> |
| 71 | <# } #> |
| 72 | <div class="elementor-control-input-wrapper elementor-control-unit-5"> |
| 73 | <# var multiple = ( data.multiple ) ? 'multiple' : ''; #> |
| 74 | <select id="<?php $this->print_control_uid(); ?>" class="elementor-select2" type="select2" {{ multiple }} data-setting="{{ data.name }}"> |
| 75 | <# _.each( data.options, function( option_title, option_value ) { |
| 76 | var value = data.controlValue; |
| 77 | if ( typeof value == 'string' ) { |
| 78 | var selected = ( option_value === value ) ? 'selected' : ''; |
| 79 | } else if ( null !== value ) { |
| 80 | var value = _.values( value ); |
| 81 | var selected = ( -1 !== value.indexOf( option_value ) ) ? 'selected' : ''; |
| 82 | } |
| 83 | #> |
| 84 | <option {{ selected }} value="{{ _.escape( option_value ) }}">{{{ _.escape( option_title ) }}}</option> |
| 85 | <# } ); #> |
| 86 | </select> |
| 87 | </div> |
| 88 | </div> |
| 89 | <# if ( data.description ) { #> |
| 90 | <div class="elementor-control-field-description">{{{ data.description }}}</div> |
| 91 | <# } #> |
| 92 | <?php |
| 93 | } |
| 94 | } |
| 95 |