UNPKG

gd-bs

Version:

Bootstrap JavaScript, TypeScript and Web Components library.

45 lines (44 loc) 1.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateIcon = void 0; // Generates the html for an icon var generateIcon = function (svg, height, width, className, placeholders) { if (height === void 0) { height = 32; } if (width === void 0) { width = 32; } // See if placeholders exist if (typeof (placeholders) === "number" && placeholders > 0) { // Parse the number of placeholders for (var i = 0; i < placeholders; i++) { var regex = new RegExp("\\{" + i + "\\}", "g"); // Replace the placeholder svg = svg.replace(regex, Math.floor(Date.now() * Math.random()).toString()); } } // Get the icon element var elDiv = document.createElement("div"); elDiv.innerHTML = svg; var icon = elDiv.firstChild; if (icon) { // See if a class name exists if (className) { // Parse the class names var classNames = className.split(' '); for (var i = 0; i < classNames.length; i++) { // Add the class name icon.classList.add(classNames[i]); } } // Make this icon invisible to the screen reader icon.setAttribute("aria-hidden", "true"); // Set the height/width icon.setAttribute("height", (height ? height : 32).toString()); icon.setAttribute("width", (width ? width : 32).toString()); // Update the styling icon.style.pointerEvents = "none"; // Support for IE icon.setAttribute("focusable", "false"); } // Return the icon return icon; }; exports.generateIcon = generateIcon;