1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/js/tables/changeCaption.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 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 +function findBody(node) 1.10 +{ 1.11 + if (node.nodeType != Node.ELEMENT_NODE) { 1.12 + return null; 1.13 + } 1.14 + var children = node.childNodes; 1.15 + if (children == null) { 1.16 + return null; 1.17 + } 1.18 + var length = children.length; 1.19 + var child = null; 1.20 + var count = 0; 1.21 + while (count < length) { 1.22 + child = children[count]; 1.23 + if (child.tagName == "BODY") { 1.24 + dump("BODY found"); 1.25 + return child; 1.26 + } 1.27 + var body = findBody(child); 1.28 + if (null != body) { 1.29 + return body; 1.30 + } 1.31 + count++; 1.32 + } 1.33 + return null; 1.34 +} 1.35 + 1.36 +// Given the body element, find the first table element 1.37 +function findTable(body) 1.38 +{ 1.39 + // XXX A better way to do this would be to use getElementsByTagName(), but 1.40 + // it isn't implemented yet... 1.41 + var children = body.childNodes 1.42 + if (children == null) { 1.43 + return null; 1.44 + } 1.45 + var length = children.length; 1.46 + var child = null; 1.47 + var count = 0; 1.48 + while (count < length) { 1.49 + child = children[count]; 1.50 + if (child.nodeType == Node.ELEMENT_NODE) { 1.51 + if (child.tagName == "TABLE") { 1.52 + dump("TABLE found"); 1.53 + break; 1.54 + } 1.55 + } 1.56 + count++; 1.57 + } 1.58 + 1.59 + return child; 1.60 +} 1.61 + 1.62 +// Change the table's caption 1.63 +function changeCaption(table) 1.64 +{ 1.65 + // Get the first element. This is the caption (maybe). We really should 1.66 + // check... 1.67 + var caption = table.firstChild 1.68 + 1.69 + // Get the caption text 1.70 + var text = caption.firstChild 1.71 + 1.72 + // Append some text 1.73 + text.append(" NEW TEXT") 1.74 +} 1.75 + 1.76 +changeCaption(findTable(findBody(document.documentElement))) 1.77 +