Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot type code #3

Open
blowsie opened this issue Oct 28, 2013 · 2 comments
Open

Cannot type code #3

blowsie opened this issue Oct 28, 2013 · 2 comments

Comments

@blowsie
Copy link

blowsie commented Oct 28, 2013

Using wordpress latest + acf latest i cannot focus in the code area.

image

@blowsie
Copy link
Author

blowsie commented Oct 28, 2013

To expand on this, this happens when dynamically adding the editor, via flexible content or repeater fileds for example

@blowsie
Copy link
Author

blowsie commented Oct 28, 2013

Quick and dirty hack to fix this issue.

The problem is the flexible content plugin uses a temp id before assigning it with a proper id,

function create_field( $field )
    {
    $field['value'] = esc_textarea($field['value']);

    $language = '';
    switch($field["language"]){
        case 'css':
            $language = 'CSS';
            break;
        case 'javascript':
            $language = 'Javascript';
            break;
        case 'htmlmixed':
            $language = 'HTML';
            break;
        case 'php':
            $language = 'PHP';
            break;
    }

    echo '<textarea id="' . $field['id'] . '" rows="4" class="cm-complete-flag ' . $field['class'] . '" name="' . $field['name'] . '" >' . $field['value'] . '</textarea>';
    echo '<p style="margin-bottom:0;"><small>You are writing '.$language.' code.</small></p>';
    ?>

    <link rel="stylesheet" href="<?php echo $this->settings['dir'];?>/css/theme/<?= $field["theme"];?>.css">
    <script>
        jQuery(document).ready(function($){
          $('.cm-complete-flag').each(function(){
                var $this = $(this);
                var id = $this.attr("id");
                if (id.indexOf("_acfcloneindex") == -1 ){
                    CodeMirror.fromTextArea($this[0], {
                      lineNumbers: true,
                      tabmode: 'indent',
                      mode: '<?= $field["language"];?>',
                      theme: '<?= $field["theme"];?>'
                    });
                    $this.removeClass("cm-complete-flag");
                }
          });
        });
    </script>

    <?php
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant