I need some guides or basic advices and best practicies how to process widgets’ javascript code with my ajax content.
So, i have this structure:
Widget, lets call it CJavaScript extends CWidget which have Yii::app()->getClientScript()->registerScriptFile at init() method.
Statically loaded this widget works good, but i have 2 situations:
-
CJuiTabs loading some controller action via built-in ajax
-
I have my own function which load some controller action via ajax and then do $contanter.html(data);
widget obviously loads at this controller action and ofc doesn’t load javascript files
i also have 2 ideas:
-
echo javascript right after widget which will lead to duplication if i cann this widget 2 times…
-
awful code duplication where i stupidly load all possible widgets’ javascript files in a page and then load ajax for this code.
I want to read what is best practice to call those widgets’ javascript code if i load them via ajax, or this is bad idea overall, may be some advices?