1/* 2 * jQuery Superfish Menu Plugin - v1.7.4 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 $ul.stop(true, true).animate(o.animationOut, speed, function () { 147 var $this = $(this); 148 o.onHide.call($this); 149 }); 150 } 151 return this; 152 }, 153 show: function () { 154 var o = getOptions(this); 155 if (!o) { 156 return this; 157 } 158 var $this = this.addClass(o.hoverClass), 159 $ul = $this.children(o.popUpSelector); 160 161 o.onBeforeShow.call($ul); 162 163 164 //make sure the ul has space 165 if(!$($ul).parents('li').hasClass('megamenu') && !$($ul).parents('ul').hasClass('sub-menu') && $ul.offset()) { 166 167 $ul.addClass('temp-hidden-display'); 168 var docW = $("#top .container").width(); 169 var elm = $ul; 170 var off = elm.offset(); 171 var l = off.left - ($(window).width() - docW)/2; 172 var w = elm.width(); 173 var isEntirelyVisible = (l+w <= $(window).width()-100); 174 175 if ( ! isEntirelyVisible ) { 176 $ul.parents('li').addClass('edge'); 177 } else { 178 $ul.parents('li').removeClass('edge'); 179 } 180 $ul.removeClass('temp-hidden-display'); 181 182 } 183 184 185 $ul.stop(true, true).animate(o.animation, o.speed, function () { 186 o.onShow.call($ul); 187 }); 188 return this; 189 }, 190 destroy: function () { 191 return this.each(function () { 192 var $this = $(this), 193 o = $this.data('sf-options'), 194 $hasPopUp; 195 if (!o) { 196 return false;
197 } 198 $hasPopUp = $this.find(o.popUpSelector).parent('li'); 199 clearTimeout(o.sfTimer); 200 toggleMenuClasses($this, o); 201 toggleAnchorClass($hasPopUp); 202 toggleTouchAction($this); 203 // remove event handlers 204 $this.off('.superfish').off('.hoverIntent'); 205 // clear animation's inline display style 206 $hasPopUp.children(o.popUpSelector).attr('style', function (i, style) { 207 return style.replace(/display[^;]+;?/g, ''); 208 }); 209 // reset 'current' path classes 210 o.$path.removeClass(o.hoverClass + ' ' + c.bcClass).addClass(o.pathClass); 211 $this.find('.' + o.hoverClass).removeClass(o.hoverClass); 212 o.onDestroy.call($this); 213 $this.removeData('sf-options'); 214 }); 215 }, 216 init: function (op) { 217 return this.each(function () { 218 var $this = $(this); 219 if ($this.data('sf-options')) { 220 return false; 221 } 222 var o = $.extend({}, $.fn.superfish.defaults, op), 223 $hasPopUp = $this.find(o.popUpSelector).parent('li'); 224 o.$path = setPathToCurrent($this, o); 225 226 $this.data('sf-options', o); 227 228 toggleMenuClasses($this, o); 229 toggleAnchorClass($hasPopUp); 230 toggleTouchAction($this); 231 applyHandlers($this, o); 232 233 $hasPopUp.not('.' + c.bcClass).superfish('hide', true); 234 235 o.onInit.call(this); 236 }); 237 } 238 }; 239 })(); 240 241 $.fn.superfish = function (method, args) { 242 if (methods[method]) { 243 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 244 } 245 else if (typeof method === 'object' || ! method) { 246 return methods.init.apply(this, arguments); 247 } 248 else { 249 return $.error('Method ' + method + ' does not exist on jQuery.fn.superfish'); 250 } 251 }; 252 253 $.fn.superfish.defaults = { 254 popUpSelector: 'ul,.sf-mega', // within menu context 255 hoverClass: 'sfHover', 256 pathClass: 'overrideThisToUse', 257 pathLevels: 1, 258 delay: 800, 259 animation: {opacity: 'show'}, 260 animationOut: {opacity: 'hide'}, 261 speed: 'normal', 262 speedOut: 'fast', 263 cssArrows: true, 264 disableHI: false, 265 onInit: $.noop, 266 onBeforeShow: $.noop, 267 onShow: $.noop, 268 onBeforeHide: $.noop, 269 onHide: $.noop, 270 onIdle: $.noop, 271 onDestroy: $.noop 272 }; 273 274 // soon to be deprecated 275 $.fn.extend({ 276 hideSuperfishUl: methods.hide, 277 showSuperfishUl: methods.show 278 }); 279 280})(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.