UNPKG

vanillajs-datepicker

Version:

A vanilla JavaScript remake of bootstrap-datepicker for Bulma and other CSS frameworks

80 lines (67 loc) 2.03 kB
var domUtils = (function (exports) { 'use strict'; const range = document.createRange(); function parseHTML(html) { return range.createContextualFragment(html); } function getParent(el) { return el.parentElement || (el.parentNode instanceof ShadowRoot ? el.parentNode.host : undefined); } function isActiveElement(el) { return el.getRootNode().activeElement === el; } // equivalent to jQuery's :visble function isVisible(el) { return !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length); } function hideElement(el) { if (el.style.display === 'none') { return; } // back up the existing display setting in data-style-display if (el.style.display) { el.dataset.styleDisplay = el.style.display; } el.style.display = 'none'; } function showElement(el) { if (el.style.display !== 'none') { return; } if (el.dataset.styleDisplay) { // restore backed-up dispay property el.style.display = el.dataset.styleDisplay; delete el.dataset.styleDisplay; } else { el.style.display = ''; } } function emptyChildNodes(el) { if (el.firstChild) { el.removeChild(el.firstChild); emptyChildNodes(el); } } function replaceChildNodes(el, newChildNodes) { emptyChildNodes(el); if (newChildNodes instanceof DocumentFragment) { el.appendChild(newChildNodes); } else if (typeof newChildNodes === 'string') { el.appendChild(parseHTML(newChildNodes)); } else if (typeof newChildNodes.forEach === 'function') { newChildNodes.forEach((node) => { el.appendChild(node); }); } } exports.emptyChildNodes = emptyChildNodes; exports.getParent = getParent; exports.hideElement = hideElement; exports.isActiveElement = isActiveElement; exports.isVisible = isVisible; exports.parseHTML = parseHTML; exports.replaceChildNodes = replaceChildNodes; exports.showElement = showElement; return exports; })({});