Sha256: a1486be408ce8e72f88b6d99e47c3932e57032db3e14b40b53d5b0d516cf80f8

Contents?: true

Size: 953 Bytes

Versions: 5

Compression:

Stored size: 953 Bytes

Contents

// copy-paste from https://bradb.net/blog/promise-based-js-script-loader/
$(function () {
    window.loadJSAsync = function(url) {
      if(Array.isArray(url)) {
          var self = this, prom = [];
          url.forEach(function(item) {
              prom.push(self.script(item));
          });
          return Promise.all(prom);
      }

      return new Promise(function (resolve, reject) {
          var r = false,
              t = document.getElementsByTagName("script")[0],
              s = document.createElement("script");

          s.type = "text/javascript";
          s.src = url;
          s.async = true;
          s.onload = s.onreadystatechange = function () {
              if (!r && (!this.readyState || this.readyState == "complete")) {
                  r = true;
                  resolve(this);
              }
          };
          s.onerror = s.onabort = reject;
          t.parentNode.insertBefore(s, t);
      });
  }
});

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lcms-engine-0.1.4 app/assets/javascripts/lcms/engine/initializers/loadasync.js
lcms-engine-0.1.3 app/assets/javascripts/lcms/engine/initializers/loadasync.js
lcms-engine-0.2.0 app/assets/javascripts/lcms/engine/initializers/loadasync.js
lcms-engine-0.1.2 app/assets/javascripts/lcms/engine/initializers/loadasync.js
lcms-engine-0.1.0 app/assets/javascripts/lcms/engine/initializers/loadasync.js