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