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