From 890a377ce7bfb089f1efd809132682fa5ffee6ab Mon Sep 17 00:00:00 2001 From: Shantanu Dutta <7542135+nlern@users.noreply.github.com> Date: Sun, 25 Aug 2019 20:55:50 +0530 Subject: [PATCH] 1. Added vanilla js script dom-is-ready.js to check if DOM content is loaded. 2. Added script source to index.html. 3. Used script in index.js. --- .../1. Bin2Dec/Web/dom-is-ready.js | 25 +++++++++++++++++++ .../1. Bin2Dec/Web/index.html | 9 ++++++- .../1. Bin2Dec/Web/index.js | 6 +++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 Solutions/1. Tier 1 - Begineer Projects/1. Bin2Dec/Web/dom-is-ready.js diff --git a/Solutions/1. Tier 1 - Begineer Projects/1. Bin2Dec/Web/dom-is-ready.js b/Solutions/1. Tier 1 - Begineer Projects/1. Bin2Dec/Web/dom-is-ready.js new file mode 100644 index 00000000..5d59faa9 --- /dev/null +++ b/Solutions/1. Tier 1 - Begineer Projects/1. Bin2Dec/Web/dom-is-ready.js @@ -0,0 +1,25 @@ +var domIsReady = (function (domIsReady) { + var isBrowserIeOrNot = function () { + return (!document.attachEvent || typeof document.attachEvent === "undefined" ? 'not-ie' : 'ie'); + } + + domIsReady = function (callback) { + if (callback && typeof callback === 'function') { + if (isBrowserIeOrNot() !== 'ie') { + document.addEventListener("DOMContentLoaded", function () { + return callback(); + }); + } else { + document.attachEvent("onreadystatechange", function () { + if (document.readyState === "complete") { + return callback(); + } + }); + } + } else { + console.error('The callback is not a function!'); + } + } + + return domIsReady; +})(domIsReady || {}); \ No newline at end of file diff --git a/Solutions/1. Tier 1 - Begineer Projects/1. Bin2Dec/Web/index.html b/Solutions/1. Tier 1 - Begineer Projects/1. Bin2Dec/Web/index.html index ecc648f0..339603de 100644 --- a/Solutions/1. Tier 1 - Begineer Projects/1. Bin2Dec/Web/index.html +++ b/Solutions/1. Tier 1 - Begineer Projects/1. Bin2Dec/Web/index.html @@ -7,6 +7,13 @@