1 # Copyright 2002-2008 Interchange Development Group and others
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version. See the LICENSE file for details.
8 UserTag button Order name src text
10 UserTag button attrAlias value text
11 UserTag button hasEndTag
12 UserTag button Version 1.25
13 UserTag button Routine <<EOR
15 my ($name, $src, $text, $opt, $action) = @_;
19 if($opt->{wait_text}) {
20 $trigger_text = $opt->{wait_text};
23 $trigger_text = $text;
29 my @from_html = qw/class id style/;
32 if( $opt->{srcliteral} || $src =~ m{^https?://}i ) {
36 my $dr = $::Variable->{DOCROOT};
37 my $id = $Tag->image( { dir_only => 1 } );
41 if( $dr and $id and $src =~ m{^[^/]} and -f "$dr$id/$src" ) {
44 elsif( $dr and $src =~ m{^/} and -f "$dr/$src" ) {
48 ::logError("No image file '$src' found or image file name is invalid.");
55 while($action =~ s! \[
57 j (?:ava)? s (?:cript)?
68 if($script =~ s/\bonclick\s*=\s*"(.*?)"//is) {
72 if ($script =~ s/\bonmouse(\w+)\s*=\s*"(.*?)"//is) {
73 if (lc($1) eq 'over') {
74 $onmouseover .= ($onmouseover ? ';' : '') . $2;
76 elsif (lc($1) eq 'out') {
77 $onmouseout .= ($onmouseout ? ';' : '') . $2;
80 logError(q{Skipping 'onmouse%s', invalid JavaScript event}, $1);
87 if(! $name or $name eq 'mv_click') {
90 my $set_text = HTML::Entities::decode($trigger_text);
91 $::Scratch->{$set_text} = $action;
92 $name = 'mv_click' if ! $name;
98 $opt->{extra} = $opt->{extra} ? " $opt->{extra}" : '';
100 $opt->{confirm} =~ s/'/\\'/g;
101 $confirm = "confirm('$opt->{confirm}')";
105 $confirm .= ' && ' if $confirm;
106 $onclick = qq{ onClick="$confirm$onclick"};
109 # Constructing form button. Will be sent back in all cases,
110 # either as the primary button or as the <noscript> option
111 # for JavaScript-challenged browsers.
112 $text =~ s/"/"/g;
113 $name =~ s/"/"/g;
114 $out = qq{<input type="submit" name="$name" value="$text"$onclick$Vend::Xtrailer>};
116 $out =~ s/ /join "\n", '', @js, ''/e;
119 $opt->{extra} ||= '';
121 next unless $opt->{$_};
122 $opt->{extra} .= qq{ $_="$opt->{$_}"};
125 # return submit button if not an image
127 $text =~ s/"/"/g;
128 $name =~ s/"/"/g;
129 if(! $onclick and $confirm) {
130 $onclick = qq{ onclick="return $confirm"};
132 elsif(! $onclick and $opt->{wait_text}) {
133 $opt->{wait_text} = HTML::Entities::encode($trigger_text);
134 $onclick = qq{ onClick="};
135 $onclick .= qq{var msg = 'Already submitted.';};
136 $onclick .= qq{this.value = '$opt->{wait_text}';};
137 $onclick .= qq{this.onclick = 'alert(msg)'; return true;};
141 my $out = $opt->{bold} ? '<b>' : '';
142 $out .= qq{<input$opt->{extra} type="submit" name="$name" value="$text"$onclick$Vend::Xtrailer>};
143 $out .= '</b>' if $opt->{bold};
145 $out =~ s/ /join "\n", '', @js, ''/e;
150 # If we got here the button is an image
151 # Wrap form button code in <noscript>
152 my $no_script = qq{<noscript>$out</noscript>\n};
155 my $wstatus = $opt->{alt} || $text;
156 $wstatus =~ s/'/\\'/g;
158 my $clickname = $name;
159 my $clickvar = $name;
160 if($image and $name eq 'mv_click') {
162 $clickvar =~ s/\W/_/g;
163 $clickname = "mv_click_$clickvar";
164 $out = qq{<input type='hidden' name='mv_click_map' value='$clickvar'$Vend::Xtrailer>};
167 $out .= qq{<input type='hidden' name='$clickname' value=''$Vend::Xtrailer>} if $image;
170 $opt->{form} = 'forms[0]'
173 $confirm .= ' && ' if $confirm;
174 $opt->{border} = 0 if ! $opt->{border};
176 if($opt->{getsize}) {
179 ($opt->{width}, $opt->{height}) = Image::Size::imgsize($image);
183 $opt->{align} = 'top' if ! $opt->{align};
186 for(qw/height width vspace hspace align/) {
187 $position .= " $_='$opt->{$_}'" if $opt->{$_};
191 unless( $opt->{hidetext}) {
192 $anchor = $opt->{anchor} || $text;
193 $anchor =~ s/ / /g;
194 $anchor = "<b>$anchor</b>";
197 my $a_before = '</a>';
199 if($opt->{link_text_too}) {
204 $opt->{link_href} ||= 'javascript: void 0';
205 if ($onclick =~ /^\s*onclick\s*=\s*"(.*?)"/i) {
206 $onclick = $1 . ' && ';
208 # QUOTING (fix here too?)
210 <a href="$opt->{link_href}"$opt->{extra} onMouseOver="window.status='$wstatus';$onmouseover"
212 $out .= <<EOF if $onmouseout;
213 onMouseOut="$onmouseout"
216 onClick="$confirm $onclick mv_click_map_unique(document.$opt->{form}, '$clickname', '$text') && $opt->{form}.submit(); return(false);"
217 alt="$wstatus"><img alt="$wstatus" src="$src" border='$opt->{border}'$position>$a_before$anchor$a_after
221 unless ($::Instance->{js_functions}{mv_do_click}++) {
222 $function = "\n" . <<'EOJS';
223 function mv_click_map_unique(myform, clickname, clicktext) {
224 for (var i = 0; i < myform.length; i++) {
225 var widget = myform.elements[i];
227 (widget.type == 'hidden')
228 && (widget.name != 'mv_click_map')
229 && (widget.name.indexOf('mv_click_') == 0)
231 widget.value = (widget.name == clickname) ? clicktext : '';
238 # Must escape backslashes and single quotes for JavaScript write function.
239 # Also must get rid of newlines and carriage returns.
240 $out =~ s/(['\\])/\\$1/g;
241 $out =~ s/[\n\r]+/ /g;
243 <script language="javascript1.2" type="text/javascript">
245 document.write('$out');