简体   繁体   English

Magento Jquery Bootstrap和原型冲突? 导航选项卡不起作用

[英]Magento Jquery Bootstrap and Prototype conflict? nav-tabs dont work

I use Magento 1.9.2.4 and the following Theme 我使用Magento 1.9.2.4和以下主题

https://github.com/webcomm/magento-boilerplate https://github.com/webcomm/magento-boilerplate

The description of it is "HTML5 Twitter Bootstrap 3.1 Magento Boilerplate Template" 它的描述为“ HTML5 Twitter Bootstrap 3.1 Magento Boilerplate模板”

It works fine with everything else of "Bootstrap responsive". 它与“ Bootstrap响应式”其他所有功能均正常工作。 My problem is, that all of the following on this Site did not work on my Installation: 我的问题是,此站点上的以下所有内容都无法在我的安装中正常工作:

http://www.w3schools.com/bootstrap/bootstrap_tabs_pills.asp http://www.w3schools.com/bootstrap/bootstrap_tabs_pills.asp

And "did not work" means you can click on next tab but the border and highlighting and so on is still on the first tab. “没有工作”表示您可以单击下一个选项卡,但是边框和突出显示等仍在第一个选项卡上。

Same thing on "nav-pills" of Bootstrap. 在Bootstrap的“ nav-pills”上也是如此。

In this Boilerplate there is a Workaround for Bootstrap dropdown: 在此样板中,有一个Bootstrap下拉列表的解决方法:

jQuery.noConflict();
;(function ($) {
'use strict';

function Site(settings) {

    this.windowLoaded = false;

}

Site.prototype = {
    constructor: Site,

    start: function () {
        var me = this;

        $(window).load(function () {
            me.windowLoaded = true;
        });

        this.attach();
    },

    attach: function () {
        this.attachBootstrapPrototypeCompatibility();
        this.attachMedia();
    },

    attachBootstrapPrototypeCompatibility: function () {

        /*// Bootstrap and Prototype don't play nice, in the sense that
         // prototype is a really wacky horrible library. It'll
         // hard-code CSS to hide an element when a hide() event
         // is fired. See http://stackoverflow.com/q/19139063
         // To overcome this with dropdowns that are both
         // toggle style and hover style, we'll add a CSS
         // class which has "display: block !important"
         $('*').on('show.bs.dropdown show.bs.collapse active nav-tabs.active', function (e) {
         $(e.target).addClass('bs-prototype-override');
         });

         $('*').on('hidden.bs.collapse nav-tabs', function (e) {
         $(e.target).removeClass('bs-prototype-override');
         });*/

        var isBootstrapEvent = false;
        if (window.jQuery) {
            var all = jQuery('*');
            jQuery.each(['hide.bs.dropdown',
                'hide.bs.collapse',
                'hide.bs.modal',
                'hide.bs.tooltip',
                'hide.bs.popover',
                'hide.bs.tab'], function (index, eventName) {
                all.on(eventName, function (event) {
                    isBootstrapEvent = true;
                });
            });
        }
        var originalHide = Element.hide;
        Element.addMethods({
            hide: function (element) {
                if (isBootstrapEvent) {
                    isBootstrapEvent = false;
                    return element;
                }
                return originalHide(element);
            }
        });

    },

    attachMedia: function () {
        var $links = $('[data-toggle="media"]');
        if (!$links.length) return;

        // When somebody clicks on a link, slide the
        // carousel to the slide which matches the
        // image index and show the modal
        $links.on('click', function (e) {
            e.preventDefault();

            var $link = $(this),
                $modal = $($link.attr('href')),
                $carousel = $modal.find('.carousel'),
                index = parseInt($link.data('index'));

            $carousel.carousel(index);
            $modal.modal('show');

            return false;
        });
    }
};

jQuery(document).ready(function ($) {
    var site = new Site();
    site.start();
});

})(jQuery);

I already asked on github with no response question on github 我已经在github上问过了,而在github上没有回应问题

So the Dropdown of Bootstrap is working. 因此,Bootstrap的下拉列表正在运行。 My Question am i doing anything wrong or am i missing something? 我的问题是我做错了什么还是错过了什么?

Why does the nav-tabs not work in here? 为什么导航选项卡在这里不起作用?

Adding the "'bower_components/bootstrap/js/tab.js'," tab.js to the gulpfile.js AND adding the tab class to the script.js solved my Problem with Bootstrap Nav Pills and Tabs. 将“ bower_components / bootstrap / js / tab.js”,tab.js添加到gulpfile.js并将tab类添加到script.js,解决了我的Bootstrap Nav Pills和Tabs问题。

       $('*').on('show.bs.dropdown show.bs. hide.bs.tab hidden.bs.tab', function(e) {
            $(e.target).addClass('bs-prototype-override');
        });

        $('*').on('hidden.bs.collapse', function(e) {
            $(e.target).removeClass('bs-prototype-override');
        });

At the end the code looks just like this: 最后,代码如下所示:

jQuery.noConflict();
;(function($) {
'use strict';

function Site(settings) {

    this.windowLoaded = false;

}

Site.prototype = {
    constructor: Site,

    start: function() {
        var me = this;

        $(window).load(function() {
            me.windowLoaded = true;
        });

        this.attach();
    },

    attach: function() {
        this.attachBootstrapPrototypeCompatibility();
        this.attachMedia();
    },
    attachBootstrapPrototypeCompatibility: function() {

        // Bootstrap and Prototype don't play nice, in the sense that
        // prototype is a really wacky horrible library. It'll
        // hard-code CSS to hide an element when a hide() event
        // is fired. See http://stackoverflow.com/q/19139063
        // To overcome this with dropdowns that are both
        // toggle style and hover style, we'll add a CSS
        // class which has "display: block !important"
        $('*').on('show.bs.dropdown show.bs. hide.bs.tab hidden.bs.tab', function(e) {
            $(e.target).addClass('bs-prototype-override');
        });

        $('*').on('hidden.bs.collapse', function(e) {
            $(e.target).removeClass('bs-prototype-override');
        });
    },

    attachMedia: function() {
        var $links = $('[data-toggle="media"]');
        if ( ! $links.length) return;

        // When somebody clicks on a link, slide the
        // carousel to the slide which matches the
        // image index and show the modal
        $links.on('click', function(e) {
            e.preventDefault();

            var $link = $(this),
                $modal = $($link.attr('href')),
                $carousel = $modal.find('.carousel'),
                index = parseInt($link.data('index'));

            $carousel.carousel(index);
            $modal.modal('show');

            return false;
        });
    }
};

jQuery(document).ready(function($) {
    var site = new Site();
    site.start();
});

})(jQuery);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM