0

i am using Modernizr to load ressources to construct a jQuery layout. The problem is that i cannot retrieve my $('body').layout() variable since it is inside one of the loaded resources (in script/webframe.js). I tried :

var myLayout;

function loadDefaultLayout() {

    Modernizr.load([{
        load: ['stylesheets/jquery.layout.css',
                'script/jquery.layout.min.js',
                'script/webframe.js'],
        complete: function () {
            myLayout = onDesktopWebFrameLoadComplete();
        }
    }]);

    alert(myLayout.options.west.resizable);
}

Where onDesktopWebFrameLoadComplete is in script/webframe.js and returns the layout.

I tried moving alert(myLayout.options.west.resizable); just after onDesktopWebFrameLoadComplete and the alert was showing true. But when I move it out of the load() scope, I have an undefined error (for myLayout variable).

My question is : I would like to know if it is possible to retrieve a variable outside of Modernizr.load() complete function scope.

1 Answers1

0

My problem was only that I did not define my global variable in the right html file that called the function from the JavaScript file.

So in summary. Define your variable this way before everything else :

window.myLayout;

Then add your resource that will change your variable (that contains the load() function)

Change your variable in this resource : window.myLayout = "something-else";

You can now use it in the html file that included your resource.