/
button.tag
254 lines (224 loc) · 6.21 KB
/
button.tag
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# Copyright 2002-2008 Interchange Development Group and others
#
# 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. See the LICENSE file for details.
UserTag button Order name src text
UserTag button addAttr
UserTag button attrAlias value text
UserTag button hasEndTag
UserTag button Version $Revision: 1.25 $
UserTag button Routine <<EOR
sub {
my ($name, $src, $text, $opt, $action) = @_;
my $trigger_text;
if($opt->{wait_text}) {
$trigger_text = $opt->{wait_text};
}
else {
$trigger_text = $text;
}
my @js;
my $image;
my @from_html = qw/class id style/;
if($src) {
if( $opt->{srcliteral} || $src =~ m{^https?://}i ) {
$image = $src;
}
else {
my $dr = $::Variable->{DOCROOT};
my $id = $Tag->image( { dir_only => 1 } );
$id =~ s:/+$::;
$id =~ s:/~[^/]+::;
if( $dr and $id and $src =~ m{^[^/]} and -f "$dr$id/$src" ) {
$image = $src;
}
elsif( $dr and $src =~ m{^/} and -f "$dr/$src" ) {
$image = "$id/$src";
}
else {
::logError("No image file '$src' found or image file name is invalid.");
}
}
}
my $onclick = '';
my $onmouseover = '';
my $onmouseout = '';
while($action =~ s! \[
(
j (?:ava)? s (?:cript)?
)
\]
(.*?)
\[ / \1 \]
!!xis
)
{
my $script = $2;
$script =~ s/\s+$//;
$script =~ s/^\s+//;
if($script =~ s/\bonclick\s*=\s*"(.*?)"//is) {
$onclick = $1;
next;
}
if ($script =~ s/\bonmouse(\w+)\s*=\s*"(.*?)"//is) {
if (lc($1) eq 'over') {
$onmouseover .= ($onmouseover ? ';' : '') . $2;
}
elsif (lc($1) eq 'out') {
$onmouseout .= ($onmouseout ? ';' : '') . $2;
}
else {
logError(q{Skipping 'onmouse%s', invalid JavaScript event}, $1);
}
next;
}
push @js, $script;
}
if(! $name or $name eq 'mv_click') {
$action =~ s/^\s+//;
$action =~ s/\s+$//;
my $set_text = HTML::Entities::decode($trigger_text);
$::Scratch->{$set_text} = $action;
$name = 'mv_click' if ! $name;
}
my $out = '';
my $confirm = '';
my $wait = '';
$opt->{extra} = $opt->{extra} ? " $opt->{extra}" : '';
if($opt->{confirm}) {
$opt->{confirm} =~ s/'/\\'/g;
$confirm = "confirm('$opt->{confirm}')";
}
if($onclick) {
$confirm .= ' && ' if $confirm;
$onclick = qq{ onClick="$confirm$onclick"};
}
# Constructing form button. Will be sent back in all cases,
# either as the primary button or as the <noscript> option
# for JavaScript-challenged browsers.
$text =~ s/"/"/g;
$name =~ s/"/"/g;
$out = qq{<input type="submit" name="$name" value="$text"$onclick$Vend::Xtrailer>};
if (@js) {
$out =~ s/ /join "\n", '', @js, ''/e;
}
$opt->{extra} ||= '';
for(@from_html) {
next unless $opt->{$_};
$opt->{extra} .= qq{ $_="$opt->{$_}"};
}
# return submit button if not an image
if(! $image) {
$text =~ s/"/"/g;
$name =~ s/"/"/g;
if(! $onclick and $confirm) {
$onclick = qq{ onclick="return $confirm"};
}
elsif(! $onclick and $opt->{wait_text}) {
$opt->{wait_text} = HTML::Entities::encode($trigger_text);
$onclick = qq{ onClick="};
$onclick .= qq{var msg = 'Already submitted.';};
$onclick .= qq{this.value = '$opt->{wait_text}';};
$onclick .= qq{this.onclick = 'alert(msg)'; return true;};
$onclick .= qq{"};
}
my $out = $opt->{bold} ? '<b>' : '';
$out .= qq{<input$opt->{extra} type="submit" name="$name" value="$text"$onclick$Vend::Xtrailer>};
$out .= '</b>' if $opt->{bold};
if(@js) {
$out =~ s/ /join "\n", '', @js, ''/e;
}
return $out;
}
# If we got here the button is an image
# Wrap form button code in <noscript>
my $no_script = qq{<noscript>$out</noscript>\n};
$out = '';
my $wstatus = $opt->{alt} || $text;
$wstatus =~ s/'/\\'/g;
my $clickname = $name;
my $clickvar = $name;
if($image and $name eq 'mv_click') {
$clickvar = $text;
$clickvar =~ s/\W/_/g;
$clickname = "mv_click_$clickvar";
$out = qq{<input type='hidden' name='mv_click_map' value='$clickvar'$Vend::Xtrailer>};
}
$out .= qq{<input type='hidden' name='$clickname' value=''$Vend::Xtrailer>} if $image;
my $formname;
$opt->{form} = 'forms[0]'
if ! $opt->{form};
$confirm .= ' && ' if $confirm;
$opt->{border} = 0 if ! $opt->{border};
if($opt->{getsize}) {
eval {
require Image::Size;
($opt->{width}, $opt->{height}) = Image::Size::imgsize($image);
};
}
$opt->{align} = 'top' if ! $opt->{align};
my $position = '';
for(qw/height width vspace hspace align/) {
$position .= " $_='$opt->{$_}'" if $opt->{$_};
}
my $anchor = '';
unless( $opt->{hidetext}) {
$anchor = $opt->{anchor} || $text;
$anchor =~ s/ / /g;
$anchor = "<b>$anchor</b>";
}
my $a_before = '</a>';
my $a_after = '';
if($opt->{link_text_too}) {
$a_before = '';
$a_after = '</a>';
}
$opt->{link_href} ||= 'javascript: void 0';
if ($onclick =~ /^\s*onclick\s*=\s*"(.*?)"/i) {
$onclick = $1 . ' && ';
}
# QUOTING (fix here too?)
$out .= <<EOF;
<a href="$opt->{link_href}"$opt->{extra} onMouseOver="window.status='$wstatus';$onmouseover"
EOF
$out .= <<EOF if $onmouseout;
onMouseOut="$onmouseout"
EOF
$out .= <<EOF;
onClick="$confirm $onclick mv_click_map_unique(document.$opt->{form}, '$clickname', '$text') && $opt->{form}.submit(); return(false);"
alt="$wstatus"><img alt="$wstatus" src="$src" border='$opt->{border}'$position>$a_before$anchor$a_after
EOF
my $function = '';
unless ($::Instance->{js_functions}{mv_do_click}++) {
$function = "\n" . <<'EOJS';
function mv_click_map_unique(myform, clickname, clicktext) {
for (var i = 0; i < myform.length; i++) {
var widget = myform.elements[i];
if (
(widget.type == 'hidden')
&& (widget.name != 'mv_click_map')
&& (widget.name.indexOf('mv_click_') == 0)
)
widget.value = (widget.name == clickname) ? clicktext : '';
}
return true;
}
EOJS
}
# Must escape backslashes and single quotes for JavaScript write function.
# Also must get rid of newlines and carriage returns.
$out =~ s/(['\\])/\\$1/g;
$out =~ s/[\n\r]+/ /g;
$out = <<EOV;
<script language="javascript1.2" type="text/javascript">
<!--$function
document.write('$out');
// -->
</script>
$no_script
EOV
return $out;
}
EOR