1

I have a situation where some third party code is executing a callback with

YUI({
  delayUntil: 'domready'
}).use(....)

My issue is that I'm using another asynchronous script loader for my code, and I need to delay that callback until after my scripts have loaded. I'm using Yeti for unit testing which injects YUI into test pages, otherwise my code has nothing to do with YUI.

jQuery has a holdReady method that delays executing domready handlers registered through jQuery until some later time. I'm wondering if YUI has some equivalent method. This is for a test page and the code under test doesn't use YUI, so if the solution involves some ugly hack that'll be fine.

EDIT:

It turns out that Yeti uses its own scoped YUI object, and there isn't a way to access it anyway, so even if I found an answer to this question, it wouldn't help me here. In case anyone is wondering how I fixed the Yeti specific problem without finding a way in YUI to defer document ready handlers, here is my code:

!function(){
    var mochaListeners = [];
    var fakeRunner;
    // Stub for Yeti in case mocha isn't loaded on domready
    window.mocha = {
        run : function(){
            return fakeRunner = {
                on : function(type, fn){
                    mochaListeners.push([type, fn]);
                }
            };
        }
    };
    yepnope([
        {
            load : [
                'assets/lib/lodash.js',
                'assets/lib/jquery.js',
                'assets/lib/css/mocha.css',
                'assets/lib/mocha.js', 
                'assets/lib/chai.js', 
                'assets/lib/sinon.js'
            ],
            complete : function(){
                mocha.setup('bdd')
            }
        },{
            load : 'assets/js/my_tests.js',
            complete : function(){
                executeTests = function(){
                    var runner = mocha.run();
                    runner.ignoreLeaks = true;
                    _.forEach(mochaListeners, function(listener){
                        runner.on(listener[0], function(){
                            _.extend(fakeRunner, runner);
                            listener[1].apply(this, arguments);
                        });
                    });
                };
                if(document.readyState === 'complete')
                    executeTests();
                else
                    $(executeTests);
            }
    }]);
}();
Ryan Lynch
  • 7,676
  • 1
  • 24
  • 33
  • Something like this here, perhaps? : javascript - trying to fire onload event on script tag - Stack Overflow http://stackoverflow.com/questions/16230886/trying-to-fire-onload-event-on-script-tag – Leo Jan 28 '14 at 22:41
  • That might point to an answer, but Yeti injects its own code prior to mine, so I assume that YUI attaches the event listener before Yepnope (the loader I'm using) injects the script tags. – Ryan Lynch Jan 28 '14 at 22:51
  • I actually found this [post](http://50.57.100.169/forum/viewtopic.php?f=230&t=12589) in which someone brings up the exact same issue I'm having with Yeti, but it doesn't appear that its been fixed in the latest version. – Ryan Lynch Jan 28 '14 at 22:55

0 Answers0