| 1 |
<?php |
| 2 |
namespace Elementor; |
| 3 |
|
| 4 |
use Elementor\Modules\DynamicTags\Module as TagsModule; |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; // Exit if accessed directly. |
| 8 |
} |
| 9 |
|
| 10 |
/** |
| 11 |
* Elementor code control. |
| 12 |
* |
| 13 |
* A base control for creating code control. Displays a code editor textarea. |
| 14 |
* Based on Ace editor (@see https://ace.c9.io/). |
| 15 |
* |
| 16 |
* @since 1.0.0 |
| 17 |
*/ |
| 18 |
class Control_Code extends Base_Data_Control { |
| 19 |
|
| 20 |
/** |
| 21 |
* Get code control type. |
| 22 |
* |
| 23 |
* Retrieve the control type, in this case `code`. |
| 24 |
* |
| 25 |
* @since 1.0.0 |
| 26 |
* @access public |
| 27 |
* |
| 28 |
* @return string Control type. |
| 29 |
*/ |
| 30 |
public function get_type() { |
| 31 |
return 'code'; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Get code control default settings. |
| 36 |
* |
| 37 |
* Retrieve the default settings of the code control. Used to return the default |
| 38 |
* settings while initializing the code control. |
| 39 |
* |
| 40 |
* @since 1.0.0 |
| 41 |
* @access protected |
| 42 |
* |
| 43 |
* @return array Control default settings. |
| 44 |
*/ |
| 45 |
protected function get_default_settings() { |
| 46 |
return [ |
| 47 |
'label_block' => true, |
| 48 |
'language' => 'html', // html/css |
| 49 |
'rows' => 10, |
| 50 |
'ai' => [ |
| 51 |
'active' => true, |
| 52 |
'type' => 'code', |
| 53 |
], |
| 54 |
'dynamic' => [ |
| 55 |
'categories' => [ TagsModule::TEXT_CATEGORY ], |
| 56 |
], |
| 57 |
]; |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* Render code control output in the editor. |
| 62 |
* |
| 63 |
* Used to generate the control HTML in the editor using Underscore JS |
| 64 |
* template. The variables for the class are available using `data` JS |
| 65 |
* object. |
| 66 |
* |
| 67 |
* @since 1.0.0 |
| 68 |
* @access public |
| 69 |
*/ |
| 70 |
public function content_template() { |
| 71 |
?> |
| 72 |
<div class="elementor-control-field"> |
| 73 |
<label for="<?php $this->print_control_uid(); ?>" class="elementor-control-title">{{{ data.label }}}</label> |
| 74 |
<div class="elementor-control-input-wrapper elementor-control-dynamic-switcher-wrapper"> |
| 75 |
<textarea id="<?php $this->print_control_uid(); ?>" rows="{{ data.rows }}" class="e-input-style elementor-code-editor" data-setting="{{ data.name }}"></textarea> |
| 76 |
</div> |
| 77 |
</div> |
| 78 |
<# if ( data.description ) { #> |
| 79 |
<div class="elementor-control-field-description">{{{ data.description }}}</div> |
| 80 |
<# } #> |
| 81 |
<?php |
| 82 |
} |
| 83 |
} |
| 84 |
|