jQuery reference error

Goodafternoon all,

I’m trying to add a jquery splitter plugin. I use the registerscript method to add the splitter.js and a function to be executed when the document is ready to get the actual splitter. The css is loaded in the main, together with other css-files.

This results in an error, that jquery is not defined (Uncaught ReferenceError: jquery is not defined)

and afterwards the splitter is not executed cause it’s not defined, giving an alert.

code:

Yii::app()->clientScript->registerScript(‘splitter’, Yii::app()->request->getBaseUrl().’/js/jquery.splitter.js;’, CClientScript::POS_HEAD);

$splitterScript = 'if(jQuery.splitter) {

				$("#splitterContainer").splitter({minAsize:100,maxAsize:300,splitVertical:true,A:$("#leftPane"),B:$("rightPane"),slave:$("#rightSplitterContainer"),closeableto:0});


				$("#rightSplitterContainer").splitter({splitHorizontal:true,A:$("#rightTopPane"),B:$("#rightBottomPane"),closeableto:100});


			} else {


				alert("Splitter not loaded");


			}';

Yii::app()->clientScript->registerScript(‘splitterScript’,$splitterScript, CClientScript::POS_READY);

Regards,

Maubert

from what you said the script is probably placed before the jquery is included. So try changing CClientScript::POS_HEAD to CClientScript::POS_END to insert it in the end of your page

Could be that jquery is not included at all… for this you need to use registerCoreScript(‘jquery’) - http://www.yiiframework.com/doc/api/1.1/CClientScript#registerCoreScript-detail

and

registerScript() is used to register a piece of javascript code, to register a JS file like jquery.splitter.js use registerScriptFile() - http://www.yiiframework.com/doc/api/1.1/CClientScript#registerScriptFile-detail

Sorry, but it didn’t work. However, it made me realize that I use the wrong register-method. I should use the registerScriptFile as I want to include a script file, not a script. So now the file is loaded, even with the POS_HEAD-option. When I added the CSS-file, it became a mess so that’s the next step.

Danila, thank you for your reply!

Regards,

Maubert

Mdomba, you’re right. I did use the wrong method.

Thank you!

Maubert

btw

When you post code please use the code button (<> on the editor toolbar) or use the code directive ([ code]yourcode[ /code] - without spaces)

so that the code is styled and more readable…

P.S. You can even edit your first post to add this…