dom/tests/js/tables/changeCaption.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

michael@0 1 /* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 function findBody(node)
michael@0 7 {
michael@0 8 if (node.nodeType != Node.ELEMENT_NODE) {
michael@0 9 return null;
michael@0 10 }
michael@0 11 var children = node.childNodes;
michael@0 12 if (children == null) {
michael@0 13 return null;
michael@0 14 }
michael@0 15 var length = children.length;
michael@0 16 var child = null;
michael@0 17 var count = 0;
michael@0 18 while (count < length) {
michael@0 19 child = children[count];
michael@0 20 if (child.tagName == "BODY") {
michael@0 21 dump("BODY found");
michael@0 22 return child;
michael@0 23 }
michael@0 24 var body = findBody(child);
michael@0 25 if (null != body) {
michael@0 26 return body;
michael@0 27 }
michael@0 28 count++;
michael@0 29 }
michael@0 30 return null;
michael@0 31 }
michael@0 32
michael@0 33 // Given the body element, find the first table element
michael@0 34 function findTable(body)
michael@0 35 {
michael@0 36 // XXX A better way to do this would be to use getElementsByTagName(), but
michael@0 37 // it isn't implemented yet...
michael@0 38 var children = body.childNodes
michael@0 39 if (children == null) {
michael@0 40 return null;
michael@0 41 }
michael@0 42 var length = children.length;
michael@0 43 var child = null;
michael@0 44 var count = 0;
michael@0 45 while (count < length) {
michael@0 46 child = children[count];
michael@0 47 if (child.nodeType == Node.ELEMENT_NODE) {
michael@0 48 if (child.tagName == "TABLE") {
michael@0 49 dump("TABLE found");
michael@0 50 break;
michael@0 51 }
michael@0 52 }
michael@0 53 count++;
michael@0 54 }
michael@0 55
michael@0 56 return child;
michael@0 57 }
michael@0 58
michael@0 59 // Change the table's caption
michael@0 60 function changeCaption(table)
michael@0 61 {
michael@0 62 // Get the first element. This is the caption (maybe). We really should
michael@0 63 // check...
michael@0 64 var caption = table.firstChild
michael@0 65
michael@0 66 // Get the caption text
michael@0 67 var text = caption.firstChild
michael@0 68
michael@0 69 // Append some text
michael@0 70 text.append(" NEW TEXT")
michael@0 71 }
michael@0 72
michael@0 73 changeCaption(findTable(findBody(document.documentElement)))
michael@0 74

mercurial