2amigos / yii2-tinymce-widget

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

file_picker_callback / file_browser_callback #20

Closed ahalejcio closed 7 years ago

ahalejcio commented 8 years ago

Hi, I found problem with assign tinymce to file browser (function) sample code:

<script>function nameJsFunction().....</script>

 <?= $form->field($model, 'content')->widget(TinyMce::className(), [
         'options' => ['rows' => 16],
         'language' => 'en_GB',
         'clientOptions' => 
             'file_picker_callback' => 'nameJsFunction',
         ]
     ]); ?>

this generate something like this: "file_picker_callback":"nameJsFunction" but nameJsFunction, can't be in quotations.

Sample solution, maybe is something better, but that works for me:

TinyMce.php after $options

// @codeCoverageIgnoreEnd $options = Json::encode($this->clientOptions);

  //check is there editor and replace "function" to function 
    if(isset($this->clientOptions['file_picker_callback']))
        $options = str_replace('"'.$this->clientOptions['file_picker_callback'].'"', $this->clientOptions['file_picker_callback'], $options);

i guess something like this is should be for "file_browser_callback" too,

if(isset($this->clientOptions['file_browser_callback'])) $options = str_replace('"'.$this->clientOptions['file_browser_callback'].'"', $this->clientOptions['file_picker_callback'], $options);

tonydspaniard commented 7 years ago

@ahalejcio to do that, please use new JsExpression('nameJsFunction'). Thats why that object was created on Yii2. ;)

ermGit commented 7 years ago

This (e.g. new JsExpression("...") ) should be in the documentation for the Widget. It would save people a lot of time.

tonydspaniard commented 7 years ago

Thanks @ermGit