Как сохранить вкладку текущей категории открытой, используя ddaccordian.init? - PullRequest
0 голосов
/ 20 декабря 2011

У меня есть список категорий , некоторые имеют подкатегорию , а некоторые имеют подкатегорию , которые находятся таким образом:

Main menu
   sub menu
      sub menu

Я использовал ddaccordian.init для наблюдения за событиями открытого закрытия.Все работает нормально, но теперь я хочу, чтобы текущая выбранная категория URL-адресов оставалась открытой.

Я попробовал следующий код:

<script type="text/javascript">
ddaccordion.init({
    headerclass: "question", //Shared CSS class name of headers group
    contentclass: "theanswer", //Shared CSS class name of contents group
    revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
    mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
    collapseprev: false, //Collapse previous content (so only one open at any time)? true/false
    defaultexpanded: [], //index of content(s) open by default [index1, index2, etc]. [] denotes no content.
    onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
    animatedefault: false, //Should contents open by default be animated into view?
    persiststate: false, //persist state of opened contents within browser session?
    toggleclass: ["closedanswer", "openanswer"], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
    //togglehtml: ["prefix", "<img src='images/plus.gif' /> ", "<img src='images/minus.gif' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
    animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
    oninit:function(expandedindices){ //custom code to run when headers have initalized
        //do nothing
    },
    onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
        //do nothing
    }
})
</script>

и чтобы активировать текущую категорию, т.е.оставаясь открытым, я сделал это:

<a <?php if($_category->hasChildren()): ?>class="question"<?php endif; ?><?php if ($currentUrl == $this->getCategoryUrl($_category)): ?> class="current"<?php endif; ?> href="<?php echo $this->getCategoryUrl($_category) ?>">
    <?php echo $_category['name']; ?>
</a>

<?php $potential1 = $_category->hasChildren(); ?>
<?php if($_category->hasChildren()): ?>
    <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
    <?php $_subcategories = $_category->getChildrenCategories() ?>
    <ul <?php if($_subcategories): ?>class="theanswer"<?php endif; ?>>
    <?php foreach($_subcategories as $subcat): ?>
        <li>
            <a <?php if($subcat->hasChildren()): ?>class="question"<?php endif; ?><?php if ($currentUrl == $this->getCategoryUrl($subcat)): ?> class="current"<?php endif; ?> href="<?php echo $this->getCategoryUrl($subcat); ?>">
                <?php echo $subcat->getName(); ?>
            </a>
            <?php if($subcat->hasChildren()): ?>
            <?php
                $_subcat = Mage::getModel('catalog/category')->load($subcat->getId());
                $childrens = $_subcat->getChildrenCategories();
            ?>
            <ul <?php if($childrens): ?>class="theanswer"<?php endif; ?>>
            <?php foreach($childrens as $_childrens): ?>
                <li>
                    <a <?php if ($currentUrl == $this->getCategoryUrl($_childrens)): ?> class="current"<?php endif; ?>href="<?php echo $this->getCategoryUrl($_childrens); ?>">
                        <?php echo $_childrens->getName(); ?>
                    </a>
                </li>
            <?php endforeach; ?>
            </ul>
            <?php endif ?>
        </li>
    <?php endforeach ?>
    </ul>
<?php endif ?>
</li>

Но я не получаю ответа на веб-интерфейс :( Не берите в голову, если вы думаете, что я пропускаю цикл foreach и т. д.
Я только что вставил часть кодатак скажите мне, где я не прав: (
Хотя я правильно получаю текущий URL.

Ответы [ 2 ]

0 голосов
/ 22 декабря 2011

Это решило мою проблему. То, что я сделал, добавило <?php if ($this->isCategoryActive($_category)): ?> вместо if($currentUrl == $this->getCategoryUrl($_category)): ?> и добавил класс Css внизу.

<div class="content-links">
                                <ul>
                    <?php  $i=0; foreach ($catlist as $_category): ?>
                        <?php if($_category->getIsActive()): ?>

                            <li>

                                <a <?php if($_category->hasChildren()): ?>class="question"<?php endif; ?> href="<?php echo $this->getCategoryUrl($_category) ?>">
                                    <?php echo $_category['name']; ?>
                                </a>

                                            <?php $potential1 = $_category->hasChildren(); ?>

                                    <?php if($_category->hasChildren()): ?>

                                        <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
                                        <?php $_subcategories = $_category->getChildrenCategories() ?>
                                        <ul class="<?php if($_subcategories): ?>theanswer<?php endif; ?><?php //if($currentUrl == $this->getCategoryUrl($_category)): ?><?php if ($this->isCategoryActive($_category)): ?> opened<?php endif; ?>">

                                            <?php foreach($_subcategories as $subcat): ?>


                                                <li>
                                                <a <?php if($subcat->hasChildren()): ?>class="question"<?php endif; ?> href="<?php echo $this->getCategoryUrl($subcat); ?>">
                                                    <?php echo $subcat->getName(); ?>
                                                </a>
                                                <?php if($subcat->hasChildren()): ?>

                                                    <?php
                                                        $_subcat = Mage::getModel('catalog/category')->load($subcat->getId());
                                                        $childrens = $_subcat->getChildrenCategories();
                                                    ?>
                                                        <ul class="<?php if($childrens): ?>theanswer<?php endif; ?><?php if ($this->isCategoryActive($_subcat)): ?> opened<?php endif; ?>">
                                                    <?php   foreach($childrens as $_childrens):
                                                    ?>
                                                        <li>
                                                            <a <?php if ($currentUrl == $this->getCategoryUrl($_childrens)): ?>class="current"<?php endif; ?>href="<?php echo $this->getCategoryUrl($_childrens); ?>">
                                                                <?php echo $_childrens->getName(); ?>
                                                            </a>
                                                        </li>
                                                    <?php
                                                        endforeach;
                                                        echo "</ul>";
                                                    ?>
                                                <?php endif ?>
                                                </li>

                                            <?php endforeach ?>
                                        </ul>

                                    <?php endif ?>
                            </li>
                        <?php endif ?>
                    <?php endforeach ?>
                                </ul>
                            </div>
                            </div>

                            <div class="clear" style="height:218px;"></div>
                        </div>
                    </div>
                    <div class="event-bot"></div>
                </div>

            </div> <!--inner right end here-->
<style type="text/css">
.opened { display:block !important;}
</style>
0 голосов
/ 21 декабря 2011

Выбранный плагин для аккордеона, похоже, не имеет возможности держать раздел открытым, поэтому вам придется перехватить его самостоятельно и остановить.Единственное возможное событие, которое оно предоставляет, это onopenclose, но оно называется после того, как slideUp закончено, что бесполезно.

Вы должны выбрать другой плагин, который удовлетворяетваши потребности.


К счастью, Magento уже поставляется с Prototype и его собственным классом аккордеона, вы можете заменить или wrap это sectionClicked метод и остановить там событие.

Accordion.prototype.sectionClicked = function(event) {
    var element = $(Event.element(event)).up('.section');
    if (!element.hasClassName('current')) {
        this.openSection(element);
    }
    Event.stop(event);
};
...