package ONO::Lib::UI::Tags;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################
use strict;
use ONO::Lib::Code::RandomID;
###############################################################################
# tags
###############################################################################
sub tags {
#: Display tag list.
#:
#: * selected item (will be green)
#:
#: -d offer option to de-select by clicking again
#: -D offer option to de-select using an additional orange '$option' button
#: -L default Link mode (link=tag)
#: -s splitter mode (ID:text)
my (
$self,
$tags,
$link,
$switches,
$option,
$ID,
) = @_;
if (!$ID) {
$ID = ONO::Lib::Code::RandomID->make;
}
my ($TAGS,%used,$selected);
foreach my $tag (sort split(/\,/,",$tags")) {
$tag =~ s~^ +~~g;
$tag =~ s~ +$~~g;
my $tag2 = lc $tag;
$tag2 =~ s~[^a-z0-9]~~g;
if ($tag =~ /[A-Za-z0-9]/ && !$used{$tag2}) {
$used{$tag2}++;
my $bg_color = "bg_fabric";
my $color = "col6";
my $out = "out";
if ($tag =~ s/^\*//) {
$selected++;
$bg_color = "box_green";
$color = "colf";
$out = "highlight";
}
my $id = $tag;
if ($switches =~ /s/ && $tag =~ /^(.*?):(.*?)$/) {
$id = $1;
$tag = $2;
}
my $TAG = qq~<div id="ono_tag_${ID}_$tag2" class="$bg_color $color small pad10_2 bo radius5 fl mr5 mb5" onmouseover="onojs_ui_tag_hover_in('${ID}_$tag2');" onmouseout="onojs_ui_tag_hover_$out('${ID}_$tag2');">$tag</div>~;
if ($link) {
my $link_use = $link;
$link_use =~ s~###ID###~$id~g;
$link_use =~ s~###TAG###~$tag~g;
$link_use =~ s~###TAG2###~$tag2~g;
$link_use =~ s~###ID###~ono_tag_${ID}_$tag2~g;
if ($switches =~ /L/) {
$link_use .= "$tag";
}
if ($link =~ /\(/) {
$TAG = qq~<a href="javascript:void(0);" onclick="$link_use" class="col3">$TAG</a>~;
} else {
$TAG = qq~<a href="$link_use" class="col3">$TAG</a>~;
}
}
$TAGS .= $TAG;
}
}
if ($switches =~ /D/ && $selected) {
$link =~ s~###(.*?)###~~g;
$TAGS .= qq~<a href="$link" class="col3"><div id="ono_tag_${ID}__deselect" class="box_yellow small pad10_2 bo radius5 fl mr5 mb5">$option</div></a>~;
}
return $TAGS;
}
###############################################################################
# end of script
###############################################################################
1;
__END__