1 2function UCAccordionMenu(menuWrapperID){ 3 4 var g_menuWrapper, g_isCloseOnOpen = false, g_isCurrentParentItemOpened = false, g_dataStartClosedAlways ; 5 var isInited =false; 6 7 /** 8 * collapse inner section 9 */ 10 function collapseInnerSection(element, link){ 11 12 var sectionHeight = element.scrollHeight; 13 14 var elementTransition = element.style.transition; 15 element.style.transition = ''; 16 17 //check if parent link has same href as current window location href 18 //if so, then set 'data-collapsed' attribute to 'false' and go to next link 19 var currentLocation = window.location.href; 20 var objLinkItemHref = jQuery(link).attr('href'); 21 22 if(currentLocation == objLinkItemHref && g_isCurrentParentItemOpened == false && g_dataStartClosedAlways == false){ 23 24 element.setAttribute('data-collapsed', 'false'); 25 26 g_isCurrentParentItemOpened = true; 27 28 return(true) 29 } 30 31 32 requestAnimationFrame(function() { 33 element.style.height = sectionHeight + 'px'; 34 element.style.transition = elementTransition; 35 36 requestAnimationFrame(function() { 37 element.style.height = 0 + 'px'; 38 39 }); 40 }); 41 42 element.setAttribute('data-collapsed', 'true'); 43 } 44 45 /** 46 * expand the inner of the section 47 */ 48 function expandSectionInner(element){ 49 var sectionHeight = element.scrollHeight; 50 51 element.style.height = sectionHeight + 'px'; 52 53 element.addEventListener('transitionend', function(e) { 54 element.removeEventListener('transitionend', arguments.callee); 55 element.style.height = null; 56 }); 57 58 element.setAttribute('data-collapsed', 'false'); 59 60 } 61 62 /** 63 * expand section 64 */ 65 function expandSection(section, objLink){ 66 67 expandSectionInner(section); 68 69 section.setAttribute('data-collapsed', 'false') 70 objLink.removeClass("collapsed"); 71 objLink.addClass("expanded"); 72 73 } 74 75 /** 76 * collapse the section 77 */ 78 function collapseSection(section, objLink){ 79 80 collapseInnerSection(section, objLink); 81 82 objLink.addClass("collapsed"); 83 objLink.removeClass("expanded"); 84 } 85 86 /** 87 * collapse all expanded sections 88 */ 89 function collapseAllExpanded(clickedItem){ 90 91 var clickedParentExpanded = jQuery(clickedItem).parents('.sub-menu').prev(); 92 var clickedChildrenExpanded = jQuery(clickedItem).next().find('.expanded'); 93 94 var objAllExpanded = g_menuWrapper.find(".expanded").not(clickedChildrenExpanded).not(clickedParentExpanded); 95 96 if(objAllExpanded.length == false) 97 return(false); 98 99 jQuery.each(objAllExpanded, function(index, link){ 100 var objLink = jQuery(link); 101 var section = link.nextElementSibling; 102 103 collapseSection(section, objLink); 104 105 }); 106 } 107 108 /** 109 * close or open link 110 */ 111 function toggleSection(objLink){ 112 113 var link = objLink[0]; 114 var section = link.nextElementSibling; 115 116 var isCollapsed = section.getAttribute('data-collapsed') === 'true'; 117 118 if (isCollapsed) { //expend current 119 120 if(g_isCloseOnOpen == true) 121 collapseAllExpanded(link); 122 123 expandSection(section, objLink); 124 125 } else { //collapse current 126 127 collapseSection(section,objLink); 128 } 129 130 } 131 132 /** 133 * open or close some item 134 */ 135 function openCloseItem(link, event){ 136 137 var section = link.nextElementSibling; 138 139 if(!section) 140 return(true); 141 142 var objSection = jQuery(section); 143 if(objSection.hasClass("sub-menu") == false) 144 return(true); 145 146 if(event) 147 event.preventDefault(); 148 149 var objLink = jQuery(link); 150 151 var isCollapsed = section.getAttribute('data-collapsed') === 'true'; 152 153 if (isCollapsed) { //expend current 154 155 if(g_isCloseOnOpen == true) 156 collapseAllExpanded(link); 157 158 expandSection(section, objLink); 159 160 } else { //collapse current 161 162 collapseSection(section,objLink); 163 } 164 165 } 166 167 168 /** 169 * on menu item click, if sub menu, open or close 170 */ 171 function onMenuItemClick(event){ 172 173 openCloseItem(this, event); 174 175 } 176 177 178 /** 179 * console log shorcut 180 */ 181 function trace(str){ 182 183 console.log(str); 184 } 185 186 187 /** 188 * init from popups 189 */ 190 function checkInitFromPopups(){ 191 192 jQuery( document ).on( 'elementor/popup/show', (event) => { 193 runMenu(); 194 }); 195 196 } 197 198 199 /** 200 * expand current item tree 201 */ 202 function expandCurrentItemTree(){ 203 204 //disable transition 205 206 var objCurrentItem = g_menuWrapper.find(".uc-list-menu ul .current-menu-item"); 207 208 if(objCurrentItem.length == 0) 209 return(false); 210 211 g_menuWrapper.addClass("uc-no-transition"); 212 213 setTimeout(function(){ 214 g_menuWrapper.removeClass("uc-no-transition"); 215 },300); 216 217 var objParents = objCurrentItem.parents("li"); 218 219 if(objParents.length == 0) 220 return(false); 221 222 jQuery.each(objParents, function(index, parent){ 223 224 var objParent = jQuery(parent); 225 var objLink = objParent.children("a"); 226 227 var link = objLink[0]; 228 229 openCloseItem(link); 230 231 }); 232 233 } 234 235 /** 236 * run the menu, init 237 */ 238 function runMenu(){ 239 240 //init globals 241 g_menuWrapper = jQuery("#"+menuWrapperID); 242 243 g_dataStartClosedAlways = g_menuWrapper.data('start-closed-always'); 244 g_isCloseOnOpen = g_menuWrapper.data("closeothers"); 245 g_isCloseOnOpen = (g_isCloseOnOpen == "yes"); 246
247 var isClickable = g_menuWrapper.data("clickable"); 248 249 if(g_menuWrapper.length == 0){ 250 console.log("menu with ID: "+menuWrapperID+" not found!"); 251 252 checkInitFromPopups(); 253 254 return(false); 255 } 256 257 //collapse all except the current 258 259 g_menuWrapper.find("ul.uc-list-menu li a").each((i, item) => { 260 261 if(item.nextElementSibling){ 262 263 var objItem = jQuery(item); 264 var objItemPointer = objItem.find('.uc-menu-item-pointer'); 265 266 if(objItemPointer.length == 0) 267 objItem.append("<span class='uc-menu-item-pointer'></span>"); 268 269 //check if parent link has same href as current window location href 270 //if so, then open current accordion item 271 var currentLocation = window.location.href; 272 var objLinkItemHref = jQuery(item).attr('href'); 273 274 if(currentLocation == objLinkItemHref && g_isCurrentParentItemOpened == false && g_dataStartClosedAlways == false){ 275 276 collapseInnerSection(item.nextElementSibling, item); 277 278 item.nextElementSibling.style.display = "block"; 279 280 jQuery(item).addClass("expanded"); 281 jQuery(item).removeClass("collapsed"); 282 283 return(true); 284 285 } 286 287 collapseInnerSection(item.nextElementSibling, item); 288 289 item.nextElementSibling.style.display = "block"; 290 291 jQuery(item).addClass("collapsed"); 292 jQuery(item).removeClass("expanded"); 293 294 } 295 296 }); 297 298 //init events 299 300 if(isClickable == false){ 301 302 g_menuWrapper.find("ul.uc-list-menu li a").on("click", onMenuItemClick); 303 304 }else{ 305 306 //pointer click - toggle section 307 308 g_menuWrapper.find("ul.uc-list-menu li .uc-menu-item-pointer").on("click", function(event){ 309 310 event.preventDefault(); 311 var objLink = jQuery(this).parent(); 312 toggleSection(objLink); 313 314 }); 315 316 } 317 318 319 //open the section with current item 320 321 setTimeout(expandCurrentItemTree,100); 322 323 isInited = true; 324 325 } 326 327 if(isInited == false) 328 runMenu(); 329 330 //init from custom popup event 331 jQuery(document).on('uc_burger_popup_open', function(){ 332 333 setTimeout(function(){ 334 runMenu(); 335 },50); 336 337 }); 338 339} 340
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.