Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow async load? #34

Open
dxe4 opened this issue Oct 28, 2016 · 0 comments
Open

allow async load? #34

dxe4 opened this issue Oct 28, 2016 · 0 comments

Comments

@dxe4
Copy link

dxe4 commented Oct 28, 2016

if this line is removed
if (!window.OT) throw new Error('You must include the OT library before the OT_Angular library');

and this is removed

  .factory('OT', function() {
    return OT;
  })

and OT injection changes to window.OT

and OT.$.eventing(OTSession);
changes to

      var _interval = $interval(function(){
        if (window.TB) {
                $interval.cancel(_interval);
                OT.$.eventing(OTSession);
        }
      }, 500);

then you can have:

        service.addScript = function(url, defer) {

           if (window.TB) {
                 defer.resolve()
                 return
            }

            var script = document.createElement('script');
            script.type = 'text/javascript';
            script.async = true;
            script.onload = function(){
                defer.resolve();
            };
            script.src = url;
            document.getElementsByTagName('head')[0].appendChild(script);
        }

and in state definition:

resolve : {
    TBloaded: function(){
            service.addScript("...tokboxjslink...", defer)
           return defer.promise
     }
}

so then you can load tokbox asynchronously (and you can also register window.onload event to download tokbox after everything else has loaded). I think it makes a big difference because its a big library.

I could make a pull request but i probably won't find time to unit-test it, but if someone feels like doing it here's the coded needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant