6 | export function addSvg (el, binding, vnode) { |
7 | let classNames = ['icon'] |
8 | const id = binding.expression || vnode.data.attrs.symbol |
9 | let svg = el |
10 | |
11 | |
12 | if (vnode.tag === 'span') { |
13 | |
14 | svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg') |
15 | el.appendChild(svg) |
16 | } |
17 | |
18 | |
19 | classNames.push(`icon--${id}`) |
20 | classNames.forEach(function (className) { |
21 | el.classList.add(className) |
22 | }) |
23 | |
24 | |
25 | const title = document.createElementNS('http://www.w3.org/2000/svg', 'title') |
26 | |
27 | title.textContent = id |
28 | svg.appendChild(title) |
29 | |
30 | |
31 | const href = `#icon--${id}` |
32 | const use = document.createElementNS('http://www.w3.org/2000/svg', 'use') |
33 | |
34 | use.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', href) |
35 | svg.appendChild(use) |
36 | } |