globalize.js: dynamic loading

1.1k views Asked by At

I am trying to the example for plain JS of the gloablize (https://github.com/jquery/globalize) running in an advanced way based on https://github.com/jquery/globalize/blob/master/doc/cldr.md.

Therefore I created a loader script to load all dependencies:

var url = new URL(window.location.href);
//STATIC_URL: global variable from base.html
$.when( 
        $.getScript( url.origin + STATIC_URL + "js/globalize2/cldrjs/cldr.js" ),
        $.getScript( url.origin + STATIC_URL + "js/globalize2/cldrjs/cldr/event.js" ),
        $.getScript( url.origin + STATIC_URL + "js/globalize2/cldrjs/cldr/supplemental.js" ),
        $.getScript( url.origin + STATIC_URL + "js/globalize2/globalize.js" ),
        $.getScript( url.origin + STATIC_URL + "js/globalize2/globalize/date.js" ),
        $.getScript( url.origin + STATIC_URL + "js/globalize2/globalize/number.js" ),
        $.getScript( url.origin + STATIC_URL + "js/globalize2/globalize/plural.js" ),

        $.Deferred(function( deferred ){
            $( deferred.resolve );
        })
).done(function(){
    $.when(
      $.get( url.origin + STATIC_URL + "js/globalize2/cldr/main/de/ca-gregorian.json" ),
      $.get( url.origin + STATIC_URL + "js/globalize2/cldr/supplemental/likelySubtags.json" ),
      $.get( url.origin + STATIC_URL + "js/globalize2/cldr/supplemental/timeData.json" ),
      $.get( url.origin + STATIC_URL + "js/globalize2/cldr/supplemental/weekData.json" )
    ).then(function() {

      // Normalize $.get results, we only need the JSON, not the request statuses.
      return [].slice.apply( arguments, [ 0 ] ).map(function( result ) {
          return result[ 0 ];
      });

    }).then( Globalize.load ).then(function() {

      // Your code goes here.

    }); 
});

All files are loaded correctly as far as i can see in Firebug. But when it comes to the Globalize.load step, the reference is marked as not defined.

I don't have a clue whats wrong at the moment. Any help welcome.

0

There are 0 answers