1/* 2 * jQuery Superfish Menu Plugin 3 * Copyright (c) 2013 Joel Birch 4 * 5 * Dual licensed under the MIT and GPL licenses: 6 * http://www.opensource.org/licenses/mit-license.php 7 * http://www.gnu.org/licenses/gpl.html 8 */ 9 10(function ($) { 11 "use strict"; 12 13 var methods = (function () { 14 // private properties and methods go here 15 var c = { 16 bcClass: 'sf-breadcrumb', 17 menuClass: 'sf-js-enabled', 18 anchorClass: 'sf-with-ul', 19 menuArrowClass: 'sf-arrows' 20 }, 21 ios = (function () { 22 var ios = /iPhone|iPad|iPod/i.test(navigator.userAgent); 23 if (ios) { 24 // iOS clicks only bubble as far as body children 25 $(window).load(function () { 26 $('body').children().on('click', $.noop); 27 }); 28 } 29 return ios; 30 })(), 31 wp7 = (function () { 32 var style = document.documentElement.style; 33 return ('behavior' in style && 'fill' in style && /iemobile/i.test(navigator.userAgent)); 34 })(), 35 toggleMenuClasses = function ($menu, o) { 36 var classes = c.menuClass; 37 if (o.cssArrows) { 38 classes += ' ' + c.menuArrowClass; 39 } 40 $menu.toggleClass(classes); 41 }, 42 setPathToCurrent = function ($menu, o) { 43 return $menu.find('li.' + o.pathClass).slice(0, o.pathLevels) 44 .addClass(o.hoverClass + ' ' + c.bcClass) 45 .filter(function () { 46 return ($(this).children(o.popUpSelector).hide().show().length); 47 }).removeClass(o.pathClass); 48 }, 49 toggleAnchorClass = function ($li) { 50 $li.children('a').toggleClass(c.anchorClass); 51 }, 52 toggleTouchAction = function ($menu) { 53 var touchAction = $menu.css('ms-touch-action'); 54 touchAction = (touchAction === 'pan-y') ? 'auto' : 'pan-y'; 55 $menu.css('ms-touch-action', touchAction); 56 }, 57 applyHandlers = function ($menu, o) { 58 var targets = 'li:has(' + o.popUpSelector + ')'; 59 if ($.fn.hoverIntent && !o.disableHI) { 60 $menu.hoverIntent(over, out, targets); 61 } 62 else { 63 $menu 64 .on('mouseenter.superfish', targets, over) 65 .on('mouseleave.superfish', targets, out); 66 } 67 var touchevent = 'MSPointerDown.superfish'; 68 if (!ios) { 69 touchevent += ' touchend.superfish'; 70 } 71 if (wp7) { 72 touchevent += ' mousedown.superfish'; 73 } 74 $menu 75 .on('focusin.superfish', 'li', over) 76 .on('focusout.superfish', 'li', out) 77 .on(touchevent, 'a', o, touchHandler); 78 }, 79 touchHandler = function (e) { 80 var $this = $(this), 81 $ul = $this.siblings(e.data.popUpSelector); 82 83 if ($ul.length > 0 && $ul.is(':hidden')) { 84 $this.one('click.superfish', false); 85 if (e.type === 'MSPointerDown') { 86 $this.trigger('focus'); 87 } else { 88 $.proxy(over, $this.parent('li'))(); 89 } 90 } 91 }, 92 over = function () { 93 var $this = $(this), 94 o = getOptions($this); 95 clearTimeout(o.sfTimer); 96 $this.siblings().superfish('hide').end().superfish('show'); 97 }, 98 out = function () { 99 var $this = $(this), 100 o = getOptions($this); 101 if (ios) { 102 $.proxy(close, $this, o)(); 103 } 104 else { 105 clearTimeout(o.sfTimer); 106 o.sfTimer = setTimeout($.proxy(close, $this, o), o.delay); 107 } 108 }, 109 close = function (o) { 110 o.retainPath = ($.inArray(this[0], o.$path) > -1); 111 this.superfish('hide'); 112 113 if (!this.parents('.' + o.hoverClass).length) { 114 o.onIdle.call(getMenu(this)); 115 if (o.$path.length) { 116 $.proxy(over, o.$path)(); 117 } 118 } 119 }, 120 getMenu = function ($el) { 121 return $el.closest('.' + c.menuClass); 122 }, 123 getOptions = function ($el) { 124 return getMenu($el).data('sf-options'); 125 }; 126 127 return { 128 // public methods 129 hide: function (instant) { 130 if (this.length) { 131 var $this = this, 132 o = getOptions($this); 133 if (!o) { 134 return this; 135 } 136 var not = (o.retainPath === true) ? o.$path : '', 137 $ul = $this.find('li.' + o.hoverClass).add(this).not(not).removeClass(o.hoverClass).children(o.popUpSelector), 138 speed = o.speedOut; 139 140 if (instant) { 141 $ul.show(); 142 speed = 0; 143 } 144 o.retainPath = false; 145 o.onBeforeHide.call($ul); 146 147 // gdlr modify 148 var gdlr_input = false;
149 $(this).find('input:focus').each(function(){ gdlr_input = true; }); 150 if(gdlr_input) return $(this); 151 152 $ul.stop(true, true).animate(o.animationOut, speed, function () { 153 var $this = $(this); 154 o.onHide.call($this); 155 }); 156 } 157 return this; 158 }, 159 show: function () { 160 var o = getOptions(this); 161 if (!o) { 162 return this; 163 } 164 var $this = this.addClass(o.hoverClass), 165 $ul = $this.children(o.popUpSelector); 166 167 o.onBeforeShow.call($ul); 168 $ul.stop(true, true).animate(o.animation, o.speed, function () { 169 o.onShow.call($ul); 170 }); 171 return this; 172 }, 173 destroy: function () { 174 return this.each(function () { 175 var $this = $(this), 176 o = $this.data('sf-options'), 177 $hasPopUp; 178 if (!o) { 179 return false; 180 } 181 $hasPopUp = $this.find(o.popUpSelector).parent('li'); 182 clearTimeout(o.sfTimer); 183 toggleMenuClasses($this, o); 184 toggleAnchorClass($hasPopUp); 185 toggleTouchAction($this); 186 // remove event handlers 187 $this.off('.superfish').off('.hoverIntent'); 188 // clear animation's inline display style 189 $hasPopUp.children(o.popUpSelector).attr('style', function (i, style) { 190 return style.replace(/display[^;]+;?/g, ''); 191 }); 192 // reset 'current' path classes 193 o.$path.removeClass(o.hoverClass + ' ' + c.bcClass).addClass(o.pathClass); 194 $this.find('.' + o.hoverClass).removeClass(o.hoverClass); 195 o.onDestroy.call($this); 196 $this.removeData('sf-options'); 197 }); 198 }, 199 init: function (op) { 200 return this.each(function () { 201 var $this = $(this); 202 if ($this.data('sf-options')) { 203 return false; 204 } 205 var o = $.extend({}, $.fn.superfish.defaults, op), 206 $hasPopUp = $this.find(o.popUpSelector).parent('li'); 207 o.$path = setPathToCurrent($this, o); 208 209 $this.data('sf-options', o); 210 211 toggleMenuClasses($this, o); 212 toggleAnchorClass($hasPopUp); 213 toggleTouchAction($this); 214 applyHandlers($this, o); 215 216 $hasPopUp.not('.' + c.bcClass).superfish('hide', true); 217 218 o.onInit.call(this); 219 }); 220 } 221 }; 222 })(); 223 224 $.fn.superfish = function (method, args) { 225 if (methods[method]) { 226 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 227 } 228 else if (typeof method === 'object' || ! method) { 229 return methods.init.apply(this, arguments); 230 } 231 else { 232 return $.error('Method ' + method + ' does not exist on jQuery.fn.superfish'); 233 } 234 }; 235 236 $.fn.superfish.defaults = { 237 popUpSelector: 'ul,.sf-mega', // within menu context 238 hoverClass: 'sfHover', 239 pathClass: 'overrideThisToUse', 240 pathLevels: 1, 241 delay: 800, 242 animation: {opacity: 'show'}, 243 animationOut: {opacity: 'hide'}, 244 speed: 'normal', 245 speedOut: 'fast', 246 cssArrows: true, 247 disableHI: false, 248 onInit: $.noop, 249 onBeforeShow: $.noop, 250 onShow: $.noop, 251 onBeforeHide: $.noop, 252 onHide: $.noop, 253 onIdle: $.noop, 254 onDestroy: $.noop 255 }; 256 257 // soon to be deprecated 258 $.fn.extend({ 259 hideSuperfishUl: methods.hide, 260 showSuperfishUl: methods.show 261 }); 262 263})(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.