Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yepnope.js - problem with scripts on same page

I included yepnope.js and then the following:

<script type="text/javascript"> 
/*<![CDATA[*/
    yepnope([{
      load: 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js',
      complete: function () {
        if (!window.jQuery) {
          yepnope('local/jquery.min.js');
        } ...

However, while jquery is loading from the cdn, the following script at the end of the page is showing an error:

/*<![CDATA[*/
jQuery(function($) {
jQuery('#Project_projectDateStart').datepicker({'dateFormat...

the error is jQuery is not defined

I have no option but to load the script at the end (loaded with Yii datepicker in this instance).

Any help much appreciated.

like image 721
Joe Avatar asked Nov 29 '25 01:11

Joe


1 Answers

If you are going to use yepnope, you need to use callback functions. You cannot directly call jQuery since it is loaded asynchronously. It's a little difficult to parse the documentation on yepnopejs.com but that's the gist of it.

Basically, none of Yii's default AJAX and other JS helpers are going to work with yenope, from what I can tell. Or if they do work, it will be because Yii included another copy of jQuery in addition to the yepnope async loaded on from Google. You will probably need to do a bunch of work modifying the way Yii loads scripts to get it work correctly with an asynchronous loader like yepnope.

Good luck though! Async loaders are great for page performance, I use the Facebook one all the time.

like image 89
thaddeusmt Avatar answered Nov 30 '25 17:11

thaddeusmt