1 | const xlinkNS = "http://www.w3.org/1999/xlink";
|
2 | const xmlNS = "http://www.w3.org/XML/1998/namespace";
|
3 | const colonChar = 58;
|
4 | const xChar = 120;
|
5 | function updateAttrs(oldVnode, vnode) {
|
6 | let key;
|
7 | const elm = vnode.elm;
|
8 | let oldAttrs = oldVnode.data.attrs;
|
9 | let attrs = vnode.data.attrs;
|
10 | if (!oldAttrs && !attrs)
|
11 | return;
|
12 | if (oldAttrs === attrs)
|
13 | return;
|
14 | oldAttrs = oldAttrs || {};
|
15 | attrs = attrs || {};
|
16 |
|
17 | for (key in attrs) {
|
18 | const cur = attrs[key];
|
19 | const old = oldAttrs[key];
|
20 | if (old !== cur) {
|
21 | if (cur === true) {
|
22 | elm.setAttribute(key, "");
|
23 | }
|
24 | else if (cur === false) {
|
25 | elm.removeAttribute(key);
|
26 | }
|
27 | else {
|
28 | if (key.charCodeAt(0) !== xChar) {
|
29 | elm.setAttribute(key, cur);
|
30 | }
|
31 | else if (key.charCodeAt(3) === colonChar) {
|
32 |
|
33 | elm.setAttributeNS(xmlNS, key, cur);
|
34 | }
|
35 | else if (key.charCodeAt(5) === colonChar) {
|
36 |
|
37 | elm.setAttributeNS(xlinkNS, key, cur);
|
38 | }
|
39 | else {
|
40 | elm.setAttribute(key, cur);
|
41 | }
|
42 | }
|
43 | }
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 | for (key in oldAttrs) {
|
49 | if (!(key in attrs)) {
|
50 | elm.removeAttribute(key);
|
51 | }
|
52 | }
|
53 | }
|
54 | export const attributesModule = {
|
55 | create: updateAttrs,
|
56 | update: updateAttrs,
|
57 | };
|
58 |
|
\ | No newline at end of file |