PageSourceSearch

https://images.adoptapet.com/js/superfish.js

js adoptapet.com collected 2026-09-24 08:48:41 UTC 6,977 bytes, 257 lines download raw bytes

1/*
2 * jQuery Superfish Menu Plugin
3 * Copyright (c) 2013 Joel Birch
4 *
5 * Dual licensed under the MIT and GPL licenses:
6 *	https://www.opensource.org/licenses/mit-license.php
7 *	https://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				$ul.stop(true, true).animate(o.animation, o.speed, function () {
163					o.onShow.call($ul);
164				});
165				return this;
166			},
167			destroy: function () {
168				return this.each(function () {
169					var $this = $(this),
170						o = $this.data('sf-options'),
171						$hasPopUp;
172					if (!o) {
173						return false;
174					}
175					$hasPopUp = $this.find(o.popUpSelector).parent('li');
176					clearTimeout(o.sfTimer);
177					toggleMenuClasses($this, o);
178					toggleAnchorClass($hasPopUp);
179					toggleTouchAction($this);
180					// remove event handlers
181					$this.off('.superfish').off('.hoverIntent');
182					// clear animation's inline display style
183					$hasPopUp.children(o.popUpSelector).attr('style', function (i, style) {
184						return style.replace(/display[^;]+;?/g, '');
185					});
186					// reset 'current' path classes
187					o.$path.removeClass(o.hoverClass + ' ' + c.bcClass).addClass(o.pathClass);
188					$this.find('.' + o.hoverClass).removeClass(o.hoverClass);
189					o.onDestroy.call($this);
190					$this.removeData('sf-options');
191				});
192			},
193			init: function (op) {
194				return this.each(function () {
195					var $this = $(this);
196					if ($this.data('sf-options')) {
197						return false;
198					}
199					var o = $.extend({}, $.fn.superfish.defaults, op),
200						$hasPopUp = $this.find(o.popUpSelector).parent('li');
201					o.$path = setPathToCurrent($this, o);
202
203					$this.data('sf-options', o);
204
205					toggleMenuClasses($this, o);
206					toggleAnchorClass($hasPopUp);
207					toggleTouchAction($this);
208					applyHandlers($this, o);
209
210					$hasPopUp.not('.' + c.bcClass).superfish('hide', true);
211
212					o.onInit.call(this);
213				});
214			}
215		};
216	})();
217
218	$.fn.superfish = function (method, args) {
219		if (methods[method]) {
220			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
221		}
222		else if (typeof method === 'object' || ! method) {
223			return methods.init.apply(this, arguments);
224		}
225		else {
226			return $.error('Method ' +  method + ' does not exist on jQuery.fn.superfish');
227		}
228	};
229
230	$.fn.superfish.defaults = {
231		popUpSelector: 'ul,.sf-mega', // within menu context
232		hoverClass: 'sfHover',
233		pathClass: 'overrideThisToUse',
234		pathLevels: 1,
235		delay: 800,
236		animation: {opacity: 'show'},
237		animationOut: {opacity: 'hide'},
238		speed: 'normal',
239		speedOut: 'fast',
240		cssArrows: true,
241		disableHI: false,
242		onInit: $.noop,
243		onBeforeShow: $.noop,
244		onShow: $.noop,
245		onBeforeHide: $.noop,
246		onHide: $.noop,
247		onIdle: $.noop,
248		onDestroy: $.noop
249	};
250
251	// soon to be deprecated
252	$.fn.extend({
253		hideSuperfishUl: methods.hide,
254		showSuperfishUl: methods.show
255	});
256
257})(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.