2017 © Pedro Peláez
 

yii2-extension codemirror

Yii2 codemirror widget

image

conquer/codemirror

Yii2 codemirror widget

  • Tuesday, February 6, 2018
  • by borodulin
  • Repository
  • 2 Watchers
  • 26 Stars
  • 23,311 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 9 Forks
  • 1 Open issues
  • 5 Versions
  • 17 % Grown

The README.md

Codemirror widget for Yii2 framework

Description

CodeMirror is a versatile text editor implemented in JavaScript for the browser. It is specialized for editing code, and comes with a number of language modes and addons that implement more advanced editing functionality. For more information please visit CodeMirror, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

To install, either run, (*3)

$ php composer.phar require conquer/codemirror "*"

or add, (*4)

"conquer/codemirror": "*"

to the require section of your composer.json file., (*5)

Usage

use conquer\codemirror\CodemirrorWidget;

$form->field($model, 'code')->widget(
    CodemirrorWidget::className(),
    [
        'preset'=>'php',
        'options'=>['rows' => 20],
    ]
);

You can use ready-made presets, or create your own. To do this, specify the folder to your presets., (*6)

use conquer\codemirror\CodemirrorWidget;

$form->field($model, 'code')->widget(
    CodemirrorWidget::className(),
    [
        'presetsDir'=>'/path_to_your_presets',
        'preset'=>'sql',
    ]
);

In general, you can customize the widget directly specifying its properties., (*7)

use conquer\codemirror\CodemirrorWidget;
use conquer\codemirror\CodemirrorAsset;

$form->field($model, 'code')->widget(
    CodemirrorWidget::className(),
    [
        'assets'=>[
            CodemirrorAsset::MODE_CLIKE,
            CodemirrorAsset::KEYMAP_EMACS,
            CodemirrorAsset::ADDON_EDIT_MATCHBRACKETS,
            CodemirrorAsset::ADDON_COMMENT,
            CodemirrorAsset::ADDON_DIALOG,
            CodemirrorAsset::ADDON_SEARCHCURSOR,
            CodemirrorAsset::ADDON_SEARCH,
        ],
        'settings'=>[
            'lineNumbers' => true,
            'mode' => 'text/x-csrc',
            'keyMap' => 'emacs'
        ],
    ]
);
JavaScript

For access the instance of CodeMirror from JavaScript, you can use CodeMirror.instances[] . Example:, (*8)

    var instanceName = document.getElementById('textarea-id').dataset.codeMirror;

    var cm = CodeMirror.instances[instanceName];

    var code = cm.getValue();   // Get the current editor content
    /*
        cm.save();              // Copy the content of the editor into the textarea
        cm.toTextArea();        // Remove the editor, and restore the original textarea
    */

License

conquer/codemirror is released under the MIT License. See the bundled LICENSE.md for details., (*9)

The Versions

06/02 2018

dev-master

9999999-dev https://github.com/borodulin/yii2-codemirror

Yii2 codemirror widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget codemirror

13/10 2015

2.0

2.0.0.0 https://github.com/borodulin/yii2-codemirror

Yii2 codemirror widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget codemirror

27/04 2015

1.2

1.2.0.0 https://github.com/borodulin/yii2-codemirror

Yii2 codemirror widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget codemirror

17/04 2015

1.1

1.1.0.0 https://github.com/borodulin/yii2-codemirror

Yii2 codemirror widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget codemirror

10/04 2015

1.0

1.0.0.0 https://github.com/borodulin/yii2-codemirror

Yii2 codemirror widget

  Sources   Download

MIT

The Requires

 

extension yii2 widget codemirror