dom/tests/js/DumpHTML.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     7 //
     8 // Dump the html content in html format
     9 //
    10 function html(node)
    11 {
    12     var type = node.nodeType;
    13     if (type == Node.ELEMENT_NODE) {
    15         // open tag
    16         dump("<" + node.tagName)
    18         // dump the attributes if any
    19         attributes = node.attributes;
    20         if (null != attributes) {
    21             var countAttrs = attributes.length;
    22             var index = 0
    23             while(index < countAttrs) {
    24                 att = attributes[index];
    25                 if (null != att) {
    26                     dump(" " + att.value)
    27                 }
    28                 index++
    29             }
    30         }
    32         // close tag
    33         dump(">")
    35         // recursively dump the children
    36         if (node.hasChildNodes()) {
    37             // get the children
    38             var children = node.childNodes;
    39             var length = children.length;
    40             var count = 0;
    41             while(count < length) {
    42                 child = children[count]
    43                 html(child)
    44                 count++
    45             }
    46             dump("</" + node.tagName + ">");
    47         }
    50     }
    51     // if it's a piece of text just dump the text
    52     else if (type == Node.TEXT_NODE) {
    53         dump(node.data)
    54     }
    55 }
    57 html(document.documentElement)
    58 dump("\n")

mercurial