1/* Nav Accordion Plugin v1.1.2 2************************************/ 3(function($){ 4 $('.menu-mobile').click(function(){ 5 $('.navmenumobile').slideToggle(); 6 }); 7 $.fn.navAccordion = function(options, callback){ 8 this.each(function(){ 9 10 //Options 11 var settings = $.extend({ 12 expandButtonText : "+", //Text inside of expand button 13 collapseButtonText: "-", //Text inside of collapse button 14 selectedExpand: "true", //Expand the selected channel 15 selectedClass: "selected", //Class that will be used to detect the currently selected channel - this will check the "parentElement" for this class (the parent <li> by default) 16 multipleLevels: "true", //Apply accordion to all levels - setting this to false will apply the accordion only to the first level 17 buttonWidth: "50px", //Width of accordion expand/collapse button as a percentage or pixels 18 buttonPosition: "right", //Position of button - 'right' is default - you can also choose 'left' 19 slideSpeed: "fast", //Speed of slide animation - "fast", "slow", or number in milliseconds such as 500 20 parentElement: "li", //Parent element type, class or ID - you don't need to change this if you're using a ul > li > ul pattern 21 childElement: "ul", //Child element type, class or ID - you don't need to change this if you're using a ul > li > ul pattern 22 headersOnly: false, //False is default - setting to true will make any link with sub-nav behave as if it were set to header only, making the link inaccessible - this option is useful if you are using the plugin for a non-navigation area 23 headersOnlyCheck: false, // False is default - set to true to apply the accordion only to links that are set as "header only" (have no href) 24 delayLink: false, //Delay following the href of links until after the accordion the has expanded 25 delayAmount: null //Time in milliseconds to delay before following href - will use "slideSpeed" by default if nothing else is set 26 }, options); 27 28 var container = this, 29 //Multiple levels variable 30 multi = settings.multipleLevels ? '': ' > ' + settings.childElement + ' > '; 31 32 //Add class to container 33 $(container) 34 .addClass('accordion-nav'); 35 36 //Apply has-subnav class to lis with uls - also add accordion buttons with styles 37 $(multi + settings.parentElement, container).each(function(){ 38 if ( ($(this).contents(settings.childElement).length > 0 39 && settings.headersOnlyCheck == false) || (!($('> a', this).attr('href')) 40 && settings.headersOnlyCheck == true) ) 41 { 42 //Apply Class and styles to parent item 43 $(this).addClass('has-subnav') 44 .css('position', 'relative') 45 .find('>a') 46 .css('margin-' + settings.buttonPosition, settings.buttonWidth); 47 48 //Add expand button elements 49 $(' > ' + settings.childElement, this) 50 .before('<span class="accordion-btn-wrap"><span class="accordion-btn accordion-collapsed">' 51 + settings.expandButtonText + '</span><span class="accordion-btn accordion-expanded">' 52 + settings.collapseButtonText + '</span></span>'); 53 54 //Apply Styles to expand button 55 $('.accordion-btn-wrap', this) 56 .css({ 57 'width': settings.buttonWidth, 58 'position': 'absolute', 59 'top': 0, 60 'text-align': 'center', 61 'cursor': 'pointer', 62 'display': 'inline-block', 63 'line-height': '42px', 64 'background-color': '#e152e8', 65 }) 66 .css(settings.buttonPosition, 0); 67 $('.accordion-btn ', this) 68 .css({ 69 'display': 'inline-block', 70 'width': '100%' 71 }); 72 $('.accordion-expanded', this) 73 .css('display', 'none'); 74 } 75 76 //Apply styles to <a> tags that are set to header only 77 if (!($('> a', this).attr('href')) || settings.headersOnly){ 78 $(this) 79 .addClass('accordion-header-only') 80 .find('.accordion-btn-wrap') 81 .css({ 82 'width': '100%', 83 'text-align': settings.buttonPosition 84 }) 85 .find('.accordion-btn ') 86 .css({ 87 'width': settings.buttonWidth, 88 'text-align': 'center' 89 }); 90 } 91 92 //Delay Link Mode
93 if (settings.delayLink && !settings.headersOnly) { 94 var currentThis = this, 95 speed = settings.delayAmount != null ? settings.delayAmount : settings.slideSpeed; 96 if (speed == "fast") { 97 speed = 200; 98 } else if (speed == "slow") { 99 speed = 600; 100 } 101 $('> a', currentThis).on('click',function(e){ 102 if (!$('> .accordion-btn-wrap', currentThis).hasClass("accordion-active")) { 103 e.preventDefault(); 104 var href = $(this).attr('href'); 105 clickToggle($('> .accordion-btn-wrap', currentThis)); 106 //Go to link after delay 107 setTimeout(function(){ 108 window.location = href; 109 }, speed) 110 } 111 }) 112 } 113 114 }); 115 116 var selectedNavAccordion = $(settings.parentElement + '.' + settings.selectedClass + ' > .accordion-btn-wrap', container); 117 118 //Debounced Button height event listener 119 var buttonheightResize = debounce(function(){ 120 //Run button height 121 buttonheight(); 122 //Expand Selected Channel 123 expandSelected(); 124 }, 250); 125 $(window).on('resize', buttonheightResize); 126 127 //Set button heights
128 buttonheight(); 129 130 //Expand Selected Channel 131 expandSelected(); 132 133 //On click function 134 $(container).on('click', '.accordion-btn-wrap', function(e) { 135 e.preventDefault(); 136 clickToggle(this); 137 }); 138 139 //Callback 140 if (typeof callback == "function") { 141 callback(); 142 } 143 144 145 /* Functions 146 *******************************/ 147 //Click Toggle function 148 function clickToggle(element) { 149 var nextChild = $(element).next(settings.childElement), 150 currentExpandBtn = $('.accordion-expanded', element), 151 currentCollapseBtn = $('.accordion-collapsed', element), 152 parentObj = $(element).closest(settings.parentElement); 153 if (nextChild.is(':visible')) { 154 nextChild 155 .slideUp(settings.slideSpeed); 156 $(element) 157 .removeClass('accordion-active'); 158 currentExpandBtn 159 .css('display', 'none'); 160 currentCollapseBtn 161 .css('display', 'inline-block'); 162 parentObj.add(parentObj.siblings('.active')).add(parentObj.find('.active')).removeClass('active'); 163 } else { 164 $(element).closest(settings.childElement).find('.accordion-active') 165 .removeClass('accordion-active') 166 .next(settings.childElement) 167 .slideUp(settings.slideSpeed).prev() 168 .find('.accordion-expanded') 169 .css('display', 'none') 170 .parent().find('.accordion-collapsed') 171 .css('display', 'inline-block'); 172 parentObj.add(parentObj.siblings('.active')).add(parentObj.find('.active')).removeClass('active'); 173 $(element) 174 .addClass('accordion-active'); 175 nextChild 176 .slideToggle(settings.slideSpeed); 177 currentExpandBtn 178 .css('display', 'inline-block'); 179 currentCollapseBtn 180 .css('display', 'none'); 181 parentObj.addClass('active'); 182 } 183 } 184 185 //Expand Selected Channel Function 186 function expandSelected(){ 187 if(settings.selectedExpand){ 188 if(!settings.headersOnlyCheck){ 189 selectedNavAccordion.find('.accordion-expanded') 190 .css('display', 'inline-block'); 191 selectedNavAccordion.find('.accordion-collapsed') 192 .css('display', 'none'); 193 selectedNavAccordion.addClass('accordion-active') 194 .next(settings.childElement) 195 .css('display', 'block'); 196 selectedNavAccordion.closest(settings.parentElement) 197 .addClass('active'); 198 } else { 199 $(settings.parentElement + '.' + settings.selectedClass + ' > ' + settings.childElement, container) 200 .css('display', 'block'); 201 $(settings.parentElement + '.' + settings.selectedClass).addClass('active'); 202 } 203 } 204 } 205 206 //Accordion Button Height Function 207 function buttonheight(){ 208 $('.accordion-btn', container).each(function(){ 209 //Show uls so heights are calculated correctly 210 $(settings.parentElement + '.has-subnav > ' + settings.childElement, container) 211 .css('display', 'block'); 212 213 //Calculate and set heights 214 var parentItem = $(this).closest(settings.parentElement), 215 lineheight = $('> a', parentItem).innerHeight(); 216 $(this) 217 .css({'line-height': lineheight + 'px', 'height': lineheight}); 218 219 //Hide uls under lis and reset expand/collapse buttons 220 $(settings.parentElement + ((settings.headersOnlyCheck) ? ' ' : '.has-subnav > ') + settings.childElement, container) 221 .css('display', 'none'); 222 $('.accordion-expanded') 223 .css('display', 'none'); 224 $('.accordion-collapsed') 225 .css('display', 'inline-block'); 226 }) 227 } 228 229 //Debounce function 230 function debounce(func, wait, immediate) { 231 var timeout; 232 return function() { 233 var context = this, args = arguments; 234 var later = function() { 235 timeout = null; 236 if (!immediate) func.apply(context, args); 237 }; 238 var callNow = immediate && !timeout; 239 clearTimeout(timeout); 240 timeout = setTimeout(later, wait); 241 if (callNow) func.apply(context, args); 242 }; 243 }; 244 245 246 }); 247 } 248})(jQuery);
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.