1/*! 2 * SmartMenus jQuery Plugin Bootstrap Addon - v0.2.0 - June 1, 2015 3 * http://www.smartmenus.org/ 4 * 5 * Copyright 2015 Vasil Dinkov, Vadikom Web Ltd. 6 * http://vadikom.com 7 * 8 * Licensed MIT 9 */ 10 11(function($) { 12 13 // init ondomready 14 $(function() { 15 16 // init all navbars that don't have the "data-sm-skip" attribute set 17 var $navbars = $('ul.navbar-nav:not([data-sm-skip])'); 18 $navbars.each(function() { 19 var $this = $(this); 20 $this.addClass('sm').smartmenus({ 21 22 // these are some good default options that should work for all 23 // you can, of course, tweak these as you like 24 subMenusSubOffsetX: 2, 25 subMenusSubOffsetY: -6, 26 subIndicators: false, 27 collapsibleShowFunction: null, 28 collapsibleHideFunction: null, 29 rightToLeftSubMenus: $this.hasClass('navbar-right'), 30 bottomToTopSubMenus: $this.closest('.navbar').hasClass('navbar-fixed-bottom') 31 }) 32 .bind({ 33 // set/unset proper Bootstrap classes for some menu elements 34 'show.smapi': function(e, menu) { 35 var $menu = $(menu), 36 $scrollArrows = $menu.dataSM('scroll-arrows'); 37 if ($scrollArrows) { 38 // they inherit border-color from body, so we can use its background-color too 39 $scrollArrows.css('background-color', $(document.body).css('background-color')); 40 } 41 $menu.parent().addClass('open'); 42 }, 43 'hide.smapi': function(e, menu) { 44 $(menu).parent().removeClass('open'); 45 } 46 }) 47 // set Bootstrap's "active" class to SmartMenus "current" items (should someone decide to enable markCurrentItem: true) 48 .find('a.current').parent().addClass('active'); 49 50 // keep Bootstrap's default behavior for parent items when the "data-sm-skip-collapsible-behavior" attribute is set to the ul.navbar-nav 51 // i.e. use the whole item area just as a sub menu toggle and don't customize the carets 52 var obj = $this.data('smartmenus'); 53 if ($this.is('[data-sm-skip-collapsible-behavior]')) { 54 $this.bind({ 55 // click the parent item to toggle the sub menus (and reset deeper levels and other branches on click) 56 'click.smapi': function(e, item) { 57 if (obj.isCollapsible()) { 58 var $item = $(item), 59 $sub = $item.parent().dataSM('sub'); 60 if ($sub && $sub.dataSM('shown-before') && $sub.is(':visible')) { 61 obj.itemActivate($item); 62 obj.menuHide($sub); 63 return false; 64 } 65 } 66 } 67 }); 68 } 69 70 var $carets = $this.find('.caret'); 71 72 // onresize detect when the navbar becomes collapsible and add it the "sm-collapsible" class 73 var winW; 74 function winResize() { 75 var newW = obj.getViewportWidth(); 76 if (newW != winW) { 77 if (obj.isCollapsible()) { 78 $this.addClass('sm-collapsible'); 79 // set "navbar-toggle" class to carets (so they look like a button) if the "data-sm-skip-collapsible-behavior" attribute is not set to the ul.navbar-nav 80 if (!$this.is('[data-sm-skip-collapsible-behavior]')) { 81 $carets.addClass('navbar-toggle sub-arrow'); 82 } 83 } else { 84 $this.removeClass('sm-collapsible'); 85 if (!$this.is('[data-sm-skip-collapsible-behavior]')) { 86 $carets.removeClass('navbar-toggle sub-arrow'); 87 } 88 } 89 winW = newW; 90 } 91 }; 92 winResize(); 93 $(window).bind('resize.smartmenus' + obj.rootId, winResize); 94 }); 95 96 }); 97 98 // fix collapsible menu detection for Bootstrap 3 99 $.SmartMenus.prototype.isCollapsible = function() { 100 return this.$firstLink.parent().css('float') != 'left'; 101 }; 102 103})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.