{"version":3,"file":"smartmenu.min.js","sources":["https:\/\/univirtual.correios.com.br\/theme\/boost_union\/amd\/src\/smartmenu.js"],"sourcesContent":["\/\/ This file is part of Moodle - http:\/\/moodle.org\/\n\/\/\n\/\/ Moodle is free software: you can redistribute it and\/or modify\n\/\/ it under the terms of the GNU General Public License as published by\n\/\/ the Free Software Foundation, either version 3 of the License, or\n\/\/ (at your option) any later version.\n\/\/\n\/\/ Moodle is distributed in the hope that it will be useful,\n\/\/ but WITHOUT ANY WARRANTY; without even the implied warranty of\n\/\/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\/\/ GNU General Public License for more details.\n\/\/\n\/\/ You should have received a copy of the GNU General Public License\n\/\/ along with Moodle. If not, see .\n\n\/**\n * Theme Boost Union - JS for smart menu to realize the third level submenu support.\n *\n * @module theme_boost_union\/smartmenu\n * @copyright 2023 bdecent GmbH \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\ndefine([\"jquery\", \"core\/moremenu\", \"theme_boost_union\/submenu\"], function($, MoreMenu, SubMenu) {\n\n const Selectors = {\n dropDownMenu: \"dropdownmoremenu\",\n forceOut: \"force-menu-out\",\n navLink: \"nav-link\",\n dropDownItem: \"dropdown-item\",\n classes: {\n dropDownMenuList: \".dropdownmoremenu ul.dropdown-menu\",\n forceOut: \".dropdownmoremenu .force-menu-out\",\n dropdownmoremenu: '.dropdownmoremenu',\n primaryNavigation: '.primary-navigation',\n\n },\n regions: {\n moredropdown: '[data-region=\"moredropdown\"]'\n\n }\n };\n\n \/**\n * Make the no wrapped card menus scroll using swipe or drag.\n *\/\n const cardScroll = () => {\n var cards = document.querySelectorAll('.card-dropdown.card-overflow-no-wrap');\n if (cards !== null) {\n var scrollStart; \/\/ Verify the mouse is clicked and still in click not released.\n var scrollMoved; \/\/ Prevent the click on scrolling.\n let startPos, scrollPos;\n\n cards.forEach((card) => {\n var scrollElement = card.querySelector('.dropdown-menu');\n\n scrollElement.addEventListener('mousedown', (e) => {\n scrollStart = true;\n var target = e.currentTarget.querySelector('.card-block-wrapper');\n startPos = e.pageX;\n scrollPos = target.scrollLeft;\n });\n\n scrollElement.addEventListener('mousemove', (e) => {\n e.preventDefault();\n if (!scrollStart) {\n return;\n }\n scrollMoved = true;\n var target = e.currentTarget.querySelector('.card-block-wrapper');\n const scroll = e.pageX - startPos;\n target.scrollLeft = scrollPos - scroll;\n });\n\n scrollElement.addEventListener('click', (e) => {\n if (scrollMoved) {\n e.preventDefault();\n scrollMoved = false;\n }\n e.stopPropagation();\n });\n scrollElement.addEventListener('mouseleave', () => {\n scrollStart = false;\n scrollMoved = false;\n });\n scrollElement.addEventListener('mouseup', () => {\n scrollStart = false;\n });\n });\n }\n };\n\n \/**\n * Move the menubar and primary navigation menu items from more menu.\n *\/\n const autoCollapse = () => {\n var primaryNav = document.querySelector('.primary-navigation ul.more-nav');\n if (primaryNav != undefined) {\n setOutMenuPositions(primaryNav); \/\/ Create a data flag to maintain the original position of the menus.\n moveOutMoreMenu(primaryNav);\n }\n\n var menuBar = document.querySelector('nav.menubar ul.more-nav');\n if (menuBar != undefined) {\n setOutMenuPositions(menuBar);\n moveOutMoreMenu(menuBar);\n }\n\n window.onresize = (e) => {\n \/\/ Verify the event is original by browser resize.\n if (e.isTrusted) {\n moveOutMoreMenu(primaryNav);\n moveOutMoreMenu(menuBar);\n }\n };\n };\n\n \/**\n * Finds and sets the positions of all menus before moving them,\n * helping to maintain the positions of the menus after being moved out from the moremenu.\n *\n * @param {HTMLElement} navMenu The navbar container.\n *\/\n const setOutMenuPositions = (navMenu) => {\n\n if (navMenu === undefined || navMenu === null) {\n return;\n }\n\n \/\/ Find all menu items excluding the dropdownmoremenu class.\n var li = Array.from(navMenu.children).filter((e) => !e.classList.contains(Selectors.dropDownMenu));\n\n \/\/ Initialize the position variable.\n var position = 0;\n\n \/\/ Loop through each menu item and set its original position.\n li.forEach((menu) => {\n position = li.indexOf(menu);\n menu.dataset.orgposition = position; \/\/ Store the original position in the menu's dataset.\n });\n\n \/\/ Maintain the positions of the menus inside the moremenu from the last position of the outside menus.\n var moreMenu = navMenu.querySelector(Selectors.classes.dropDownMenuList);\n Array.from(moreMenu.children).forEach((menu) => {\n menu.dataset.orgposition = position++;\n });\n };\n\n \/**\n * Rearranges the menus placed outside the more menu based on their original positions.\n *\n * @param {HTMLElement} navMenu The navbar container.\n *\/\n const reArrangeMenuOrgPositions = (navMenu) => {\n \/\/ Retrieve all menu items and sort them based on their original positions.\n var li = Array.from(navMenu.children).sort((a, b) => a.dataset.orgposition - b.dataset.orgposition);\n \/\/ Append the sorted menu items back to the navbar container.\n li.forEach((menu) => navMenu.appendChild(menu));\n };\n\n \/**\n * Move the items from more menu, items which is set to force outside more menu.\n * Remove those items from more menu and insert the menu before the last normal item.\n * Find the length and children's length to insert the out menus in that positions.\n * Move the non forced more menu to moremenu to make the menu alignment.\n * Rerun the more menu it will more the other normal menus into more menu to fix the alignmenu issue.\n * After the menus are move out, rearrange menus to its original positions.\n *\n * @param {HTMLElement} navMenu The navbar container.\n *\/\n const moveOutMoreMenu = (navMenu) => {\n\n if (navMenu === null) {\n return;\n }\n\n \/\/ Filter the available menus to move inside of more menu.\n var li = Array.from(navMenu.children).reverse().filter(\n (e) => !e.classList.contains(Selectors.forceOut) && !e.classList.contains(Selectors.dropDownMenu));\n\n \/\/ Alternate menus are not available for move to moremenu, stop make the menus move to outside.\n if (li.length < 1) {\n return;\n }\n\n var outMenus = navMenu.querySelectorAll(Selectors.classes.forceOut);\n var menuslist = [];\n\n if (outMenus === null) {\n return;\n }\n\n outMenus.forEach((menu) => {\n menu.querySelector('a').classList.remove(Selectors.dropDownItem);\n menu.querySelector('a').classList.add(Selectors.navLink);\n\n menuslist.push(menu);\n menu.parentNode.removeChild(menu);\n });\n\n \/\/ Insert the stored menus before the more menu.\n var moveMenus = [];\n menuslist.forEach((menu) => {\n if (navMenu.insertBefore(menu, navMenu.lastElementChild) && li.length > 0) {\n \/\/ Instead of move into moremenu, place the menus before the moremenu will moved to moremenu by moremenu.js.\n moveMenus.push(li.shift());\n }\n });\n\n \/\/ Move the non forced more menu before the moremenu to make the menu alignment.\n moveMenus.forEach((menu) => {\n navMenu.insertBefore(menu, navMenu.lastElementChild);\n });\n\n window.dispatchEvent(new Event('resize')); \/\/ Dispatch the resize event to create more menu.\n\n \/\/ After the menus are move out, rearrange menus to its original positions.\n reArrangeMenuOrgPositions(navMenu);\n };\n\n return {\n init: () => {\n\n SubMenu.init();\n cardScroll();\n autoCollapse();\n\n \/\/ Prevent the closing of dropdown during the click on help icon.\n var helpIcon = document.querySelectorAll('.moremenu .dropdown .menu-helpicon');\n if (helpIcon !== null) {\n helpIcon.forEach((icon) => {\n icon.addEventListener('click', (e) => {\n e.stopPropagation();\n });\n });\n }\n\n const toggledropdown = e => e.stopPropagation();\n\n \/\/ If there are dropdowns in the MoreMenu, add a new\n \/\/ event listener to show the contents on click and prevent the\n \/\/ moreMenu from closing.\n \/\/ In moodle 5.0, only the first moremenu is initialized. if the menubar and primary navigation are present,\n \/\/ the moremenu is initialized on the menubar.\n \/\/ So we need to add the event listener to the primary navigation if the menubar is present.\n var primaryNav = document\n .querySelector(Selectors.classes.primaryNavigation + ' ' + Selectors.classes.dropdownmoremenu);\n\n if (document.querySelector(Selectors.classes.dropdownmoremenu) !== primaryNav) {\n\n primaryNav?.addEventListener('show.bs.dropdown', () => {\n const moreDropdown = document.querySelector(Selectors.classes.primaryNavigation)\n ?.querySelector(Selectors.regions.moredropdown);\n moreDropdown?.querySelectorAll('.dropdown').forEach((dropdown) => {\n dropdown.removeEventListener('click', toggledropdown, true);\n dropdown.addEventListener('click', toggledropdown, true);\n });\n\n });\n }\n }\n };\n});\n"],"names":["define","$","MoreMenu","SubMenu","Selectors","dropDownMenuList","forceOut","dropdownmoremenu","primaryNavigation","moredropdown","setOutMenuPositions","navMenu","li","Array","from","children","filter","e","classList","contains","position","forEach","menu","indexOf","dataset","orgposition","moreMenu","querySelector","moveOutMoreMenu","reverse","length","outMenus","querySelectorAll","menuslist","remove","add","push","parentNode","removeChild","moveMenus","insertBefore","lastElementChild","shift","window","dispatchEvent","Event","sort","a","b","appendChild","reArrangeMenuOrgPositions","init","cards","document","scrollStart","scrollMoved","startPos","scrollPos","card","scrollElement","addEventListener","target","currentTarget","pageX","scrollLeft","preventDefault","scroll","stopPropagation","cardScroll","primaryNav","undefined","menuBar","onresize","isTrusted","autoCollapse","helpIcon","icon","toggledropdown","moreDropdown","_document$querySelect","dropdown","removeEventListener"],"mappings":";;;;;;;AAuBAA,qCAAO,CAAC,SAAU,gBAAiB,8BAA8B,SAASC,EAAGC,SAAUC,eAE7EC,uBACY,mBADZA,mBAEQ,iBAFRA,kBAGO,WAHPA,uBAIY,gBAJZA,kBAKO,CACLC,iBAAkB,qCAClBC,SAAU,oCACVC,iBAAkB,oBAClBC,kBAAmB,uBATrBJ,kBAYO,CACLK,aAAc,gCAqFhBC,oBAAuBC,aAErBA,MAAAA,aAKAC,GAAKC,MAAMC,KAAKH,QAAQI,UAAUC,QAAQC,IAAOA,EAAEC,UAAUC,SAASf,0BAGtEgB,SAAW,EAGfR,GAAGS,SAASC,OACRF,SAAWR,GAAGW,QAAQD,MACtBA,KAAKE,QAAQC,YAAcL,gBAI3BM,SAAWf,QAAQgB,cAAcvB,kBAAkBC,kBACvDQ,MAAMC,KAAKY,SAASX,UAAUM,SAASC,OACnCA,KAAKE,QAAQC,YAAcL,gBA0B7BQ,gBAAmBjB,aAEL,OAAZA,aAKAC,GAAKC,MAAMC,KAAKH,QAAQI,UAAUc,UAAUb,QAC3CC,IAAOA,EAAEC,UAAUC,SAASf,sBAAwBa,EAAEC,UAAUC,SAASf,+BAG1EQ,GAAGkB,OAAS,QAIZC,SAAWpB,QAAQqB,iBAAiB5B,kBAAkBE,UACtD2B,UAAY,MAEC,OAAbF,UAIJA,SAASV,SAASC,OACdA,KAAKK,cAAc,KAAKT,UAAUgB,OAAO9B,wBACzCkB,KAAKK,cAAc,KA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