blob: ae4d6a2fc9f44f6d61fd8dd4fa988efde36400e7 [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
Felix Meschberger5af75272008-06-25 20:26:13 +000072/* Element */ function tr( /* String */ cssClass, /* Map */ attrs, /* Element[] */ children )
Felix Meschberger88c3dcb2008-06-25 08:44:16 +000073{
Felix Meschberger5af75272008-06-25 20:26:13 +000074 return createElement( "tr", cssClass, attrs, children );
Felix Meschberger88c3dcb2008-06-25 08:44:16 +000075}
76
77
Felix Meschberger5af75272008-06-25 20:26:13 +000078/* Element */ function td( /* String */ cssClass, /* Map */ attrs, /* Element[] */ children )
Felix Meschberger88c3dcb2008-06-25 08:44:16 +000079{
Felix Meschberger5af75272008-06-25 20:26:13 +000080 return createElement( "td", cssClass, attrs, children );
Felix Meschberger88c3dcb2008-06-25 08:44:16 +000081}
82
83
Felix Meschberger5af75272008-06-25 20:26:13 +000084/* Element */ function text( /* String */ textValue )
85{
86 return document.createTextNode( textValue );
87}
88
89
90/* Element */ function createElement( /* String */ name, /* String */ cssClass, /* Map */ attrs, /* Element[] */ children )
Felix Meschberger88c3dcb2008-06-25 08:44:16 +000091{
92 var element = document.createElement( name );
93
94 if (cssClass)
95 {
Carsten Ziegeler21359442009-03-05 16:14:55 +000096 $(element).addClass(cssClass);
Felix Meschberger88c3dcb2008-06-25 08:44:16 +000097 }
98
99 if (attrs)
100 {
101 for (var lab in attrs)
102 {
Felix Meschberger018b1442008-06-25 23:09:26 +0000103 if ("style" == lab)
104 {
105 var styles = attrs[lab];
106 for (var styleName in styles)
107 {
Carsten Ziegeler21359442009-03-05 16:14:55 +0000108 $(element).css(styleName, styles[styleName]);
Felix Meschberger018b1442008-06-25 23:09:26 +0000109 }
110 }
111 else
112 {
Carsten Ziegeler21359442009-03-05 16:14:55 +0000113 $(element).attr( lab, attrs[lab] );
Felix Meschberger018b1442008-06-25 23:09:26 +0000114 }
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000115 }
116 }
117
Felix Meschberger5af75272008-06-25 20:26:13 +0000118 if (children && children.length)
119 {
120 for (var i=0; i < children.length; i++)
121 {
122 element.appendChild( children[i] );
123 }
124 }
125
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000126 return element;
127}
128
129
Felix Meschberger5af75272008-06-25 20:26:13 +0000130/* Element */ function addText( /* Element */ element, /* String */ textValue )
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000131{
Felix Meschberger5af75272008-06-25 20:26:13 +0000132 if (element && textValue)
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000133 {
Felix Meschberger5af75272008-06-25 20:26:13 +0000134 element.appendChild( text( textValue ) );
Felix Meschberger88c3dcb2008-06-25 08:44:16 +0000135 }
136
137 return element;
138}