| | 259 | |
|---|
| | 260 | /** |
|---|
| | 261 | * APIMethod: getChildValue |
|---|
| | 262 | * Get the value of the first child node if it exists, or return an |
|---|
| | 263 | * optional default string. Returns an empty string if no first child |
|---|
| | 264 | * exists and no default value is supplied. |
|---|
| | 265 | * |
|---|
| | 266 | * Parameters: |
|---|
| | 267 | * node - {DOMElement} The element used to look for a first child value. |
|---|
| | 268 | * def - {String} Optional string to return in the event that no |
|---|
| | 269 | * first child value exists. |
|---|
| | 270 | * |
|---|
| | 271 | * Returns: |
|---|
| | 272 | * {String} The value of the first child of the given node. |
|---|
| | 273 | */ |
|---|
| | 274 | getChildValue: function(node, def) { |
|---|
| | 275 | var value; |
|---|
| | 276 | try { |
|---|
| | 277 | value = node.firstChild.nodeValue; |
|---|
| | 278 | } catch(e) { |
|---|
| | 279 | value = (def != undefined) ? def : ""; |
|---|
| | 280 | } |
|---|
| | 281 | return value; |
|---|
| | 282 | }, |
|---|
| | 283 | |
|---|
| | 284 | /** |
|---|
| | 285 | * APIMethod: concatChildValues |
|---|
| | 286 | * Concatenate the value of all child nodes if any exist, or return an |
|---|
| | 287 | * optional default string. Returns an empty string if no children |
|---|
| | 288 | * exist and no default value is supplied. Not optimized for large |
|---|
| | 289 | * numbers of child nodes. |
|---|
| | 290 | * |
|---|
| | 291 | * Parameters: |
|---|
| | 292 | * node - {DOMElement} The element used to look for child values. |
|---|
| | 293 | * def - {String} Optional string to return in the event that no |
|---|
| | 294 | * child exist. |
|---|
| | 295 | * |
|---|
| | 296 | * Returns: |
|---|
| | 297 | * {String} The concatenated value of all child nodes of the given node. |
|---|
| | 298 | */ |
|---|
| | 299 | concatChildValues: function(node, def) { |
|---|
| | 300 | var value = ""; |
|---|
| | 301 | var child = node.firstChild; |
|---|
| | 302 | var childValue; |
|---|
| | 303 | while(child) { |
|---|
| | 304 | childValue = child.nodeValue; |
|---|
| | 305 | if(childValue) { |
|---|
| | 306 | value += childValue; |
|---|
| | 307 | } |
|---|
| | 308 | child = child.nextSibling; |
|---|
| | 309 | } |
|---|
| | 310 | if(value == "" && def != undefined) { |
|---|
| | 311 | value = def; |
|---|
| | 312 | } |
|---|
| | 313 | return value; |
|---|
| | 314 | }, |
|---|