ad_color_widget_js

one of the documented procedures in this installation of the ACS
Usage:
ad_color_widget_js
What it does:
Returns JavaScript code necessary to use color widgets.
Defined in: /web/philip/packages/acs-core/widgets-procs.tcl

Source code:


    return {

var adHexTupletValues = '0123456789ABCDEF';

function adHexTuplet(val) {
    return adHexTupletValues.charAt(Math.floor(val / 16)) + adHexTupletValues.charAt(Math.floor(val % 16));
}

function adUpdateColorText(field) {
    var form = document.forms[0];
    var element = form[field + ".list"];
    var rgb = element.options[element.selectedIndex].value;
    var r,g,b;
    if (rgb == "" || rgb == "none" || rgb == "custom") {
        r = g = b = "";
    } else {
        var components = rgb.split(",");
        r = components[0];
        g = components[1];
        b = components[2];
    }
    form[field + ".c1"].value = r;
    form[field + ".c2"].value = g;
    form[field + ".c3"].value = b;

    document['color_' + field].src = '/shared/1pixel.tcl?r=' + r + '&g=' + g + '&b=' + b;
}

function adUpdateColorList(field) {
    var form = document.forms[0];
    var element = form[field + ".list"];

    var c1 = form[field + ".c1"].value;
    var c2 = form[field + ".c2"].value;
    var c3 = form[field + ".c3"].value;
    if (c1 != parseInt(c1) || c2 != parseInt(c2) || c3 != parseInt(c3) ||
        c1 < 0 || c2 < 0 || c3 < 0 || c1 > 255 || c2 > 255 || c3 > 255) {
        element.selectedIndex = 1;
        document['color_' + field].src = '/shared/1pixel.tcl?r=255&g=255&b=255';
        return;
    }

    document['color_' + field].src = '/shared/1pixel.tcl?r=' + c1 + '&g=' + c2 + '&b=' + c3;

    var rgb = parseInt(form[field + ".c1"].value) + "," + parseInt(form[field + ".c2"].value) + "," + parseInt(form[field + ".c3"].value);
    var found = 0;
    for (var i = 0; i < element.length; ++i)
        if (element.options[i].value == rgb) {
            element.selectedIndex = i;
	    found = 1;
            break;
        }
    if (!found)
        element.selectedIndex = 0;
}

    }


philg@mit.edu