1/* 2 * jQuery Superfish Menu Plugin - v1.7.5 3 * Copyright (c) 2014 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 ($, w) { 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 $(w).on('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 unprefixedPointerEvents = (function () { 36 return (!!w.PointerEvent); 37 })(), 38 toggleMenuClasses = function ($menu, o) { 39 var classes = c.menuClass; 40 if (o.cssArrows) { 41 classes += ' ' + c.menuArrowClass; 42 } 43 $menu.toggleClass(classes); 44 }, 45 setPathToCurrent = function ($menu, o) { 46 return $menu.find('li.' + o.pathClass).slice(0, o.pathLevels) 47 .addClass(o.hoverClass + ' ' + c.bcClass) 48 .filter(function () { 49 return ($(this).children(o.popUpSelector).hide().show().length); 50 }).removeClass(o.pathClass); 51 }, 52 toggleAnchorClass = function ($li) { 53 $li.children('a').toggleClass(c.anchorClass); 54 }, 55 toggleTouchAction = function ($menu) { 56 var msTouchAction = $menu.css('ms-touch-action'); 57 var touchAction = $menu.css('touch-action'); 58 touchAction = touchAction || msTouchAction; 59 touchAction = (touchAction === 'pan-y') ? 'auto' : 'pan-y'; 60 $menu.css({ 61 'ms-touch-action': touchAction, 62 'touch-action': touchAction 63 }); 64 }, 65 applyHandlers = function ($menu, o) { 66 var targets = 'li:has(' + o.popUpSelector + ')'; 67 if ($.fn.hoverIntent && !o.disableHI) { 68 $menu.hoverIntent(over, out, targets); 69 } 70 else { 71 $menu 72 .on('mouseenter.superfish', targets, over) 73 .on('mouseleave.superfish', targets, out); 74 } 75 var touchevent = 'MSPointerDown.superfish'; 76 if (unprefixedPointerEvents) { 77 touchevent = 'pointerdown.superfish'; 78 } 79 if (!ios) { 80 touchevent += ' touchend.superfish'; 81 } 82 if (wp7) { 83 touchevent += ' mousedown.superfish'; 84 } 85 $menu 86 .on('focusin.superfish', 'li', over) 87 .on('focusout.superfish', 'li', out) 88 .on(touchevent, 'a', o, touchHandler); 89 }, 90 touchHandler = function (e) { 91 var $this = $(this), 92 $ul = $this.siblings(e.data.popUpSelector); 93 94 if ($ul.length > 0 && $ul.is(':hidden')) { 95 $this.one('click.superfish', false); 96 if (e.type === 'MSPointerDown' || e.type === 'pointerdown') { 97 $this.trigger('focus'); 98 } else { 99 $.proxy(over, $this.parent('li'))(); 100 } 101 } 102 }, 103 over = function () { 104 var $this = $(this), 105 o = getOptions($this); 106 clearTimeout(o.sfTimer); 107 $this.siblings().superfish('hide').end().superfish('show'); 108 }, 109 out = function () { 110 var $this = $(this), 111 o = getOptions($this); 112 if (ios) { 113 $.proxy(close, $this, o)(); 114 } 115 else { 116 clearTimeout(o.sfTimer); 117 o.sfTimer = setTimeout($.proxy(close, $this, o), o.delay); 118 } 119 }, 120 close = function (o) { 121 o.retainPath = ($.inArray(this[0], o.$path) > -1); 122 this.superfish('hide'); 123 124 if (!this.parents('.' + o.hoverClass).length) { 125 o.onIdle.call(getMenu(this)); 126 if (o.$path.length) { 127 $.proxy(over, o.$path)(); 128 } 129 } 130 }, 131 getMenu = function ($el) { 132 return $el.closest('.' + c.menuClass); 133 }, 134 getOptions = function ($el) { 135 return getMenu($el).data('sf-options'); 136 }; 137 138 return { 139 // public methods 140 hide: function (instant) { 141 if (this.length) { 142 var $this = this, 143 o = getOptions($this); 144 if (!o) { 145 return this; 146 } 147 var not = (o.retainPath === true) ? o.$path : '', 148 $ul = $this.find('li.' + o.hoverClass).add(this).not(not).removeClass(o.hoverClass).children(o.popUpSelector), 149 speed = o.speedOut; 150 151 if (instant) { 152 $ul.show(); 153 speed = 0; 154 } 155 o.retainPath = false;
156 o.onBeforeHide.call($ul); 157 $ul.stop(true, true).animate(o.animationOut, speed, function () { 158 var $this = $(this); 159 o.onHide.call($this); 160 }); 161 } 162 return this; 163 }, 164 show: function () { 165 var o = getOptions(this); 166 if (!o) { 167 return this; 168 } 169 var $this = this.addClass(o.hoverClass), 170 $ul = $this.children(o.popUpSelector); 171 172 o.onBeforeShow.call($ul); 173 $ul.stop(true, true).animate(o.animation, o.speed, function () { 174 o.onShow.call($ul); 175 }); 176 177 // ================================================================================== 178 // MEGAFIX 179 // ================================================================================== 180 var subUL = this.children('ul').first(); 181 182 if( subUL.length ){ 183 184 var winWidth = $(window).width(), 185 locUL = subUL.offset().left + subUL.width(); 186 187 if ( ( locUL > winWidth || subUL.parent().parent().hasClass('on-viewport') ) ) { 188 var parent = subUL.parent().parent(); 189 if ( parent.hasClass('sf-menu') ) { 190 subUL.css('left', '-' + ( locUL - winWidth ) + 'px'); 191 } else { 192 subUL.addClass('on-viewport'); 193 subUL.css('left', '-' + ( subUL.width() ) + 'px'); 194 } 195 } 196 197 } 198 // ================================================================================== 199 200 return this; 201 }, 202 destroy: function () { 203 return this.each(function () { 204 var $this = $(this), 205 o = $this.data('sf-options'), 206 $hasPopUp; 207 if (!o) { 208 return false; 209 } 210 $hasPopUp = $this.find(o.popUpSelector).parent('li'); 211 clearTimeout(o.sfTimer); 212 toggleMenuClasses($this, o); 213 toggleAnchorClass($hasPopUp); 214 toggleTouchAction($this); 215 // remove event handlers 216 $this.off('.superfish').off('.hoverIntent'); 217 // clear animation's inline display style 218 $hasPopUp.children(o.popUpSelector).attr('style', function (i, style) { 219 return style.replace(/display[^;]+;?/g, ''); 220 }); 221 // reset 'current' path classes 222 o.$path.removeClass(o.hoverClass + ' ' + c.bcClass).addClass(o.pathClass); 223 $this.find('.' + o.hoverClass).removeClass(o.hoverClass); 224 o.onDestroy.call($this); 225 $this.removeData('sf-options'); 226 }); 227 }, 228 init: function (op) { 229 return this.each(function () { 230 var $this = $(this); 231 if ($this.data('sf-options')) { 232 return false; 233 } 234 var o = $.extend({}, $.fn.superfish.defaults, op), 235 $hasPopUp = $this.find(o.popUpSelector).parent('li'); 236 o.$path = setPathToCurrent($this, o); 237 238 $this.data('sf-options', o); 239 240 toggleMenuClasses($this, o); 241 toggleAnchorClass($hasPopUp); 242 toggleTouchAction($this); 243 applyHandlers($this, o); 244 245 $hasPopUp.not('.' + c.bcClass).superfish('hide', true); 246 247 o.onInit.call(this); 248 }); 249 } 250 }; 251 })(); 252 253 $.fn.superfish = function (method, args) { 254 if (methods[method]) { 255 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 256 } 257 else if (typeof method === 'object' || ! method) { 258 return methods.init.apply(this, arguments); 259 } 260 else { 261 return $.error('Method ' + method + ' does not exist on jQuery.fn.superfish'); 262 } 263 }; 264 265 $.fn.superfish.defaults = { 266 popUpSelector: 'ul,.sf-mega', // within menu context 267 hoverClass: 'sfHover', 268 pathClass: 'overrideThisToUse', 269 pathLevels: 1, 270 delay: 800, 271 animation: {opacity: 'show'}, 272 animationOut: {opacity: 'hide'}, 273 speed: 'normal', 274 speedOut: 'fast', 275 cssArrows: true, 276 disableHI: false, 277 onInit: $.noop, 278 onBeforeShow: $.noop, 279 onShow: $.noop, 280 onBeforeHide: $.noop, 281 onHide: $.noop, 282 onIdle: $.noop, 283 onDestroy: $.noop 284 }; 285 286})(jQuery, window);
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.