Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Created October 5, 2018 09:51
Show Gist options
  • Save GaryJones/420823e683653c0773f4cf8a59edfb46 to your computer and use it in GitHub Desktop.
Save GaryJones/420823e683653c0773f4cf8a59edfb46 to your computer and use it in GitHub Desktop.
--- /var/folders/5h/n5kgg5w13h77n1ffpd4hm2800000gn/T/rPo5nh_superfish.js 2018-10-05 10:50:58.000000000 +0100
+++ /Users/gary/Local Sites/genesis/app/public/wp-content/themes/genesis/lib/js/menu/superfish.js 2018-10-05 10:50:59.000000000 +0100
@@ -1,13 +1,13 @@
/*
- * jQuery Superfish Menu Plugin
- * Copyright (c) 2013 Joel Birch
+ * jQuery Superfish Menu Plugin - v1.7.10
+ * Copyright (c) 2018 Joel Birch
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
-(function ($, w) {
+;(function ($, w) {
"use strict";
var methods = (function () {
@@ -19,12 +19,10 @@
menuArrowClass: 'sf-arrows'
},
ios = (function () {
- var ios = /iPhone|iPad|iPod/i.test(navigator.userAgent);
+ var ios = /^(?![\w\W]*Windows Phone)[\w\W]*(iPhone|iPad|iPod)/i.test(navigator.userAgent);
if (ios) {
- // iOS clicks only bubble as far as body children
- $(w).load(function () {
- $('body').children().on('click', $.noop);
- });
+ // tap anywhere on iOS to unfocus a submenu
+ $('html').css('cursor', 'pointer').on('click', $.noop);
}
return ios;
})(),
@@ -35,12 +33,14 @@
unprefixedPointerEvents = (function () {
return (!!w.PointerEvent);
})(),
- toggleMenuClasses = function ($menu, o) {
- var classes = c.menuClass;
+ toggleMenuClasses = function ($menu, o, add) {
+ var classes = c.menuClass,
+ method;
if (o.cssArrows) {
classes += ' ' + c.menuArrowClass;
}
- $menu.toggleClass(classes);
+ method = (add) ? 'addClass' : 'removeClass';
+ $menu[method](classes);
},
setPathToCurrent = function ($menu, o) {
return $menu.find('li.' + o.pathClass).slice(0, o.pathLevels)
@@ -49,8 +49,9 @@
return ($(this).children(o.popUpSelector).hide().show().length);
}).removeClass(o.pathClass);
},
- toggleAnchorClass = function ($li) {
- $li.children('a').toggleClass(c.anchorClass);
+ toggleAnchorClass = function ($li, add) {
+ var method = (add) ? 'addClass' : 'removeClass';
+ $li.children('a')[method](c.anchorClass);
},
toggleTouchAction = function ($menu) {
var msTouchAction = $menu.css('ms-touch-action');
@@ -62,6 +63,58 @@
'touch-action': touchAction
});
},
+ getMenu = function ($el) {
+ return $el.closest('.' + c.menuClass);
+ },
+ getOptions = function ($el) {
+ return getMenu($el).data('sfOptions');
+ },
+ over = function () {
+ var $this = $(this),
+ o = getOptions($this);
+ clearTimeout(o.sfTimer);
+ $this.siblings().superfish('hide').end().superfish('show');
+ },
+ close = function (o) {
+ o.retainPath = ($.inArray(this[0], o.$path) > -1);
+ this.superfish('hide');
+
+ if (!this.parents('.' + o.hoverClass).length) {
+ o.onIdle.call(getMenu(this));
+ if (o.$path.length) {
+ $.proxy(over, o.$path)();
+ }
+ }
+ },
+ out = function () {
+ var $this = $(this),
+ o = getOptions($this);
+ if (ios) {
+ $.proxy(close, $this, o)();
+ }
+ else {
+ clearTimeout(o.sfTimer);
+ o.sfTimer = setTimeout($.proxy(close, $this, o), o.delay);
+ }
+ },
+ touchHandler = function (e) {
+ var $this = $(this),
+ o = getOptions($this),
+ $ul = $this.siblings(e.data.popUpSelector);
+
+ if (o.onHandleTouch.call($ul) === false) {
+ return this;
+ }
+
+ if ($ul.length > 0 && $ul.is(':hidden')) {
+ $this.one('click.superfish', false);
+ if (e.type === 'MSPointerDown' || e.type === 'pointerdown') {
+ $this.trigger('focus');
+ } else {
+ $.proxy(over, $this.parent('li'))();
+ }
+ }
+ },
applyHandlers = function ($menu, o) {
var targets = 'li:has(' + o.popUpSelector + ')';
if ($.fn.hoverIntent && !o.disableHI) {
@@ -86,53 +139,6 @@
.on('focusin.superfish', 'li', over)
.on('focusout.superfish', 'li', out)
.on(touchevent, 'a', o, touchHandler);
- },
- touchHandler = function (e) {
- var $this = $(this),
- $ul = $this.siblings(e.data.popUpSelector);
-
- if ($ul.length > 0 && $ul.is(':hidden')) {
- $this.one('click.superfish', false);
- if (e.type === 'MSPointerDown' || e.type === 'pointerdown') {
- $this.trigger('focus');
- } else {
- $.proxy(over, $this.parent('li'))();
- }
- }
- },
- over = function () {
- var $this = $(this),
- o = getOptions($this);
- clearTimeout(o.sfTimer);
- $this.siblings().superfish('hide').end().superfish('show');
- },
- out = function () {
- var $this = $(this),
- o = getOptions($this);
- if (ios) {
- $.proxy(close, $this, o)();
- }
- else {
- clearTimeout(o.sfTimer);
- o.sfTimer = setTimeout($.proxy(close, $this, o), o.delay);
- }
- },
- close = function (o) {
- o.retainPath = ($.inArray(this[0], o.$path) > -1);
- this.superfish('hide');
-
- if (!this.parents('.' + o.hoverClass).length) {
- o.onIdle.call(getMenu(this));
- if (o.$path.length) {
- $.proxy(over, o.$path)();
- }
- }
- },
- getMenu = function ($el) {
- return $el.closest('.' + c.menuClass);
- },
- getOptions = function ($el) {
- return getMenu($el).data('sf-options');
};
return {
@@ -153,7 +159,11 @@
speed = 0;
}
o.retainPath = false;
- o.onBeforeHide.call($ul);
+
+ if (o.onBeforeHide.call($ul) === false) {
+ return this;
+ }
+
$ul.stop(true, true).animate(o.animationOut, speed, function () {
var $this = $(this);
o.onHide.call($this);
@@ -169,7 +179,10 @@
var $this = this.addClass(o.hoverClass),
$ul = $this.children(o.popUpSelector);
- o.onBeforeShow.call($ul);
+ if (o.onBeforeShow.call($ul) === false) {
+ return this;
+ }
+
$ul.stop(true, true).animate(o.animation, o.speed, function () {
o.onShow.call($ul);
});
@@ -178,7 +191,7 @@
destroy: function () {
return this.each(function () {
var $this = $(this),
- o = $this.data('sf-options'),
+ o = $this.data('sfOptions'),
$hasPopUp;
if (!o) {
return false;
@@ -192,29 +205,31 @@
$this.off('.superfish').off('.hoverIntent');
// clear animation's inline display style
$hasPopUp.children(o.popUpSelector).attr('style', function (i, style) {
- return style.replace(/display[^;]+;?/g, '');
+ if (typeof style !== 'undefined') {
+ return style.replace(/display[^;]+;?/g, '');
+ }
});
// reset 'current' path classes
o.$path.removeClass(o.hoverClass + ' ' + c.bcClass).addClass(o.pathClass);
$this.find('.' + o.hoverClass).removeClass(o.hoverClass);
o.onDestroy.call($this);
- $this.removeData('sf-options');
+ $this.removeData('sfOptions');
});
},
init: function (op) {
return this.each(function () {
var $this = $(this);
- if ($this.data('sf-options')) {
+ if ($this.data('sfOptions')) {
return false;
}
var o = $.extend({}, $.fn.superfish.defaults, op),
$hasPopUp = $this.find(o.popUpSelector).parent('li');
o.$path = setPathToCurrent($this, o);
- $this.data('sf-options', o);
+ $this.data('sfOptions', o);
- toggleMenuClasses($this, o);
- toggleAnchorClass($hasPopUp);
+ toggleMenuClasses($this, o, true);
+ toggleAnchorClass($hasPopUp, true);
toggleTouchAction($this);
applyHandlers($this, o);
@@ -256,7 +271,8 @@
onBeforeHide: $.noop,
onHide: $.noop,
onIdle: $.noop,
- onDestroy: $.noop
+ onDestroy: $.noop,
+ onHandleTouch: $.noop
};
})(jQuery, window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment