/* * jquery superfish menu plugin - v1.7.4 * copyright (c) 2013 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 ($) { "use strict"; var methods = (function () { // private properties and methods go here var c = { bcclass: 'sf-breadcrumb', menuclass: 'sf-js-enabled', anchorclass: 'sf-with-ul', menuarrowclass: 'sf-arrows' }, ios = (function () { var ios = /iphone|ipad|ipod/i.test(navigator.useragent); if (ios) { // ios clicks only bubble as far as body children $(window).load(function () { $('body').children().on('click', $.noop); }); } return ios; })(), wp7 = (function () { var style = document.documentelement.style; return ('behavior' in style && 'fill' in style && /iemobile/i.test(navigator.useragent)); })(), togglemenuclasses = function ($menu, o) { var classes = c.menuclass; if (o.cssarrows) { classes += ' ' + c.menuarrowclass; } $menu.toggleclass(classes); }, setpathtocurrent = function ($menu, o) { return $menu.find('li.' + o.pathclass).slice(0, o.pathlevels) .addclass(o.hoverclass + ' ' + c.bcclass) .filter(function () { return ($(this).children(o.popupselector).hide().show().length); }).removeclass(o.pathclass); }, toggleanchorclass = function ($li) { $li.children('a').toggleclass(c.anchorclass); }, toggletouchaction = function ($menu) { var touchaction = $menu.css('ms-touch-action'); touchaction = (touchaction === 'pan-y') ? 'auto' : 'pan-y'; $menu.css('ms-touch-action', touchaction); }, applyhandlers = function ($menu, o) { var targets = 'li:has(' + o.popupselector + ')'; if ($.fn.hoverintent && !o.disablehi) { $menu.hoverintent(over, out, targets); } else { $menu .on('mouseenter.superfish', targets, over) .on('mouseleave.superfish', targets, out); } var touchevent = 'mspointerdown.superfish'; if (!ios) { touchevent += ' touchend.superfish'; } if (wp7) { touchevent += ' mousedown.superfish'; } $menu .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') { $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 { // public methods hide: function (instant) { if (this.length) { var $this = this, o = getoptions($this); if (!o) { return this; } var not = (o.retainpath === true) ? o.$path : '', $ul = $this.find('li.' + o.hoverclass).add(this).not(not).removeclass(o.hoverclass).children(o.popupselector), speed = o.speedout; if (instant) { $ul.show(); speed = 0; } o.retainpath = false; o.onbeforehide.call($ul); $ul.stop(true, true).animate(o.animationout, speed, function () { var $this = $(this); o.onhide.call($this); }); } return this; }, show: function () { var o = getoptions(this); if (!o) { return this; } var $this = this.addclass(o.hoverclass), $ul = $this.children(o.popupselector); o.onbeforeshow.call($ul); $ul.stop(true, true).animate(o.animation, o.speed, function () { o.onshow.call($ul); }); return this; }, destroy: function () { return this.each(function () { var $this = $(this), o = $this.data('sf-options'), $haspopup; if (!o) { return false; } $haspopup = $this.find(o.popupselector).parent('li'); cleartimeout(o.sftimer); togglemenuclasses($this, o); toggleanchorclass($haspopup); toggletouchaction($this); // remove event handlers $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, ''); }); // 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'); }); }, init: function (op) { return this.each(function () { var $this = $(this); if ($this.data('sf-options')) { 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); togglemenuclasses($this, o); toggleanchorclass($haspopup); toggletouchaction($this); applyhandlers($this, o); $haspopup.not('.' + c.bcclass).superfish('hide', true); o.oninit.call(this); }); } }; })(); $.fn.superfish = function (method, args) { if (methods[method]) { return methods[method].apply(this, array.prototype.slice.call(arguments, 1)); } else if (typeof method === 'object' || ! method) { return methods.init.apply(this, arguments); } else { return $.error('method ' + method + ' does not exist on jquery.fn.superfish'); } }; $.fn.superfish.defaults = { popupselector: 'ul,.sf-mega', // within menu context hoverclass: 'sfhover', pathclass: 'overridethistouse', pathlevels: 1, delay: 800, animation: {opacity: 'show'}, animationout: {opacity: 'hide'}, speed: 'normal', speedout: 'fast', cssarrows: true, disablehi: false, oninit: $.noop, onbeforeshow: $.noop, onshow: $.noop, onbeforehide: $.noop, onhide: $.noop, onidle: $.noop, ondestroy: $.noop }; // soon to be deprecated $.fn.extend({ hidesuperfishul: methods.hide, showsuperfishul: methods.show }); })(jquery);