blob: 56215544dd8127a4eafa1f99b14849ed03fb632c [file] [log] [blame]
Felix Meschberger88c3dcb2008-06-25 08:44:16 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18
19/* Element */ function clearChildren( /* Element */ element )
20{
21 while (element.firstChild)
22 {
23 element.removeChild(element.firstChild);
24 }
25
26 return element;
27}
28
29/* String */ function serialize( /* Element */ element )
30{
31 var result = "";
32
33 if (element)
34 {
35 if (element.nodeValue)
36 {
37 result = element.nodeValue;
38 }
39 else {
40 result += "<" + element.tagName;
41
42 var attrs = element.attributes;
43 for (var i=0; i < attrs.length; i++)
44 {
45 if (attrs[i].nodeValue)
46 {
47 result += " " + attrs[i].nodeName + "='" + attrs[i].nodeValue + "'";
48 }
49 }
50
51 var children = element.childNodes;
52 if (children && children.length)
53 {
54 result += ">";
55
56 for (var i=0; i < children.length; i++)
57 {
58 result += serialize( children[i] );
59 }
60 result += "</" + element.tagName + ">";
61 }
62 else
63 {
64 result += "/>";
65 }
66 }
67 }
68
69 return result;
70}
71
72/* Element */ function tr( /* String */ cssClass, /* Object */ attrs )
73{
74 return createElement( "tr", cssClass, attrs );
75}
76
77
78/* Element */ function td( /* String */ cssClass, /* Object */ attrs )
79{
80 return createElement( "td", cssClass, attrs );
81}
82
83
84/* Element */ function createElement( /* String */ name, /* String */ cssClass, /* Object */ attrs )
85{
86 var element = document.createElement( name );
87
88 if (cssClass)
89 {
90 element.setAttribute( "class", cssClass );
91 }
92
93 if (attrs)
94 {
95 for (var lab in attrs)
96 {
97 element.setAttribute( lab, attrs[lab] );
98 }
99 }
100
101 return element;
102}
103
104
105/* Element */ function addText( /* Element */ element, /* String */ text )
106{
107 if (element && text)
108 {
109 var textNode = document.createTextNode( text );
110 element.appendChild( textNode );
111 }
112
113 return element;
114}