_comment.php
4 months ago
_db.php
4 months ago
_hidden.php
4 months ago
_label.php
4 months ago
_row.php
4 months ago
attachment.php
4 months ago
checkbox.php
4 months ago
cleditor.php
4 months ago
codemirror.php
4 months ago
color.php
4 months ago
currency.php
4 months ago
date.php
4 months ago
datetime.php
4 months ago
email.php
4 months ago
link.php
4 months ago
number.php
4 months ago
oembed.php
4 months ago
password.php
4 months ago
phone.php
4 months ago
radio.php
4 months ago
select.php
4 months ago
slider.php
4 months ago
slug.php
4 months ago
text.php
4 months ago
textarea.php
4 months ago
time.php
4 months ago
tinymce.php
4 months ago
website.php
4 months ago
codemirror.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | // Don't load directly. |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | die( '-1' ); |
| 6 | } |
| 7 | |
| 8 | // phpcs:ignoreFile WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound |
| 9 | |
| 10 | pods_form_enqueue_script( 'pods-codemirror' ); |
| 11 | pods_form_enqueue_style( 'pods-codemirror' ); |
| 12 | pods_form_enqueue_style( 'pods-styles' ); |
| 13 | pods_form_enqueue_script( 'pods-codemirror-loadmode' ); |
| 14 | |
| 15 | $type = 'textarea'; |
| 16 | $attributes = array(); |
| 17 | $attributes['tabindex'] = 2; |
| 18 | $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options, 'pods-ui-field-codemirror' ); |
| 19 | ?> |
| 20 | <div class="pods-codemirror pods-compat-container pods-form-ui-field"> |
| 21 | <div class="code-toolbar"><!-- Placeholder --></div> |
| 22 | <textarea<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?>><?php echo esc_textarea( $value ); ?></textarea> |
| 23 | <div class="code-footer"><!-- Placeholder --></div> |
| 24 | |
| 25 | <script> |
| 26 | var $textarea_<?php echo esc_js( pods_js_name( $attributes['id'] ) ); ?>, |
| 27 | codemirror_<?php echo esc_js( pods_js_name( $attributes['id'] ) ); ?>; |
| 28 | |
| 29 | jQuery( function ( $ ) { |
| 30 | $textarea_<?php echo esc_js( pods_js_name( $attributes['id'] ) ); ?> = jQuery( 'textarea#<?php echo esc_js( $attributes['id'] ); ?>' ); |
| 31 | |
| 32 | CodeMirror.modeURL = "<?php echo esc_js( PODS_URL ); ?>ui/js/codemirror/mode/%N/%N.js"; |
| 33 | if ( 'undefined' == typeof codemirror_<?php echo esc_js( pods_js_name( $attributes['id'] ) ); ?> ) { |
| 34 | |
| 35 | codemirror_<?php echo esc_js( pods_js_name( $attributes['id'] ) ); ?> = CodeMirror.fromTextArea( document.getElementById( "<?php echo esc_js( $attributes['id'] ); ?>" ), { |
| 36 | lineNumbers : true, |
| 37 | matchBrackets : true, |
| 38 | mode : "application/x-httpd-php", |
| 39 | indentUnit : 4, |
| 40 | indentWithTabs : false, |
| 41 | lineWrapping : true, |
| 42 | enterMode : "keep", |
| 43 | tabMode : "shift" |
| 44 | } ); |
| 45 | codemirror_<?php echo esc_js( pods_js_name( $attributes['id'] ) ); ?>.on( 'blur', function () { |
| 46 | var value = codemirror_<?php echo esc_js( pods_js_name( $attributes['id'] ) ); ?>.getValue(); |
| 47 | $textarea_<?php echo esc_js( pods_js_name( $attributes['id'] ) ); ?>.val( value ); |
| 48 | } ); |
| 49 | |
| 50 | CodeMirror.autoLoadMode( codemirror_<?php echo esc_js( pods_js_name( $attributes['id'] ) ); ?>, 'php' ); |
| 51 | } |
| 52 | } ); |
| 53 | </script> |
| 54 | </div> |
| 55 |