1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/js/DumpHTML.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +// 1.11 +// Dump the html content in html format 1.12 +// 1.13 +function html(node) 1.14 +{ 1.15 + var type = node.nodeType; 1.16 + if (type == Node.ELEMENT_NODE) { 1.17 + 1.18 + // open tag 1.19 + dump("<" + node.tagName) 1.20 + 1.21 + // dump the attributes if any 1.22 + attributes = node.attributes; 1.23 + if (null != attributes) { 1.24 + var countAttrs = attributes.length; 1.25 + var index = 0 1.26 + while(index < countAttrs) { 1.27 + att = attributes[index]; 1.28 + if (null != att) { 1.29 + dump(" " + att.value) 1.30 + } 1.31 + index++ 1.32 + } 1.33 + } 1.34 + 1.35 + // close tag 1.36 + dump(">") 1.37 + 1.38 + // recursively dump the children 1.39 + if (node.hasChildNodes()) { 1.40 + // get the children 1.41 + var children = node.childNodes; 1.42 + var length = children.length; 1.43 + var count = 0; 1.44 + while(count < length) { 1.45 + child = children[count] 1.46 + html(child) 1.47 + count++ 1.48 + } 1.49 + dump("</" + node.tagName + ">"); 1.50 + } 1.51 + 1.52 + 1.53 + } 1.54 + // if it's a piece of text just dump the text 1.55 + else if (type == Node.TEXT_NODE) { 1.56 + dump(node.data) 1.57 + } 1.58 +} 1.59 + 1.60 +html(document.documentElement) 1.61 +dump("\n")