| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
/** |
| 9 |
* Elementor dimension control. |
| 10 |
* |
| 11 |
* A base control for creating dimension control. Displays input fields for top, |
| 12 |
* right, bottom, left and the option to link them together. |
| 13 |
* |
| 14 |
* @since 1.0.0 |
| 15 |
*/ |
| 16 |
class Control_Dimensions extends Control_Base_Units { |
| 17 |
|
| 18 |
/** |
| 19 |
* Get dimensions control type. |
| 20 |
* |
| 21 |
* Retrieve the control type, in this case `dimensions`. |
| 22 |
* |
| 23 |
* @since 1.0.0 |
| 24 |
* @access public |
| 25 |
* |
| 26 |
* @return string Control type. |
| 27 |
*/ |
| 28 |
public function get_type() { |
| 29 |
return 'dimensions'; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Get dimensions control default values. |
| 34 |
* |
| 35 |
* Retrieve the default value of the dimensions control. Used to return the |
| 36 |
* default values while initializing the dimensions control. |
| 37 |
* |
| 38 |
* @since 1.0.0 |
| 39 |
* @access public |
| 40 |
* |
| 41 |
* @return array Control default value. |
| 42 |
*/ |
| 43 |
public function get_default_value() { |
| 44 |
return array_merge( |
| 45 |
parent::get_default_value(), [ |
| 46 |
'top' => '', |
| 47 |
'right' => '', |
| 48 |
'bottom' => '', |
| 49 |
'left' => '', |
| 50 |
'isLinked' => true, |
| 51 |
] |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Get dimensions control default settings. |
| 57 |
* |
| 58 |
* Retrieve the default settings of the dimensions control. Used to return the |
| 59 |
* default settings while initializing the dimensions control. |
| 60 |
* |
| 61 |
* @since 1.0.0 |
| 62 |
* @access protected |
| 63 |
* |
| 64 |
* @return array Control default settings. |
| 65 |
*/ |
| 66 |
protected function get_default_settings() { |
| 67 |
return array_merge( |
| 68 |
parent::get_default_settings(), [ |
| 69 |
'label_block' => true, |
| 70 |
'allowed_dimensions' => 'all', |
| 71 |
'placeholder' => '', |
| 72 |
] |
| 73 |
); |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Render dimensions control output in the editor. |
| 78 |
* |
| 79 |
* Used to generate the control HTML in the editor using Underscore JS |
| 80 |
* template. The variables for the class are available using `data` JS |
| 81 |
* object. |
| 82 |
* |
| 83 |
* @since 1.0.0 |
| 84 |
* @access public |
| 85 |
*/ |
| 86 |
public function content_template() { |
| 87 |
$dimensions = [ |
| 88 |
'top' => __( 'Top', 'elementor' ), |
| 89 |
'right' => __( 'Right', 'elementor' ), |
| 90 |
'bottom' => __( 'Bottom', 'elementor' ), |
| 91 |
'left' => __( 'Left', 'elementor' ), |
| 92 |
]; |
| 93 |
?> |
| 94 |
<div class="elementor-control-field"> |
| 95 |
<label class="elementor-control-title">{{{ data.label }}}</label> |
| 96 |
<?php $this->print_units_template(); ?> |
| 97 |
<div class="elementor-control-input-wrapper"> |
| 98 |
<ul class="elementor-control-dimensions"> |
| 99 |
<?php |
| 100 |
foreach ( $dimensions as $dimension_key => $dimension_title ) : |
| 101 |
$control_uid = $this->get_control_uid( $dimension_key ); |
| 102 |
?> |
| 103 |
<li class="elementor-control-dimension"> |
| 104 |
<input id="<?php echo $control_uid; ?>" type="number" data-setting="<?php echo esc_attr( $dimension_key ); ?>" |
| 105 |
placeholder="<# |
| 106 |
if ( _.isObject( data.placeholder ) ) { |
| 107 |
if ( ! _.isUndefined( data.placeholder.<?php echo $dimension_key; ?> ) ) { |
| 108 |
print( data.placeholder.<?php echo $dimension_key; ?> ); |
| 109 |
} |
| 110 |
} else { |
| 111 |
print( data.placeholder ); |
| 112 |
} #>" |
| 113 |
<# if ( -1 === _.indexOf( allowed_dimensions, '<?php echo $dimension_key; ?>' ) ) { #> |
| 114 |
disabled |
| 115 |
<# } #> |
| 116 |
/> |
| 117 |
<label for="<?php echo esc_attr( $control_uid ); ?>" class="elementor-control-dimension-label"><?php echo $dimension_title; ?></label> |
| 118 |
</li> |
| 119 |
<?php endforeach; ?> |
| 120 |
<li> |
| 121 |
<button class="elementor-link-dimensions tooltip-target" data-tooltip="<?php echo esc_attr__( 'Link values together', 'elementor' ); ?>"> |
| 122 |
<span class="elementor-linked"> |
| 123 |
<i class="eicon-link" aria-hidden="true"></i> |
| 124 |
<span class="elementor-screen-only"><?php echo __( 'Link values together', 'elementor' ); ?></span> |
| 125 |
</span> |
| 126 |
<span class="elementor-unlinked"> |
| 127 |
<i class="eicon-chain-broken" aria-hidden="true"></i> |
| 128 |
<span class="elementor-screen-only"><?php echo __( 'Unlinked values', 'elementor' ); ?></span> |
| 129 |
</span> |
| 130 |
</button> |
| 131 |
</li> |
| 132 |
</ul> |
| 133 |
</div> |
| 134 |
</div> |
| 135 |
<# if ( data.description ) { #> |
| 136 |
<div class="elementor-control-field-description">{{{ data.description }}}</div> |
| 137 |
<# } #> |
| 138 |
<?php |
| 139 |
} |
| 140 |
} |
| 141 |
|