summaryrefslogtreecommitdiff
path: root/httemplate/elements/qlib/label.js
blob: 2d8b1e710083fcfdc0cad0f1a5093e29a69e7e8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
 * QLIB 1.0 Text Label
 * Copyright (C) 2002 2003, Quazzle.com Serge Dolgov
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * http://qlib.quazzle.com
 */

function QLabel_set_ie(value) {
    this.label.innerText = (this.value = value) || "\xA0";
}

function QLabel_set_dom2(value) {
    with (this.label) {
        replaceChild(this.document.createTextNode((this.value = value) || "\xA0"), firstChild);
    }
}

function QLabel_set_ns4(value) {
    this.value = value || "";
    with (this) {
        document.open();
        document.write('<div class="qlabel">' + (clickable ? '<a href="#" title="' + tooltip + '" onClick="return ' +
            name + '.doEvent()" onMouseOut="window.top.status=\'\'" onMouseOver="window.top.status=' + name +
            '.tooltip;return true">' + value + '</a>' : value) + '</div>');
        document.close();
    }
}

function QLabel_doEvent() {
    this.onClick(this.value, this.tag);
    return false;
}

function QLabel(parent, name, value, clickable, tooltip) {
    this.init(parent, name);
    this.value = value || "";
    this.clickable = clickable || false;
    this.tooltip = tooltip || "";
    this.doEvent = QLabel_doEvent;
    this.onClick = QControl.event;
    with (this) {
        if (document.getElementById || document.all) {
            document.write(clickable ? '<div class="qlabel" unselectable="on"><a id="' + id + '" href="#" title="' +
                tooltip + '" onClick="return ' + name + '.doEvent()" onMouseOver="window.top.status=' + name +
                '.tooltip;return true" onMouseOut="window.top.status=\'\'" hidefocus="true" unselectable="on">' +
                (value || '&nbsp;') + '</a></div>' : '<div id="' + id + '" class="qlabel" unselectable="on">' +
                (value || '&nbsp;') + '</div>');
            this.label = document.getElementById ? document.getElementById(id) :
                (document.all.item ? document.all.item(id) : document.all[id]);
            this.set = (label && (label.innerText ? QLabel_set_ie :
                (label.replaceChild && QLabel_set_dom2))) || QControl.nop;
        } else if (document.layers) {
            var suffix = "";
            for (var j=value.length; j<QLabel.TEXTQUOTA; j++) suffix += " &nbsp;";
            document.write('<div><ilayer id="i' + id + '"><layer id="' + id + '"><div class="qlabel">' +
                (clickable ? '<a href="#" title="' + tooltip + '" onClick="return ' + name +
                '.doEvent()" onMouseOver="window.top.status=' + name +
                '.tooltip;return true" onMouseOut="window.top.status=\'\'">' + value + suffix + '</a>' :
                value + suffix) + '</div></layer></ilayer></div>');
            this.label = (this.label = document.layers["i" + id]) && label.document.layers[id];
            this.document = label && label.document;
            this.set = (label && document) ? QLabel_set_ns4 : QControl.nop;
        } else {
            document.write("Object is not supported");
        }
    }
}
QLabel.prototype = new QControl();
QLabel.TEXTQUOTA = 50;