Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/duzun/jquery.loading
Add class(es) to DOM elements while waiting for async action. Promise or callback.
https://github.com/duzun/jquery.loading
javascript jquery jquery-plugin loader promise
Last synced: 20 days ago
JSON representation
Add class(es) to DOM elements while waiting for async action. Promise or callback.
- Host: GitHub
- URL: https://github.com/duzun/jquery.loading
- Owner: duzun
- License: mit
- Created: 2018-08-01T12:19:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-18T06:28:58.000Z (about 1 year ago)
- Last Synced: 2024-11-16T09:07:41.808Z (about 2 months ago)
- Topics: javascript, jquery, jquery-plugin, loader, promise
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/class-loading
- Size: 242 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jquery.loading
Add class(es) to DOM elements while waiting for async action. Promise or callback.
## Install
The simplest way is to include `loading.js` in your HTML after `jQuery` script:
```html
```
If you are using `npm`:
```sh
npm install -S class-loading
```## Import or require
This library can be included either as an ESM or UMD.
#### ESM
```js
import initLoading from 'class-loading';
import $ from 'jquery';initLoading($);
```#### CommonJS
```js
const initLoading = require('class-loading');
const $ = require('jquery');initLoading($);
```## Usage
```js
// 1. Stack multiple loaders
$('selector').loading('loading loader-1'); // add classes
$('selector').loading('disabled'); // add another class
// ...
$('selector').loading(false); // remove .disabled
$('selector').loading(false); // remove .loading.loader-1// 2. Get a callback to remove classes
var cb = $('selector').loading('loading loader-2', true);
// ...
cb(); // remove added loading class// 3. Wait for a Promise to resolve/reject
$('selector').loading('loading loader-3', promise);
```