line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
package Graphics::ColorPicker; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
5593
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
65
|
|
5
|
|
|
|
|
|
|
#use diagnostics; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
866
|
use lib qw(./blib/lib); |
|
1
|
|
|
|
|
841
|
|
|
1
|
|
|
|
|
7
|
|
8
|
1
|
|
|
1
|
|
442
|
use vars qw($VERSION $msie_frame $colwidth $leftwidth $force_msie $obfuscate $server_only $use_mdown $image); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
162
|
|
9
|
1
|
|
|
1
|
|
1649
|
use AutoLoader 'AUTOLOAD'; |
|
1
|
|
|
|
|
1876
|
|
|
1
|
|
|
|
|
8
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = do { my @r = (q$Revision: 0.17 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
################################################ |
14
|
|
|
|
|
|
|
# set some things, should not need to be changed |
15
|
|
|
|
|
|
|
################################################ |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# NOTE: set var c24flip in sub picker for the initial dark or light palette |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$server_only = 0; # overides $obfuscate, $force_msie, $use_mdown, $p_gen::jsl |
20
|
|
|
|
|
|
|
# normally set to one for external client based xy resolution |
21
|
|
|
|
|
|
|
$obfuscate = 1; # overides force_msie, and frames(parameter) |
22
|
|
|
|
|
|
|
# forces jslib to be loaded by copyright page |
23
|
|
|
|
|
|
|
#### THIS SHOULD ALWAYS BE SET TO ONE !!! |
24
|
|
|
|
|
|
|
# the new xy resolution methods work for all clients |
25
|
|
|
|
|
|
|
$use_mdown = 1; # use new onMouseDown routines, overides client side $force_msie |
26
|
|
|
|
|
|
|
$force_msie = 0; # normally 0 set 1 to use msie stuff in netscape for debug |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$colwidth = 85; # width of columns, right side is 2X this |
29
|
|
|
|
|
|
|
$leftwidth = 450; # color picker width |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$image = 1; # starting picker image, 0=dark, 1=light |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
################################################ |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $greyimg = 'grey.jpg'; |
36
|
|
|
|
|
|
|
my $darkimg = 'darkb409.jpg'; |
37
|
|
|
|
|
|
|
my $liteimg = 'liteb409.jpg'; |
38
|
|
|
|
|
|
|
my $size = 409; |
39
|
|
|
|
|
|
|
my $button = 38; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
################################################ |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$_ = $colwidth << 1; |
44
|
|
|
|
|
|
|
$msie_frame = 'ColorPicker © 2002-'. ((localtime())[5] + 1900). ' Michael Robinton loading, please wait | '; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
if ($server_only) { |
47
|
|
|
|
|
|
|
$obfuscate = 0; |
48
|
|
|
|
|
|
|
$force_msie = 1; |
49
|
|
|
|
|
|
|
$use_mdown = 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
$force_msie = 0 if ($use_mdown); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# helper |
54
|
|
|
|
|
|
|
# return useable (force_msie, use_mdown) |
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
sub _force_mdown { |
57
|
|
|
|
|
|
|
# only needed for Gecko |
58
|
0
|
0
|
|
0
|
|
|
unless ($server_only) { |
59
|
0
|
0
|
|
|
|
|
return (0,1) if $ENV{HTTP_USER_AGENT} =~ /GECKO/i; |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
return ($force_msie,$use_mdown); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 NAME |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Graphics::ColorPicker : A perl module for WYSIWYG web |
67
|
|
|
|
|
|
|
applications that allow selection of HEX color numbers |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 SYNOPSIS |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
use Graphics::ColorPicker; |
72
|
|
|
|
|
|
|
or |
73
|
|
|
|
|
|
|
require Graphics::ColorPicker; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
make_page($path_to_images); |
76
|
|
|
|
|
|
|
send_page(\$html_txt,$type); |
77
|
|
|
|
|
|
|
$time_string = http_date($time); |
78
|
|
|
|
|
|
|
$name = script_name; |
79
|
|
|
|
|
|
|
$butabref = buttontext([optional array ref]) |
80
|
|
|
|
|
|
|
$html_text=frames($websafe); |
81
|
|
|
|
|
|
|
$html_text = msie_frame; |
82
|
|
|
|
|
|
|
$html_text=picker($darkimg,$liteimg,$size,$bsize,greyimg); |
83
|
|
|
|
|
|
|
$html_text=no_picker; |
84
|
|
|
|
|
|
|
$html_text=cp216_ds($clrdot,$border,$square) |
85
|
|
|
|
|
|
|
$javascript_text = jslib; |
86
|
|
|
|
|
|
|
$html=make_buttons(\%look_n_feel,$url,$active,\@buttons,$xtra); |
87
|
|
|
|
|
|
|
$html_text=pluck($color); |
88
|
|
|
|
|
|
|
$html_text=hex_update($hex_color); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 SAMPLE WEBSITE - 24 million color picker |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 L |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 L |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 DESCRIPTION |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This module generates a set of palettes to select a HEX or DECIMAL color |
99
|
|
|
|
|
|
|
number via a web browser. B can be called by C from |
100
|
|
|
|
|
|
|
your web page and will set the HEX value in a variable in the calling page |
101
|
|
|
|
|
|
|
and scope. The selector page can be created for 24 million or web safe |
102
|
|
|
|
|
|
|
colors only. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
action="p_gen.cgi" target="colorpicker"> |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
web safe colors only |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
See B and B |
127
|
|
|
|
|
|
|
Read INSTALL |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
NOTE: as of version 0.13 ColorPicker can be used in a captive frame to |
130
|
|
|
|
|
|
|
dynamically update color values in the DOM. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
See B, |
133
|
|
|
|
|
|
|
B and |
134
|
|
|
|
|
|
|
B |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=over 4 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item make_page($path_to_images); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Generate Color Picker Pages |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This is the only routine that really needs to be called |
143
|
|
|
|
|
|
|
externally. You could roll your own from the following |
144
|
|
|
|
|
|
|
calls for a special purpose, but it's really not necessary. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
i.e. Graphics::ColorPicker::make_page('./'); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
will generate the picker pages as required |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub make_page { |
153
|
0
|
|
|
0
|
1
|
|
my ($dir) = @_; |
154
|
0
|
|
|
|
|
|
my ($x,$y,$html,$scale,$type); |
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
0
|
|
|
|
if ( $ENV{QUERY_STRING} =~ /what=picker/) { # color picker page |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
$html = &picker($dir.$darkimg,$dir.$liteimg,$size,$button,$dir.$greyimg); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
elsif ($ENV{QUERY_STRING} =~ /what=no_picker/) { # blank minimum color picker page |
160
|
0
|
|
|
|
|
|
$html = &no_picker; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
elsif ($ENV{QUERY_STRING} =~ /what=digits/) { # digits page |
163
|
0
|
|
|
|
|
|
$html = &cp216_ds($dir.'cleardot.gif'); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
# accomodate dumb browsers that don't understand all of javascript1.1 |
166
|
|
|
|
|
|
|
# or use server base XY resolution |
167
|
|
|
|
|
|
|
elsif ($ENV{QUERY_STRING} =~ /what=(msie)/) { |
168
|
0
|
|
|
|
|
|
$html = &msie_frame; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# need for MSIE workaround, mostly browser side update |
172
|
|
|
|
|
|
|
# preferred method |
173
|
|
|
|
|
|
|
elsif ($ENV{QUERY_STRING} =~ /what=(color)/ || |
174
|
|
|
|
|
|
|
$ENV{QUERY_STRING} =~ /what=(grey)/) { |
175
|
0
|
|
|
|
|
|
$html = &pluck($1,$size,$button); |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
elsif ($ENV{QUERY_STRING} =~ /what=init/) { |
179
|
0
|
0
|
|
|
|
|
$_ = ($ENV{QUERY_STRING} =~ /hex=[\#]*([0-9a-fA-F]{6})/) ? $1 : '000000'; |
180
|
0
|
|
|
|
|
|
$html = &hex_update($_); |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
elsif ($ENV{QUERY_STRING} =~ /what=jslib/) { |
183
|
0
|
|
|
|
|
|
$html = &jslib; |
184
|
0
|
|
|
|
|
|
$type = 'application/x-javascript'; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
elsif ($ENV{QUERY_STRING} =~ /what=wo/) { # frames for web safe colors only |
187
|
0
|
|
|
|
|
|
$html = &frames(1); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
else { # call frames for browser based xy resolution, 24 megacolors |
190
|
0
|
|
|
|
|
|
$html = &frames(0); |
191
|
|
|
|
|
|
|
} |
192
|
0
|
|
|
|
|
|
&send_page(\$html,$type); |
193
|
|
|
|
|
|
|
} |
194
|
|
|
|
|
|
|
=item send_page(\$html_txt,$type); |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
Sends a page of html text to browser. |
197
|
|
|
|
|
|
|
Uses Apache mod_perl if available |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
input: \$html text, |
200
|
|
|
|
|
|
|
$type, # text/html, text/plain, etc... |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=cut |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
################################################# |
205
|
|
|
|
|
|
|
# send a page to the browser, use mod_perl if available |
206
|
|
|
|
|
|
|
# |
207
|
|
|
|
|
|
|
# input: pointer to text, content-type [optional] |
208
|
|
|
|
|
|
|
# sends: text to server |
209
|
|
|
|
|
|
|
# |
210
|
|
|
|
|
|
|
# default content type = text/html |
211
|
|
|
|
|
|
|
# if not specified |
212
|
|
|
|
|
|
|
# |
213
|
|
|
|
|
|
|
sub send_page { |
214
|
0
|
|
|
0
|
0
|
|
my ($hp,$type) = @_; |
215
|
0
|
0
|
|
|
|
|
$type = 'text/html' unless $type; |
216
|
0
|
|
|
|
|
|
my $size = length($$hp); |
217
|
0
|
|
|
|
|
|
my $now = time; |
218
|
0
|
|
|
|
|
|
my $r; |
219
|
0
|
|
|
|
|
|
eval { require Apache; |
|
0
|
|
|
|
|
|
|
220
|
0
|
|
|
|
|
|
$r = Apache->request; |
221
|
|
|
|
|
|
|
}; |
222
|
0
|
0
|
|
|
|
|
unless ($@) { # unless error, it's Apache |
223
|
0
|
|
|
|
|
|
$r->status(200); |
224
|
0
|
|
|
|
|
|
$r->content_type($type); |
225
|
0
|
|
|
|
|
|
$r->header_out("Content-length","$size"); |
226
|
0
|
|
|
|
|
|
$r->header_out("Last-modified",http_date($now)); |
227
|
0
|
|
|
|
|
|
$r->header_out("Expires",http_date($now)); |
228
|
0
|
|
|
|
|
|
$r->send_http_header; |
229
|
0
|
|
|
|
|
|
$r->print ($$hp); |
230
|
0
|
|
|
|
|
|
return 200; # HTTP_OK |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
} else { # sigh... no mod_perl |
233
|
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
|
print q |
235
|
|
|
|
|
|
|
|Content-type: |, $type, q| |
236
|
|
|
|
|
|
|
Content-length: |, $size, q| |
237
|
|
|
|
|
|
|
Last-modified: |, http_date($now), q| |
238
|
|
|
|
|
|
|
Connection: close |
239
|
|
|
|
|
|
|
Expires: |, http_date($now), qq| |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
|, $$hp |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=item $time_string = http_date($time); |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Returns time string in HTTP date format, same as... |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
Apache::Util::ht_time(time, "%a, %d %b %Y %T %Z",1)); |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
i.e. Sat, 13 Apr 2002 17:36:42 GMT |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=cut |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub http_date { |
256
|
0
|
|
|
0
|
1
|
|
my($time) = @_; |
257
|
0
|
|
|
|
|
|
my($sec,$min,$hr,$mday,$mon,$yr,$wday) = gmtime($time); |
258
|
|
|
|
|
|
|
return |
259
|
0
|
|
|
|
|
|
(qw(Sun Mon Tue Wed Thu Fri Sat))[$wday] . ', ' . # "%a, " |
260
|
|
|
|
|
|
|
sprintf("%02d ",$mday) . # "%d " |
261
|
|
|
|
|
|
|
(qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec))[$mon] . ' ' . # "%b " |
262
|
|
|
|
|
|
|
($yr + 1900) . ' ' . # "%Y " |
263
|
|
|
|
|
|
|
sprintf("%02d:%02d:%02d ",$hr,$min,$sec) . # "%T " |
264
|
|
|
|
|
|
|
'GMT'; # "%Z" |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
=item $name = script_name; |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
Returns the subroutine name of the calling |
270
|
|
|
|
|
|
|
script external to this library |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=cut |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
############################################### |
275
|
|
|
|
|
|
|
# MUST NOT BE AUTOLOADED |
276
|
|
|
|
|
|
|
############################################### |
277
|
|
|
|
|
|
|
# return the name of the script that called this library |
278
|
|
|
|
|
|
|
# |
279
|
|
|
|
|
|
|
# input: none |
280
|
|
|
|
|
|
|
# returns: script name |
281
|
|
|
|
|
|
|
# |
282
|
|
|
|
|
|
|
sub script_name { |
283
|
0
|
|
|
0
|
1
|
|
for (my $i=1;$i<4;$i++) { # find script name, fail after a few tries |
284
|
0
|
|
|
|
|
|
@_ = split('/',(caller($i))[1]); |
285
|
0
|
|
|
|
|
|
my $rv = pop @_; |
286
|
0
|
0
|
|
|
|
|
return $rv unless __FILE__ =~ /$rv$/; |
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=item $but_table_ref = buttontext([optional ref]); |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
Always return and optionally set the contents of cp216_ds button text. |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
input: optional reference to button table array |
295
|
|
|
|
|
|
|
returns: reference to button table array |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
Default contents: |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
my $butable = [ |
300
|
|
|
|
|
|
|
'Submit' => 'javascript:void(0);" OnMouseDown="doSubmit();return false;', |
301
|
|
|
|
|
|
|
'','', |
302
|
|
|
|
|
|
|
'Restore' => 'javascript:void(0);" OnClick="doRestore();return false;', |
303
|
|
|
|
|
|
|
'','', |
304
|
|
|
|
|
|
|
'Close' => 'javascript:void (0);" OnClick="parent.close();return false;', |
305
|
|
|
|
|
|
|
]; |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=cut |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
# use on click as workaround for buggy Opera browser. |
310
|
|
|
|
|
|
|
my $_butab = [ |
311
|
|
|
|
|
|
|
# 'Submit' => 'javascript:void doSubmit();', |
312
|
|
|
|
|
|
|
'Submit' => 'javascript:void(0);" OnMouseDown="doSubmit();return false;', |
313
|
|
|
|
|
|
|
'','', |
314
|
|
|
|
|
|
|
# 'Restore' => 'javascript:void doRestore();', |
315
|
|
|
|
|
|
|
'Restore' => 'javascript:void(0);" OnClick="doRestore();return false;', |
316
|
|
|
|
|
|
|
'','', |
317
|
|
|
|
|
|
|
'Close' => 'javascript:void (0);" OnClick="parent.close();return false;', |
318
|
|
|
|
|
|
|
]; |
319
|
|
|
|
|
|
|
|
320
|
|
|
|
|
|
|
sub buttontext { |
321
|
0
|
0
|
|
0
|
1
|
|
if (@_) { |
322
|
0
|
|
|
|
|
|
$_butab = $_[0]; # set new button table values |
323
|
|
|
|
|
|
|
} |
324
|
0
|
|
|
|
|
|
$_butab; # always return the reference |
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
# define autoload subroutines |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
sub frames; |
330
|
|
|
|
|
|
|
sub msie_frame; |
331
|
|
|
|
|
|
|
sub picker; |
332
|
|
|
|
|
|
|
sub no_picker; |
333
|
|
|
|
|
|
|
sub cp216_ds; |
334
|
|
|
|
|
|
|
sub jslib; |
335
|
|
|
|
|
|
|
sub j2s; |
336
|
|
|
|
|
|
|
sub make_buttons; |
337
|
|
|
|
|
|
|
sub pluck; |
338
|
|
|
|
|
|
|
sub env_dumb_browser; |
339
|
|
|
|
|
|
|
sub hex_update; |
340
|
0
|
|
|
0
|
|
|
sub DESTROY {}; |
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
1; |
343
|
|
|
|
|
|
|
__END__ |