let imgpreview = document.getElementById('sourcepreview');
if (imgpreview) {
let imginput = document.getElementById('source');
+ imginput.parentNode.parentNode.append(imgpreview); // separate row
let previewbutton = imginput.parentNode.appendChild(document.createElement('button'));
previewbutton.type = 'button';
previewbutton.append('View');
next;
};
- my $imgpath = "data/word/org/$row->{id}.jpg";
+ my $imgpath = Shiar_Sheet::FormRow::imagepath($row, 'source');
my $reimage = eval {
($row->{source} // '') ne ($replace->{source} // '') or return;
# copy changed remote url to local file
$reimage ||= $row->{cover} ~~ $replace->{cover}; # resize
$reimage++ if $fields{rethumb}; # force refresh
- my $thumbpath = "data/word/eng/$row->{form}.jpg";
+ my $thumbpath = Shiar_Sheet::FormRow::imagepath($row => 'thumb');
if ($reimage) {
if (-e $imgpath) {
my $xyres = $row->{cover} ? '600x400' : '300x200';
sprintf('<input id="%s" name="%1$s" value="%s"%s />',
$col, PLP::Functions::EscapeHTML($val), $html
),
+ (map {
+ sprintf '<img id="%spreview" src="/%s" alt="%s"%s />',
+ $col, $_, $row->{form}, $col eq 'source' ? ' hidden' : '';
+ } grep { -e } $row->imagepath($col)),
);
}
}
+
+ sub imagepath {
+ my ($row, $col) = @_;
+ return "data/word/org/$row->{id}.jpg" if $col eq 'source';
+ return "data/word/eng/$row->{form}.jpg" if $col eq 'thumb';
+ return;
+ }
}
bless $row, 'Shiar_Sheet::FormRow';
:>
}
else {
print $row->input($col);
- -e and printf '<img id="%spreview" src="/%s" alt="%s" />', $col, $_, $row->{form}
- for $col eq 'thumb' ? "data/word/eng/$row->{form}.jpg" : ();
print $row->input(ref => {}, 'Reference') if $col eq 'cat';
}
print '</span>';
- -e and printf('<img id="%spreview" src="/%s" alt="%s" hidden />',
- $col, $_, $row->{form}
- ) for $col eq 'source' ? "data/word/org/$row->{id}.jpg" : ();
say '</p></li>';
}