Yii Framework Forum: Yiibooster, Redactorjs, Custom Js File Positioning - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yiibooster, Redactorjs, Custom Js File Positioning

#1 User is offline   Fabio P. 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 01-March 13

Posted 03 May 2013 - 05:54 AM

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()->clientScript->registerScriptFile(
    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">
/*<![CDATA[*/
jQuery(function($) {
jQuery('body').tooltip({'selector':'[rel=tooltip]'});
jQuery('body').popover({'selector':'[rel=popover]'});
jQuery('#Prodotti_schedaTecnica').redactor({'lang':'it','minHeight':200,'plugins':['templateGenerator','imageListing'],'buttons':['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':'/medispo/index.php?r=prodotti/imageUpload&prodottoId=','imageGetJson':'/medispo/index.php?r=prodotti/listImages&prodottoId='});
});



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
0

#2 User is offline   Antonio Ramirez 

  • Elite Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 1,450
  • Joined: 04-October 10

Posted 03 May 2013 - 06:09 AM

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...
┬┐How long would it take for you to understand that you own nothing in this world?

www.ramirezcobos.com
www.2amigos.us
www.github.com/tonydspaniard
www.github.com/2amigos


Posted Image
0

#3 User is offline   Fabio P. 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 01-March 13

Posted 03 May 2013 - 07:26 AM

Thanks for the quick response

View PostAntonio Ramirez, on 03 May 2013 - 06:09 AM, said:

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...


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
0

#4 User is offline   Fabio P. 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 01-March 13

Posted 06 May 2013 - 07:58 AM

View PostFabio P., on 03 May 2013 - 07:26 AM, said:

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?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users