Yiibooster, Redactorjs, Custom Js File Positioning

Hi everybody

Lately i’m extending/modifying redactorJs (the one that comes with yiibooster) in order to fit my needs

For that i written a custom js file that operates under the premise that the redactor widget has already been initialized (obviosly) but here i have a problem… even if i register my script, at the end of my view file, with


    Yii::app()->theme->baseUrl.'/js/redactorImgHook.js', CClientScript::POS_END


the resulting html in my page is like that:

<script type="text/javascript" src="/medispo/themes/bootstrap/js/redactorImgHook.js"></script>

<script type="text/javascript">


jQuery(function($) {





so i’m wondering, how to put my js file AFTER the redactor widget init??

FYI i call redactor this way:

     <?php echo $form->redactorRow($model, 'schedaTecnica', array('options' => array('lang'=>'it', 'minHeight' => 200, 

                'plugins' => array('templateGenerator','imageListing'),

                'buttons' => array(

                   'html', 'formatting', '|', 'bold', 'italic', 'deleted',

                   'underline', 'alignleft', 'aligncenter', 'alignright', 'justify', '|',

                   'unorderedlist', 'orderedlist', 'outdent', 'indent', '|',

                   'image', 'video', 'file', 'table', 'link', '|',

                   'fontcolor', 'backcolor', '|', 'alignment', '|', 'horizontalrule', '|', 'tplGenerator'


                'imageUpload' => Yii::app()->createUrl('prodotti/imageUpload'),

                'imageGetJson' => Yii::app()->createUrl('prodotti/listImages'),


         ))); ?>

Thanks in advance

I do not understand why you want to put an included file after a document.ready script. The only thing that you need to ensure is that the jquery file is registered previous your custom redactor file.

For the ordering and location of scripts on the page you are facing a common problem of Yii’s CClientScript. They tried to solve the problem with ‘packages’, but IMHO, that is not enough. It would be great if each script has a ‘weight’ of preference in how they are rendered on the page and also according to its location.

To solve that issue I had to register the scripts writing my own script…

Thanks for the quick response

Ops i didn’t notice that the js block at the end was inside the document.ready… indeed after a further debugging i can see that redactor is properly initialized, i assumed the cause was the order because the same code worked fine if embedded directly in the view page… well i’ll have to find out the real issue then! Thanks again

As i thought, at the time my script is invoked, redactor isn’t initialized yet, an ugly way to solve this issue will be to put my script inside the view, sort of inlined, at the end of the page, but writing javascript + regex inside the clientscript string is an escaping hell…

Could you elaborate more what have you done to solve that?