Reputation: 6300
$(function() {
$('#dialog').click(function() {
alert("hello");
});
});
$('select').yaselect();
I am genuinely confused about how javascript script inclusion works. So the click handler for the dialog works fine. But the yaselect does not. I get $("select").yaselect is not a function
So jQuery seems to work, but the yaselect somehow not. It is included in the head section of the file though.
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/libs/jquery-1.7.2.min.js?"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/libs/jquery-ui-1.8.20.custom.min.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/libs/jquery.yaselect.min.js"></script>
However, the yii framework somehow includes jquery again later in the head section:
<script type="text/javascript" src="/assets/ab20866e/jquery.js"></script>
<script type="text/javascript" src="/assets/ab20866e/jquery.yiiactiveform.js"></script>
I understand this might be a problem, however I took over this code, I am new to yii and so am confused about what to do.
Upvotes: 0
Views: 1555
Reputation: 45124
This is due to the particular script which has yaselect(); implementation has not been included correctly. If you go through your javascript code you can find it where the code breaks. Click handler might be working fine because the jquery file has been imported correctly.
Also don't forget to check for jQuery duplicates and conflicts(Read more about noConflict()). This might cause the problem too. So make sure to remove the duplicates, in your case you have have included jquery as well as the framework too. Try to use a single version of jquery across the site.
if (jQuery) {
alert('jQuery is loaded!');
}
By using above code you can check whether the jquery has present in the page or not. If jquery does not exist in the page you can include.
Upvotes: 2
Reputation: 6300
http://www.yiiframework.com/wiki/311/assetmanager-clearing-browser-s-cache-on-site-update/
This appears to solve the problem. In Yii framework, you can use the AssetManager to handle static resources. If they then get referenced through the AssetManager instead of directly including them in the html source files, the yii framework takes care that resources are included once only.
Nice :)
Upvotes: 0