A beautiful animated loader with a js busy queuing system.
busy.start('fetching dinner', 30, true); // modal spinner with 30 second timeout window.setTimeout( function () { busy.stop('fetching dinner') // stop spinner after 10 seconds }, 10000);
- Easy to use.
- Lazy loading (small initial page load).
- Usable as a webpack/ES6 module or a pre-built browser bundle.
- Loaders can be 'modal', and are queued allowing for representation of multiple slow operations.
- Download & copy this package's "dist" folder into your web server's public folder eg.
public/js/dist/*
. - Rename "dist" to "busy" eg.
public/js/busy
- Load the busy script at the end of your web page (before the closing
body
tag) like this:
<body>
...
<script src="/js/busy/busy.js"></script>
</body>
</html>
- When the browser loads, busy will be attached to the browser's global window object. Use it anywhere in your scripts like this:
<button>Target</button>
<script>
busy.start('test-1', 15); // start a loader
busy.start('test-2', 60); // register another loader
...
busy.stop('test-1'); // stop the specified loader
...
busy.reset(); // clear all loaders
</script>
Install the busy package into your project using npm:
$ cd to/your/project $ npm install @aamasri/busy
Then import and use it in your project's ES6 modules:
import busy from 'busy';Leveraging Webpack's on-demand (lazy) loading and code-splitting:function fetchDataFromApi() { busy.start('fetching data', 10, true); }
import(/* webpackChunkName: "busy" */ 'busy').then((busy) => { busy.start('loading');fetch(api....) .then(data => { busy.stop('loading'); ... })...
});
busy.start(id, timeout, modal) // create a new loader instance
busy.stop(id) // stop a specific loader instance
busy.reset() // close all loaders (clear busy queue)
busy.queue // the actual busy queue object
Option | Type | Description | Default |
---|---|---|---|
id | string | unique id (enables it to be stopped later) | '' |
timeout | int | undefined | timeout (in seconds) after which loader will stop automatically. | 7 seconds |
modal | boolean | undefined | background blurring & dimming | false |
Option | Type | Description | Default |
---|---|---|---|
id | string | unique id (enabling a specific loader to be stopped) | '' |
Busy supports npm under the name @aamasri/busy
.
$ npm install @aamasri/busy --save
@aamasri/busy depends on 2 external packages:
- jquery
- @aamasri/dom-utils
Invoking the busy.start() function will dynamically load these dependencies at run-time (if these scripts don't already exist on the page) and they'll be added to the global window object.
- Increment the "version" attribute of `package.json`.
- Update the "versionDescription" string of `package.json`.
- Re-build the browser output bundle...
npm run build-production
...and observe that webpack completed with no errors. - Test the bundle by loading page: "dist/index.html" in a browser (setup a development webserver).
- Publish to the git repository and npm package registry:
npm run publish
- Ananda Masri
- And awesome contributors