|
61 | 61 |
|
62 | 62 | export class Fields {
|
63 | 63 | attrs: { attr: Attr, origValue: string }[] = [];
|
64 |
| - elems: { elem: Element, origText: string }[] = []; |
| 64 | + elems: { elem: Node, origText: string }[] = []; |
65 | 65 |
|
66 | 66 | set(data: any): void {
|
67 | 67 | for (let a of this.attrs) {
|
|
82 | 82 | let list = text.split(pattern);
|
83 | 83 | for (let i = 0; i < list.length; ++i) {
|
84 | 84 | let word = list[i]
|
85 |
| - if (word.startsWith("{{") && word.endsWith("}}")) { |
| 85 | + if (word.substring(0, 2) === "{{" && word.substring(word.length - 2) === "}}") { |
86 | 86 | let fname = word.substr(2, word.length - 4).trim();
|
87 | 87 | if (data[fname] !== undefined) {
|
88 | 88 | list[i] = data[fname];
|
|
124 | 124 | }
|
125 | 125 |
|
126 | 126 | private scanListItem(baseElem: Element) {
|
127 |
| - for (let i = 0; i < baseElem.children.length; ++i) { |
128 |
| - let elem = baseElem.children[i]; |
| 127 | + for (let i = 0; i < baseElem.childNodes.length; ++i) { |
| 128 | + let elem = baseElem.childNodes[i] as Element; |
| 129 | + if (elem.nodeType !== elem.ELEMENT_NODE) continue; |
129 | 130 |
|
130 | 131 | if (elem.hasAttribute('j8-listItem')) {
|
131 | 132 | let itemId = elem.getAttribute('j8-listItem');
|
|
144 | 145 | }
|
145 | 146 | }
|
146 | 147 |
|
147 |
| - private visitElem(elem: Element) { |
148 |
| - let childNodes = elem.children; |
| 148 | + private visitElem(elem: Node) { |
| 149 | + let childNodes = elem.childNodes; |
149 | 150 | if (childNodes.length > 0) {
|
150 | 151 | for (let i = 0; i < childNodes.length; ++i) {
|
151 | 152 | this.visitElem(childNodes[i])
|
|
158 | 159 | }
|
159 | 160 | }
|
160 | 161 |
|
161 |
| - for (let i = 0; i < elem.attributes.length; ++i) { |
162 |
| - let attr = elem.attributes[i]; |
163 |
| - if (attr.value.search(pattern) >= 0) { |
164 |
| - if (attr.name === 'style') { console.error("(Jul8) can't use {{ ... }} notation in `style` attribute."); } |
165 |
| - if (attr.name === 'class') { console.error("(Jul8) can't use {{ ... }} notation in `class` attribute."); } |
166 |
| - let a = { attr: attr, origValue: attr.value }; |
167 |
| - this.fields.attrs.push(a); |
| 162 | + if (elem.attributes) { |
| 163 | + for (let i = 0; i < elem.attributes.length; ++i) { |
| 164 | + let attr = elem.attributes[i]; |
| 165 | + if (attr.value.search(pattern) >= 0) { |
| 166 | + if (attr.name === 'style') { console.error("(Jul8) can't use {{ ... }} notation in `style` attribute."); } |
| 167 | + if (attr.name === 'class') { console.error("(Jul8) can't use {{ ... }} notation in `class` attribute."); } |
| 168 | + let a = { attr: attr, origValue: attr.value }; |
| 169 | + this.fields.attrs.push(a); |
| 170 | + } |
168 | 171 | }
|
169 | 172 | }
|
170 | 173 | }
|
|
0 commit comments