| 1 |
<?php if (!defined('ABSPATH')) { |
| 2 |
die; |
| 3 |
} // Cannot access directly. |
| 4 |
/** |
| 5 |
* |
| 6 |
* Field: code_editor |
| 7 |
* |
| 8 |
* @since 1.0.0 |
| 9 |
* @version 1.0.0 |
| 10 |
*/ |
| 11 |
if (!class_exists('DRK_LITE_Field_code_editor')) { |
| 12 |
class DRK_LITE_Field_code_editor extends DRK_LITE_Fields |
| 13 |
{ |
| 14 |
|
| 15 |
public $version = '6.65.7'; |
| 16 |
|
| 17 |
public function __construct($field, $value = '', $unique = '', $where = '', $parent = '') |
| 18 |
{ |
| 19 |
parent::__construct($field, $value, $unique, $where, $parent); |
| 20 |
} |
| 21 |
|
| 22 |
public function render() |
| 23 |
{ |
| 24 |
|
| 25 |
$default_settings = array( |
| 26 |
'tabSize' => 2, |
| 27 |
'lineNumbers' => true, |
| 28 |
'theme' => 'default', |
| 29 |
'mode' => 'htmlmixed', |
| 30 |
); |
| 31 |
|
| 32 |
$settings = (!empty($this->field['settings'])) ? $this->field['settings'] : array(); |
| 33 |
$settings = wp_parse_args($settings, $default_settings); |
| 34 |
|
| 35 |
echo wp_kses_post($this->field_before()); |
| 36 |
echo '<textarea name="' . esc_attr($this->field_name()) . '"' . wp_kses_post($this->field_attributes()) . ' data-editor="' . esc_attr(wp_json_encode($settings)) . '">' . wp_kses_post($this->value) . '</textarea>'; |
| 37 |
echo wp_kses_post($this->field_after()); |
| 38 |
} |
| 39 |
|
| 40 |
public function enqueue() |
| 41 |
{ |
| 42 |
|
| 43 |
$page = (!empty($_GET['page'])) ? sanitize_text_field(wp_unslash($_GET['page'])) : ''; |
| 44 |
|
| 45 |
// Do not loads CodeMirror in revslider page. |
| 46 |
if (in_array($page, array('revslider'))) { |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
if (!wp_script_is('drk_lite-codemirror')) { |
| 51 |
wp_enqueue_script('wp-codemirror-js', 'path_to_wp_codemirror_js_file', array('jquery'), null, true); |
| 52 |
wp_enqueue_script('loadmode', DRK_LITE_DIR_URL . 'admin/ta-framework/assets/js/loadmode.min.js', array('drk_lite-codemirror'), $this->version, true); |
| 53 |
} |
| 54 |
|
| 55 |
if (!wp_style_is('drk_lite-codemirror')) { |
| 56 |
wp_enqueue_style('wp-codemirror', 'path_to_wp_codemirror_css_file'); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
} |
| 61 |
|