gecko-dev/webtools/leak-o-matic/balance.js

97 строки
2.7 KiB
JavaScript

/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* 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/
*
* 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.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
* $Id: balance.js,v 1.1 1999/11/15 22:31:33 waterson%netscape.com Exp $
*/
/*
Script for the HTML generated by ``balance.cgi''
*/
function toggle(target)
{
var tt = target.parentNode;
// ensure that we're actuallly looking at a method
if (tt.getAttribute('class') != 'method') return;
// toggle the selected state
var selected = tt.getAttribute('selected') == 'true';
selected = !selected;
tt.setAttribute('selected', selected ? 'true' : 'false');
// add/remove from the 'exclude' list
var exclude = document.getElementById('exclude');
var value = target.nodeValue;
if (selected) {
var found = false;
for (var i = 0; i < exclude.length; ++i) {
if (exclude.options[i].text == value) {
found = true;
break;
}
}
if (! found) {
dump('adding ' + value + '\n');
var option = document.createElement('option');
option.setAttribute('selected', 'true');
option.appendChild(document.createTextNode(value));
exclude.appendChild(option);
}
}
else {
for (var i = 0; i < exclude.length; ++i) {
if (exclude.options[i].text == value) {
exclude.removeChild(exclude.options[i]);
break;
}
}
}
}
function remove() {
// remove all of the selected items from the 'exclude' list
var exclude = document.getElementById('exclude');
for (var i = 0; i < exclude.length; ++i) {
if (exclude.options[i].selected) {
exclude.removeChild(exclude.options[i]);
--i;
}
}
}
function onsubmit() {
// make sure that all of the elements in the select are actually
// -selected- so that the HTTP GET will contain them as excludes.
var exclude = document.getElementById('exclude');
for (var i = 0; i < exclude.length; ++i) {
// XXX doing this with 'options[i].selected = true' actually
// -changes- the selection. Oops.
exclude.options[i].setAttribute('selected', 'true');
}
}