зарефакторил скрипт в шаблоне левого меню

parent 9553b57b
<?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?> <?if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();?>
<?if (!empty($arResult)):?> <?if (!empty($arResult)):?>
<ul id="side_menu_multilevel"> <ul id="side_menu_multilevel">
<? <?
$previousLevel = 0; $previousLevel = 0;
foreach($arResult as $arItem):?> foreach($arResult as $arItem):?>
<?if ($previousLevel && $arItem["DEPTH_LEVEL"] < $previousLevel):?> <?if ($previousLevel && $arItem["DEPTH_LEVEL"] < $previousLevel):?>
<?=str_repeat("</ul></li>", ($previousLevel - $arItem["DEPTH_LEVEL"]));?> <?=str_repeat("</ul></li>", ($previousLevel - $arItem["DEPTH_LEVEL"]));?>
...@@ -46,39 +46,30 @@ foreach($arResult as $arItem):?> ...@@ -46,39 +46,30 @@ foreach($arResult as $arItem):?>
<?$previousLevel = $arItem["DEPTH_LEVEL"];?> <?$previousLevel = $arItem["DEPTH_LEVEL"];?>
<?endforeach?> <?endforeach?>
<?if ($previousLevel > 1)://close last item tags?> <?if ($previousLevel > 1)://close last item tags?>
<?=str_repeat("</ul></li>", ($previousLevel-1) );?> <?=str_repeat("</ul></li>", ($previousLevel-1) );?>
<?endif?> <?endif?>
</ul> </ul>
<?endif?> <?endif?>
<script> <script>
$(document).ready(function() { $(document).ready(function() {
if ($("#side_menu_multilevel li").is(".item-selected")) {$("#side_menu_multilevel li.root-item-selected").addClass("hide_selection")} const $menu = $("#side_menu_multilevel");
//$("#side_menu_multilevel li.item-selected").parent('#side_menu_multilevel').find("li.root-item-selected").addClass("hide_selection"); if ($("li", $menu).is(".item-selected")) {$("li.root-item-selected", $menu).addClass("hide_selection")}
//console.log("!!!!!!!!!!111234!!!!!!!!!!!!!"+$("#side_menu_multilevel li.item-selected").parent('#side_menu_multilevel'));
const clickHandler = function(){
$('#side_menu_multilevel li.root-item a span.roll-out').click( const $a = $(this).parent('a');
function(){ if($a.next('ul').is('.root-item'))
if($(this).parent('a').next('ul').is('.root-item'))
{
$(this).parent('a').parent().toggleClass("opened");
$(this).parent('a').next("ul.root-item").toggle(150);
return false;
}
}
);
$('#side_menu_multilevel li.root-item-selected a span.roll-out').click(
function(){
if($(this).parent('a').next('ul').is('.root-item'))
{ {
$(this).parent('a').parent().toggleClass("opened"); $a.parent().toggleClass("opened");
$(this).parent('a').next("ul.root-item").toggle(150); $a.next("ul.root-item").toggle(150);
return false; return false;
} }
} };
);
}); $('li.root-item a span.roll-out', $menu).click( clickHandler );
$('li.root-item-selected a span.roll-out', $menu).click( clickHandler );
});
</script> </script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment