[interchange-cvs] interchange - heins modified lib/Vend/Menu.pm
interchange-core@icdevgroup.org
interchange-core@icdevgroup.org
Mon Jan 20 11:51:01 2003
User: heins
Date: 2003-01-20 16:50:28 GMT
Modified: lib/Vend Menu.pm
Log:
* Add category-specific image links and toggles for the tree menu.
To enable this for toggles, do:
[menu
menu-type=tree
...
specific-image-toggle=N
]
Where N is the level (1 == 0) to which you wish to do this.
The image for a non-toggled category comes from the tree database field
img_up, for a toggled category from img_dn.
You can set the base URL for the images with:
specific-image-base="__IMAGE_DIR__";
A trailing / is added if not already present.
If you wish to allow image anchors for links as well, put the image
name in the img_up field and add the parameter:
specific-image-link=1
If the image name is not present, the normal "name" field is used.
To enable all of this for the example product_tree component, you would
have a call of:
[menu tree-selector="[control tree_selector Products]"
link-class="[control link_class barlink]"
link-style="[control link_style]"
link-class-open="[control link_class_open]"
link-style-open="[control link_style_open font-size: larger;]"
link-class-closed="[control link_class_closed]"
link-style-closed="[control link_style_closed font-size: larger;]"
no-image="[control no_image]"
menu-type=tree
specific-image-toggle=1
specific-image-base="__IMAGE_DIR__/tree"
specific-image-link=1
reparse=0]
Revision Changes Path
2.22 +107 -17 interchange/lib/Vend/Menu.pm
rev 2.22, prev_rev 2.21
Index: Menu.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Menu.pm,v
retrieving revision 2.21
retrieving revision 2.22
diff -u -r2.21 -r2.22
--- Menu.pm 14 Jan 2003 00:24:27 -0000 2.21
+++ Menu.pm 20 Jan 2003 16:50:28 -0000 2.22
@@ -1,6 +1,6 @@
# Vend::Menu - Interchange menu processing routines
#
-# $Id: Menu.pm,v 2.21 2003/01/14 00:24:27 mheins Exp $
+# $Id: Menu.pm,v 2.22 2003/01/20 16:50:28 mheins Exp $
#
# Copyright (C) 2002 Mike Heins, <mike@perusion.net>
#
@@ -21,7 +21,7 @@
package Vend::Menu;
-$VERSION = substr(q$Revision: 2.21 $, 10);
+$VERSION = substr(q$Revision: 2.22 $, 10);
use Vend::Util;
use strict;
@@ -947,6 +947,30 @@
push @out, $out;
+ if($opt->{specific_image_toggle}) {
+ $opt->{specific_image_toggle} =~ s/\D+//;
+ if(defined $opt->{specific_image_base}) {
+ $opt->{specific_image_base} =~ s:/*$:/:;
+ }
+ else {
+ $opt->{specific_image_base} = $Vend::Cfg->{ImageDir};
+ }
+ }
+
+ if($opt->{specific_image_link}) {
+ if(defined $opt->{specific_image_base}) {
+ $opt->{specific_image_base} =~ s:/*$:/:;
+ }
+ else {
+ $opt->{specific_image_base} = $Vend::Cfg->{ImageDir};
+ }
+ }
+
+ $opt->{image_link_extra} = Vend::Tags->jsq($opt->{image_link_extra});
+ $opt->{image_link_extra} ||= qq{'border=0'};
+
+ $opt->{specific_image_toggle} ||= 0;
+
push @out, <<EOF;
var ${vpf}next_level = 0;
var ${vpf}openstring = '';
@@ -956,14 +980,44 @@
var ${vpf}link_style = '$opt->{link_style}';
var ${vpf}link_style_open = '$opt->{link_style_open}';
var ${vpf}link_style_closed = '$opt->{link_style_closed}';
+var ${vpf}specific_image_toggle = $opt->{specific_image_toggle};
+var ${vpf}specific_image_base = '$opt->{specific_image_base}';
+var ${vpf}specific_image_link;
+var ${vpf}image_link_extra = $opt->{image_link_extra};
var ${vpf}toggle_class = '$opt->{toggle_class}';
var ${vpf}toggle_anchor_clear = '$opt->{toggle_anchor_clear}';
var ${vpf}toggle_anchor_closed = '$opt->{toggle_anchor_closed}';
var ${vpf}toggle_anchor_open = '$opt->{toggle_anchor_open}';
var ${vpf}treebox = document.getElementById('${vpf}treebox');
+if(${vpf}image_link_extra)
+ ${vpf}image_link_extra = ' ' + ${vpf}image_link_extra;
+var alert_shown;
EOF
+ push @out, "${vpf}specific_image_link = 1;"
+ if $opt->{specific_image_link};
+
push @out, <<EOF unless $opt->{no_emit_code};
+
+function ${vpf}image_link (rec) {
+ if(rec == undefined)
+ return;
+ var out;
+ if(rec[ ${vpf}IMG_UP ]) {
+ out = '<img src="';
+ out += ${vpf}specific_image_base;
+ out += rec[ ${vpf}IMG_UP ];
+ out += '"';
+ out += ${vpf}image_link_extra;
+ out += '>';
+// alert('img=' + out);
+ }
+ else {
+ out = rec[${vpf}NAME];
+ }
+ return out;
+}
+
function ${vpf}tree_link (idx) {
var out = '';
@@ -978,6 +1032,18 @@
if(l[${vpf}MV_LEVEL] > ${vpf}next_level)
return '';
+ var spec_toggle = 0;
+ if(${vpf}specific_image_toggle > 0) {
+ var toglevel = ${vpf}specific_image_toggle - 1;
+// if(alert_shown == undefined) {
+// alert('specific image toggle triggered, toglevel=' + toglevel + ", mv_level=" + l[${vpf}MV_LEVEL]);
+// alert_shown = 1;
+// }
+ if(l[${vpf}MV_LEVEL] <= toglevel) {
+ spec_toggle = 1;
+ }
+ }
+
var i;
var needed = l[${vpf}MV_LEVEL];
for(i = 1; i <= needed; i++)
@@ -989,13 +1055,31 @@
if(${vpf}openstatus[idx] == 1) {
tclass = ${vpf}link_class_open;
tstyle = ${vpf}link_style_open;
- tanchor = ${vpf}toggle_anchor_open;
+ if(spec_toggle > 0) {
+ tanchor = '<img border=0 src="' + ${vpf}specific_image_base + l[${vpf}IMG_DN] + '">';
+// if(alert_shown < 2) {
+// alert('tanchor=' + tanchor);
+// alert_shown = 2;
+// }
+ }
+ else {
+ tanchor = ${vpf}toggle_anchor_open;
+ }
${vpf}next_level = l[${vpf}MV_LEVEL] + 1;
}
else {
tclass = ${vpf}link_class_closed;
tstyle = ${vpf}link_style_closed;
- tanchor = ${vpf}toggle_anchor_closed;
+ if(spec_toggle > 0) {
+ tanchor = '<img border=0 src="' + ${vpf}specific_image_base + l[${vpf}IMG_UP] + '">';
+// if(alert_shown < 2) {
+// alert('tanchor=' + tanchor);
+// alert_shown = 2;
+// }
+ }
+ else {
+ tanchor = ${vpf}toggle_anchor_closed;
+ }
${vpf}next_level = l[${vpf}MV_LEVEL];
}
@@ -1013,19 +1097,25 @@
next_level = l[${vpf}MV_LEVEL];
}
- if(l[${vpf}PAGE]) {
- out = out + '<a href="' + l[${vpf}PAGE] + ${vpf}openstring + '"';
- if(tclass)
- out = out + ' class="' + tclass + '"';
- if(tstyle)
- out = out + ' style="' + tstyle + '"';
- if(l[${vpf}DESCRIPTION])
- out = out + ' title="' + l[${vpf}DESCRIPTION] + '"';
- out = out + '>';
- out = out + l[${vpf}NAME] + '</a>';
- }
- else {
- out = out + l[${vpf}NAME];
+ if(spec_toggle == 0) {
+ if(l[${vpf}PAGE]) {
+ out = out + '<a href="' + l[${vpf}PAGE] + ${vpf}openstring + '"';
+ if(tclass)
+ out = out + ' class="' + tclass + '"';
+ if(tstyle)
+ out = out + ' style="' + tstyle + '"';
+ if(l[${vpf}DESCRIPTION])
+ out = out + ' title="' + l[${vpf}DESCRIPTION] + '"';
+ out = out + '>';
+ if(${vpf}specific_image_link)
+ out += ${vpf}image_link(l);
+ else
+ out += l[${vpf}NAME];
+ out += '</a>';
+ }
+ else {
+ out = out + l[${vpf}NAME];
+ }
}
out = out + '<br>';