(function ($) { $.fn.bitTopMenu = function (options) { return this.each(function() { if (undefined == $(this).data('bitTopMenu')) { var plugin = new $.bitTopMenu(this, options); $(this).data('bitTopMenu', plugin); } }); }; $.bitTopMenu = function (element, options) { var _element = $(element); var plugin = this; plugin.settings = {}; //ustawienia pluginu var defaults = {}; // stan włączenia menu w trybie mobilnym var isMobileView = false; var isMoreBtnVisible = false; // Ostatnia szerokość okna. Służy do optymalizacji wywołań alignMenu() var lastWitdh = 0; var isHoverEnabled = false; plugin.turnOnHover = function() { if (isHoverEnabled) { return; } _element.find('.nav > li > a').keypress(function (e) { if (!/(37|38|39|40)/.test(e.keyCode)) return; var target = $( e.target ); switch(e.keyCode) { case 37: // next target.parent().prev().find('a:first').focus().click(); break; case 39: // next target.parent().next().find('a:first').focus().click(); break; case 40: // next target.children('li a:first').focus(); break; } }); _element.find('ul.dropdown-menu li > a').keypress(function (e) { if (!/(37|38|39|40)/.test(e.keyCode)) return; var target = $( e.target ); switch(e.keyCode) { case 37: // next target.click(); break; case 39: // next target.click(); break; case 40: // next target.children('li a:first').focus(); break; } }); // 2 level _element.find('.nav > li.dropdown').hover(function() { _element.find('.open').removeClass('open'); $(this).addClass('open'); }, function() { $(this).removeClass('open'); }).find('ul.dropdown-menu > li.dropdown').hover(function() { $(this).siblings('.open').removeClass('open'); $(this).addClass('open'); }, function() { $(this).removeClass('open'); }); _element.find('ul.dropdown-menu li a:not([data-toggle])').hover(function (event) { $(this).parent().siblings('.open').removeClass('open'); }); _element.find('ul.dropdown-menu [data-toggle=dropdown]').on('click mouseover', function(event) { // Avoid following the href location when clicking event.preventDefault(); // Avoid having the menu to close when clicking event.stopPropagation(); // If a menu is already open we close it //$('ul.dropdown-menu [data-toggle=dropdown]').parent().removeClass('open'); // opening the one you clicked on $(this).parent().siblings('.open').removeClass('open'); $(this).parent().addClass('open'); }); isHoverEnabled = true; }; plugin.turnOffHover = function() { if (isHoverEnabled) { // wyłączenie obsługi hover _element.find('.nav li.dropdown').unbind('mouseenter mouseleave'); isHoverEnabled = false; } }; plugin.removeMoreButton = function() { if (isMoreBtnVisible) { _element.find(".main-nav").append(_element.find(".navbar-right .dropdown-menu").html()); _element.find(".navbar-right").remove(); isMoreBtnVisible = false; } }; plugin.alignMenu = function() { var li_sum = 0; _element.find('.navbar-nav > li').each(function() { li_sum += $(this).outerWidth(true); }); var w = 0; var mw = _element.find(".navbar-collapse").width() - 130; var menuhtml = $('