migrate ui library
This commit is contained in:
33
lib/ui/icon.js
Normal file
33
lib/ui/icon.js
Normal file
@ -0,0 +1,33 @@
|
||||
const svgns = 'http://www.w3.org/2000/svg';
|
||||
|
||||
function createUse(type, id) {
|
||||
const c = typeof consts !== 'undefined' ? consts : {};
|
||||
const path = c.path || '';
|
||||
const ver = c.resver == null ? '' : `?${c.resver}`;
|
||||
const use = document.createElementNS(svgns, 'use');
|
||||
use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', `${path}lib/fonts/${type}.svg${ver}#${id}`);
|
||||
return use;
|
||||
}
|
||||
|
||||
function createIcon(type, id) {
|
||||
const svg = document.createElementNS(svgns, 'svg');
|
||||
svg.appendChild(createUse(type, id));
|
||||
return svg;
|
||||
}
|
||||
|
||||
function resolveIcon(container) {
|
||||
const svgs = container.querySelectorAll('svg[data-id]');
|
||||
for (let icon of svgs) {
|
||||
const type = icon.getAttribute('data-type');
|
||||
const id = icon.getAttribute('data-id');
|
||||
icon.replaceChildren(createUse(type, id));
|
||||
icon.removeAttribute('data-type');
|
||||
icon.removeAttribute('data-id');
|
||||
}
|
||||
return container;
|
||||
}
|
||||
|
||||
export {
|
||||
createIcon,
|
||||
resolveIcon
|
||||
}
|
Reference in New Issue
Block a user