Hi all, i’m trying to use some javascript component into my application.
But i don’t know how to put them after the jquery.js
I load them in my AssetBundle class:
class CropScaleAsset extends AssetBundle {
public $sourcePath = '@vendor';
public $js = [
'bower/jrac/jrac/jquery.jrac.js',
];
public $css = [
'bower/jrac/jrac/style.jrac.css',
];
public $jsOptions = array(
//'position' => View::POS_HEAD // too high
//'position' => View::POS_READY // in the html disappear the jquery.jrac.js declaration
//'position' => View::POS_LOAD // disappear the jquery.jrac.js
'position' => View::POS_END // appear in the bottom of my page, but jquery is more down again
);
}
And this is my Widget
class CropScale extends Widget{
public $message;
public function init()
{
parent::init();
$view = $this->getView();
CropScaleAsset::register($view);
$content = "
$(document).ready(function() {
alert('DOM loaded');
});
";
$this->message = Html::script($content,['type'=>'text/javascript']) ;
return $this->message;
}
public function run()
{
return $this->message;
}
}
As you see i try the $jsOptions reading in some forum but i don’t solve.
Can someone help me?
Thank’s alot.
EDIT:
i continue to study yii2 and i find the ‘depends’ property in the AssetBundle.php. After some test i solve a part of my problem (or i think so) as this:
public $depends = [
'yii\web\JqueryAsset'
];
now my problem is that if a create a simple script on a page with a simple
$(document).ready(function()
i get the error “$ is not defined” because jquery is at the bottom of the page and nod in the head.