PageSourceSearch

https://www.pspepr.fr/wp-content/plugins/6tem9Menu/js/jquery.smartmenus.bootstrap.js

js pspepr.fr collected 2026-09-25 11:12:59 UTC 5,682 bytes, 159 lines download raw bytes

1/*!
2 * SmartMenus jQuery Plugin Bootstrap Addon - v0.4.1 - July 23, 2020
3 * http://www.smartmenus.org/
4 *
5 * Copyright Vasil Dinkov, Vadikom Web Ltd.
6 * http://vadikom.com
7 *
8 * Licensed MIT
9 */
10
11(function(factory) {
12	if (typeof define === 'function' && define.amd) {
13		// AMD
14		define(['jquery', 'smartmenus'], factory);
15	} else if (typeof module === 'object' && typeof module.exports === 'object') {
16		// CommonJS
17		module.exports = factory(require('jquery'));
18	} else {
19		// Global jQuery
20		factory(jQuery);
21	}
22} (function($) {
23
24	$.extend($.SmartMenus.Bootstrap = {}, {
25		keydownFix: false,
26		init: function() {
27			// init all navbars that don't have the "data-sm-skip" attribute set
28			var $navbars = $('ul.navbar-nav:not([data-sm-skip])');
29			$navbars.each(function() {
30				var $this = $(this),
31					obj = $this.data('smartmenus');
32				// if this navbar is not initialized
33				if (!obj) {
34					$this.smartmenus({
35							// these are some good default options that should work for all
36							subMenusSubOffsetX: 2,
37							subMenusSubOffsetY: -6,
38							subIndicators: false,
39							collapsibleShowFunction: null,
40							collapsibleHideFunction: null,
41							rightToLeftSubMenus: $this.hasClass('navbar-right'),
42							bottomToTopSubMenus: $this.closest('.navbar').hasClass('navbar-fixed-bottom')
43						})
44						.on({
45							// set/unset proper Bootstrap classes for some menu elements
46							'show.smapi': function(e, menu) {
47								var $menu = $(menu),
48									$scrollArrows = $menu.dataSM('scroll-arrows');
49								if ($scrollArrows) {
50									// they inherit border-color from body, so we can use its background-color too
51									$scrollArrows.css('background-color', $(document.body).css('background-color'));
52								}
53								$menu.parent().addClass('open');
54							},
55							'hide.smapi': function(e, menu) {
56								$(menu).parent().removeClass('open');
57							}
58						});
59
60					function onInit() {
61						// set Bootstrap's "active" class to SmartMenus "current" items (should someone decide to enable markCurrentItem: true)
62						$this.find('a.current').parent().addClass('active');
63						// remove any Bootstrap required attributes that might cause conflicting issues with the SmartMenus script
64						$this.find('a.has-submenu').each(function() {
65							var $this = $(this);
66							if ($this.is('[data-toggle="dropdown"]')) {
67								$this.dataSM('bs-data-toggle-dropdown', true).removeAttr('data-toggle');
68							}
69							if ($this.is('[role="button"]')) {
70								$this.dataSM('bs-role-button', true).removeAttr('role');
71							}
72						});
73					}
74
75					onInit();
76
77					function onBeforeDestroy() {
78						$this.find('a.current').parent().removeClass('active');
79						$this.find('a.has-submenu').each(function() {
80							var $this = $(this);
81							if ($this.dataSM('bs-data-toggle-dropdown')) {
82								$this.attr('data-toggle', 'dropdown').removeDataSM('bs-data-toggle-dropdown');
83							}
84							if ($this.dataSM('bs-role-button')) {
85								$this.attr('role', 'button').removeDataSM('bs-role-button');
86							}
87						});
88					}
89
90					obj = $this.data('smartmenus');
91
92					// custom "isCollapsible" method for Bootstrap
93					obj.isCollapsible = function() {
94						return !/^(left|right)$/.test(this.$firstLink.parent().css('float')) && this.$root.css('display') == 'block';
95					};
96
97					// custom "refresh" method for Bootstrap
98					obj.refresh = function() {
99						$.SmartMenus.prototype.refresh.call(this);
100						onInit();
101						// update collapsible detection
102						detectCollapsible(true);
103					};
104
105					// custom "destroy" method for Bootstrap
106					obj.destroy = function(refresh) {
107						onBeforeDestroy();
108						$.SmartMenus.prototype.destroy.call(this, refresh);
109					};
110
111					// keep Bootstrap's default behavior for parent items when the "data-sm-skip-collapsible-behavior" attribute is set to the ul.navbar-nav
112					// i.e. use the whole item area just as a sub menu toggle and don't customize the carets
113					if ($this.is('[data-sm-skip-collapsible-behavior]')) {
114						obj.opts.collapsibleBehavior = 'toggle';
115					}
116
117					// onresize detect when the navbar becomes collapsible and add it the "sm-collapsible" class
118					var winW;
119					function detectCollapsible(force) {
120						var newW = obj.getViewportWidth();
121						if (newW != winW || force) {
122							var $carets = $this.find('.caret');
123							if (obj.isCollapsible()) {
124								$this.addClass('sm-collapsible');
125								// 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
126								if (!$this.is('[data-sm-skip-collapsible-behavior]')) {
127									$carets.addClass('navbar-toggle sub-arrow');
128								}
129							} else {
130								$this.removeClass('sm-collapsible');
131								if (!$this.is('[data-sm-skip-collapsible-behavior]')) {
132									$carets.removeClass('navbar-toggle sub-arrow');
133								}
134							}
135							winW = newW;
136						}
137					}
138					detectCollapsible();
139					$(window).on('resize.smartmenus' + obj.rootId, detectCollapsible);
140				}
141			});
142			// keydown fix for Bootstrap 3.3.5+ conflict
143			if ($navbars.length && !$.SmartMenus.Bootstrap.keydownFix) {
144				// unhook BS keydown handler for all dropdowns
145				$(document).off('keydown.bs.dropdown.data-api', '.dropdown-menu');
146				// restore BS keydown handler for dropdowns that are not inside SmartMenus navbars
147				if ($.fn.dropdown && $.fn.dropdown.Constructor) {
148					$(document).on('keydown.bs.dropdown.data-api', '.dropdown-menu:not([id^="sm-"])', $.fn.dropdown.Constructor.prototype.keydown);
149				}
150				$.SmartMenus.Bootstrap.keydownFix = true;
151			}
152		}
153	});
154
155	// init ondomready
156	$($.SmartMenus.Bootstrap.init);
157
158	return $;
159}));

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.