all files / mapbox-gl-draw/src/lib/ dom_utils.js

80% Statements 12/15
50% Branches 3/6
33.33% Functions 1/3
84.62% Lines 11/13
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38                       20× 20× 20× 40× 40×     20× 20×                            
const domUtils = {};
 
/**
 * Creates a new HTML element, appends it to a container,
 * and returns it.
 *
 * @param {string} tag Element name
 * @param {HTMLElement} [container] HTML element to append to
 * @param {Object} [attrbutes] Object containing attributes to apply to the
 * element. The attribute name corresponds to the key.
 * @returns {HTMLElement} The HTML element
 */
domUtils.create = function(tag, container, attributes) {
  const el = document.createElement(tag);
  if (attributes) E{
    for (const key in attributes) {
      Iif (!attributes.hasOwnProperty(key)) continue;
      el.setAttribute(key, attributes[key]);
    }
  }
  Eif (container) container.appendChild(el);
  return el;
};
 
/**
 * Removes classes from an array of HTML elements.
 *
 * @param {HTMLElement} elements
 * @param {String} klass
 */
domUtils.removeClass = function(elements, klass) {
  Array.prototype.forEach.call(elements, el => {
    el.classList.remove(klass);
  });
};
 
module.exports = domUtils;