Еще один вариант реализации меню
1. В <head> добавляем скрипт:
<script type="text/javascript">
function active(){
var obj = document.getElementById('active');
alert(obj.tagName);
while (obj){
obj = obj.parentNode;
if(obj.tagName=='UL'){
obj.style.display='block';
act = obj.parentNode;
}
}
}
</script>
2. Меняем
<body> на <body onload="active();">
3. В шаблоне
Этот код:
<!-- Разделы каталога товаров -->
<?php
// Проверяем, существует ли класс Интернет-магазина
if (class_exists('shop'))
{
$shop = & singleton('shop');
$shop_id = 1;
$param = array();
$param['items_on_page'] = 0;
$param['xml_show_group_type'] = 'all';
$param['xml_show_all_producers'] = false;
$param['xml_show_producers'] = false;
$param['xml_show_all_sellers'] = false;
$param['xml_show_tying_products'] = false;
$param['xml_show_modification'] = false;
$param['xml_show_group_property'] = false;
$param['xml_show_item_property'] = false;
$param['xml_show_tags'] = false;
$shop->ShowShop($shop_id, 'МагазинГруппыТоваровНаГлавной', $param);
}
?>
меняем на этот:
<!-- Разделы каталога товаров -->
<?php
$shop = new shop();
$ShopId = 1;
$rez = array();
$rez = $shop->GetItemPath($ShopId);
$external_propertys = array();
$external_propertys['ТекущаяГруппа'] = $rez['group'];
$param = array('current_group_id' => 0, 'items_on_page' => 10);
$param['xml_show_group_type'] = 'all';
$xsl_catalog = 'МагазинГруппыТоваровНаГлавной';
$shop->ShowShop($ShopId, $xsl_catalog, $param, $external_propertys);
?>
4. И добавляем XSL шаблон:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output xmlns="http://www.w3.org/TR/xhtml1/strict" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" encoding="utf-8" indent="yes" method="html" omit-xml-declaration="no" version="1.0" media-type="text/xml"/>
<xsl:template match="/">
<xsl:apply-templates select="shop"/>
</xsl:template>
<!-- Шаблон для магазина -->
<xsl:template match="/shop">
<SCRIPT>
<xsl:comment>
<xsl:text disable-output-escaping="yes">
<![CDATA[
function show_hide_menu(id)
{
if (obj = document.getElementById(id))
{
obj.style.display == 'none' ? obj.style.display = 'block' : obj.style.display = 'none';
return false;
}
return true;
}
function active(){
var obj = document.getElementById('active');
while (obj){
obj = obj.parentNode;
if(obj.tagName=='UL'){
obj.style.display='block';
act = obj.parentNode;
}
}
}
]]>
</xsl:text>
</xsl:comment>
</SCRIPT>
<xsl:variable name="parent_group_id" select="@current_group_id"/>
<!-- Выводим группы магазина -->
<ul class="left_menu">
<xsl:apply-templates select="//group[@parent=0]"/>
</ul>
</xsl:template>
<!-- Шаблон для групп товара -->
<xsl:template match="group">
<xsl:variable name="current_group_id" select="/shop/ТекущаяГруппа"/>
<li>
<xsl:if test="$current_group_id = @id">
<xsl:attribute name="id">active</xsl:attribute>
</xsl:if>
<xsl:choose>
<xsl:when test="$current_group_id = @id or count(.//group[@id=$current_group_id])=1">
<!-- Определяем стиль вывода ссылки -->
<xsl:variable name="link_style">
<xsl:choose>
<!-- Выделяем текущую страницу жирным (если это текущая страница) -->
<xsl:when test="$current_group_id = @id">font-weight: bold;</xsl:when>
<!-- Иначе обычный вывод с пустым стилем -->
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<a onClick="return show_hide_menu('{@id}');" href="{/shop/path}{fullpath}" style="{$link_style}">
<xsl:choose>
<xsl:when test="propertys/property/node()">
<xsl:value-of disable-output-escaping="yes" select="propertys/property/value"/></xsl:when>
<xsl:otherwise>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</xsl:otherwise>
</xsl:choose>
</a>
<!--
<xsl:if test="count_all_groups > 0">
<ul class="left_menu_2">
<xsl:apply-templates select="group"/>
</ul>
</xsl:if>
-->
</xsl:when>
<xsl:otherwise>
<a onClick="return show_hide_menu('{@id}');" href="{/shop/path}{fullpath}">
<xsl:choose>
<xsl:when test="propertys/property/node()">
<xsl:value-of disable-output-escaping="yes" select="propertys/property/value"/></xsl:when>
<xsl:otherwise>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</xsl:otherwise>
</xsl:choose>
</a>
</xsl:otherwise>
</xsl:choose>
<!-- Если есть подгруппы -->
<xsl:if test="group">
<ul id="{@id}" style="display: none;" class="left_menu_2">
<xsl:apply-templates select="group"/>
</ul>
</xsl:if>
</li>
</xsl:template>
</xsl:stylesheet>