@w-vision/load-yumpu-api
v1.0.0
Published
A lightweight Promise-returning helper for loading the Yumpu JavaScript API.
Downloads
13
Maintainers
Readme
A lightweight Promise-returning helper for loading the Yumpu JavaScript API.
- The Promise’s fulfilled callback is passed the
Yumpu
object - 224 bytes gzipped
Usage
import loadYumpuApi from '@w-vision/load-yumpu-api';
loadYumpuApi()
.then(Yumpu => {
const yumpu = new Yumpu();
yumpu.create_player("#magazineContainer", "17403069");
}).catch(error => {
console.error(error);
});
N.B. Just like the Yumpi API itself, this module is client-side only.
Motivation
Without this module, you would need to add a script tag to your page. For example:
<script src="https://players.yumpu.com/hub.js"></script>
<script type="text/javascript">
// `window.Yumpu` available here
</script>
This module abstracts this ceremony away, and fits better with modern bundlers like Rollup or Webpack.
API
import loadYumpuApi from '@w-vision/load-yumpu-api';
loadYumpuApi()
Returns a Promise.
- Fulfilled if loading was successful. The fulfilled callback is passed the
Yumpu
object. IfloadYumpuApi
is called multiple times on a page, the fulfilled callback will be passed the previously-loadedYumpu
object. - Rejected if we weren’t able to load the Yumpu API.
See Usage.
Installation
Install via yarn:
$ yarn add @w-vision/load-yumpu-api
Or npm:
$ npm install --save @w-vision/load-yumpu-api