1/*! 2 * SmartMenus jQuery Plugin Bootstrap 4 Addon - v0.1.0 - September 17, 2017 3 * http://www.smartmenus.org/ 4 * 5 * Copyright Vasil Dinkov, Vadikom Web Ltd. 6 * http://vadikom.com 7 * 8 * Licensed MIT 9 * 10 * This is modified and extended version by Tiki team. 11 */ 12 13(function($) { 14 $.extend($.SmartMenus.Bootstrap = {}, { 15 keydownFix: false, 16 init: function($navbars, options = {}) { 17 if ($navbars.length === 0) return; 18 $navbars.each(function() { 19 var $this = $(this); 20 var obj = $this.data('smartmenus'); 21 // return if navbar have the "data-sm-skip" attribute set 22 // or navbar is initialized 23 if ($this.is('[data-sm-skip]') || obj) return; 24 25 var skipBehavior = $this.is('[data-sm-skip-collapsible-behavior]'); 26 var rightAligned = $this.hasClass('ml-auto') || $this.prevAll('.mr-auto').length > 0; 27 var defaultOptions = { 28 // these are some good default options that should work for all 29 subMenusSubOffsetX: 2, 30 subMenusSubOffsetY: -9, 31 subIndicators: !skipBehavior, 32 collapsibleShowFunction: null, 33 collapsibleHideFunction: null, 34 rightToLeftSubMenus: rightAligned, 35 bottomToTopSubMenus: $this.closest('.fixed-bottom').length > 0, 36 // custom option(s) for the Bootstrap 4 addon 37 bootstrapHighlightClasses: 'text-dark bg-light' 38 }; 39 var extendedOptions = $.extend(defaultOptions, options); 40 41 $this.smartmenus(extendedOptions) 42 .on({ 43 // set/unset proper Bootstrap classes for some menu elements 44 'show.smapi': function(e, menu) { 45 var $menu = $(menu), 46 $scrollArrows = $menu.dataSM('scroll-arrows'); 47 if ($scrollArrows) { 48 $scrollArrows.css('background-color', $menu.css('background-color')); 49 } 50 $menu.parent().addClass('show'); 51 if (obj.opts.keepHighlighted && $menu.dataSM('level') > 2) { 52 $menu.prevAll('a').addClass(obj.opts.bootstrapHighlightClasses); 53 } 54 }, 55 'hide.smapi': function(e, menu) { 56 var $menu = $(menu); 57 $menu.parent().removeClass('show'); 58 if (obj.opts.keepHighlighted && $menu.dataSM('level') > 2) { 59 $menu.prevAll('a').removeClass(obj.opts.bootstrapHighlightClasses); 60 } 61 } 62 }); 63 // .on('beforeshow.smapi', function(e, menu) { 64 // console.log($this.data('smartmenus')); 65 // console.log(menu); 66 // $(menu).css({ 67 // position: 'static' 68 // }); 69 // }); 70 71 obj = $this.data('smartmenus'); 72 73 function onInit() { 74 // set Bootstrap's "active" class to SmartMenus "current" items (should someone decide to enable markCurrentItem: true) 75 $this.find('a.current').each(function() { 76 var $this = $(this); 77 // dropdown items require the class to be set to the A's while for nav items it should be set to the parent LI's 78 ($this.hasClass('dropdown-item') ? $this : $this.parent()).addClass('active'); 79 }); 80 // parent items fixes 81 $($this).find('a[data-bs-toggle="dropdown"]').each(function() { 82 $(this).removeAttr('data-bs-toggle'); 83 }); 84 $this.find('a.has-submenu').each(function() { 85 var $this = $(this); 86 // remove Bootstrap required attributes that might cause conflicting issues with the SmartMenus script 87 if ($this.is('[data-bs-toggle="dropdown"]')) { 88 $this.dataSM('bs-data-toggle-dropdown', true).removeAttr('data-bs-toggle'); 89 } 90 // remove Bootstrap's carets generating class 91 // if (!skipBehavior && $this.hasClass('dropdown-toggle')) { 92 // $this.dataSM('bs-dropdown-toggle', true).removeClass('dropdown-toggle'); 93 // } 94 if (!extendedOptions.subIndicators && $this.hasClass('dropdown-toggle')) { 95 $this.dataSM('bs-dropdown-toggle', true); 96 } else { 97 $this.removeClass('dropdown-toggle'); 98 } 99 }); 100 } 101 102 onInit(); 103 104 function onBeforeDestroy() { 105 $this.find('a.current').each(function() { 106 var $this = $(this); 107 ($this.hasClass('active') ? $this : $this.parent()).removeClass('active'); 108 }); 109 $this.find('a.has-submenu').each(function() { 110 var $this = $(this); 111 if ($this.dataSM('bs-dropdown-toggle')) { 112 $this.addClass('dropdown-toggle').removeDataSM('bs-dropdown-toggle'); 113 } 114 if ($this.dataSM('bs-data-toggle-dropdown')) { 115 $this.attr('data-toggle', 'dropdown').removeDataSM('bs-data-toggle-dropdown'); 116 } 117 }); 118 } 119 120 // custom "refresh" method for Bootstrap 121 obj.refresh = function() { 122 $.SmartMenus.prototype.refresh.call(this); 123 onInit(); 124 // update collapsible detection 125 detectCollapsible(true); 126 }; 127 128 // custom "destroy" method for Bootstrap 129 obj.destroy = function(refresh) { 130 onBeforeDestroy(); 131 $.SmartMenus.prototype.destroy.call(this, refresh); 132 }; 133 134 // keep Bootstrap's default behavior (i.e. use the whole item area just as a sub menu toggle) 135 if (skipBehavior) { 136 obj.opts.collapsibleBehavior = 'toggle'; 137 } 138 139 // onresize detect when the navbar becomes collapsible and add it the "sm-collapsible" class 140 var winW; 141 function detectCollapsible(force) { 142 var newW = obj.getViewportWidth(); 143 if (newW != winW || force) { 144 if (obj.isCollapsible()) { 145 $this.addClass('sm-collapsible'); 146 } else { 147 $this.removeClass('sm-collapsible'); 148 } 149 winW = newW; 150 } 151 } 152 detectCollapsible(); 153 $(window).on('resize.smartmenus' + obj.rootId, detectCollapsible); 154 }); 155 // keydown fix for Bootstrap 4 conflict 156 if ($navbars.length && !$.SmartMenus.Bootstrap.keydownFix) { 157 // unhook BS keydown handler for all dropdowns 158 $(document).off('keydown.bs.dropdown.data-api', '.dropdown-menu'); 159 // restore BS keydown handler for dropdowns that are not inside SmartMenus navbars 160 // SmartMenus won't add the "show" class so it's handy here 161 if ($.fn.dropdown && $.fn.dropdown.Constructor) { 162 $(document).on('keydown.bs.dropdown.data-api', '.dropdown-menu.show', $.fn.dropdown.Constructor.dataApiKeydownHandler); 163 } 164 $.SmartMenus.Bootstrap.keydownFix = true; 165 } 166 } 167 }); 168})(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.