|
1 /* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 |
|
7 // |
|
8 // travers the html tree and dump out the type of element |
|
9 // |
|
10 function traverse(node, indent) |
|
11 { |
|
12 dump("\n") |
|
13 indent += " " |
|
14 var type = node.nodeType; |
|
15 |
|
16 // if it's an element dump the tag and recurse the children |
|
17 if (type == Node.ELEMENT_NODE) { |
|
18 |
|
19 dump(indent + node.tagName) |
|
20 |
|
21 // go through the children |
|
22 if (node.hasChildNodes()) { |
|
23 var children = node.childNodes; |
|
24 var length = children.length; |
|
25 var count = 0; |
|
26 while(count < length) { |
|
27 child = children[count] |
|
28 traverse(child, indent) |
|
29 count++ |
|
30 } |
|
31 } |
|
32 } |
|
33 // it's just text, no tag, dump "Text" |
|
34 else if (type == Node.TEXT_NODE) { |
|
35 dump(indent + "Text") |
|
36 } |
|
37 } |
|
38 |
|
39 var node = document.documentElement |
|
40 |
|
41 traverse(node, "") |
|
42 dump("\n") |
|
43 |
|
44 |