1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0//EN">
6 <style type=
"text/css">
9 font-family: verdana
, sans-serif
;
29 text-decoration:underline
;
34 text-decoration: none
;
47 border-bottom-width:1px;
48 border-bottom-style:dotted
;
64 <table width=
"90%" border=
"0" cellspacing=
"1" cellpadding=
"5">
67 <big><tt>Global.MarkupElement.prototype.add
(child)
</tt></big><br>
73 Add a new child element
<br><br>
87 <table width=
"90%" border=
"0" cellspacing=
"1" cellpadding=
"5">
89 <td>Sourcecode in helmaTools.zip/Global/helma.Markup.js:
90 <pre><font color=
"#aaaaaa">545:
</font> MarkupElement.prototype.add = function(child) {
91 <font color=
"#aaaaaa">546:
</font> if (typeof(child) ==
<font color=
"#9999aa">"undefined
"</font>) {
92 <font color=
"#aaaaaa">547:
</font> return;
93 <font color=
"#aaaaaa">548:
</font> }
94 <font color=
"#aaaaaa">549:
</font> <font color=
"#33aa00"> // initialize child array if necessary
95 <font color=
"#aaaaaa">550:
</font> </font> if (!this.children) {
96 <font color=
"#aaaaaa">551:
</font> this.children = [];
97 <font color=
"#aaaaaa">552:
</font> }
98 <font color=
"#aaaaaa">553:
</font> if (child instanceof Array) {
99 <font color=
"#aaaaaa">554:
</font> for (var i in child) {
100 <font color=
"#aaaaaa">555:
</font> this.add(child[i]);
101 <font color=
"#aaaaaa">556:
</font> }
102 <font color=
"#aaaaaa">557:
</font> return;
103 <font color=
"#aaaaaa">558:
</font> }
104 <font color=
"#aaaaaa">559:
</font> <font color=
"#33aa00"> // add new child
105 <font color=
"#aaaaaa">560:
</font> </font> this.children.push(child);
106 <font color=
"#aaaaaa">561:
</font> <font color=
"#33aa00"> // register child if it has a name property
107 <font color=
"#aaaaaa">562:
</font> </font> if (child) {
108 <font color=
"#aaaaaa">563:
</font> if (child.name
&& !this.map[child.name]) {
109 <font color=
"#aaaaaa">564:
</font> this.map[child.name] = child;
110 <font color=
"#aaaaaa">565:
</font> }
111 <font color=
"#aaaaaa">566:
</font> <font color=
"#33aa00"> // register grandchilds unless the name slot is already taken
112 <font color=
"#aaaaaa">567:
</font> </font> for (var i in child.map) {
113 <font color=
"#aaaaaa">568:
</font> var c = child.map[i];
114 <font color=
"#aaaaaa">569:
</font> if (c
&& c.name
&& !this.map[c.name]) {
115 <font color=
"#aaaaaa">570:
</font> this.map[c.name] = c;
116 <font color=
"#aaaaaa">571:
</font> }
117 <font color=
"#aaaaaa">572:
</font> }
118 <font color=
"#aaaaaa">573:
</font> <font color=
"#33aa00"> // set parent property in child
119 <font color=
"#aaaaaa">574:
</font> </font> child.parent = this;
120 <font color=
"#aaaaaa">575:
</font> }
121 <font color=
"#aaaaaa">576:
</font> }