How to use load-script - 10 common examples

To help you get started, we’ve selected a few load-script examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github katspaugh / wavesurfer.js / src / html-init.js View on Github external
loadPlugin(name, cb) {
                    const src = _params.pluginCdnTemplate.replace(
                        '[name]',
                        name
                    );
                    loadScript(src, { async: false }, (err, plugin) => {
                        if (err) {
                            // eslint-disable-next-line no-console
                            return console.error(
                                `WaveSurfer plugin ${name} not found at ${src}`
                            );
                        }
                        cb(window.WaveSurfer[name]);
                    });
                }
            },
github gajus / youtube-player / src / loadYouTubeIframeApi.js View on Github external
const iframeAPIReady = new Promise((resolve) => {
    if (window.YT && window.YT.Player && window.YT.Player instanceof Function) {
      resolve(window.YT);

      return;
    } else {
      const protocol = window.location.protocol === 'http:' ? 'http:' : 'https:';

      load(protocol + '//www.youtube.com/iframe_api', (error) => {
        if (error) {
          emitter.trigger('error', error);
        }
      });
    }

    const previous = window.onYouTubeIframeAPIReady;

    // The API will call this function when page has finished downloading
    // the JavaScript for the player API.
    window.onYouTubeIframeAPIReady = () => {
      if (previous) {
        previous();
      }

      resolve(window.YT);
github reactioncommerce / reaction-example-plugin / client / components / availabilityMap.js View on Github external
componentDidMount() {
    if (this.props.trackingId) {
      if ($("#mapsHead").length === 0) {
        const url = `https://maps.googleapis.com/maps/api/js?key=${this.props.trackingId}`;
        loadScript(url, { attrs: { id: "mapsHead" } }, () => {
          // DocHead.loadScript(url, { attrs: { id: "mapsHead" } }, () => {
          this.renderMap();
        });
      } else {
        this.renderMap();
      }
    }
  }
github devnews / web / src / components / Sponsor / index.js View on Github external
componentDidMount() {
    if (!window.codesponsorLoaded) {
      loadScript('https://app.codesponsor.io/scripts/IQnppckqRltebNM5FH2qZg?theme=light&image=hide&width=400&height=115', (error) => {
        if (!error) window.codesponsorLoaded = true;
      });
    }
  }
github sdoomz / react-dropbox-chooser / src / react-dropbox-chooser.js View on Github external
componentDidMount() {
    if (!this.isDropboxReady() && !scriptLoadingStarted) {
      scriptLoadingStarted = true;
      loadScript(DROPBOX_SDK_URL, {
        attrs : {
          id: SCRIPT_ID,
          'data-app-key': this.props.appKey
        }
      });
    }
  }
github ckeditor / ckeditor4-react / src / getEditorNamespace.js View on Github external
promise = new Promise( ( scriptResolve, scriptReject ) => {
			loadScript( editorURL, err => {
				if ( err ) {
					scriptReject( err );
				} else {
					scriptResolve( window.CKEDITOR );
					promise = undefined;
				}
			} );
		} );
	}
github cazala / react-coin-hive / src / index.js View on Github external
this.miner = await new Promise(resolve => {
      loadScript('https://coinhive.com/lib/coinhive.min.js', () => {
        if (this.props.userName) {
          return resolve(CoinHive.User(this.props.siteKey, this.props.userName));
        }
        return resolve(CoinHive.Anonymous(this.props.siteKey));
      })
    })
    this.handleProps(this.props);
github recurly / recurly-js / lib / recurly / risk / three-d-secure / strategy / stripe.js View on Github external
return new Promise((resolve, reject) => {
      if (window.Stripe) return resolve();
      loadScript(StripeStrategy.libUrl, error => {
        if (error) reject(error);
        else resolve();
      });
    });
  }
github BEE-Plugin / Bee-plugin-official / src / bee.js View on Github external
const load = (bee) => {
  loadScript(beeLoaderUrl.beePluginUrl, err => {
    if (err) {
      throw new Error('BeePlugin.js is not reachable')
    }
    return bee()
  })
}
github recurly / recurly-js / lib / recurly / paypal / strategy / braintree.js View on Github external
const get = (lib, done = () => {}) => {
      const uri = `https://js.braintreegateway.com/web/${BRAINTREE_CLIENT_VERSION}/js/${lib}.min.js`;
      loadScript(uri, error => {
        if (error) this.error('paypal-load-error', { cause: error });
        else done();
      });
    };

load-script

Dynamic script loading for browser

MIT
Latest version published 3 years ago

Package Health Score

71 / 100
Full package analysis

Popular load-script functions