Skip to content

Commit bf7354f

Browse files
committed
first commit
0 parents  commit bf7354f

File tree

7 files changed

+222
-0
lines changed

7 files changed

+222
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
phpunit.phar
3+
/vendor
4+
composer.phar
5+
composer.lock
6+
*.project
7+
.idea/

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Jens Segers
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Javascript editor extension for laravel-admin based on code-mirror
2+
======
3+
4+
## Installation
5+
6+
```bash
7+
composer require laravel-admin-ext/js-editor
8+
9+
php artisan vendor:publish --tag=laravel-admin-code-mirror
10+
```
11+
12+
## 配置
13+
14+
`config/admin.php`文件的`extensions`,加上属于这个扩展的一些配置
15+
```php
16+
17+
'extensions' => [
18+
19+
'js-editor' => [
20+
21+
// 如果要关掉这个扩展,设置为false
22+
'enable' => true,
23+
24+
// 编辑器的配置
25+
'config' => [
26+
27+
]
28+
]
29+
]
30+
31+
```
32+
33+
更多配置可以到[CodeMirror文档](https://codemirror.net/)找到
34+
35+
## 使用
36+
37+
在form表单中使用它:
38+
```php
39+
$form->js('code');
40+
41+
$form->javascript('code');
42+
```
43+
44+
设置高度
45+
```php
46+
$form->js('code')->height(500);
47+
```
48+
49+
## 支持
50+
51+
如果觉得这个项目帮你节约了时间,不妨支持一下;)
52+
53+
![-1](https://cloud.githubusercontent.com/assets/1479100/23287423/45c68202-fa78-11e6-8125-3e365101a313.jpg)
54+
55+
License
56+
------------
57+
Licensed under [The MIT License (MIT)](LICENSE).

composer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "laravel-admin-ext/js-editor",
3+
"description": "Javascript editor extension for laravel-admin",
4+
"type": "library",
5+
"keywords": ["laravel-admin", "extension", "code mirror", "js", "javascript", "editor"],
6+
"homepage": "https://github.com/laravel-admin-ext/js-editor",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "song",
11+
"email": "[email protected]"
12+
}
13+
],
14+
"require": {
15+
"php": ">=7.0.0",
16+
"jxlwqq/code-mirror": "*"
17+
},
18+
"require-dev": {
19+
"phpunit/phpunit": "~6.0"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Encore\\JsEditor\\": "src/"
24+
}
25+
},
26+
"extra": {
27+
"laravel": {
28+
"providers": [
29+
"Encore\\JsEditor\\JsEditorServiceProvider"
30+
]
31+
32+
}
33+
}
34+
}

src/Editor.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Encore\JsEditor;
4+
5+
use Encore\Admin\Form\Field;
6+
7+
class Editor extends Field
8+
{
9+
/**
10+
* {@inheritdoc}
11+
*/
12+
protected $view = 'laravel-admin-code-mirror::editor';
13+
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
protected static $css = [
18+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/lib/codemirror.css',
19+
];
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected static $js = [
25+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/lib/codemirror.js',
26+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/addon/edit/matchbrackets.js',
27+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/addon/comment/continuecomment.js',
28+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/addon/comment/comment.js',
29+
'vendor/laravel-admin-ext/code-mirror/codemirror-5.40.0/mode/javascript/javascript.js',
30+
];
31+
32+
/**
33+
* Set editor height.
34+
*
35+
* @param int $height
36+
* @return $this
37+
*/
38+
public function height($height = 10)
39+
{
40+
return $this->addVariables(compact('height'));
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public function render()
47+
{
48+
$options = array_merge(
49+
[
50+
'mode' => 'javascript',
51+
'lineNumbers' => true,
52+
'matchBrackets' => true,
53+
'continueComments' => true,
54+
'extraKeys' => [
55+
'Ctrl-Q' => 'toggleComment',
56+
],
57+
],
58+
JsEditor::config('config', [])
59+
);
60+
61+
$options = json_encode($options);
62+
63+
$this->script = <<<EOT
64+
CodeMirror.fromTextArea(document.getElementById("{$this->id}"), $options);
65+
EOT;
66+
67+
return parent::render();
68+
}
69+
}

src/JsEditor.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Encore\JsEditor;
4+
5+
use Encore\Admin\Extension;
6+
7+
class JsEditor extends Extension
8+
{
9+
public $name = 'js-editor';
10+
}

src/JsEditorServiceProvider.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Encore\JsEditor;
4+
5+
use Encore\Admin\Admin;
6+
use Encore\Admin\Form;
7+
use Illuminate\Support\ServiceProvider;
8+
9+
class JsEditorServiceProvider extends ServiceProvider
10+
{
11+
/**
12+
* {@inheritdoc}
13+
*/
14+
public function boot(JsEditor $extension)
15+
{
16+
if (! JsEditor::boot()) {
17+
return ;
18+
}
19+
20+
Admin::booting(function () {
21+
Form::extend('js', Editor::class);
22+
Form::alias('js', 'javascript');
23+
});
24+
}
25+
}

0 commit comments

Comments
 (0)