{"id":13701049,"url":"https://github.com/f/dom-wait","last_synced_at":"2025-02-28T19:42:16.547Z","repository":{"id":45754172,"uuid":"140401959","full_name":"f/dom-wait","owner":"f","description":"Complex Loader and Progress Management for Vanilla JS","archived":false,"fork":false,"pushed_at":"2018-07-24T08:00:52.000Z","size":4647,"stargazers_count":143,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-11T11:48:02.334Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/f.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-10T08:32:25.000Z","updated_at":"2024-09-17T10:06:00.000Z","dependencies_parsed_at":"2022-07-30T13:18:12.694Z","dependency_job_id":null,"html_url":"https://github.com/f/dom-wait","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fdom-wait","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fdom-wait/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fdom-wait/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f%2Fdom-wait/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f","download_url":"https://codeload.github.com/f/dom-wait/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241214316,"owners_count":19928297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T20:01:15.363Z","updated_at":"2025-02-28T19:42:16.524Z","avatar_url":"https://github.com/f.png","language":"HTML","readme":"## ↺ DOM-wait\n\nMultiple Process Loader Management for vanilla JavaScript.\n\n**Read the [Medium post \"Managing Complex Waiting Experiences on Web UIs\"](https://medium.com/@fkadev/managing-complex-waiting-experiences-on-web-uis-29534d2d92a8).**\n\n\u003e DOM wait is a vanilla implementation of [vue-wait](https://github.com/f/vue-wait).\n\n**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.\n\n\u003cimg src=\"./resources/dom-wait.gif?v1\" width=\"100%\"\u003e\n\n# 🗝 Key Features\n\n - Zero-dependency. Requires nothing to work.\n - No CSS. Attaches and detaches elements instead of showing and hiding them.\n - Very simple API.\n\n# 🚀 Quick Start\n\nAdd `dom-wait.js` to `head`.\n\n```html\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cscript src=\"dom-wait.js\"\u003e\u003c/script\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n# ✂️ Usage\n\n## 1. Write your HTML\n\n`dom-wait` is very easy to use and migrate your current projects. Assume you have some API calls `ipapi.co` to get client IP.\n\n```html\n\u003cdiv\u003e\n  \u003ch2\u003eYour IP is:\u003c/h2\u003e\n  \u003cdiv id='ip'\u003e#.#.#.#\u003c/div\u003e\n\n  \u003cscript\u003e\n    var $ip = document.getElementById('ip');\n    fetch('https://ipapi.co/json')\n      .then(response =\u003e response.json())\n      .then(response =\u003e {\n        $ip.innerHTML = response.ip;\n      });\n  \u003c/script\u003e\n\u003c/div\u003e\n```\n\n## 2. Add `data-wait-for` attribute\n\n`dom-wait` watches elements with `data-wait-for` attribute with loading message.\n\n```html\n\u003cdiv data-wait-for='getting ip'\u003e\n  \u003ch2\u003eYour IP is:\u003c/h2\u003e\n  \u003cdiv id='ip'\u003e#.#.#.#\u003c/div\u003e\n\u003c/div\u003e\n```\n\n## 2. Add `.waiting` element\n\nThis element will be **attached** when loading starts and **detached** when loading ends.\n\n```html\n\u003cdiv data-wait-for='getting ip'\u003e\n\n  \u003cdiv class='waiting'\u003eGetting IP...\u003c/div\u003e\n\n  \u003ch2\u003eYour IP is:\u003c/h2\u003e\n  \u003cdiv id='ip'\u003e#.#.#.#\u003c/div\u003e\n\u003c/div\u003e\n```\n\n## 3. Start and stop waiters with `wait.start` and `wait.end`\n\n```js\nvar $ip = document.getElementById('ip');\n\n// start waiting\nwait.start('getting ip');\n\nfetch('https://ipapi.co/json')\n  .then(function (response) {\n    return response.json();\n  })\n  .then(function (response) {\n    $ip.innerHTML = response.ip;\n    // end waiting\n    wait.end('getting ip');\n  });\n```\n\n# 🚦 Attach/Detach Based DOM Management\n\n**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.\n\n```html\n\u003cdiv data-wait-for=\"getting ip\"\u003e\n  \u003c!--wait:8ef4c4e7--\u003e\n  \u003cdiv id=\"ip\"\u003e#.#.#.#\u003c/div\u003e\n\u003c/div\u003e\n```\n\nDOM-Wait detaches `.waiting` elements from DOM and inserts a comment node instead. When loading starts it attaches back and detaches rest of the siblings:\n\n```html\n\u003cdiv data-wait-for=\"getting ip\"\u003e\n  \u003cdiv class=\"waiting\"\u003eLoading...\u003c/div\u003e\n  \u003c!--wait:c9169aa9--\u003e\n\u003c/div\u003e\n```\n\n# License\n\nMIT \u0026copy; [Fatih Kadir Akın](https://github.com/f)\n","funding_links":[],"categories":["HTML"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff%2Fdom-wait","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff%2Fdom-wait","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff%2Fdom-wait/lists"}