Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 1 | /* |
| 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 Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 72 | /* Element */ function tr( /* String */ cssClass, /* Map */ attrs, /* Element[] */ children ) |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 73 | { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 74 | return createElement( "tr", cssClass, attrs, children ); |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 78 | /* Element */ function td( /* String */ cssClass, /* Map */ attrs, /* Element[] */ children ) |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 79 | { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 80 | return createElement( "td", cssClass, attrs, children ); |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 84 | /* 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 Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 91 | { |
| 92 | var element = document.createElement( name ); |
| 93 | |
| 94 | if (cssClass) |
| 95 | { |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 96 | $(element).addClass(cssClass); |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | if (attrs) |
| 100 | { |
| 101 | for (var lab in attrs) |
| 102 | { |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 103 | if ("style" == lab) |
| 104 | { |
| 105 | var styles = attrs[lab]; |
| 106 | for (var styleName in styles) |
| 107 | { |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 108 | $(element).css(styleName, styles[styleName]); |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 109 | } |
| 110 | } |
| 111 | else |
| 112 | { |
Carsten Ziegeler | 2135944 | 2009-03-05 16:14:55 +0000 | [diff] [blame] | 113 | $(element).attr( lab, attrs[lab] ); |
Felix Meschberger | 018b144 | 2008-06-25 23:09:26 +0000 | [diff] [blame] | 114 | } |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 115 | } |
| 116 | } |
| 117 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 118 | if (children && children.length) |
| 119 | { |
| 120 | for (var i=0; i < children.length; i++) |
| 121 | { |
| 122 | element.appendChild( children[i] ); |
| 123 | } |
| 124 | } |
| 125 | |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 126 | return element; |
| 127 | } |
| 128 | |
| 129 | |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 130 | /* Element */ function addText( /* Element */ element, /* String */ textValue ) |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 131 | { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 132 | if (element && textValue) |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 133 | { |
Felix Meschberger | 5af7527 | 2008-06-25 20:26:13 +0000 | [diff] [blame] | 134 | element.appendChild( text( textValue ) ); |
Felix Meschberger | 88c3dcb | 2008-06-25 08:44:16 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | return element; |
| 138 | } |