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

Commit

Permalink
jul8.ts에서 IE에서 제대로 동작하지 않는 부분을 고침
Browse files Browse the repository at this point in the history
- String.prototype.{startsWith,endsWith} 없음
- SVGElement.prototype.children 없음, childNodes로 변경
- `<p><b>foo</b> {{bar}}</p>` 같은 템플릿이 파싱되지 않는 문제 수정
  • Loading branch information
lifthrasiir committed Mar 16, 2018
1 parent e15a8bb commit 917bcd3
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions Library/jul8.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

export class Fields {
attrs: { attr: Attr, origValue: string }[] = [];
elems: { elem: Element, origText: string }[] = [];
elems: { elem: Node, origText: string }[] = [];

set(data: any): void {
for (let a of this.attrs) {
Expand All @@ -82,7 +82,7 @@
let list = text.split(pattern);
for (let i = 0; i < list.length; ++i) {
let word = list[i]
if (word.startsWith("{{") && word.endsWith("}}")) {
if (word.substring(0, 2) === "{{" && word.substring(word.length - 2) === "}}") {
let fname = word.substr(2, word.length - 4).trim();
if (data[fname] !== undefined) {
list[i] = data[fname];
Expand Down Expand Up @@ -124,8 +124,9 @@
}

private scanListItem(baseElem: Element) {
for (let i = 0; i < baseElem.children.length; ++i) {
let elem = baseElem.children[i];
for (let i = 0; i < baseElem.childNodes.length; ++i) {
let elem = baseElem.childNodes[i] as Element;
if (elem.nodeType !== elem.ELEMENT_NODE) continue;

if (elem.hasAttribute('j8-listItem')) {
let itemId = elem.getAttribute('j8-listItem');
Expand All @@ -144,8 +145,8 @@
}
}

private visitElem(elem: Element) {
let childNodes = elem.children;
private visitElem(elem: Node) {
let childNodes = elem.childNodes;
if (childNodes.length > 0) {
for (let i = 0; i < childNodes.length; ++i) {
this.visitElem(childNodes[i])
Expand All @@ -158,13 +159,15 @@
}
}

for (let i = 0; i < elem.attributes.length; ++i) {
let attr = elem.attributes[i];
if (attr.value.search(pattern) >= 0) {
if (attr.name === 'style') { console.error("(Jul8) can't use {{ ... }} notation in `style` attribute."); }
if (attr.name === 'class') { console.error("(Jul8) can't use {{ ... }} notation in `class` attribute."); }
let a = { attr: attr, origValue: attr.value };
this.fields.attrs.push(a);
if (elem.attributes) {
for (let i = 0; i < elem.attributes.length; ++i) {
let attr = elem.attributes[i];
if (attr.value.search(pattern) >= 0) {
if (attr.name === 'style') { console.error("(Jul8) can't use {{ ... }} notation in `style` attribute."); }
if (attr.name === 'class') { console.error("(Jul8) can't use {{ ... }} notation in `class` attribute."); }
let a = { attr: attr, origValue: attr.value };
this.fields.attrs.push(a);
}
}
}
}
Expand Down

0 comments on commit 917bcd3

Please sign in to comment.