1/* 2FlexNav.js 1.2 3 4Created by Jason Weaver http://jasonweaver.name 5Released under http://unlicense.org/ 6 7// 8*/ 9 10(function() { 11 var $; 12 13 $ = jQuery; 14 15 $.fn.flexNav = function(options) { 16 var $nav, breakpoint, resetMenu, resizer, selector, settings, showMenu, checkPath; 17 settings = $.extend({ 18 'animationSpeed': 250, 19 'transitionOpacity': true, 20 'buttonSelector': '.menu-button', 21 'branchCls': 'item-with-ul', 22 'hoverIntent': false, 23 'toggleIcon': '▼', 24 'hoverIntentTimeout': 150, 25 'activeSelector': '', 26 'maxWidth': 1000000, 27 'openActive': false, 28 'openActiveSub': false, 29 'pathNode': false, 30 'noDropDown': false, 31 'ignoreFocus': false, 32 'activeAlwaysVisible': false 33 }, options); 34 35 var me = this[0]; 36 37 $nav = $(this); 38 39 $nav.addClass('with-js'); 40 if (settings.transitionOpacity === true) { 41 $nav.addClass('opacity'); 42 } 43 $nav.find("li").each(function() { 44 if ($(this).has("ul.dropdown").length) { 45 return $(this).addClass(settings.branchCls).find("ul.dropdown").hide(); 46 } 47 }); 48 49 //Aktuellen Pfad oeffnen 50 if (settings.openActive == true) { 51 $nav.addClass('show-active'); 52 $nav.pathNode = $(settings.activeSelector+':last', this); 53 $nav.touchButton = $('.touch-button', $nav); 54 var pNodes = $nav.pathNode.parentsUntil($nav, 'ul.dropdown').get(); 55 $nav.allPathNodes = pNodes; 56 $(pNodes).addClass('show').show(); 57 $nav.pathNode.parentsUntil($nav, 'span.touch-button').addClass('active'); 58 $nav.touchButton.addClass('active'); 59 } 60 61 if (settings.openActiveSub) { 62 var activeSub = $(settings.activeSelector+':last ul.dropdown:first', this).get(0); 63 if (activeSub) { 64 $(activeSub).addClass('show').show(); 65 $nav.allPathNodes.push(activeSub); 66 } 67 } 68 69 70 if ($nav.data('breakpoint')) { 71 breakpoint = $nav.data('breakpoint'); 72 } 73 showMenu = function() { 74 if ($nav.hasClass('lg-screen') === true) { 75 if (settings.transitionOpacity === true) { 76 return $(this).find('>ul.dropdown').addClass('show').stop(true, true).animate({ 77 height: ["toggle", "swing"], 78 opacity: "toggle" 79 }, settings.animationSpeed); 80 } else { 81 return $(this).find('>ul.dropdown').addClass('show').stop(true, true).animate({ 82 height: ["toggle", "swing"] 83 }, settings.animationSpeed); 84 } 85 } 86 }; 87 resetMenu = function() { 88 if ($nav.hasClass('lg-screen') === true && $(this).find('>ul.dropdown').hasClass('show') === true) { 89 if (settings.transitionOpacity === true) { 90 return $(this).find('>ul.dropdown').removeClass('show').stop(true, true).animate({ 91 height: ["toggle", "swing"], 92 opacity: "toggle" 93 }, settings.animationSpeed); 94 } else { 95 return $(this).find('>ul.dropdown').removeClass('show').stop(true, true).animate({ 96 height: ["toggle", "swing"] 97 }, settings.animationSpeed); 98 } 99 } 100 }; 101 resizer = function() { 102 if ($(window).width() <= breakpoint) { 103 $nav.removeClass("lg-screen").addClass("sm-screen"); 104 return $('.one-page li a').on('click', function() { 105 return $nav.removeClass('show'); 106 }); 107 } else if ($(window).width() > breakpoint) { 108 $nav.removeClass("sm-screen").addClass("lg-screen"); 109 $nav.removeClass('show'); 110 if (settings.noDropDown) return; 111 if (settings.hoverIntent === true) { 112 return $('.'+settings.branchCls).hoverIntent({ 113 over: showMenu, 114 out: resetMenu, 115 timeout: settings.hoverIntentTimeout 116 }); 117 } else if (settings.hoverIntent === false) { 118 return $('.'+settings.branchCls).on('mouseenter', showMenu).on('mouseleave', resetMenu); 119 } 120 } 121 }; 122 123 checkPath = function(nav, sub, $touchButton) { 124 if (!nav.hasClass('show-active') || !nav.pathNode) 125 return false; 126 127 var pNodes = nav.pathNode.parentsUntil(nav, 'ul.dropdown').get(), 128 isRoot = nav == sub, 129 hit = 0; 130 131 nav.pathNode = false; 132 nav.removeClass('show-active'); 133 nav.addClass('show').show(); 134 135 if (isRoot) { 136 $(pNodes).removeClass('show').hide(); 137 $(pNodes[pNodes.length-1]).addClass('show').show(); 138 } else { 139 pNodes.reverse(); 140 sub = sub[0] || sub; 141 for (var i=0; i < pNodes.length; i++) { 142 $(pNodes[i])[hit ? 'remove' : 'add'+'Class']('show')[hit ? 'hide' : 'show'](); 143 if (sub == pNodes[i]) hit = 1; 144 } 145 146 if (!hit) { 147 if ($(sub).hasClass('show') === true) {
148 $(sub).removeClass('show').slideUp(settings.animationSpeed); 149 $touchButton.removeClass('active'); 150 } else if ($(sub).hasClass('show') === false) { 151 $(sub).addClass('show').slideDown(settings.animationSpeed); 152 $touchButton.addClass('active'); 153 } 154 } 155 156 //hit || $(sub).addClass('show').show(); 157 } 158 return true; 159 }; 160 161 $(settings['buttonSelector']).data('navEl', $nav); 162 selector = '.'+settings.branchCls+', ' + settings['buttonSelector']; 163 $(selector).append('<span class="touch-button"><i class="fa-sort-down">'+settings.toggleIcon+'</i></span>'); 164 $('ul.show '+settings.activeSelector+' > span.touch-button', $nav).addClass('active'); 165 selector = settings['buttonSelector'] + ', ' + settings['buttonSelector'] + ' .touch-button'; 166 $(selector).on('click', function(e) { 167 var $btnParent, $thisNav, bs; 168 e.preventDefault(); 169 e.stopPropagation(); 170 bs = settings['buttonSelector']; 171 $btnParent = $(this).is(bs) ? $(this) : $(this).parent(bs); 172 $thisNav = $btnParent.data('navEl'); 173 return (checkPath($thisNav, $thisNav) == true) ? $thisNav.addClass('show') : $thisNav.toggleClass('show'); 174 }); 175 176 $('.touch-button', $nav).on('click', function(e) { 177 var $sub, $touchButton; 178 $sub = $(this).parent('.'+settings.branchCls).find('>ul.dropdown'); 179 $touchButton = $(this).parent('.'+settings.branchCls).find('>span.touch-button'); 180 if (checkPath($nav, $sub, $touchButton) === true) { 181 return $touchButton; 182 } 183 184 if ($nav.hasClass('lg-screen') === true) { 185 186 if (settings.activeAlwaysVisible === true) { 187 var tempNodes = $(this).parent('.'+settings.branchCls).siblings().find('ul.dropdown.show').get(); 188 for (var i=0; i < tempNodes.length; i++) { 189 if ($.inArray(tempNodes[i], $nav.allPathNodes) == -1) { 190 $(tempNodes[i]).removeClass('show').hide(); 191 } 192 } 193 } else { 194 $(this).parent('.'+settings.branchCls).siblings().find('ul.dropdown.show').removeClass('show').hide(); 195 } 196 } 197 if ($sub.hasClass('show') === true) { 198 $sub.removeClass('show').slideUp(settings.animationSpeed); 199 return $touchButton.removeClass('active'); 200 } else if ($sub.hasClass('show') === false) { 201 $sub.addClass('show').slideDown(settings.animationSpeed); 202 return $touchButton.addClass('active'); 203 } 204 }); 205 206 if (settings.ignoreFocus !== true) { 207 $nav.find('.'+settings.branchCls+' *').focus(function() { 208 $(this).parent('.'+settings.branchCls).parent().find(".open").not(this).removeClass("open").hide(); 209 return $(this).parent('.'+settings.branchCls).find('>ul.dropdown').addClass("open").show(); 210 }); 211 } 212 213 resizer(); 214 return $(window).on('resize', resizer); 215 }; 216}).call(this);
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.