PageSourceSearch

https://www.shineling.org/wp-content/plugins/trx_addons/components/cpt/layouts/shortcodes/menu/menu.js

js shineling.org collected 2026-10-02 07:28:36 UTC 8,258 bytes, 208 lines download raw bytes

1/* global jQuery:false */
2
3(function() {
4	"use strict";
5
6	jQuery(document).on('action.before_ready_trx_addons', function() {
7		// Init Superfish menu - global declaration to use in other scripts
8		window.trx_addons_init_sfmenu = function(selector) {
9			jQuery(selector).show().each(function() {
10				var animation_in = jQuery(this).parent().data('animation-in');
11				if (animation_in == undefined) animation_in = "none";
12				var animation_out = jQuery(this).parent().data('animation-out');
13				if (animation_out == undefined) animation_out = "none";
14				jQuery(this).addClass('inited').superfish({
15					delay: 500,
16					animation: {
17						opacity: 'show'
18					},
19					animationOut: {
20						opacity: 'hide'
21					},
22					speed: 		animation_in!='none' ? 500 : 200,
23					speedOut:	animation_out!='none' ? 500 : 200,
24					autoArrows: false,
25					dropShadows: false,
26					onBeforeShow: function(ul) {
27						// Disable show submenus in the vertival menu on the mobile screen
28						//if (jQuery(window).width() < 768 && jQuery(this).parents(".sc_layouts_menu_dir_vertical").length > 0)
29						//	return false;
30						// Detect position (left | right)
31						if (jQuery(this).parents("ul").length > 1){
32							var w = jQuery('.page_wrap').length > 0 ? jQuery('.page_wrap').width() : jQuery(window).width();
33							var par_offset = jQuery(this).parents("ul").offset().left;
34							var par_width  = jQuery(this).parents("ul").outerWidth();
35							var ul_width   = jQuery(this).outerWidth();
36							if (par_offset+par_width+ul_width > w-20 && par_offset-ul_width > 0)
37								jQuery(this).addClass('submenu_left');
38							else
39								jQuery(this).removeClass('submenu_left');
40						}
41						// Animation in
42						if (jQuery(this).parents('[class*="columns-"]').length == 0 && animation_in!='none') {
43							jQuery(this).removeClass('animated fast '+animation_out);
44							jQuery(this).addClass('animated fast '+animation_in);
45						}
46					},
47					onBeforeHide: function(ul) {
48						// Remove video
49						jQuery(this).find('.trx_addons_video_player.with_cover.video_play').removeClass('video_play').find('.video_embed').empty();
50						// Disable show submenus in the vertival menu on the mobile screen
51						//if (jQuery(window).width() < 768 && jQuery(this).parents(".sc_layouts_menu_dir_vertical").length > 0)
52						//	return false;
53						// Animation out
54						if (jQuery(this).parents('[class*="columns-"]').length == 0 && animation_out!='none') {
55							jQuery(this).removeClass('animated fast '+animation_in);
56							jQuery(this).addClass('animated fast '+animation_out);
57						}
58					},
59					onShow: function(ul) {
60						// Init layouts
61						if (!jQuery(this).hasClass('layouts_inited')) {
62							jQuery(this).addClass('layouts_inited');
63							jQuery(document).trigger('action.init_hidden_elements', [jQuery(this)]);
64						}
65					}
66				});
67			});
68		};
69	
70		// Init superfish menus
71		trx_addons_init_sfmenu('.sc_layouts_menu:not(.inited) > ul:not(.inited)');
72	
73		// Check if menu need collapse (before menu showed)
74		trx_addons_menu_collapse();
75
76		// Show menu		
77		jQuery('.sc_layouts_menu:not(.inited)').each(function() {
78			if (jQuery(this).find('>ul.inited').length == 1) jQuery(this).addClass('inited');
79		});
80	
81		// Slide effect for menu
82		jQuery('.menu_hover_slide_line:not(.slide_inited),.menu_hover_slide_box:not(.slide_inited)').each(function() {
83			var menu = jQuery(this).addClass('slide_inited');
84			var style = menu.hasClass('menu_hover_slide_line') ? 'line' : 'box';
85			setTimeout(function() {
86				menu.find('>ul').spasticNav({
87					style: style,
88					//color: '',
89					colorOverride: false
90				});
91			}, 500);
92		});
93	
94		// Burger with popup
95		jQuery('.sc_layouts_menu_mobile_button_burger:not(.inited)').each(function() {
96			var burger = jQuery(this);
97			var popup = burger.find('.sc_layouts_menu_popup');
98			if (popup.length == 1) {
99				burger.addClass('inited').on('click', '>a', function(e) {
100					popup.toggleClass('opened').slideToggle();
101					e.preventDefault();
102					return false;
103				});
104				jQuery(document).on('click', function(e) {
105					jQuery('.sc_layouts_menu_popup.opened').removeClass('opened').slide
105Up();
106				});
107			}
108		});
109	
110	});
111	
112
113	// Collapse menu on resize
114	jQuery(document).on('action.resize_trx_addons', function() {
115		trx_addons_menu_collapse();
116	});
117	
118	// Collapse menu items
119	function trx_addons_menu_collapse() {
120		if (TRX_ADDONS_STORAGE['menu_collapse'] == 0) return;
121		jQuery('.sc_layouts_menu:not(.sc_layouts_menu_dir_vertical)').each(function() {
122			if (jQuery(this).parents('div:hidden,section:hidden,article:hidden').length > 0) return;
123			var ul = jQuery(this).find('>ul:not(.sc_layouts_menu_no_collapse).inited');
124			if (ul.length == 0 || ul.find('> li').length < 2) return;
125			var sc_layouts_item = ul.parents('.sc_layouts_item');
126			if (!sc_layouts_item.parent().hasClass('wpb_wrapper') && !sc_layouts_item.parent().hasClass('sc_layouts_column')) return;
127			// Calculate max free space for menu
128			var w_max = sc_layouts_item.parent().width()
129						- (Math.ceil(parseFloat(sc_layouts_item.css('marginLeft'))) + Math.ceil(parseFloat(sc_layouts_item.css('marginRight'))))
130						- 2;	// Leave additional 2px empty
131			var w_siblings = 0, in_group = 0, ul_id = ul.attr('id');
132			sc_layouts_item.parent().find('>div').each(function() {
133				if (in_group > 1) return;
134				if (jQuery(this).hasClass('vc_empty_space') || jQuery(this).hasClass('vc_separator')) {
135					if (in_group == 1)
136						in_group = 2;
137					else
138						w_siblings = 0;
139				} else {
140					if (jQuery(this).find('#'+ul_id).length > 0)
141						in_group = 1;
142					else
143						w_siblings += (jQuery(this).outerWidth() + Math.ceil(parseFloat(jQuery(this).css('marginLeft'))) + Math.ceil(parseFloat(jQuery(this).css('marginRight'))));
144				}
145			});
146			w_max -= w_siblings;
147			// Add collapse item if not exists
148			var w_all = 0;
149			var move = false;
150			var li_collapse = ul.find('li.menu-item.menu-collapse');
151			if (li_collapse.length==0) {
152				ul.append('<li class="menu-item menu-collapse"><a href="#" class="sf-with-ul '+TRX_ADDONS_STORAGE['menu_collapse_icon']+'"></a><ul class="submenu"></ul></li>');
153				li_collapse = ul.find('li.menu-item.menu-collapse');
154			}
155			var li_collapse_ul = li_collapse.find('> ul');
156			// Check if need to move items
157			ul.find('> li').each(function(idx) {
158				var cur_item = jQuery(this);
159				cur_item.data('index', idx);
160				if (move || cur_item.attr('id') == 'blob') return;
161				w_all += !cur_item.hasClass('menu-collapse') || cur_item.css('display')!='none' 
162							? cur_item.outerWidth() + Math.ceil(parseFloat(cur_item.css('marginLeft'))) + Math.ceil(parseFloat(cur_item.css('marginRight')))
163							: 0;
164				if (w_all > w_max) move = true;
165			});
166			// If need to move items to the collapsed item
167			if (move) {
168				w_all = li_collapse.outerWidth() + Math.ceil(parseFloat(li_collapse.css('marginLeft'))) + Math.ceil(parseFloat(li_collapse.css('marginRight')));
169				ul.find("> li:not('.menu-collapse')").each(function(idx) {
170					var cur_item = jQuery(this);
171					var cur_width = cur_item.outerWidth() + Math.ceil(parseFloat(cur_item.css('marginLeft'))) + Math.ceil(parseFloat(cur_item.css('marginRight')));
172					if (w_all <= w_max) w_all += cur_width;
173					if (w_all > w_max) {
174						var moved = false;
175						li_collapse_ul.find('>li').each(function() {
176							if (!moved && Number(jQuery(this).data('index')) > idx) {
177								cur_item.attr('data-width', cur_width).insertBefore(jQuery(this));
178								moved = true;
179							}
180						});
181						if (!moved) cur_item.attr('data-width', cur_width).appendTo(li_collapse_ul);
182					}
183				});
184				li_collapse.show();
185				
186			// Else - move items to the menu again
187			} else {
188				var items = li_collapse_ul.find('>li');
189				var cnt = 0;
190				move = true;
191				//w_all += 20; 	// Leave 20px empty
192				items.each(function() {
193					if (!move) return;
194					if (items.length - cnt == 1)
195						w_all -= (li_collapse.outerWidth() + Math.ceil(parseFloat(li_collapse.css('marginLeft'))) + Math.ceil(parseFloat(li_collapse.css('marginRight'))));
196					w_all += parseFloat(jQuery(this).data('width'));
197					if (w_all < w_max) {
198						jQuery(this).insertBefore(li_collapse);
199						cnt++;
200					} else
201						move = false;
202				});
203				if (items.length - cnt == 0) li_collapse.hide();
204			}
205		});
206	}
207
208})();

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.