1class MultilevelMenu { 2 static BLOCKED_SECTIONS_IDS = [980, 955, 3105]; // ÐевоÑкам: 980, ÐалÑÑикам: 955, Baby line: 3105 3 static BLOCKED_SECTIONS_CODES = ['devochkam', 'malchikam', 'yasli']; 4 static BLOCKED_SECTIONS_NAMES = ['девоÑкам', 'малÑÑикам', 'baby line']; 5 6 constructor(containerId, menuData, commonBlock3Items = [], block4Items = [], collectionsSectionId = 0) { 7 this.containerId = containerId; 8 this.menuData = this.prepareMenuData(menuData, commonBlock3Items); 9 this.commonBlock3Items = []; 10 this.block4Items = block4Items; 11 // ID Ñаздела «ÐоллекÑии» пÑÐ¸Ñ Ð¾Ð´Ð¸Ñ Ð¸Ð· Mf\Constants::COLLECTIONS_PARENT_SECTION (Ñм. template.php). 12 this.collectionsSectionId = parseInt(collectionsSectionId, 10) || 0; 13 this.currentSecondLevelItem = null; 14 this.currentThirdLevelItem = null; 15 this.currentFourthLevelItem = null; 16 17 this.mobileMenuHistory = []; 18 this.isMobile = window.innerWidth <= 1023; 19 20 this.init(); 21 this.initMobileMenu(); 22 this.initFirstLevelHover(); 23 this.initSecondLevelScroll(); 24 25 window.addEventListener('resize', () => { 26 const wasMobile = this.isMobile; 27 this.isMobile = window.innerWidth <= 1023; 28 if (wasMobile !== this.isMobile) { 29 this.initMobileMenu(); 30 } 31 }); 32 } 33 34 prepareMenuData(menuData, commonBlock3Items) { 35 const preparedData = JSON.parse(JSON.stringify(menuData)); 36 37 if (commonBlock3Items && Array.isArray(commonBlock3Items) && commonBlock3Items.length > 0) { 38 preparedData.forEach(firstLevelItem => { 39 if (!firstLevelItem.CHILDREN) { 40 firstLevelItem.CHILDREN = []; 41 } 42 43 commonBlock3Items.forEach(block3Item => { 44 const exists = firstLevelItem.CHILDREN.some(child => child.ID === block3Item.ID); 45 if (!exists) { 46 firstLevelItem.CHILDREN.push({ 47 ID: block3Item.ID, 48 CODE: block3Item.CODE, 49 NAME: block3Item.NAME, 50 LINK: block3Item.LINK, 51 DEPTH_LEVEL: 2, 52 IS_PARENT: block3Item.IS_PARENT, 53 SELECTED: block3Item.SELECTED, 54 PERMISSION: block3Item.PERMISSION, 55 PARAMS: block3Item.PARAMS, 56 CHILDREN: block3Item.CHILDREN || [] 57 }); 58 } 59 }); 60 }); 61 } 62 63 return preparedData; 64 } 65 66 init() { 67 let firstActiveItem = null; 68 69 for (const item of this.menuData) { 70 if (item.SELECTED) { 71 firstActiveItem = item; 72 break; 73 } 74 } 75 76 if (!firstActiveItem && this.menuData.length > 0) { 77 firstActiveItem = this.menuData[0]; 78 } 79 80 if (firstActiveItem && firstActiveItem.ID) { 81 this.loadSecondLevel(firstActiveItem.ID); 82 } 83 } 84 85 initFirstLevelHover() { 86 const firstLevelItems = document.querySelectorAll(`#${this.containerId} .first-level-item`); 87 firstLevelItems.forEach(item => { 88 item.addEventListener('mouseenter', () => { 89 if (this.menuCloseTimeout) { 90 clearTimeout(this.menuCloseTimeout); 91 this.menuCloseTimeout = null; 92 } 93 }); 94 }); 95 } 96 97 initSecondLevelScroll() { 98 const container = document.querySelector(`#${this.containerId}`); 99 if (!container) return; 100 101 const desktopMenuWrapper = container.querySelector('.desktop-menu-wrapper'); 102 if (!desktopMenuWrapper) return; 103 104 desktopMenuWrapper.addEventListener('wheel', (e) => { 105 // ÐÑовеÑÑем, оÑкÑÑÑ Ð»Ð¸ ÑÑеÑий ÑÑÐ¾Ð²ÐµÐ½Ñ 106 const thirdLevelContainer = document.getElementById(`thirdLevelContainer_${this.containerId}`); 107 const isThirdLevelOpen = thirdLevelContainer && thirdLevelContainer.innerHTML.trim() !== ''; 108 109 // ÐÑли ÑÑеÑий ÑÑÐ¾Ð²ÐµÐ½Ñ Ð½Ðµ оÑкÑÑÑ, пÑокÑÑÑиваем вÑоÑой ÑÑÐ¾Ð²ÐµÐ½Ñ 110 if (!isThirdLevelOpen) { 111 const secondLevelColumn = container.querySelector('.second-level-column'); 112 if (secondLevelColumn) { 113 // ÐеÑÐµÑ Ð²Ð°ÑÑваем пÑокÑÑÑÐºÑ Ð¸ пÑименÑем ÐµÑ ÐºÐ¾ вÑоÑÐ¾Ð¼Ñ ÑÑÐ¾Ð²Ð½Ñ 114 e.preventDefault(); 115 const currentScroll = secondLevelColumn.scrollTop; 116 const scrollAmount = e.deltaY; 117 secondLevelColumn.scrollTop = currentScroll + scrollAmount; 118 } 119 } 120 }, { passive: false }); 121 } 122 123 findItemById(id, items = null) { 124 if (items === null) { 125 const foundInMenu = this.findItemByIdInArray(id, this.menuData); 126 if (foundInMenu) { 127 return foundInMenu; 128 } 129 130 if (this.commonBlock3Items && Array.isArray(this.commonBlock3Items)) { 131 return this.findItemByIdInArray(id, this.commonBlock3Items); 132 } 133 134 return null; 135 } 136 137 return this.findItemByIdInArray(id, items); 138 } 139 140 findItemByIdInArray(id, items) { 141 if (!items || !Array.isArray(items)) { 142 return null; 143 } 144 145 for (const item of items) { 146 if (item && item.ID == id) { 147 return item; 148 } 149 if (item && item.CHILDREN && item.CHILDREN.length > 0) { 150 const found = this.findItemByIdInArray(id, item.CHILDREN); 151 if (found) return found; 152 } 153 } 154 155 return null; 156 } 157 158 getParentItem(childId, items = this.menuData, parent = null) { 159 for (const item of items) {
160 if (item.ID == childId) { 161 return parent; 162 } 163 if (item.CHILDREN && item.CHILDREN.length > 0) { 164 const found = this.getParentItem(childId, item.CHILDREN, item); 165 if (found) return found; 166 } 167 } 168 return null; 169 } 170 171 findSelectedItemPath(items = this.menuData, path = []) { 172 let deepestPath = null; 173 let deepestLevel = 0; 174 for (const item of items) { 175 const currentPath = [...path, item]; 176 177 if (item.SELECTED) { 178 const currentLevel = currentPath.length; 179 if (currentLevel > deepestLevel) { 180 deepestPath = currentPath; 181 deepestLevel = currentLevel; 182 } 183 } 184 185 if (item.CHILDREN && item.CHILDREN.length > 0) { 186 const found = this.findSelectedItemPath(item.CHILDREN, currentPath); 187 if (found && found.length > deepestLevel) { 188 deepestPath = found; 189 deepestLevel = found.length; 190 } 191 } 192 } 193 194 return deepestPath; 195 } 196 197 handleSecondLevelClick(itemId, element, link) { 198 const itemDataForSecondLevel = this.findItemById(itemId); 199 if (itemDataForSecondLevel && this.isYuridicheskimLitsamSection(itemDataForSecondLevel)) { 200 return; 201 } 202 203 if (this.isMobile) { 204 const hasChildren = element.dataset.hasChildren === 'true'; 205 const hasViewAll = element.dataset.hasViewAll === 'true'; 206 207 if (hasViewAll) { 208 const itemData = this.findItemById(itemId); 209 if (itemData) { 210 this.loadViewAllLevel(itemData, element, 2); 211 } 212 } else if (hasChildren) { 213 this.loadThirdLevel(itemId, element); 214 } else if (link) { 215 element.classList.add('active'); 216 window.location.href = link; 217 } else { 218 this.clearActiveClass('second-level-item'); 219 element.classList.add('active'); 220 this.currentSecondLevelItem = element; 221 this.clearRightColumns(2); 222 } 223 } else { 224 if (link) { 225 if (this.isTagsSection(link)) { 226 return; 227 } 228 element.classList.add('active'); 229 window.location.href = link; 230 } else { 231 this.clearActiveClass('second-level-item'); 232 element.classList.add('active'); 233 this.currentSecondLevelItem = element; 234 this.clearRightColumns(2); 235 } 236 } 237 } 238 239 handleThirdLevelClick(itemId, element, link, parentId) { 240 const itemDataForThirdLevel = this.findItemById(itemId); 241 if (itemDataForThirdLevel && this.isYuridicheskimLitsamSection(itemDataForThirdLevel)) { 242 return; 243 } 244 245 if (this.isMobile) { 246 const hasChildren = element.dataset.hasChildren === 'true'; 247 if (hasChildren) { 248 this.loadFourthLevel(itemId, element, parentId); 249 } else if (link) { 250 element.classList.add('active'); 251 window.location.href = link; 252 } else { 253 this.clearActiveClass('level-3-item'); 254 element.classList.add('active'); 255 this.currentThirdLevelItem = element; 256 this.clearRightColumns(3); 257 258 const fifthLevelContainer = document.getElementById(`fifthLevelContainer_${this.containerId}`); 259 if (fifthLevelContainer) { 260 fifthLevelContainer.innerHTML = ''; 261 } 262 } 263 } else { 264 if (link) { 265 element.classList.add('active'); 266 window.location.href = link; 267 } else { 268 this.clearActiveClass('level-3-item'); 269 element.classList.add('active'); 270 this.currentThirdLevelItem = element; 271 this.clearRightColumns(3); 272 273 const fifthLevelContainer = document.getElementById(`fifthLevelContainer_${this.containerId}`); 274 if (fifthLevelContainer) { 275 fifthLevelContainer.innerHTML = ''; 276 } 277 } 278 } 279 } 280 281 handleFourthLevelClick(itemId, element, link, parentId) { 282 const itemDataForFourthLevel = this.findItemById(itemId); 283 if (itemDataForFourthLevel && this.isYuridicheskimLitsamSection(itemDataForFourthLevel)) { 284 return; 285 } 286 287 if (this.isMobile) { 288 const hasChildren = element.dataset.hasChildren === 'true'; 289 const hasViewAll = element.dataset.hasViewAll === 'true'; 290 291 if (hasViewAll) { 292 const itemData = this.findItemById(itemId); 293 if (itemData) { 294 this.loadMobileViewAllLevel(itemData, 4); 295 } 296 } else if (hasChildren) { 297 this.loadFifthLevel(itemId, element, parentId); 298 } else if (link) { 299 element.classList.add('active'); 300 window.location.href = link; 301 } else { 302 this.clearActiveClass('level-4-item'); 303 element.classList.add('active'); 304 this.currentFourthLevelItem = element; 305 this.clearRightColumns(5); 306 307 const fifthLevelContainer = document.getElementById(`fifthLevelContainer_${this.containerId}`); 308 if (fifthLevelContainer) { 309 fifthLevelContainer.innerHTML = ''; 310 } 311 } 312 } else { 313 if (link) { 314 element.classList.add('active'); 315 window.location.href = link; 316 } else { 317 this.clearActiveClass('level-4-item'); 318 element.classList.add('active'); 319 this.currentFourthLevelItem = element; 320 this.clearRightColumns(5); 321 322 const fifthLevelContainer = document.getElementById(`fifthLevelContainer_${this.containerId}`); 323 if (fifthLevelContainer) { 324 fifthLevelContainer.innerHTML = ''; 325 } 326 } 327 } 328 } 329 330 loadSecondLevel(parentId, clickedElement = null) { 331 const parent = this.findItemById(parentId); 332 if (!parent) return; 333 334 this.clearActiveClass('first-level-item'); 335 336 if (clickedElement) { 337 clickedElement.classList.add('active'); 338 } else { 339 const element = document.querySelector(`#${this.containerId} .first-level-item[data-id="${parentId}"]`); 340 if (element) { 341 element.classList.add('active'); 342 } 343 } 344 345 const secondLevelMenu = document.getElementById(`secondLevelMenu_${this.containerId}`); 346 secondLevelMenu.innerHTML = ''; 347 348 const container = document.querySelector(`#${this.containerId}`); 349 if (container) { 350 const secondLevelColumn = container.querySelector('.second-level-column'); 351 if (secondLevelColumn) { 352 secondLevelColumn.scrollTop = 0; 353 } 354 } 355 356 if (parent.CHILDREN && parent.CHILDREN.length > 0) { 357 const block1 = []; 358 const block2 = []; 359 const block3 = []; 360 361 parent.CHILDREN.forEach(child => { 362 const menuBlock = child.PARAMS && child.PARAMS.UF_MENU_BLOCK ? parseInt(child.PARAMS.UF_MENU_BLOCK) : 0; 363 if (menuBlock === 1) { 364 block1.push(child); 365 } else if (menuBlock === 3) { 366 block3.push(child); 367 } else { 368 block2.push(child); 369 } 370 }); 371 372 if (this.commonBlock3Items && Array.isArray(this.commonBlock3Items)) {
373 this.commonBlock3Items.forEach(item => { 374 block3.push({ 375 ID: item.ID, 376 CODE: item.CODE, 377 NAME: item.NAME, 378 LINK: item.LINK, 379 DEPTH_LEVEL: 2, 380 IS_PARENT: item.IS_PARENT, 381 SELECTED: item.SELECTED, 382 PERMISSION: item.PERMISSION, 383 PARAMS: item.PARAMS, 384 CHILDREN: item.CHILDREN || [] 385 }); 386 }); 387 } 388 389 const createBlock = (children, blockClass) => { 390 const blockDiv = document.createElement('div'); 391 blockDiv.className = `second-level-block ${blockClass}`; 392 393 children.forEach(child => { 394 const div = document.createElement('div'); 395 div.className = 'second-level-item item-custom-style' + child.ID; 396 div.dataset.id = child.ID; 397 const hasChildren = child.CHILDREN && child.CHILDREN.length > 0; 398 const hasViewAll = !hasChildren && child.LINK; 399 const shouldShowArrow = hasChildren || hasViewAll; 400 div.dataset.hasChildren = shouldShowArrow ? 'true' : 'false'; 401 div.dataset.hasViewAll = hasViewAll ? 'true' : 'false'; 402 div.dataset.link = child.LINK || ''; 403 404 if (child.SELECTED) { 405 div.classList.add('active'); 406 } 407 408 const arrowSvg = shouldShowArrow ? this.createArrowSvg(child.ID, false) : ''; 409 div.innerHTML = ` 410 <span class="item-name">${this.escapeHtml(child.NAME)}</span> 411 ${arrowSvg} 412 `; 413 414 if (!this.isMobile) { 415 if (shouldShowArrow) { 416 div.addEventListener('mouseenter', (e) => { 417 e.stopPropagation(); 418 if (this.menuCloseTimeout) { 419 clearTimeout(this.menuCloseTimeout); 420 this.menuCloseTimeout = null; 421 } 422 const existingTimeout = div.dataset.hoverTimeout; 423 if (existingTimeout) { 424 clearTimeout(parseInt(existingTimeout)); 425 } 426 const timeoutId = setTimeout(() => { 427 if (hasViewAll) { 428 this.loadViewAllLevel(child, div, 2); 429 } else { 430 this.loadThirdLevel(child.ID, div); 431 } 432 div.dataset.hoverTimeout = ''; 433 }, 150); 434 div.dataset.hoverTimeout = timeoutId.toString(); 435 }); 436 437 div.addEventListener('mouseleave', (e) => { 438 e.stopPropagation(); 439 const existingTimeout = div.dataset.hoverTimeout; 440 if (existingTimeout) { 441 clearTimeout(parseInt(existingTimeout)); 442 div.dataset.hoverTimeout = ''; 443 } 444 }); 445 } else { 446 div.addEventListener('mouseenter', (e) => { 447 e.stopPropagation(); 448 if (this.menuCloseTimeout) { 449 clearTimeout(this.menuCloseTimeout); 450 } 451 this.menuCloseTimeout = setTimeout(() => { 452 this.clearRightColumns(2); 453 }, 200); 454 }); 455 } 456 } 457 458 div.onclick = (e) => { 459 e.stopPropagation(); 460 if (!this.isMobile && shouldShowArrow) { 461 const existingTimeout = div.dataset.hoverTimeout; 462 if (existingTimeout) { 463 clearTimeout(parseInt(existingTimeout)); 464 div.dataset.hoverTimeout = ''; 465 } 466 } 467 if (this.isMobile && hasViewAll) {
468 this.loadViewAllLevel(child, div, 2); 469 } else { 470 this.handleSecondLevelClick(child.ID, div, child.LINK || ''); 471 } 472 }; 473 474 blockDiv.appendChild(div); 475 }); 476 477 return blockDiv; 478 }; 479 480 if (block1.length > 0) { 481 secondLevelMenu.appendChild(createBlock(block1, 'block-1')); 482 } 483 if (block2.length > 0) { 484 secondLevelMenu.appendChild(createBlock(block2, 'block-2')); 485 } 486 if (block3.length > 0) { 487 secondLevelMenu.appendChild(createBlock(block3, 'block-3')); 488 } 489 } else { 490 secondLevelMenu.innerHTML = ''; 491 } 492 493 this.clearRightColumns(1); 494 this.currentSecondLevelItem = null; 495 this.currentThirdLevelItem = null; 496 this.currentFourthLevelItem = null; 497 498 const activeSecondLevel = secondLevelMenu.querySelector('.second-level-item.active'); 499 if (activeSecondLevel && activeSecondLevel.dataset.hasChildren === 'true') { 500 const hasViewAll = activeSecondLevel.dataset.hasViewAll === 'true'; 501 if (hasViewAll) { 502 const itemData = this.findItemById(parseInt(activeSecondLevel.dataset.id)); 503 if (itemData) { 504 this.loadViewAllLevel(itemData, activeSecondLevel, 2); 505 } 506 } else { 507 this.loadThirdLevel(activeSecondLevel.dataset.id, activeSecondLevel); 508 } 509 } 510 } 511 512 loadViewAllLevel(itemData, element, level) { 513 if (!itemData || !itemData.LINK || this.isCollectionsSection(itemData)) { 514 return; 515 } 516 517 let container; 518 if (level === 2) { 519 container = document.getElementById(`thirdLevelContainer_${this.containerId}`); 520 } else if (level === 3) { 521 container = document.getElementById(`fourthLevelContainer_${this.containerId}`); 522 } else if (level === 4) { 523 container = document.getElementById(`fifthLevelContainer_${this.containerId}`); 524 } else { 525 return; 526 } 527 528 if (!container) { 529 return; 530 } 531 532 container.innerHTML = ''; 533 534 const levelDiv = document.createElement('div'); 535 levelDiv.className = `nested-level level-${level + 1}`; 536 levelDiv.dataset.parent = itemData.ID; 537 538 const viewAllLink = document.createElement('a'); 539 viewAllLink.className = 'nested-item view-all-link'; 540 viewAllLink.href = itemData.LINK; 541 viewAllLink.textContent = 'СмоÑÑеÑÑ Ð²Ñе'; 542 viewAllLink.onclick = (e) => { 543 e.stopPropagation(); 544 viewAllLink.classList.add('active'); 545 return true; 546 }; 547 548 levelDiv.appendChild(viewAllLink); 549 container.appendChild(levelDiv); 550 551 if (level === 2) { 552 this.clearRightColumns(3); 553 } else if (level === 3) { 554 this.clearRightColumns(4); 555 } else if (level === 4) { 556 this.clearRightColumns(5); 557 } 558 559 if (level === 2) { 560 this.clearActiveClass('second-level-item'); 561 element.classList.add('active'); 562 this.currentSecondLevelItem = element; 563 } else if (level === 3) { 564 this.clearActiveClass('level-3-item'); 565 element.classList.add('active'); 566 this.currentThirdLevelItem = element; 567 } else if (level === 4) { 568 this.clearActiveClass('level-4-item'); 569 element.classList.add('active'); 570 this.currentFourthLevelItem = element; 571 } 572 } 573 574 loadThirdLevel(parentId, element) { 575 if (this.currentSecondLevelItem && this.currentSecondLevelItem !== element) { 576 this.currentSecondLevelItem.classList.remove('active'); 577 } 578 579 this.clearActiveClass('second-level-item'); 580 element.classList.add('active'); 581 this.currentSecondLevelItem = element; 582 583 const data = this.findItemById(parentId); 584 585 if (!data) { 586 if (element.dataset.link) { 587 const link = element.dataset.link; 588 const itemData = this.findItemById(parentId); 589 if (!(itemData && this.isYuridicheskimLitsamSection(itemData))) { 590 element.classList.add('active'); 591 window.location.href = link; 592 } 593 } 594 this.clearRightColumns(2); 595 return; 596 } 597 598 if (!data.CHILDREN || data.CHILDREN.length === 0) { 599 if (data.LINK && !this.isYuridicheskimLitsamSection(data)) { 600 element.classList.add('active'); 601 window.location.href = data.LINK; 602 return; 603 } 604 605 this.clearRightColumns(2); 606 return; 607 } 608 609 const container = document.getElementById(`thirdLevelContainer_${this.containerId}`); 610 if (!container) { 611 return; 612 } 613 container.innerHTML = ''; 614 615 const levelDiv = document.createElement('div'); 616 levelDiv.className = 'nested-level level-3'; 617 levelDiv.dataset.parent = parentId; 618 619 const isBlockedSection = this.isBlockedSection(data); 620 const isCert = this.isCertSection(data, parentId); 621 const isTags = this.isTagsSection(data.LINK, data); 622 623 if (!isBlockedSection && !isCert && !isTags && data.LINK) { 624 levelDiv.innerHTML = this.createViewAllLink(data.LINK, data); 625 } 626 627 if (isBlockedSection) { 628 const block1 = []; 629 const block2 = []; 630 const block3 = []; 631 632 data.CHILDREN.forEach(item => { 633 const menuBlock = item.PARAMS && item.PARAMS.UF_MENU_BLOCK ? parseInt(item.PARAMS.UF_MENU_BLOCK) : 0; 634 if (menuBlock === 1) { 635 block1.push(item); 636 } else if (menuBlock === 3) { 637 block3.push(item); 638 } else { 639 block2.push(item); 640 } 641 }); 642 643 const createThirdLevelBlock = (children, blockClass) => { 644 const blockDiv = document.createElement('div'); 645 blockDiv.className = `third-level-block ${blockClass}`; 646
647 children.forEach(item => { 648 const itemElement = this.createMenuItemElement(item, 3, parentId, this.handleThirdLevelClick.bind(this)); 649 blockDiv.appendChild(itemElement); 650 }); 651 652 return blockDiv; 653 }; 654 655 if (block1.length > 0) { 656 levelDiv.appendChild(createThirdLevelBlock(block1, 'block-1')); 657 } 658 if (block2.length > 0) { 659 levelDiv.appendChild(createThirdLevelBlock(block2, 'block-2')); 660 } 661 if (block3.length > 0) { 662 levelDiv.appendChild(createThirdLevelBlock(block3, 'block-3')); 663 } 664 } else { 665 data.CHILDREN.forEach(item => { 666 const itemElement = this.createMenuItemElement(item, 3, parentId, this.handleThirdLevelClick.bind(this)); 667 levelDiv.appendChild(itemElement); 668 }); 669 } 670 671 container.appendChild(levelDiv); 672 673 this.clearRightColumns(3); 674 675 const fifthLevelContainer = document.getElementById(`fifthLevelContainer_${this.containerId}`); 676 if (fifthLevelContainer) { 677 fifthLevelContainer.innerHTML = ''; 678 } 679 680 if (!this.menuCloseTimeout) { 681 this.menuCloseTimeout = null; 682 } 683 684 const cancelMenuClose = () => { 685 if (this.menuCloseTimeout) { 686 clearTimeout(this.menuCloseTimeout); 687 this.menuCloseTimeout = null; 688 } 689 }; 690 691 const scheduleMenuClose = (e) => { 692 cancelMenuClose(); 693 const relatedTarget = e ? e.relatedTarget : null; 694 695 const isOnMenuLevel = relatedTarget && ( 696 relatedTarget.closest(`#${this.containerId} .menu-columns-wrapper`) || 697 relatedTarget.closest(`#${this.containerId} .second-level-item`) || 698 relatedTarget.closest(`#${this.containerId} .third-level-column`) || 699 relatedTarget.closest(`#${this.containerId} .fourth-level-column`) || 700 relatedTarget.closest(`#${this.containerId} .fifth-level-column`) || 701 relatedTarget.closest(`#${this.containerId} .nested-level`) || 702 relatedTarget.closest(`#${this.containerId} .level-3-item`) || 703 relatedTarget.closest(`#${this.containerId} .level-4-item`) || 704 relatedTarget.closest(`#${this.containerId} .level-5-item`) 705 ); 706 707 if (!isOnMenuLevel) { 708 this.menuCloseTimeout = setTimeout(() => { 709 this.clearRightColumns(2); 710 }, 100); 711 } 712 }; 713 714 if (container) { 715 container.addEventListener('mouseenter', cancelMenuClose); 716 container.addEventListener('mouseleave', scheduleMenuClose); 717 } 718 719 const secondLevelColumn = document.querySelector(`#${this.containerId} .second-level-column`); 720 if (secondLevelColumn) { 721 secondLevelColumn.addEventListener('mouseenter', cancelMenuClose); 722 secondLevelColumn.addEventListener('mouseleave', scheduleMenuClose); 723 } 724 725 const thirdLevelColumn = document.querySelector(`#${this.containerId} .third-level-column`); 726 if (thirdLevelColumn) { 727 thirdLevelColumn.addEventListener('mouseenter', cancelMenuClose); 728 thirdLevelColumn.addEventListener('mouseleave', scheduleMenuClose); 729 } 730 731 const fourthLevelColumn = document.querySelector(`#${this.containerId} .fourth-level-column`); 732 if (fourthLevelColumn) { 733 fourthLevelColumn.addEventListener('mouseenter', cancelMenuClose); 734 fourthLevelColumn.addEventListener('mouseleave', scheduleMenuClose); 735 } 736 737 const fifthLevelColumn = document.querySelector(`#${this.containerId} .fifth-level-column`); 738 if (fifthLevelColumn) { 739 fifthLevelColumn.addEventListener('mouseenter', cancelMenuClose); 740 fifthLevelColumn.addEventListener('mouseleave', scheduleMenuClose); 741 } 742 743 const activeThirdLevel = levelDiv.querySelector('.level-3-item.active'); 744 if (activeThirdLevel && activeThirdLevel.dataset.hasChildren === 'true') { 745 const hasViewAll = activeThirdLevel.dataset.hasViewAll === 'true'; 746 if (hasViewAll) { 747 const itemData = this.findItemById(parseInt(activeThirdLevel.dataset.id)); 748 if (itemData) { 749 this.loadViewAllLevel(itemData, activeThirdLevel, 3); 750 } 751 } else { 752 this.loadFourthLevel(activeThirdLevel.dataset.id, activeThirdLevel, parentId); 753 } 754 } 755 } 756 757 loadFourthLevel(itemId, element, parentId) { 758 if (this.currentThirdLevelItem && this.currentThirdLevelItem !== element) { 759 this.currentThirdLevelItem.classList.remove('active'); 760 } 761 762 this.clearActiveClass('level-3-item'); 763 element.classList.add('active'); 764 this.currentThirdLevelItem = element; 765 766 const data = this.findItemById(itemId); 767 768 if (!data) { 769 if (element.dataset.link) { 770 const link = element.dataset.link; 771 const itemData = this.findItemById(itemId); 772 if (!(itemData && this.isYuridicheskimLitsamSection(itemData))) { 773 element.classList.add('active'); 774 window.location.href = link; 775 } 776 } 777 return; 778 } 779 780 if (!data.CHILDREN || data.CHILDREN.length === 0) { 781 if (data.LINK && !this.isYuridicheskimLitsamSection(data)) { 782 element.classList.add('active'); 783 window.location.href = data.LINK; 784 } 785 786 this.clearRightColumns(4); 787 return; 788 } 789 790 const container = document.getElementById(`fourthLevelContainer_${this.containerId}`); 791 if (!container) { 792 return; 793 } 794 container.innerHTML = ''; 795 796 const parentElement = document.querySelector(`#${this.containerId} [data-id='${parentId}']`); 797 const itemNameElement = parentElement ? parentElement.querySelector('.item-name') : null; 798 const parentName = itemNameElement ? itemNameElement.textContent : ''; 799 800 let breadcrumbsHtml = ''; 801 if (parentName) { 802 breadcrumbsHtml = `
803 <div class="breadcrumbs"> 804 <span class="breadcrumb-item" onclick="window.multilevelMenu_${this.containerId}.loadThirdLevel(${parentId}, document.querySelector('#${this.containerId} [data-id=\\'${parentId}\\']'))"> 805 ${this.escapeHtml(parentName)} 806 </span> 807 <span class="breadcrumb-separator">âº</span> 808 <span class="breadcrumb-item current">${this.escapeHtml(data.NAME)}</span> 809 </div> 810 `; 811 } 812 813 const levelDiv = document.createElement('div'); 814 levelDiv.className = 'nested-level level-4'; 815 levelDiv.dataset.parent = itemId; 816 const isCert = this.isCertSection(data, parentId); 817 const isTags = this.isTagsSection(data.LINK, data); 818 if (!isCert && !isTags) { 819 levelDiv.innerHTML = `${this.createViewAllLink(data.LINK, data)}`; 820 } 821 822 data.CHILDREN.forEach(item => { 823 const itemElement = this.createMenuItemElement(item, 4, itemId, this.handleFourthLevelClick.bind(this)); 824 levelDiv.appendChild(itemElement); 825 }); 826 827 container.appendChild(levelDiv); 828 829 const fourthLevelColumn = container.closest('.fourth-level-column'); 830 if (fourthLevelColumn) { 831 setTimeout(() => { 832 fourthLevelColumn.scrollIntoView({behavior: 'smooth', block: 'nearest', inline: 'nearest'}); 833 }, 100); 834 } 835 836 this.clearRightColumns(5); 837 838 const fifthLevelContainer = document.getElementById(`fifthLevelContainer_${this.containerId}`); 839 if (fifthLevelContainer) { 840 fifthLevelContainer.innerHTML = ''; 841 } 842 843 const activeFourthLevel = levelDiv.querySelector('.level-4-item.active'); 844 if (activeFourthLevel && activeFourthLevel.dataset.hasChildren === 'true') { 845 const hasViewAll = activeFourthLevel.dataset.hasViewAll === 'true'; 846 if (hasViewAll) { 847 const itemData = this.findItemById(parseInt(activeFourthLevel.dataset.id)); 848 if (itemData) { 849 this.loadViewAllLevel(itemData, activeFourthLevel, 4); 850 } 851 } else { 852 this.loadFifthLevel(activeFourthLevel.dataset.id, activeFourthLevel, itemId); 853 } 854 } 855 } 856 857 loadFifthLevel(itemId, element, parentId) { 858 if (this.currentFourthLevelItem && this.currentFourthLevelItem !== element) { 859 this.currentFourthLevelItem.classList.remove('active'); 860 } 861 862 this.clearActiveClass('level-4-item'); 863 element.classList.add('active'); 864 this.currentFourthLevelItem = element; 865 866 const data = this.findItemById(itemId); 867 868 if (!data) { 869 if (element.dataset.link) { 870 const link = element.dataset.link; 871 const itemData = this.findItemById(itemId); 872 if (!(itemData && this.isYuridicheskimLitsamSection(itemData))) { 873 element.classList.add('active'); 874 window.location.href = link; 875 } 876 } 877 return; 878 } 879 880 if (!data.CHILDREN || data.CHILDREN.length === 0) { 881 if (data.LINK && !this.isYuridicheskimLitsamSection(data)) { 882 element.classList.add('active'); 883 window.location.href = data.LINK; 884 } 885 886 document.getElementById(`fifthLevelContainer_${this.containerId}`).innerHTML = ''; 887 return; 888 } 889 890 const container = document.getElementById(`fifthLevelContainer_${this.containerId}`); 891 if (!container) { 892 return; 893 } 894 container.innerHTML = ''; 895 896 const parentElement = document.querySelector(`#${this.containerId} [data-id='${parentId}']`); 897 const itemNameElement = parentElement ? parentElement.querySelector('.item-name') : null; 898 const parentName = itemNameElement ? itemNameElement.textContent : ''; 899 const parentData = this.getParentItem(parentId); 900 const grandParentId = parentData ? parentData.ID : 'null';
901 902 let breadcrumbsHtml = ''; 903 if (parentName) { 904 breadcrumbsHtml = ` 905 <div class="breadcrumbs"> 906 <span class="breadcrumb-item" onclick="window.multilevelMenu_${this.containerId}.loadFourthLevel(${parentId}, document.querySelector('#${this.containerId} [data-id=\\'${parentId}\\']'), ${grandParentId})"> 907 ${this.escapeHtml(parentName)} 908 </span> 909 <span class="breadcrumb-separator">âº</span> 910 <span class="breadcrumb-item current">${this.escapeHtml(data.NAME)}</span> 911 </div> 912 `; 913 } 914 915 const levelDiv = document.createElement('div'); 916 levelDiv.className = 'nested-level level-5'; 917 levelDiv.dataset.parent = itemId; 918 const isTags = this.isTagsSection(data.LINK, data); 919 if (!isTags) { 920 levelDiv.innerHTML = `${this.createViewAllLink(data.LINK, data)}`; 921 } 922 923 data.CHILDREN.forEach(item => { 924 const itemElement = this.createMenuItemElement(item, 5, itemId, (itemId, element, link) => { 925 element.classList.add('active'); 926 if (link) { 927 window.location.href = link; 928 } 929 }); 930 levelDiv.appendChild(itemElement); 931 }); 932 933 container.appendChild(levelDiv); 934 935 const fifthLevelColumn = container.closest('.fifth-level-column'); 936 if (fifthLevelColumn) { 937 setTimeout(() => { 938 fifthLevelColumn.scrollIntoView({behavior: 'smooth', block: 'nearest', inline: 'nearest'}); 939 }, 100); 940 } 941 } 942 943 clearRightColumns(fromLevel) { 944 if (fromLevel <= 2) { 945 document.getElementById(`thirdLevelContainer_${this.containerId}`).innerHTML = ''; 946 document.getElementById(`fourthLevelContainer_${this.containerId}`).innerHTML = ''; 947 document.getElementById(`fifthLevelContainer_${this.containerId}`).innerHTML = ''; 948 if (this.currentSecondLevelItem) { 949 setTimeout(() => { 950 if (this.currentSecondLevelItem && typeof this.currentSecondLevelItem.scrollIntoView === 'function') { 951 this.currentSecondLevelItem.scrollIntoView({ 952 behavior: 'smooth', 953 block: 'nearest', 954 inline: 'nearest' 955 }); 956 } 957 }, 50); 958 } 959 } else if (fromLevel <= 3) { 960 document.getElementById(`fourthLevelContainer_${this.containerId}`).innerHTML = ''; 961 document.getElementById(`fifthLevelContainer_${this.containerId}`).innerHTML = ''; 962 } else if (fromLevel <= 4) { 963 document.getElementById(`fifthLevelContainer_${this.containerId}`).innerHTML = ''; 964 } 965 } 966 967 clearActiveClass(className) { 968 document.querySelectorAll(`#${this.containerId} .${className}.active`).forEach(item => { 969 item.classList.remove('active'); 970 }); 971 } 972 973 createViewAllLink(link, data = null) { 974 if (!link) { 975 return ''; 976 } 977 if (data && this.isCertSection(data)) { 978 return ''; 979 } 980 if (this.isTagsSection(link, data)) { 981 return ''; 982 } 983 if (this.isCollectionsSection(data)) { 984 return ''; 985 } 986 return `<a class="nested-item view-all-link" href="${this.escapeHtml(link)}">СмоÑÑеÑÑ Ð²Ñе</a>`; 987 } 988 989 decodeHtmlEntities(text) { 990 if (!text) return ''; 991 const temp = document.createElement('div'); 992 temp.innerHTML = text; 993 return temp.textContent || temp.innerText || text; 994 } 995 996 escapeHtml(text) { 997 if (!text) return ''; 998 const decoded = this.decodeHtmlEntities(text); 999 const map = { 1000 '<': '<', 1001 '>': '>', 1002 '"': '"', 1003 "'": ''' 1004 }; 1005 return decoded.replace(/[<>"']/g, function (m) { 1006 return map[m]; 1007 }); 1008 } 1009 1010 createArrowSvg(itemId, isMobile = false) { 1011 const prefix = isMobile ? 'mobile-menu-item-arrow' : 'desktop-menu-item-arrow'; 1012 return `<span class="${prefix} ${prefix}-custom${itemId}"> 1013 <svg width="20" height="20" viewBox="8 6 4 8" fill="none" xmlns="http://www.w3.org/2000/svg"> 1014 <path d="M8 6L12 10L8 14" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round"></path> 1015 </svg> 1016 </span>`;
1017 } 1018 1019 createMenuItemElement(item, level, parentId, clickHandler, isMobile = false) { 1020 const hasChildren = item.CHILDREN && item.CHILDREN.length > 0; 1021 const hasViewAll = !hasChildren && item.LINK && level < 5; 1022 const shouldShowArrow = hasChildren || hasViewAll; 1023 const itemElement = document.createElement('div'); 1024 itemElement.className = isMobile 1025 ? `mobile-menu-item item-custom-style${item.ID}` 1026 : `nested-item level-${level}-item item-custom-style${item.ID}`; 1027 itemElement.dataset.id = item.ID; 1028 itemElement.dataset.hasChildren = shouldShowArrow ? 'true' : 'false'; 1029 itemElement.dataset.hasViewAll = hasViewAll ? 'true' : 'false'; 1030 itemElement.dataset.link = item.LINK || ''; 1031 1032 if (item.SELECTED) { 1033 itemElement.classList.add('active'); 1034 } 1035 1036 if (shouldShowArrow) { 1037 itemElement.classList.add('has-children'); 1038 } 1039 1040 const arrowSvg = shouldShowArrow ? this.createArrowSvg(item.ID, isMobile) : ''; 1041 const nameClass = isMobile ? 'mobile-menu-item-name' : 'item-name'; 1042 itemElement.innerHTML = `<span class="${nameClass} item-custom-style${item.ID}">${this.escapeHtml(item.NAME)}</span>${arrowSvg}`; 1043 1044 if (!isMobile && shouldShowArrow) { 1045 itemElement.addEventListener('mouseenter', (e) => { 1046 e.stopPropagation(); 1047 if (this.menuCloseTimeout) { 1048 clearTimeout(this.menuCloseTimeout); 1049 this.menuCloseTimeout = null; 1050 } 1051 const existingTimeout = itemElement.dataset.hoverTimeout; 1052 if (existingTimeout) { 1053 clearTimeout(parseInt(existingTimeout)); 1054 } 1055 const timeoutId = setTimeout(() => { 1056 if (hasViewAll) { 1057 this.loadViewAllLevel(item, itemElement, level); 1058 } else { 1059 if (level === 3) { 1060 this.loadFourthLevel(item.ID, itemElement, parentId); 1061 } else if (level === 4) { 1062 this.loadFifthLevel(item.ID, itemElement, parentId); 1063 } 1064 } 1065 itemElement.dataset.hoverTimeout = ''; 1066 }, 150); 1067 itemElement.dataset.hoverTimeout = timeoutId.toString(); 1068 }); 1069 1070 itemElement.addEventListener('mouseleave', (e) => { 1071 e.stopPropagation(); 1072 const existingTimeout = itemElement.dataset.hoverTimeout; 1073 if (existingTimeout) { 1074 clearTimeout(parseInt(existingTimeout)); 1075 itemElement.dataset.hoverTimeout = ''; 1076 } 1077 }); 1078 } else if (!isMobile && !shouldShowArrow) { 1079 itemElement.addEventListener('mouseenter', (e) => { 1080 e.stopPropagation(); 1081 if (this.menuCloseTimeout) { 1082 clearTimeout(this.menuCloseTimeout); 1083 } 1084 this.menuCloseTimeout = setTimeout(() => { 1085 if (level === 3) { 1086 this.clearRightColumns(4); 1087 } else if (level === 4) { 1088 this.clearRightColumns(5); 1089 } 1090 }, 200); 1091 }); 1092 } 1093 1094 itemElement.onclick = (e) => { 1095 e.stopPropagation(); 1096 if (!isMobile && shouldShowArrow) { 1097 const existingTimeout = itemElement.dataset.hoverTimeout; 1098 if (existingTimeout) { 1099 clearTimeout(parseInt(existingTimeout)); 1100 itemElement.dataset.hoverTimeout = ''; 1101 } 1102 } 1103 1104 if (isMobile && hasViewAll) { 1105 this.loadMobileViewAllLevel(item, level); 1106 } else { 1107 clickHandler(item.ID, itemElement, item.LINK || '', parentId); 1108 } 1109 }; 1110 1111 return itemElement; 1112 } 1113 1114 isBlockedSection(data) { 1115 if (!data) return false;
1116 1117 const sectionCode = data.CODE ? data.CODE.toLowerCase().trim() : ''; 1118 const sectionName = data.NAME ? data.NAME.toLowerCase().trim() : ''; 1119 const sectionId = data.ID; 1120 1121 return (MultilevelMenu.BLOCKED_SECTIONS_IDS.length > 0 && MultilevelMenu.BLOCKED_SECTIONS_IDS.includes(sectionId)) 1122 || MultilevelMenu.BLOCKED_SECTIONS_CODES.includes(sectionCode) 1123 || MultilevelMenu.BLOCKED_SECTIONS_NAMES.includes(sectionName); 1124 } 1125 1126 isCertSection(data, parentId = null) { 1127 if (!data) return false; 1128 1129 const sectionCode = data.CODE ? data.CODE.toLowerCase().trim() : ''; 1130 const certCodes = [ 1131 'elektronnyy-sertifikat-physics', 1132 'elektronnyy-sertifikat-jure', 1133 'fizicheskim-litsam', 1134 'yuridicheskim-litsam' 1135 ]; 1136 if (certCodes.includes(sectionCode)) { 1137 return true; 1138 } 1139 1140 const link = data.LINK ? data.LINK.toLowerCase() : ''; 1141 if (link.includes('/catalog/certifikaty/') || link.includes('/electronic-gift-card/')) { 1142 return true; 1143 } 1144 1145 if (parentId) { 1146 const parent = this.findItemById(parentId); 1147 if (parent && this.isCertSection(parent)) { 1148 return true; 1149 } 1150 } 1151 1152 return false; 1153 } 1154 1155 isYuridicheskimLitsamSection(data) { 1156 if (!data) return false; 1157 1158 const sectionCode = data.CODE ? data.CODE.toLowerCase().trim() : ''; 1159 return sectionCode === 'yuridicheskim-litsam'; 1160 } 1161 1162 /** 1163 * «ÐоллекÑии» â Ñаздел-конÑейнеÑ: обÑей ÑÑÑаниÑÑ ÑоваÑов Ñ Ð½ÐµÐ³Ð¾ Ð½ÐµÑ 1164 * (/catalog/collections/ ÑедиÑекÑÐ¸Ñ Ð½Ð° главнÑÑ), поÑÑÐ¾Ð¼Ñ Â«Ð¡Ð¼Ð¾ÑÑеÑÑ Ð²Ñе» по Ð½ÐµÐ¼Ñ Ð½Ðµ вÑводим. 1165 * РеалÑнÑй ID Ñаздела Ð»ÐµÐ¶Ð¸Ñ Ð² PARAMS.ID: поле ID Ñ Ð¿ÑнкÑа Ð¼ÐµÐ½Ñ â его индекÑ, а не ID Ñаздела. 1166 */ 1167 isCollectionsSection(data) { 1168 if (!data || !this.collectionsSectionId) { 1169 return false; 1170 } 1171 1172 const sectionId = data.PARAMS && data.PARAMS.ID ? parseInt(data.PARAMS.ID, 10) : 0; 1173 1174 return sectionId === this.collectionsSectionId; 1175 } 1176 1177 isTagsSection(link, data = null) { 1178 if (!link) return false; 1179 1180 const linkLower = link.toLowerCase(); 1181 if (linkLower.includes('/tags/')) { 1182 return true; 1183 } 1184 1185 if (data && data.LINK) { 1186 const dataLinkLower = data.LINK.toLowerCase(); 1187 if (dataLinkLower.includes('/tags/')) { 1188 return true; 1189 } 1190 } 1191 1192 return false; 1193 } 1194 updateMenuBottomBlock() { 1195 const menuBottomBlock = document.querySelector(`#${this.containerId} .menu-bottom-block`); 1196 if (!menuBottomBlock) return; 1197 1198 const block4 = []; 1199 if (this.menuData && Array.isArray(this.menuData)) { 1200 this.menuData.forEach(item => { 1201 const menuBlock = item.PARAMS && item.PARAMS.UF_MENU_BLOCK ? parseInt(item.PARAMS.UF_MENU_BLOCK) : 0; 1202 if (menuBlock === 4) { 1203 block4.push(item); 1204 } 1205 }); 1206 } 1207 1208 const defaultMenuItems = [ 1209 {NAME: 'ÐкÑии', LINK: '/internet-magazin/promo/'}, 1210 {NAME: 'ÐоÑÑавка', LINK: '/internet-magazin/delivery/'}, 1211 {NAME: 'ÐозвÑÐ°Ñ Ð¸ обмен', LINK: '/internet-magazin/return/'} 1212 ]; 1213 1214 const currentUrl = window.location.pathname || ''; 1215 1216 menuBottomBlock.innerHTML = ''; 1217 1218 const isItemActive = (item) => { 1219 if (item.SELECTED) return true; 1220 if (item.LINK && currentUrl && currentUrl.indexOf(item.LINK) !== -1) return true; 1221 return false; 1222 }; 1223 1224 block4.forEach(item => { 1225 const isActive = isItemActive(item); 1226 const linkElement = document.createElement('a'); 1227 linkElement.href = item.LINK || '#'; 1228 linkElement.className = `menu-bottom-item ${isActive ? 'active' : ''}`; 1229 linkElement.textContent = item.NAME || ''; 1230 menuBottomBlock.appendChild(linkElement); 1231 }); 1232
1233 defaultMenuItems.forEach(item => { 1234 const isActive = currentUrl && currentUrl.indexOf(item.LINK) !== -1; 1235 const linkElement = document.createElement('a'); 1236 linkElement.href = item.LINK; 1237 linkElement.className = `menu-bottom-item ${isActive ? 'active' : ''}`; 1238 linkElement.textContent = item.NAME; 1239 menuBottomBlock.appendChild(linkElement); 1240 }); 1241 } 1242 1243 updateMobileMenuBottomBlock() { 1244 const menuBottomBlock = document.querySelector(`#${this.containerId} .mobile-menu-bottom-block`); 1245 if (!menuBottomBlock) return; 1246 1247 const block4 = this.block4Items || []; 1248 1249 const defaultMenuItems = [ 1250 {NAME: 'ÐкÑии', LINK: '/internet-magazin/promo/'}, 1251 {NAME: 'ÐоÑÑавка', LINK: '/internet-magazin/delivery/'}, 1252 {NAME: 'ÐозвÑÐ°Ñ Ð¸ обмен', LINK: '/internet-magazin/return/'} 1253 ]; 1254 1255 const currentUrl = window.location.pathname || ''; 1256 1257 menuBottomBlock.innerHTML = ''; 1258 1259 const isItemActive = (item) => { 1260 if (item.SELECTED) return true; 1261 if (item.LINK && currentUrl && currentUrl.indexOf(item.LINK) !== -1) return true; 1262 return false; 1263 }; 1264 1265 block4.forEach(item => { 1266 const itemLink = item.LINK || ''; 1267 if (!itemLink) return; 1268 1269 const isActive = isItemActive(item); 1270 const linkElement = document.createElement('a'); 1271 linkElement.href = itemLink; 1272 linkElement.className = `menu-bottom-item ${isActive ? 'active' : ''}`; 1273 linkElement.textContent = item.NAME || ''; 1274 menuBottomBlock.appendChild(linkElement); 1275 }); 1276 1277 defaultMenuItems.forEach(item => { 1278 const isActive = currentUrl && currentUrl.indexOf(item.LINK) !== -1; 1279 const linkElement = document.createElement('a'); 1280 linkElement.href = item.LINK; 1281 linkElement.className = `menu-bottom-item ${isActive ? 'active' : ''}`; 1282 linkElement.textContent = item.NAME; 1283 menuBottomBlock.appendChild(linkElement); 1284 }); 1285 } 1286 1287 initMobileMenu() { 1288 if (!this.isMobile) { 1289 return; 1290 } 1291 1292 const breadcrumb = document.getElementById(`mobileBreadcrumb_${this.containerId}`); 1293 if (breadcrumb) { 1294 breadcrumb.onclick = () => { 1295 this.mobileGoBack(); 1296 }; 1297 } 1298 1299 const firstLevel = document.getElementById(`mobileFirstLevel_${this.containerId}`); 1300 if (firstLevel) { 1301 const firstLevelItems = firstLevel.querySelectorAll('.mobile-first-level-item'); 1302 firstLevelItems.forEach(item => { 1303 const itemId = parseInt(item.dataset.id); 1304 item.onclick = (e) => { 1305 e.stopPropagation(); 1306 const itemData = this.findItemById(itemId); 1307 if (itemData) { 1308 firstLevelItems.forEach(i => i.classList.remove('active')); 1309 item.classList.add('active'); 1310 this.mobileMenuHistory = []; 1311 this.mobileMenuHistory.push({ 1312 id: itemId, 1313 name: itemData.NAME, 1314 level: 1 1315 }); 1316 this.loadMobileSecondLevel(itemId, itemData.NAME); 1317 } 1318 }; 1319 }); 1320 } 1321 1322 const menuLevel = document.getElementById(`mobileMenuLevel_${this.containerId}`); 1323 if (menuLevel) { 1324 const menuItems = menuLevel.querySelectorAll('.mobile-menu-item'); 1325 menuItems.forEach(item => { 1326 const itemId = item.dataset.id; 1327 const hasChildren = item.dataset.hasChildren === 'true'; 1328 const link = item.dataset.link; 1329 1330 item.onclick = (e) => { 1331 e.stopPropagation(); 1332 if (hasChildren) { 1333 const itemData = this.findItemById(parseInt(itemId)); 1334 if (itemData) { 1335 this.loadMobileLevel(itemData.ID, itemData.NAME, 2); 1336 } 1337 } else if (link) { 1338 item.classList.add('active'); 1339 window.location.href = link; 1340 } 1341 }; 1342 }); 1343 } 1344 1345 const selectedPath = this.findSelectedItemPath(); 1346 1347 if (selectedPath && selectedPath.length > 0) { 1348 if (menuLevel) { 1349 menuLevel.innerHTML = ''; 1350 } 1351 1352 const activeLevel = selectedPath.length; 1353 const activeItem = selectedPath[selectedPath.length - 1]; 1354 1355 this.mobileMenuHistory = []; 1356 1357 if (firstLevel) { 1358 const firstLevelItem = firstLevel.querySelector(`[data-id="${selectedPath[0].ID}"]`); 1359 if (firstLevelItem) { 1360 firstLevel.querySelectorAll('.mobile-first-level-item').forEach(i => i.classList.remove('active')); 1361 firstLevelItem.classList.add('active'); 1362 } 1363 } 1364 1365 if (activeLevel === 1) { 1366 this.mobileMenuHistory.push({ 1367 id: activeItem.ID, 1368 name: activeItem.NAME, 1369 level: 1 1370 }); 1371 this.loadMobileSecondLevel(activeItem.ID, activeItem.NAME, false); 1372 } else if (activeLevel === 2) { 1373 const parent = selectedPath[0]; 1374 this.mobileMenuHistory.push({ 1375 id: parent.ID, 1376 name: parent.NAME, 1377 level: 1 1378 }); 1379 this.loadMobileSecondLevel(parent.ID, parent.NAME, false); 1380 } else { 1381 const parent = selectedPath[selectedPath.length - 2]; 1382 1383 for (let i = 0; i < selectedPath.length - 1; i++) { 1384 this.mobileMenuHistory.push({ 1385 id: selectedPath[i].ID, 1386 name: selectedPath[i].NAME, 1387 level: i + 1 1388 }); 1389 } 1390 1391 this.loadMobileLevel(parent.ID, parent.NAME, activeLevel); 1392 } 1393 } else { 1394 if (menuLevel) { 1395 menuLevel.innerHTML = ''; 1396 } 1397 1398 let firstActiveItem = null; 1399 for (const item of this.menuData) { 1400 if (item.SELECTED) { 1401 firstActiveItem = item; 1402 break; 1403 } 1404 } 1405 if (!firstActiveItem && this.menuData.length > 0) { 1406 firstActiveItem = this.menuData[0]; 1407 } 1408 1409 if (firstActiveItem && firstActiveItem.ID) { 1410 this.mobileMenuHistory = []; 1411 this.mobileMenuHistory.push({ 1412 id: firstActiveItem.ID, 1413 name: firstActiveItem.NAME, 1414 level: 1 1415 }); 1416 1417 if (firstLevel) { 1418 const firstLevelItem = firstLevel.querySelector(`[data-id="${firstActiveItem.ID}"]`); 1419 if (firstLevelItem) { 1420 firstLevel.querySelectorAll('.mobile-first-level-item').forEach(i => i.classList.remove('active')); 1421 firstLevelItem.classList.add('active'); 1422 } 1423 } 1424 1425 this.loadMobileSecondLevel(firstActiveItem.ID, firstActiveItem.NAME, false); 1426 } 1427 } 1428 } 1429
1430 loadMobileSecondLevel(parentId, parentName, isBackNavigation = false) { 1431 const parent = this.findItemById(parentId); 1432 if (!parent) return; 1433 1434 const menuLevel = document.getElementById(`mobileMenuLevel_${this.containerId}`); 1435 if (!menuLevel) return; 1436 1437 const breadcrumb = document.getElementById(`mobileBreadcrumb_${this.containerId}`); 1438 const firstLevel = document.getElementById(`mobileFirstLevel_${this.containerId}`); 1439 const menuLevel3 = document.querySelector(`.block-3`); 1440 const menuLevel4 = document.querySelector(`.mobile-menu-bottom-block`); 1441 const menuCity = document.querySelector(`.mobile-selectCity`); 1442 1443 if (breadcrumb) { 1444 breadcrumb.style.display = 'none'; 1445 if (menuLevel3) { 1446 menuLevel3.style.display = 'flex'; 1447 } 1448 if (menuLevel4) { 1449 menuLevel4.style.display = 'flex'; 1450 } 1451 if (menuCity) { 1452 menuCity.style.display = 'grid'; 1453 } 1454 if (menuLevel) { 1455 menuLevel.style.marginBottom = '0'; 1456 } 1457 } 1458 1459 if (firstLevel) { 1460 firstLevel.style.display = 'flex'; 1461 } 1462 1463 if (!isBackNavigation) { 1464 1465 const firstLevelEntry = this.mobileMenuHistory.find(entry => entry.level === 1 && entry.id === parentId); 1466 if (!firstLevelEntry) { 1467 this.mobileMenuHistory = []; 1468 this.mobileMenuHistory.push({ 1469 id: parentId, 1470 name: parentName, 1471 level: 1 1472 }); 1473 } else { 1474 this.mobileMenuHistory = this.mobileMenuHistory.filter(entry => entry.level === 1 && entry.id === parentId); 1475 } 1476 } else { 1477 this.mobileMenuHistory = this.mobileMenuHistory.filter(entry => entry.level === 1); 1478 1479 if (this.mobileMenuHistory.length === 0) { 1480 this.mobileMenuHistory.push({ 1481 id: parentId, 1482 name: parentName, 1483 level: 1 1484 }); 1485 } 1486 } 1487 1488 menuLevel.innerHTML = ''; 1489 1490 if (!parent.CHILDREN || parent.CHILDREN.length === 0) { 1491 menuLevel.innerHTML = ''; 1492 return; 1493 } 1494 1495 const block1 = []; 1496 const block2 = []; 1497 const block3 = []; 1498 1499 parent.CHILDREN.forEach(child => { 1500 const menuBlock = child.PARAMS && child.PARAMS.UF_MENU_BLOCK ? parseInt(child.PARAMS.UF_MENU_BLOCK) : 0; 1501 if (menuBlock === 1) { 1502 block1.push(child); 1503 } else if (menuBlock === 3) { 1504 block3.push(child); 1505 } else { 1506 block2.push(child); 1507 } 1508 }); 1509 1510 if (this.commonBlock3Items && Array.isArray(this.commonBlock3Items)) { 1511 this.commonBlock3Items.forEach(item => { 1512 block3.push({ 1513 ID: item.ID, 1514 CODE: item.CODE, 1515 NAME: item.NAME, 1516 LINK: item.LINK, 1517 DEPTH_LEVEL: 2, 1518 IS_PARENT: item.IS_PARENT, 1519 SELECTED: item.SELECTED, 1520 PERMISSION: item.PERMISSION, 1521 PARAMS: item.PARAMS, 1522 CHILDREN: item.CHILDREN || [] 1523 }); 1524 }); 1525 } 1526 const createBlock = (children, blockClass) => { 1527 const blockDiv = document.createElement('div'); 1528 blockDiv.className = `mobile-second-level-block ${blockClass}`; 1529 1530 children.forEach(child => { 1531 const hasChildren = child.CHILDREN && child.CHILDREN.length > 0; 1532 const isYuridicheskimLitsam = this.isYuridicheskimLitsamSection(child); 1533 const menuItem = document.createElement('div'); 1534 menuItem.className = 'mobile-menu-item'; 1535 if (child.SELECTED) { 1536 menuItem.classList.add('active'); 1537 } 1538 if (hasChildren) { 1539 menuItem.classList.add('has-children'); 1540 } 1541 1542 const arrowSvg = hasChildren ? this.createArrowSvg(child.ID, true) : ''; 1543 menuItem.innerHTML = `
1544 <span class="mobile-menu-item-name item-custom-style${child.ID}">${this.escapeHtml(child.NAME)}</span> 1545 ${arrowSvg} 1546 `; 1547 1548 menuItem.onclick = (e) => { 1549 e.stopPropagation(); 1550 if (hasChildren) { 1551 const historyEntry = { 1552 id: child.ID, 1553 name: child.NAME, 1554 level: 2 1555 }; 1556 this.mobileMenuHistory.push(historyEntry); 1557 this.loadMobileLevel(child.ID, child.NAME, 3); 1558 } else if (child.LINK && !isYuridicheskimLitsam) { 1559 menuItem.classList.add('active'); 1560 window.location.href = child.LINK; 1561 } 1562 }; 1563 1564 blockDiv.appendChild(menuItem); 1565 }); 1566 1567 return blockDiv; 1568 }; 1569 1570 if (block1.length > 0) { 1571 menuLevel.appendChild(createBlock(block1, 'block-1')); 1572 } 1573 if (block2.length > 0) { 1574 menuLevel.appendChild(createBlock(block2, 'block-2')); 1575 } 1576 if (block3.length > 0) { 1577 menuLevel.appendChild(createBlock(block3, 'block-3')); 1578 } 1579 1580 this.updateMobileMenuBottomBlock(); 1581 } 1582 1583 loadMobileViewAllLevel(itemData, level) { 1584 if (!itemData || !itemData.LINK || this.isCollectionsSection(itemData)) { 1585 return; 1586 } 1587 1588 const menuLevel = document.getElementById(`mobileMenuLevel_${this.containerId}`); 1589 const breadcrumb = document.getElementById(`mobileBreadcrumb_${this.containerId}`); 1590 const breadcrumbTitle = breadcrumb ? breadcrumb.querySelector('.mobile-breadcrumb-title') : null; 1591 const breadcrumbBack = breadcrumb ? breadcrumb.querySelector('.mobile-back-arrow') : null; 1592 const firstLevel = document.getElementById(`mobileFirstLevel_${this.containerId}`); 1593 const menuLevel3 = document.querySelector(`.block-3`); 1594 const menuLevel4 = document.querySelector(`.mobile-menu-bottom-block`); 1595 const menuCity = document.querySelector(`.mobile-selectCity`); 1596 1597 if (!menuLevel) return; 1598 1599 if (level >= 2) { 1600 if (breadcrumb) { 1601 breadcrumb.style.display = 'flex'; 1602 if (breadcrumbTitle) { 1603 breadcrumbTitle.className = `mobile-breadcrumb-title mobile-breadcrumb-title-custom${itemData.ID}`; 1604 if (breadcrumbBack) { 1605 breadcrumbBack.className = `mobile-back-arrow mobile-back-arrow-custom${itemData.ID}`; 1606 } 1607 breadcrumbTitle.textContent = itemData.NAME || ''; 1608 } 1609 } 1610 if (menuLevel3) { 1611 menuLevel3.style.display = 'none'; 1612 } 1613 if (menuLevel4) { 1614 menuLevel4.style.display = 'none'; 1615 } 1616 if (menuCity) { 1617 menuCity.style.display = 'none'; 1618 } 1619 if (menuLevel) { 1620 menuLevel.style.marginBottom = '50px'; 1621 } 1622 } 1623 1624 if (level >= 3) { 1625 if (firstLevel) { 1626 firstLevel.style.display = 'none'; 1627 } 1628 } 1629 1630 menuLevel.innerHTML = ''; 1631 1632 const viewAllItem = document.createElement('div'); 1633 viewAllItem.className = 'mobile-menu-item view-all-link'; 1634 viewAllItem.innerHTML = `<span class="mobile-menu-item-name">СмоÑÑеÑÑ Ð²Ñе</span>`; 1635 viewAllItem.onclick = (e) => { 1636 e.stopPropagation(); 1637 viewAllItem.classList.add('active'); 1638 window.location.href = itemData.LINK; 1639 }; 1640 1641 menuLevel.appendChild(viewAllItem); 1642 } 1643 loadMobileLevel(itemId, itemName, level) { 1644 const item = this.findItemById(itemId); 1645 if (!item) return; 1646 1647 const menuLevel = document.getElementById(`mobileMenuLevel_${this.containerId}`); 1648 const breadcrumb = document.getElementById(`mobileBreadcrumb_${this.containerId}`); 1649 const breadcrumbTitle = breadcrumb ? breadcrumb.querySelector('.mobile-breadcrumb-title') : null; 1650 const breadcrumbBack = breadcrumb.querySelector('.mobile-back-arrow'); 1651 const firstLevel = document.getElementById(`mobileFirstLevel_${this.containerId}`); 1652 const menuLevel3 = document.querySelector(`.block-3`); 1653 const menuLevel4 = document.querySelector(`.mobile-menu-bottom-block`); 1654 const menuCity = document.querySelector(`.mobile-selectCity`); 1655 if (!menuLevel) return; 1656 1657 let breadcrumbName = ''; 1658 if (level >= 2 && this.mobileMenuHistory.length > 0) { 1659 const parentLevel = level - 1; 1660 const parentHistory = this.mobileMenuHistory.find(entry => entry.level === parentLevel); 1661 if (parentHistory) { 1662 breadcrumbName = parentHistory.name || ''; 1663 } else { 1664 const lastHistory = this.mobileMenuHistory[this.mobileMenuHistory.length - 1]; 1665 breadcrumbName = lastHistory ? (lastHistory.name || '') : ''; 1666 } 1667 if (menuLevel3) { 1668 menuLevel3.style.display = 'none'; 1669 } 1670 if (menuLevel4) { 1671 menuLevel4.style.display = 'none'; 1672 } 1673 if (menuCity) { 1674 menuCity.style.display = 'none'; 1675 } 1676 if (menuLevel) { 1677 menuLevel.style.marginBottom = '50px'; 1678 } 1679 } 1680 1681 if (level >= 2) { 1682 if (breadcrumb) { 1683 breadcrumb.style.display = 'flex'; 1684 if (breadcrumbTitle) { 1685 breadcrumbTitle.className = `mobile-breadcrumb-title mobile-breadcrumb-title-custom${itemId}`; 1686 breadcrumbBack.className = `mobile-back-arrow mobile-back-arrow-custom${itemId}`; 1687 breadcrumbTitle.textContent = breadcrumbName || ''; 1688 } else { 1689 const titleEl = document.createElement('span'); 1690 titleEl.className = 'mobile-breadcrumb-title'; 1691 titleEl.textContent = breadcrumbName || ''; 1692 breadcrumb.appendChild(titleEl); 1693 } 1694 } 1695 } 1696 if (level >= 3) { 1697 if (firstLevel) { 1698 firstLevel.style.display = 'none'; 1699 } 1700 } else { 1701 if (firstLevel) { 1702 firstLevel.style.display = 'flex'; 1703 } 1704 } 1705 1706 menuLevel.innerHTML = ''; 1707 1708 if (!item.CHILDREN || item.CHILDREN.length === 0) { 1709 if (item.LINK) { 1710 const breadcrumb = document.getElementById(`mobileBreadcrumb_${this.containerId}`); 1711 if (breadcrumb) { 1712 breadcrumb.classList.add('active'); 1713 } 1714 window.location.href = item.LINK; 1715 return; 1716 } 1717 menuLevel.innerHTML = ''; 1718 return; 1719 } 1720 1721 const sectionId = item.ID; 1722 const sectionCode = item.CODE ? item.CODE.toLowerCase().trim() : ''; 1723 const sectionName = item.NAME ? item.NAME.toLowerCase().trim() : '';
1724 const sectionDepth = item.DEPTH_LEVEL ? parseInt(item.DEPTH_LEVEL) : 0; 1725 const blockedSectionsIds = [980, 955, 3105]; 1726 const blockedSectionsCodes = ['devochkam', 'malchikam', 'baby-line', 'babyline']; 1727 const blockedSectionsNames = ['девоÑкам', 'малÑÑикам', 'baby line']; 1728 let isBlockedSection = (blockedSectionsIds.length > 0 && blockedSectionsIds.includes(sectionId)) 1729 || (blockedSectionsCodes.includes(sectionCode) && sectionDepth === 2) 1730 || (blockedSectionsNames.includes(sectionName) && sectionDepth === 2); 1731 1732 if (!isBlockedSection && level === 3 && this.mobileMenuHistory.length > 0) { 1733 const parentHistory = this.mobileMenuHistory.find(entry => entry.level === 2); 1734 if (parentHistory) { 1735 const parentName = parentHistory.name ? parentHistory.name.toLowerCase().trim() : ''; 1736 const parentId = parentHistory.id; 1737 isBlockedSection = blockedSectionsIds.includes(parentId) 1738 || blockedSectionsCodes.some(code => parentName.includes(code)) 1739 || blockedSectionsNames.some(name => parentName === name); 1740 } 1741 } 1742 1743 const isCert = this.isCertSection(item); 1744 const isTags = this.isTagsSection(item.LINK, item); 1745 const isCollections = this.isCollectionsSection(item); 1746 if (!isBlockedSection && !isCert && !isTags && !isCollections && item.LINK) { 1747 const viewAllItem = document.createElement('div'); 1748 viewAllItem.className = 'mobile-menu-item view-all-link'; 1749 viewAllItem.innerHTML = `<span class="mobile-menu-item-name">СмоÑÑеÑÑ Ð²Ñе</span>`; 1750 viewAllItem.onclick = (e) => { 1751 e.stopPropagation(); 1752 viewAllItem.classList.add('active'); 1753 window.location.href = item.LINK; 1754 }; 1755 menuLevel.appendChild(viewAllItem); 1756 } 1757 1758 if (isBlockedSection && item.CHILDREN && item.CHILDREN.length > 0) { 1759 const block1 = []; 1760 const block2 = []; 1761 const block3 = []; 1762 1763 item.CHILDREN.forEach(child => { 1764 const menuBlock = child.PARAMS && child.PARAMS.UF_MENU_BLOCK ? parseInt(child.PARAMS.UF_MENU_BLOCK) : 0; 1765 if (menuBlock === 1) { 1766 block1.push(child); 1767 } else if (menuBlock === 3) { 1768 block3.push(child); 1769 } else { 1770 block2.push(child); 1771 } 1772 }); 1773 1774 const createMobileBlock = (children, blockClass) => { 1775 const blockDiv = document.createElement('div'); 1776 blockDiv.className = `mobile-third-level-block ${blockClass}`; 1777 1778 children.forEach(child => { 1779 const hasChildren = child.CHILDREN && child.CHILDREN.length > 0; 1780 const hasViewAll = !hasChildren && child.LINK && level < 5; 1781 const shouldShowArrow = hasChildren || hasViewAll; 1782 const menuItem = document.createElement('div'); 1783 menuItem.className = 'mobile-menu-item'; 1784 if (child.SELECTED) { 1785 menuItem.classList.add('active'); 1786 } 1787 if (shouldShowArrow) { 1788 menuItem.classList.add('has-children'); 1789 } 1790 menuItem.dataset.hasViewAll = hasViewAll ? 'true' : 'false'; 1791 1792 const arrowSvg = shouldShowArrow ? this.createArrowSvg(child.ID, true) : ''; 1793 menuItem.innerHTML = ` 1794 <span class="mobile-menu-item-name item-custom-style${child.ID}">${this.escapeHtml(child.NAME)}</span> 1795 ${arrowSvg} 1796 `; 1797 1798 menuItem.onclick = (e) => { 1799 e.stopPropagation(); 1800 if (hasViewAll) { 1801 const historyEntry = { 1802 id: child.ID, 1803 name: child.NAME, 1804 level: level 1805 }; 1806 this.mobileMenuHistory.push(historyEntry);
1807 this.loadMobileViewAllLevel(child, level); 1808 } else if (hasChildren) { 1809 const historyEntry = { 1810 id: child.ID, 1811 name: child.NAME, 1812 level: level 1813 }; 1814 this.mobileMenuHistory.push(historyEntry); 1815 this.loadMobileLevel(child.ID, child.NAME, level + 1); 1816 } else if (child.LINK) { 1817 menuItem.classList.add('active'); 1818 window.location.href = child.LINK; 1819 } 1820 }; 1821 1822 blockDiv.appendChild(menuItem); 1823 }); 1824 1825 return blockDiv; 1826 }; 1827 1828 if (block1.length > 0) { 1829 menuLevel.appendChild(createMobileBlock(block1, 'block-1')); 1830 } 1831 if (block2.length > 0) { 1832 menuLevel.appendChild(createMobileBlock(block2, 'block-2')); 1833 } 1834 if (block3.length > 0) { 1835 menuLevel.appendChild(createMobileBlock(block3, 'block-3')); 1836 } 1837 } else { 1838 item.CHILDREN.forEach(child => { 1839 const hasChildren = child.CHILDREN && child.CHILDREN.length > 0; 1840 const hasViewAll = !hasChildren && child.LINK && level < 5; 1841 const shouldShowArrow = hasChildren || hasViewAll; 1842 const menuItem = document.createElement('div'); 1843 menuItem.className = 'mobile-menu-item'; 1844 if (child.SELECTED) { 1845 menuItem.classList.add('active'); 1846 } 1847 if (shouldShowArrow) { 1848 menuItem.classList.add('has-children'); 1849 } 1850 menuItem.dataset.hasViewAll = hasViewAll ? 'true' : 'false'; 1851 1852 const arrowSvg = shouldShowArrow ? this.createArrowSvg(child.ID, true) : ''; 1853 menuItem.innerHTML = ` 1854 <span class="mobile-menu-item-name item-custom-style${child.ID}">${this.escapeHtml(child.NAME)}</span> 1855 ${arrowSvg} 1856 `; 1857 1858 menuItem.onclick = (e) => { 1859 e.stopPropagation(); 1860 if (hasViewAll) { 1861 const historyEntry = { 1862 id: child.ID, 1863 name: child.NAME, 1864 level: level 1865 }; 1866 this.mobileMenuHistory.push(historyEntry); 1867 this.loadMobileViewAllLevel(child, level); 1868 } else if (hasChildren) { 1869 const historyEntry = { 1870 id: child.ID, 1871 name: child.NAME, 1872 level: level 1873 }; 1874 this.mobileMenuHistory.push(historyEntry); 1875 this.loadMobileLevel(child.ID, child.NAME, level + 1); 1876 } else if (child.LINK) { 1877 menuItem.classList.add('active'); 1878 window.location.href = child.LINK; 1879 } 1880 }; 1881 1882 menuLevel.appendChild(menuItem); 1883 }); 1884 } 1885 } 1886 1887 mobileGoBack() { 1888 if (this.mobileMenuHistory.length === 0) { 1889 let firstActiveItem = null; 1890 const firstLevel = document.getElementById(`mobileFirstLevel_${this.containerId}`); 1891 if (firstLevel) { 1892 const activeFirstLevelItem = firstLevel.querySelector('.mobile-first-level-item.active'); 1893 if (activeFirstLevelItem) { 1894 const activeId = parseInt(activeFirstLevelItem.dataset.id); 1895 firstActiveItem = this.findItemById(activeId); 1896 } 1897 } 1898 1899 if (!firstActiveItem) { 1900 for (const menuItem of this.menuData) { 1901 if (menuItem.SELECTED) { 1902 firstActiveItem = menuItem; 1903 break; 1904 } 1905 } 1906 if (!firstActiveItem && this.menuData.length > 0) { 1907 firstActiveItem = this.menuData[0]; 1908 } 1909 } 1910 1911 if (firstActiveItem) { 1912 this.loadMobileSecondLevel(firstActiveItem.ID, firstActiveItem.NAME); 1913 } 1914 return; 1915 } 1916 1917 const firstLevel = document.getElementById(`mobileFirstLevel_${this.containerId}`); 1918 1919 if (this.mobileMenuHistory.length === 0) { 1920 let firstActiveItem = null; 1921 const firstLevel = document.getElementById(`mobileFirstLevel_${this.containerId}`); 1922 if (firstLevel) { 1923 const activeFirstLevelItem = firstLevel.querySelector('.mobile-first-level-item.active'); 1924 if (activeFirstLevelItem) { 1925 const activeId = parseInt(activeFirstLevelItem.dataset.id); 1926 firstActiveItem = this.findItemById(activeId); 1927 } 1928 } 1929 1930 if (!firstActiveItem) { 1931 for (const menuItem of this.menuData) { 1932 if (menuItem.SELECTED) { 1933 firstActiveItem = menuItem; 1934 break; 1935 } 1936 } 1937 if (!firstActiveItem && this.menuData.length > 0) { 1938 firstActiveItem = this.menuData[0]; 1939 } 1940 } 1941 1942 if (firstActiveItem) { 1943 this.loadMobileSecondLevel(firstActiveItem.ID, firstActiveItem.NAME); 1944 } 1945 return; 1946 } 1947 1948 const previous = this.mobileMenuHistory.pop(); 1949 if (!previous) { 1950 let firstActiveItem = null; 1951 const firstLevel = document.getElementById(`mobileFirstLevel_${this.containerId}`); 1952 if (firstLevel) { 1953 const activeFirstLevelItem = firstLevel.querySelector('.mobile-first-level-item.active'); 1954 if (activeFirstLevelItem) { 1955 const activeId = parseInt(activeFirstLevelItem.dataset.id); 1956 firstActiveItem = this.findItemById(activeId); 1957 } 1958 } 1959 if (!firstActiveItem && this.menuData.length > 0) { 1960 firstActiveItem = this.menuData[0]; 1961 } 1962 if (firstActiveItem) { 1963 this.loadMobileSecondLevel(firstActiveItem.ID, firstActiveItem.NAME); 1964 } 1965 return; 1966 } 1967 1968 if (previous.level === 1) { 1969 this.loadMobileSecondLevel(previous.id, previous.name, true); 1970 } else if (previous.level === 2) { 1971 const item = this.findItemById(previous.id); 1972 if (item) { 1973 const parent = this.getParentItem(previous.id); 1974 if (parent) { 1975 this.loadMobileSecondLevel(parent.ID, parent.NAME, true); 1976 } else { 1977 let firstActiveItem = null; 1978 const firstLevelEl = document.getElementById(`mobileFirstLevel_${this.containerId}`); 1979 if (firstLevelEl) { 1980 const activeFirstLevelItem = firstLevelEl.querySelector('.mobile-first-level-item.active'); 1981 if (activeFirstLevelItem) { 1982 const activeId = parseInt(activeFirstLevelItem.dataset.id); 1983 firstActiveItem = this.findItemById(activeId); 1984 } 1985 } 1986 if (!firstActiveItem && this.menuData.length > 0) { 1987 firstActiveItem = this.menuData[0]; 1988 } 1989 if (firstActiveItem) { 1990 this.loadMobileSecondLevel(firstActiveItem.ID, firstActiveItem.NAME, true); 1991 } 1992 } 1993 } 1994 } else { 1995 if (previous.level === 2) { 1996 const parentHistory = this.mobileMenuHistory.find(entry => entry.level === 1); 1997 if (parentHistory) { 1998 this.loadMobileSecondLevel(parentHistory.id, parentHistory.name, true); 1999 } else { 2000 const parent = this.getParentItem(previous.id); 2001 if (parent) { 2002 this.loadMobileSecondLevel(parent.ID, parent.NAME, true); 2003 } else { 2004 let firstActiveItem = null; 2005 const firstLevelEl = document.getElementById(`mobileFirstLevel_${this.containerId}`); 2006 if (firstLevelEl) { 2007 const activeFirstLevelItem = firstLevelEl.querySelector('.mobile-first-level-item.active'); 2008 if (activeFirstLevelItem) { 2009 const activeId = parseInt(activeFirstLevelItem.dataset.id); 2010 firstActiveItem = this.findItemById(activeId); 2011 } 2012 } 2013 if (!firstActiveItem && this.menuData.length > 0) { 2014 firstActiveItem = this.menuData[0]; 2015 } 2016 if (firstActiveItem) { 2017 this.loadMobileSecondLevel(firstActiveItem.ID, firstActiveItem.NAME, true); 2018 } 2019 } 2020 } 2021 return; 2022 } 2023 2024 const parentHistory = this.mobileMenuHistory.find(entry => entry.level === previous.level - 1); 2025 if (parentHistory) { 2026 this.loadMobileLevel(parentHistory.id, parentHistory.name, previous.level); 2027 } else { 2028 const parent = this.getParentItem(previous.id); 2029 if (parent) { 2030 this.loadMobileLevel(parent.ID, parent.NAME, previous.level); 2031 } else { 2032 let firstActiveItem = null; 2033 const firstLevelEl = document.getElementById(`mobileFirstLevel_${this.containerId}`); 2034 if (firstLevelEl) { 2035 const activeFirstLevelItem = firstLevelEl.querySelector('.mobile-first-level-item.active'); 2036 if (activeFirstLevelItem) { 2037 const activeId = parseInt(activeFirstLevelItem.dataset.id); 2038 firstActiveItem = this.findItemById(activeId); 2039 } 2040 } 2041 if (!firstActiveItem && this.menuData.length > 0) { 2042 firstActiveItem = this.menuData[0]; 2043 } 2044 if (firstActiveItem) { 2045 this.loadMobileSecondLevel(firstActiveItem.ID, firstActiveItem.NAME, true); 2046 } 2047 } 2048 } 2049 } 2050 } 2051}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.