~mortenoh/+junk/dhis2-detailed-import-export

« back to all changes in this revision

Viewing changes to dhis-2/dhis-web/dhis-web-gis/src/main/webapp/dhis-web-gis/javascript/picker.js

  • Committer: larshelge at gmail
  • Date: 2009-03-03 16:46:36 UTC
  • Revision ID: larshelge@gmail.com-20090303164636-2sjlrquo7ib1gf7r
Initial check-in

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Title: Tigra Color Picker
 
2
// URL: http://www.softcomplex.com/products/tigra_color_picker/
 
3
// Version: 1.1
 
4
// Date: 06/26/2003 (mm/dd/yyyy)
 
5
// Note: Permission given to use this script in ANY kind of applications if
 
6
//    header lines are left unchanged.
 
7
// Note: Script consists of two files: picker.js and picker.html
 
8
 
 
9
var TCP = new TColorPicker();
 
10
 
 
11
function TCPopup(field, palette) {
 
12
        this.field = field;
 
13
        this.initPalette = !palette || palette > 3 ? 0 : palette;
 
14
        var w = 194, h = 240,
 
15
        move = screen ? 
 
16
                ',left=' + ((screen.width - w) >> 1) + ',top=' + ((screen.height - h) >> 1) : '', 
 
17
        o_colWindow = window.open('picker.vm', null, "help=no,status=no,scrollbars=no,resizable=no" + move + ",width=" + w + ",height=" + h + ",dependent=yes", true);
 
18
        o_colWindow.opener = window;
 
19
        o_colWindow.focus(); 
 
20
}
 
21
 
 
22
function TCBuildCell (R, G, B, w, h) {
 
23
        return '<td bgcolor="#' + this.dec2hex((R << 16) + (G << 8) + B) + '"><a href="javascript:P.S(\'' + this.dec2hex((R << 16) + (G << 8) + B) + '\')" onmouseover="P.P(\'' + this.dec2hex((R << 16) + (G << 8) + B) + '\')"><img src="pixel.gif" width="' + w + '" height="' + h + '" border="0"></a></td>';
 
24
}
 
25
 
 
26
function TCSelect(c) {
 
27
        this.field.value = c.toUpperCase();
 
28
        this.field.style.background='#' + c.toUpperCase();
 
29
        this.win.close();
 
30
}
 
31
 
 
32
function TCPaint(c, b_noPref) {
 
33
        c = (b_noPref ? '' : '#') + c.toUpperCase();
 
34
        if (this.o_samp) 
 
35
                this.o_samp.innerHTML = '<font face=Tahoma size=2>' + c +' <font color=white>' + c + '</font></font>'
 
36
        if(this.doc.layers)
 
37
                this.sample.bgColor = c;
 
38
        else { 
 
39
                if (this.sample.backgroundColor != null) this.sample.backgroundColor = c;
 
40
                else if (this.sample.background != null) this.sample.background = c;
 
41
        }
 
42
}
 
43
 
 
44
function TCGenerateSafe() {
 
45
        var s = '';
 
46
        for (j = 0; j < 12; j ++) {
 
47
                s += "<tr>";
 
48
                for (k = 0; k < 3; k ++)
 
49
                        for (i = 0; i <= 5; i ++)
 
50
                                s += this.bldCell(k * 51 + (j % 2) * 51 * 3, Math.floor(j / 2) * 51, i * 51, 8, 10);
 
51
                s += "</tr>";
 
52
        }
 
53
        return s;
 
54
}
 
55
 
 
56
function TCGenerateWind() {
 
57
        var s = '';
 
58
        for (j = 0; j < 12; j ++) {
 
59
                s += "<tr>";
 
60
                for (k = 0; k < 3; k ++)
 
61
                        for (i = 0; i <= 5; i++)
 
62
                                s += this.bldCell(i * 51, k * 51 + (j % 2) * 51 * 3, Math.floor(j / 2) * 51, 8, 10);
 
63
                s += "</tr>";
 
64
        }
 
65
        return s        
 
66
}
 
67
function TCGenerateMac() {
 
68
        var s = '';
 
69
        var c = 0,n = 1;
 
70
        var r,g,b;
 
71
        for (j = 0; j < 15; j ++) {
 
72
                s += "<tr>";
 
73
                for (k = 0; k < 3; k ++)
 
74
                        for (i = 0; i <= 5; i++){
 
75
                                if(j<12){
 
76
                                s += this.bldCell( 255-(Math.floor(j / 2) * 51), 255-(k * 51 + (j % 2) * 51 * 3),255-(i * 51), 8, 10);
 
77
                                }else{
 
78
                                        if(n<=14){
 
79
                                                r = 255-(n * 17);
 
80
                                                g=b=0;
 
81
                                        }else if(n>14 && n<=28){
 
82
                                                g = 255-((n-14) * 17);
 
83
                                                r=b=0;
 
84
                                        }else if(n>28 && n<=42){
 
85
                                                b = 255-((n-28) * 17);
 
86
                                                r=g=0;
 
87
                                        }else{
 
88
                                                r=g=b=255-((n-42) * 17);
 
89
                                        }
 
90
                                        s += this.bldCell( r, g,b, 8, 10);
 
91
                                        n++;
 
92
                                }
 
93
                        }
 
94
                s += "</tr>";
 
95
        }
 
96
        return s;
 
97
}
 
98
 
 
99
function TCGenerateGray() {
 
100
        var s = '';
 
101
        for (j = 0; j <= 15; j ++) {
 
102
                s += "<tr>";
 
103
                for (k = 0; k <= 15; k ++) {
 
104
                        g = Math.floor((k + j * 16) % 256);
 
105
                        s += this.bldCell(g, g, g, 9, 7);
 
106
                }
 
107
                s += '</tr>';
 
108
        }
 
109
        return s
 
110
}
 
111
 
 
112
function TCDec2Hex(v) {
 
113
        v = v.toString(16);
 
114
        for(; v.length < 6; v = '0' + v);
 
115
        return v;
 
116
}
 
117
 
 
118
function TCChgMode(v) {
 
119
        for (var k in this.divs) this.hide(k);
 
120
        this.show(v);
 
121
}
 
122
 
 
123
function TColorPicker(field) {
 
124
        this.build0 = TCGenerateSafe;
 
125
        this.build1 = TCGenerateWind;
 
126
        this.build2 = TCGenerateGray;
 
127
        this.build3 = TCGenerateMac;
 
128
        this.show = document.layers ? 
 
129
                function (div) { this.divs[div].visibility = 'show' } :
 
130
                function (div) { this.divs[div].visibility = 'visible' };
 
131
        this.hide = document.layers ? 
 
132
                function (div) { this.divs[div].visibility = 'hide' } :
 
133
                function (div) { this.divs[div].visibility = 'hidden' };
 
134
        // event handlers
 
135
        this.C       = TCChgMode;
 
136
        this.S       = TCSelect;
 
137
        this.P       = TCPaint;
 
138
        this.popup   = TCPopup;
 
139
        this.draw    = TCDraw;
 
140
        this.dec2hex = TCDec2Hex;
 
141
        this.bldCell = TCBuildCell;
 
142
        this.divs = [];
 
143
}
 
144
 
 
145
function TCDraw(o_win, o_doc) {
 
146
        this.win = o_win;
 
147
        this.doc = o_doc;
 
148
        var 
 
149
        s_tag_openT  = o_doc.layers ? 
 
150
                'layer visibility=hidden top=54 left=5 width=182' : 
 
151
                'div style=visibility:hidden;position:absolute;left:6px;top:54px;width:182px;height:0',
 
152
        s_tag_openS  = o_doc.layers ? 'layer top=32 left=6' : 'div',
 
153
        s_tag_close  = o_doc.layers ? 'layer' : 'div'
 
154
                
 
155
        this.doc.write('<' + s_tag_openS + ' id=sam name=sam><table cellpadding=0 cellspacing=0 border=1 width=181 align=center class=bd><tr><td align=center height=18><div id="samp"><font face=Tahoma size=2>sample <font color=white>sample</font></font></div></td></tr></table></' + s_tag_close + '>');
 
156
        this.sample = o_doc.layers ? o_doc.layers['sam'] : 
 
157
                o_doc.getElementById ? o_doc.getElementById('sam').style : o_doc.all['sam'].style
 
158
 
 
159
        for (var k = 0; k < 4; k ++) {
 
160
                this.doc.write('<' + s_tag_openT + ' id="p' + k + '" name="p' + k + '"><table cellpadding=0 cellspacing=0 border=1 align=center>' + this['build' + k]() + '</table></' + s_tag_close + '>');
 
161
                this.divs[k] = o_doc.layers 
 
162
                        ? o_doc.layers['p' + k] : o_doc.all 
 
163
                                ? o_doc.all['p' + k].style : o_doc.getElementById('p' + k).style
 
164
        }
 
165
        if (!o_doc.layers && o_doc.body.innerHTML) 
 
166
                this.o_samp = o_doc.all 
 
167
                        ? o_doc.all.samp : o_doc.getElementById('samp');
 
168
        this.C(this.initPalette);
 
169
        if (this.field.value) this.P(this.field.value, true)
 
170
}
 
171
        
 
172