loading jQuery migrate with curl.js

203 views
Skip to first unread message

Szépe Viktor

unread,
Dec 3, 2013, 9:19:18 PM12/3/13
to cuj...@googlegroups.com
curl(['domReady!']).next(['jquery'], function (jq) {
    console
.log(typeof jq);
});

returns "function" and waits for DOM ready before loading jQuery

Please tell me how to load jQuery Migrate which is not AMD compatible

  1. wait for DOM ready
  2. begin loading jQuery
  3. when jQuery is executed load non-AMD jQuery Migrate
  4. get jQuery's return value (which should be a function)
curl(['domReady!']).next(['jquery']).next(['js!jquery-migrate'], function (jq) {
    console
.log(typeof jq);
});


returns "boolean" (so it is not good)

curl(['domReady!']).next(['jquery'], function (jq) {
    curl
(['js!jquery-migrate'], function () {
        console
.log(typeof jq);
        console
.log(jq);
        console
.log(jq === window.jQuery);
   
});
});


it there any better solution?

unscriptable

unread,
Dec 3, 2013, 11:45:43 PM12/3/13
to cuj...@googlegroups.com
Here's a run.js file from a recent project that used jquery-migrate (I removed some of the less interesting parts of it).  It uses the legacy loader ("curl/loader/legacy") to specify dependencies from non-modules to modules.  The .next() API method is deprecated.

var curl;
(function () {

   
var cjsConfig = {
        loader
: 'curl/loader/cjsm11'
   
};

    curl
.config({
        baseUrl
: baseUrl,
        packages
: {
            app
: { location: 'app', config: cjsConfig, main: 'main' },
            component
: { location: 'component', config: cjsConfig },
            curl
: { location: 'lib/curl/src/curl/' },
           
when: { location: 'lib/when', main: 'when' },
            poly
: { location: 'lib/poly' }
       
},
        paths
: {
            jquery
: 'lib/jquery/jquery.min',
           
'jquery-migrate': {
                location
: '//code.jquery.com/jquery-migrate-1.2.1.js',
                config
: {
                    loader
: 'curl/loader/legacy',
                    requires
: [ 'jquery' ],
                    exports
: '$.migrateWarnings'
               
}
           
}
       
},
        preloads
: ['poly/es5']
   
});

    curl
(['app', 'jquery', 'jquery-migrate']).then(start, fail);

   
function start(main, $, warnings) {
       
// tell the jquery migrate plugin to be quiet
        $
.migrateMute = true;
   
}

   
function fail(ex) {
       
// TODO: show a meaningful error to the user.
       
//document.location.href = '/500';
       
throw ex;
   
}

}());

Be sure to include a package declaration for curl and a path declaration for jquery.  

You probably already know that jquery-migrate is not meant for use in production.  :)

-- John
Reply all
Reply to author
Forward
0 new messages