Load Module Assets With Conditional

Hi all,

I need some help about module, I try to load assets on my init module like this :




class MyModule extends CWebModule

{

	protected $_excludeJs = false;


	public function init()

	{

            if ($this->_excludeJs == false) {

                // Load all JS for this module

            }

        }

        

        public function anotherFunction()

        {

            // Do some stuff

        }


        public function noJS()

        {

            $this->_excludeJs = true;


            return $this;

        }

}



And when I run Yii::app()->getModule(‘my’), it’ll automatically load all needed JS for this module and this is okay. But the problem is I want to skip the JS when I want to run another function that doesn’t need JS like “anotherFunction”, so I try with chaining function like this :




    Yii::app()->getModule('my')->noJS()->anotherFunction();



but It still load the JS, maybe it because I put register script in init() function, is there is any way to do this?

Thanks.

Anybody?

I’m also has searching how to unregister the script after I register it but, didn’t find the right way. Any help really appreciate.