UNPKG

gd-bs

Version:

Bootstrap JavaScript, TypeScript and Web Components library.

79 lines (78 loc) 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.show = exports.setClassNames = exports.configureParent = exports.hide = exports.appendContent = void 0; var appendContent = function (elParent, content) { // Return if the parent or content doesn't exist if (elParent == null || content == null) { return; } // See if this is a string if (typeof (content) === "string" || typeof (content) === "number") { // Set the html elParent.innerHTML = content; } else { // Append the content elParent.appendChild(typeof (content) === "function" ? content() : content); } }; exports.appendContent = appendContent; var hide = function (el) { // Ensure the alert is hidden if (el.classList.contains("d-none")) { return; } // Hide the alert el.classList.add("d-none"); }; exports.hide = hide; var configureParent = function (component, parent) { // Create the element var el = document.createElement("div"); el.appendChild(component); // See if the parent element exists if (parent) { // Ensure the class list exists and it's not the body element if (parent.classList && parent.tagName != "BODY") { // Set the bootstrap class parent.classList.contains("bs") ? null : parent.classList.add("bs"); } // Append the elements while (el.children.length > 0) { parent.appendChild(el.children[0]); } // Update the element el = parent; } else { // Set the bootstrap class el.classList.add("bs"); } // Return the parent element return el; }; exports.configureParent = configureParent; var setClassNames = function (el, className) { // Ensure the element and class name exists exists if (el && className) { // Set the class names var classNames = className.split(' '); for (var i = 0; i < classNames.length; i++) { // Ensure the class name exists var className_1 = classNames[i]; if (className_1) { // Add the class el.classList.add(className_1); } } } }; exports.setClassNames = setClassNames; var show = function (el) { // Ensure the alert is visible if (el.classList.contains("d-none")) { // Show the alert el.classList.remove("d-none"); } }; exports.show = show;