Using yep / nope with document.ready

I am using yepnope.js but have a little problem loading function download

in my head I turn on yep nope and make a call to the corresponding js file

<script type="text/javascript" src="/code/trunk/javascript/external/modernizr/modernizr-development.js"></script> <script type="text/javascript" src="/code/trunk/javascript/external/yepnope.1.5.3-min.js"></script> <script type="text/javascript"> yepnope({ test: Modernizr.mq('only all and (max-width: 700px)'), yep: ['/templates/client/jquery/qff/plugin.mobile.js'], nope:['/templates/client/jquery/qff/plugin.website.js'] }); </script> 

and then at the bottom of the page

 <script type="text/javascript"> jQuery(document).ready(function() { jQuery("#mainContent").setupQantas({ startSlide: 1, googleAnalytics:1, googleCode:"" }); }); </script> 

so I look at it on the main screen. so he suggested calling plugin.mobile.js

in plugin.mobile.js file

 (function( $ ){ $.fn.setupQantas = function( options ) { // Create some defaults, extending them with any options that were provided var settings = $.extend( { startSlide: 1, googleAnalytics:0, // 1 sends to google googleCode: "" }, options); var methods = {}; return this.each(function() { if (settings.startSlide === 1) { alert("slide = 1"); } else { alert("slide > 1"); } }); }; })( jQuery );// JavaScript Document 

instead of showing warning slide 1, it has an error

 jQuery("#mainContent").setupQantas is not a function 

If I do not use yepnope and just have it in the script tag, it works. There seems to be a delay when yepnope loads into js file and doesn't seem to work until doc.ready

Is there any way around this?

thanks

+4
source share
2 answers

Yes, there is a delay. This is all that is behind the asynchronous script loader.

You should use the callback after loading the yepnope script. Check complete and callback options.

+3
source

here is the code

 <script type="text/javascript"> yepnope({ test: Modernizr.mq('only all and (max-width: 700px)'), yep: ['/templates/client/jquery/qff/mobile.js'], nope:['/templates/client/jquery/qff/website.js'], complete: function () { jQuery("#mainContent").setupQantas({ startSlide: 1, googleAnalytics:1, googleCode:"" }); } }); </script> 
0
source

All Articles