| 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 URL control. |
| 12 |
* |
| 13 |
* A base control for creating url control. Displays a URL input with the |
| 14 |
* ability to set the target of the link to `_blank` to open in a new tab. |
| 15 |
* |
| 16 |
* @since 1.0.0 |
| 17 |
*/ |
| 18 |
class Control_URL extends Control_Base_Multiple { |
| 19 |
|
| 20 |
/** |
| 21 |
* Get url control type. |
| 22 |
* |
| 23 |
* Retrieve the control type, in this case `url`. |
| 24 |
* |
| 25 |
* @since 1.0.0 |
| 26 |
* @access public |
| 27 |
* |
| 28 |
* @return string Control type. |
| 29 |
*/ |
| 30 |
public function get_type() { |
| 31 |
return 'url'; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Get url control default values. |
| 36 |
* |
| 37 |
* Retrieve the default value of the url control. Used to return the default |
| 38 |
* values while initializing the url control. |
| 39 |
* |
| 40 |
* @since 1.0.0 |
| 41 |
* @access public |
| 42 |
* |
| 43 |
* @return array Control default value. |
| 44 |
*/ |
| 45 |
public function get_default_value() { |
| 46 |
return [ |
| 47 |
'url' => '', |
| 48 |
'is_external' => '', |
| 49 |
'nofollow' => '', |
| 50 |
'custom_attributes' => '', |
| 51 |
]; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* Get url control default settings. |
| 56 |
* |
| 57 |
* Retrieve the default settings of the url control. Used to return the default |
| 58 |
* settings while initializing the url control. |
| 59 |
* |
| 60 |
* @since 1.0.0 |
| 61 |
* @access protected |
| 62 |
* |
| 63 |
* @return array Control default settings. |
| 64 |
*/ |
| 65 |
protected function get_default_settings() { |
| 66 |
return [ |
| 67 |
'label_block' => true, |
| 68 |
'placeholder' => esc_html__( 'Paste URL or type', 'elementor' ), |
| 69 |
'autocomplete' => true, |
| 70 |
'options' => [ 'is_external', 'nofollow', 'custom_attributes' ], |
| 71 |
'dynamic' => [ |
| 72 |
'categories' => [ TagsModule::URL_CATEGORY ], |
| 73 |
'property' => 'url', |
| 74 |
], |
| 75 |
'custom_attributes_description' => esc_html__( 'Set custom attributes for the link element. Separate attribute keys from values using the | (pipe) character. Separate key-value pairs with a comma.', 'elementor' ) |
| 76 |
. ' <a href="https://go.elementor.com/panel-link-custom-attributes/" target="_blank">' . esc_html__( 'Learn More', 'elementor' ) . '</a>', |
| 77 |
]; |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Render url control output in the editor. |
| 82 |
* |
| 83 |
* Used to generate the control HTML in the editor using Underscore JS |
| 84 |
* template. The variables for the class are available using `data` JS |
| 85 |
* object. |
| 86 |
* |
| 87 |
* @since 1.0.0 |
| 88 |
* @access public |
| 89 |
*/ |
| 90 |
public function content_template() { |
| 91 |
?> |
| 92 |
<div class="elementor-control-field elementor-control-url-external-{{{ ( data.options.length || data.show_external ) ? 'show' : 'hide' }}}"> |
| 93 |
<label for="<?php $this->print_control_uid(); ?>" class="elementor-control-title">{{{ data.label }}}</label> |
| 94 |
<div class="elementor-control-input-wrapper elementor-control-dynamic-switcher-wrapper"> |
| 95 |
<i class="elementor-control-url-autocomplete-spinner eicon-loading eicon-animation-spin" aria-hidden="true"></i> |
| 96 |
<input id="<?php $this->print_control_uid(); ?>" class="elementor-control-tag-area elementor-input" data-setting="url" placeholder="{{ view.getControlPlaceholder() }}" /> |
| 97 |
<?php // PHPCS - Nonces don't require escaping. ?> |
| 98 |
<input id="_ajax_linking_nonce" type="hidden" value="<?php echo wp_create_nonce( 'internal-linking' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>" /> |
| 99 |
<div class="elementor-control-url-more tooltip-target elementor-control-unit-1" data-tooltip="<?php echo esc_html__( 'Link Options', 'elementor' ); ?>"> |
| 100 |
<i class="eicon-cog" aria-hidden="true"></i> |
| 101 |
</div> |
| 102 |
</div> |
| 103 |
<div class="elementor-control-url-more-options"> |
| 104 |
<div class="elementor-control-url-option"> |
| 105 |
<input id="<?php $this->print_control_uid( 'is_external' ); ?>" type="checkbox" class="elementor-control-url-option-input" data-setting="is_external"> |
| 106 |
<label for="<?php $this->print_control_uid( 'is_external' ); ?>"><?php echo esc_html__( 'Open in new window', 'elementor' ); ?></label> |
| 107 |
</div> |
| 108 |
<div class="elementor-control-url-option"> |
| 109 |
<input id="<?php $this->print_control_uid( 'nofollow' ); ?>" type="checkbox" class="elementor-control-url-option-input" data-setting="nofollow"> |
| 110 |
<label for="<?php $this->print_control_uid( 'nofollow' ); ?>"><?php echo esc_html__( 'Add nofollow', 'elementor' ); ?></label> |
| 111 |
</div> |
| 112 |
<div class="elementor-control-url__custom-attributes"> |
| 113 |
<label for="<?php $this->print_control_uid( 'custom_attributes' ); ?>" class="elementor-control-url__custom-attributes-label"><?php echo esc_html__( 'Custom Attributes', 'elementor' ); ?></label> |
| 114 |
<input type="text" id="<?php $this->print_control_uid( 'custom_attributes' ); ?>" class="elementor-control-unit-5" placeholder="key|value" data-setting="custom_attributes"> |
| 115 |
</div> |
| 116 |
<# if ( ( data.options && -1 !== data.options.indexOf( 'custom_attributes' ) ) && data.custom_attributes_description ) { #> |
| 117 |
<div class="elementor-control-field-description">{{{ data.custom_attributes_description }}}</div> |
| 118 |
<# } #> |
| 119 |
</div> |
| 120 |
</div> |
| 121 |
<# if ( data.description ) { #> |
| 122 |
<div class="elementor-control-field-description">{{{ data.description }}}</div> |
| 123 |
<# } #> |
| 124 |
<?php |
| 125 |
} |
| 126 |
} |
| 127 |
|