2amigos / yii2-tinymce-widget

TinyMCE WYSIWYG widget for Yii2
http://yiiwheels.com
Other
100 stars 48 forks source link

How to use CDN in configure file ? #26

Closed n3yang closed 7 years ago

n3yang commented 7 years ago

Thanks to create the widget, it's very useful.

I found a Issue maybe, it's hard to change the URL of tinymce.min.js when using CDN. In the config file, i try to set the assetManager params, like this:

$config = [
    ...
    'components' => [
        'assetManager' => [
            'bundles' => [
                // working.
                'yii\web\JqueryAsset' => [
                    'js' => ['//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js']
                ],
                //  working too, but got JS file in twice
                'dosamigos\tinymce\TinyMceAsset' => [
                    'js'    => ['//cdn.bootcss.com/tinymce/4.4.0/tinymce.min.js'],
                ],
            ],
        ],
    ],
    ...
]

So, I read the JqueryAsset.php in /yii2/web/JqueryAsset.php, and edit the TinyMceAsset.php from:

class TinyMceAsset extends AssetBundle
{
    public $sourcePath = '@vendor/tinymce/tinymce';

    public function init()
    {
        parent::init();
        $this->js[] = YII_DEBUG ? 'tinymce.js' : 'tinymce.min.js';
    }
}

to:

class TinyMceAsset extends AssetBundle
{
    public $sourcePath = '@vendor/tinymce/tinymce';
    public $js = [
        'tinymce.js'
    ];
}

the configure is working.

So, I think it's better to give a chance to config.

tonydspaniard commented 7 years ago

@n3yang I agree, I made the mistake of adding the config on init() is totally wrong. A PR would be more than welcome.

tonydspaniard commented 7 years ago

This has been fixed