javascript - Prestashop 1.6 superfish 菜单悬停点击

标签 javascript jquery prestashop prestashop-1.6 superfish

您好,我正在使用 presta 1.6,我想将子菜单的悬停更改为单击并仍然悬停在菜单(母菜单)中,但我尝试了很多次,但都成功导致了 superfish-modified.js 中的问题。 .任何人都可以提供帮助,谢谢

这是superfish-modified.js

<小时/>
(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);

最佳答案

菜单的默认值在 superfish-modified.js (/themes/default-bootstrap/js/modules/blocktopmenu/js/superfish-modified.js) 文件第 230 行左右定义。

hoverClass 也有一个默认值:

hoverClass: 'sfHover',

尝试将其替换为:

悬停类:'',

关于javascript - Prestashop 1.6 superfish 菜单悬停点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43466939/

相关文章:

.htaccess - Seo 301 绝对 URL 重定向,Prestashop

javascript - 如何向 prestashop 添加自定义代码

javascript - 在多个元素上使用 jquery 插件并稍加修改

javascript - 追加 child 不在 JavaScript 中工作

javascript - 当文本由外部源更新时,防止 ckeditor 触发设置回调

javascript - select2 ajax 不工作

javascript - Fotorama - 基于元素是否具有属性的不同标题

javascript - html帖子问题

javascript - jQuery.data() 版本兼容性和 HTML5 数据属性

javascript - Google 自定义搜索 - getElement 为 null - 无法访问 <gcse :. ..> 元素