Skip to content
Complex Loader and Progress Management for Vanilla JS
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples gif example Jul 23, 2018
resources gif example Jul 23, 2018
.editorconfig Update Jul 24, 2018
dom-wait.js readme Jul 23, 2018
index.html readme Jul 23, 2018

↺ DOM-wait

Multiple Process Loader Management for vanilla JavaScript.

Read the Medium post "Managing Complex Waiting Experiences on Web UIs".

DOM wait is a vanilla implementation of vue-wait.

DOM-wait helps to manage multiple loading states on the page without any conflict. It's based on a very simple idea that manages an array with multiple loading states.

🗝 Key Features

  • Zero-dependency. Requires nothing to work.
  • No CSS. Attaches and detaches elements instead of showing and hiding them.
  • Very simple API.

🚀 Quick Start

Add dom-wait.js to head.

    <script src="dom-wait.js"></script>

✂️ Usage

1. Write your HTML

dom-wait is very easy to use and migrate your current projects. Assume you have some API calls to get client IP.

  <h2>Your IP is:</h2>
  <div id='ip'>#.#.#.#</div>

    var $ip = document.getElementById('ip');
      .then(response => response.json())
      .then(response => {
        $ip.innerHTML = response.ip;

2. Add data-wait-for attribute

dom-wait watches elements with data-wait-for attribute with loading message.

<div data-wait-for='getting ip'>
  <h2>Your IP is:</h2>
  <div id='ip'>#.#.#.#</div>

2. Add .waiting element

This element will be attached when loading starts and detached when loading ends.

<div data-wait-for='getting ip'>

  <div class='waiting'>Getting IP...</div>

  <h2>Your IP is:</h2>
  <div id='ip'>#.#.#.#</div>

3. Start and stop waiters with wait.start and wait.end

var $ip = document.getElementById('ip');

// start waiting
wait.start('getting ip');

  .then(function (response) {
    return response.json();
  .then(function (response) {
    $ip.innerHTML = response.ip;
    // end waiting
    wait.end('getting ip');

🚦 Attach/Detach Based DOM Management

DOM-Wait doesn't make hide/show on elements. Instead, attaches and detaches elements to DOM. This makes DOM cleaner and lighter on waiting process.

<div data-wait-for="getting ip">
  <div id="ip">#.#.#.#</div>

DOM-Wait detaches .waiting elements from DOM and inserts a comment node instead. When loading starts it attaches back and detaches rest of the siblings:

<div data-wait-for="getting ip">
  <div class="waiting">Loading...</div>


MIT © Fatih Kadir Akın

You can’t perform that action at this time.