1998-06-23 09:13:22 +04:00
|
|
|
/* -*- Mode: js; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1998-06-23 09:13:22 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1998-06-23 09:13:22 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 06:40:37 +03:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-06-23 09:13:22 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
function findBody(node)
|
|
|
|
{
|
1998-10-20 21:07:23 +04:00
|
|
|
if (node.nodeType != Node.ELEMENT_NODE) {
|
1998-07-14 22:44:44 +04:00
|
|
|
return null;
|
1998-06-23 09:13:22 +04:00
|
|
|
}
|
1998-07-14 22:44:44 +04:00
|
|
|
var children = node.childNodes;
|
|
|
|
if (children == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var length = children.length;
|
|
|
|
var child = null;
|
|
|
|
var count = 0;
|
|
|
|
while (count < length) {
|
1998-10-20 21:07:23 +04:00
|
|
|
child = children[count];
|
1998-07-14 22:44:44 +04:00
|
|
|
if (child.tagName == "BODY") {
|
|
|
|
dump("BODY found");
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
var body = findBody(child);
|
|
|
|
if (null != body) {
|
|
|
|
return body;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return null;
|
1998-06-23 09:13:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Given the body element, find the first table element
|
|
|
|
function findTable(body)
|
|
|
|
{
|
|
|
|
// XXX A better way to do this would be to use getElementsByTagName(), but
|
|
|
|
// it isn't implemented yet...
|
1998-07-14 22:44:44 +04:00
|
|
|
var children = body.childNodes
|
|
|
|
if (children == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
var length = children.length;
|
|
|
|
var child = null;
|
|
|
|
var count = 0;
|
|
|
|
while (count < length) {
|
1998-10-20 21:07:23 +04:00
|
|
|
child = children[count];
|
|
|
|
if (child.nodeType == Node.ELEMENT_NODE) {
|
1998-07-14 22:44:44 +04:00
|
|
|
if (child.tagName == "TABLE") {
|
|
|
|
dump("TABLE found");
|
1998-06-23 09:13:22 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-07-14 22:44:44 +04:00
|
|
|
count++;
|
1998-06-23 09:13:22 +04:00
|
|
|
}
|
|
|
|
|
1998-07-14 22:44:44 +04:00
|
|
|
return child;
|
1998-06-23 09:13:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Change the table's caption
|
|
|
|
function changeCaption(table)
|
|
|
|
{
|
|
|
|
// Get the first element. This is the caption (maybe). We really should
|
|
|
|
// check...
|
1998-07-14 22:44:44 +04:00
|
|
|
var caption = table.firstChild
|
1998-06-23 09:13:22 +04:00
|
|
|
|
|
|
|
// Get the caption text
|
1998-07-14 22:44:44 +04:00
|
|
|
var text = caption.firstChild
|
1998-06-23 09:13:22 +04:00
|
|
|
|
|
|
|
// Append some text
|
|
|
|
text.append(" NEW TEXT")
|
|
|
|
}
|
|
|
|
|
|
|
|
changeCaption(findTable(findBody(document.documentElement)))
|
|
|
|
|