Skip to content
This repository was archived by the owner on Mar 7, 2024. It is now read-only.

Commit 917bcd3

Browse files
committed
jul8.ts에서 IE에서 제대로 동작하지 않는 부분을 고침
- String.prototype.{startsWith,endsWith} 없음 - SVGElement.prototype.children 없음, childNodes로 변경 - `<p><b>foo</b> {{bar}}</p>` 같은 템플릿이 파싱되지 않는 문제 수정
1 parent e15a8bb commit 917bcd3

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

Library/jul8.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
export class Fields {
6363
attrs: { attr: Attr, origValue: string }[] = [];
64-
elems: { elem: Element, origText: string }[] = [];
64+
elems: { elem: Node, origText: string }[] = [];
6565

6666
set(data: any): void {
6767
for (let a of this.attrs) {
@@ -82,7 +82,7 @@
8282
let list = text.split(pattern);
8383
for (let i = 0; i < list.length; ++i) {
8484
let word = list[i]
85-
if (word.startsWith("{{") && word.endsWith("}}")) {
85+
if (word.substring(0, 2) === "{{" && word.substring(word.length - 2) === "}}") {
8686
let fname = word.substr(2, word.length - 4).trim();
8787
if (data[fname] !== undefined) {
8888
list[i] = data[fname];
@@ -124,8 +124,9 @@
124124
}
125125

126126
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;
129130

130131
if (elem.hasAttribute('j8-listItem')) {
131132
let itemId = elem.getAttribute('j8-listItem');
@@ -144,8 +145,8 @@
144145
}
145146
}
146147

147-
private visitElem(elem: Element) {
148-
let childNodes = elem.children;
148+
private visitElem(elem: Node) {
149+
let childNodes = elem.childNodes;
149150
if (childNodes.length > 0) {
150151
for (let i = 0; i < childNodes.length; ++i) {
151152
this.visitElem(childNodes[i])
@@ -158,13 +159,15 @@
158159
}
159160
}
160161

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+
}
168171
}
169172
}
170173
}

0 commit comments

Comments
 (0)