PageSourceSearch

https://fenixclub.com/html/menu.js

js fenixclub.com collected 2026-10-02 14:33:50 UTC 12,411 bytes, 528 lines download raw bytes

1/*-------------------------------------------------------------------------*/
2// TBDEV BASIC MENU CLASS
3// ASSUMES "tracker.js" has been loaded
4/*-------------------------------------------------------------------------*/
5
6//----------------------------------
7// Init some variables and CSS classes
8//----------------------------------
9
10var menu_registered  = new Array();
11var menu_openfuncs   = new Array();
12var menu_built       = new Array();
13var menu_open_menus  = new Array();
14var menu_cur_open    = false;
15var css_mainwrap     = 'popupmenu';
16var css_menusep      = 'popupmenu-item';
17var css_menusep_last = 'popupmenu-item-last';
18
19/*-------------------------------------------------------------------------*/
20// menu_build_menu
21// cid: ID of opener object (img, div, etc)
22// menuinput: Array of menu entries | Variable of menu HTML
23// complexmenu: Treat as HTML stream if true, else treat as array of HTML
24/*-------------------------------------------------------------------------*/
25
26function menu_build_menu(cid, menuinput, complexmenu)
27{
28	var html = "\n<div class='" + css_mainwrap + "' id='" + cid + "_menu' style='display:none;z-index:100'>\n";
29
30	if ( ! complexmenu )
31	{
32		len = parseInt(menuinput.length);
33
34		if ( len > 0 )
35		{
36			for( var i in menuinput )
37			{
38				t = parseInt(i) + 1;
39
40				thisclass = ( t == len ) ? css_menusep_last : css_menusep;
41
42				if ( menuinput[i].match( /^--NODIV--/ ) )
43				{
44					html += menuinput[i].replace( /^--NODIV--/, '' );
45				}
46				else
47				{
48					html += "<div class='" + thisclass + "'>\n" + menuinput[i] + "\n</div>\n";
49				}
50			}
51		}
52	}
53	else
54	{
55		html += menuinput;
56	}
57
58	html += "\n</div>\n";
59
60	//----------------------------------
61	// Workaround for IE bug which shows
62	// select boxes and other windows GUI
63	// over divs. Write iframe
64	//----------------------------------
65
66	if ( is_ie )
67	{
68		html += "\n"+'<iframe id="if_' + cid + '" src="' + tb_var_image_url + '/iframe.html" scrolling="no" frameborder="1" style="position:absolute;top:0px;left:0px;display:none;"></iframe>'+"\n";
69	}
70
71	//----------------------------------
72	// Write the html
73	//----------------------------------
74
75	if ( html != '' )
76	{
77		/*document.open();
78		document.writeln( html );
79		document.close();*/
80	    $('#'+cid).append(html);
81	}
82
83	//----------------------------------
84	// Register and init
85	//----------------------------------
86
87	menu_register( cid );
88}
89
90/*-------------------------------------------------------------------------*/
91// menu_do_global_init: Initiate all registered menus in HTML
92/*-------------------------------------------------------------------------*/
93
94function menu_do_global_init()
95{
96	if ( menu_registered.length > 0 )
97	{
98		for( var i in menu_registered )
99		{
100			menu_init( menu_registered[i] );
101		}
102
103		//----------------------------------
104		// Close all menus on click
105		//----------------------------------
106
107		document.onclick = menu_action_close;
108	}
109}
110
111/*-------------------------------------------------------------------------*/
112// menu_init: Initiate a single menu
113/*-------------------------------------------------------------------------*/
114
115function menu_init(cid)
116{
117	var mid  = _menu_get_base_name(cid) + "_menu";
118	var mobj = my_getbyid(mid);
119
120	if ( document.getElementsByTagName && mobj )
121	{
122		//----------------------------------
123		// Control object (link / img, etc)
124		//----------------------------------
125
126		var cobj = my_getbyid(cid);
127
128		// Change cursor to show link
129		try
130		{
131			cobj.style.cursor = "pointer";
132		}
133		catch(e)
134		{
135			cobj.style.cursor = "hand";
136		}
137
138		cobj.unselectable = true;
139		cobj.onclick      = _event_menu_click;
140		//cobj.onmouseover  = _event_menu_mouseover;
141
142		//----------------------------------
143		// Save CPU - already init?
144		//----------------------------------
145
146		if ( typeof( menu_built[mid]) != "undefined" )
147		{
148			return;
149		}
150
151		//----------------------------------
152		// Pop-up menu obj (hidden div)
153		//----------------------------------
154
155		var pobj = my_getbyid(mid);
156
157		// Set up style defaults
158		pobj.style.display  = "none";
159		pobj.style.position = "absolute";
160		pobj.style.left     = "0px";
161		pobj.style.top      = "0px";
162		pobj.onclick        = _cancel_bubble;
163		pobj.zIndex         = 1000;
164
165		menu_built[mid] = true;
166	}
167}
168
169/*-------------------------------------------------------------------------*/
170// Register menu control ID (add to array)
171/*-------------------------------------------------------------------------*/
172
173function menu_register(cid, callback)
174{
175	if ( document.getElementsByTagName )
176	{
177		var cobj = my_getbyid(cid);
178
179		if (cobj)
180		{
181			menu_registered[menu_registered.length] = cid;
182
183			if ( callback )
184			{
185				menu_openfuncs[ cobj ] = callback;
186			}
187
188			return true;
189		}
190	}
191
192	return false;
193}
194
195/*-------------------------------------------------------------------------*/
196// ACTION: If registered control ID clicked, open menu
197/*-------------------------------------------------------------------------*/
198
199function menu_action_open(e)
200{
201	var openmenu = menu_cur_open;
202	var negpad   = true;
203
204	//----------------------------------
205	// Close current menu(s)
206	//----------------------------------
207
208	menu_action_close();
209
210	//----------------------------------
211	// Save CPU - cur open clicked?
212	//----------------------------------
213
214	if ( openmenu == e.id )
215	{
216		return false;
217	}
218
219	//----------------------------------
220	// Get ID of menu DIV to show
221	//----------------------------------
222
223	var mid         = _menu_get_base_name(e.id) + "_menu";
224	var mobj        = my_getbyid(mid);
225	var left_px     = _get_obj_leftpos(e);
226	var top_px      = _get_obj_toppos(e) + e.offsetHeight;
227	var callbackobj = my_getbyid( e.id );
228	var ifid        = e.id;
229
230	menu_open_menus[e.id] = true;
231	menu_cur_open         = e.id;
232
233	//----------------------------------
234	// Show menu DIV
235	//----------------------------------
236
237	mobj.style.display = "";
238
239	//----------------------------------
240	// Try and keep it on screen
241	//----------------------------------
242
243	var width = parseInt( mobj.style.width ) ? parseInt( mobj.style.width ) : mobj.offsetWidth;
244
245	if ( (left_px + width) >= document.body.clientWidth )
246	{
247		left_px = left_px + e.offsetWidth - width;
248		negpad  = false;
249	}
250
251	//----------------------------------
252	// IE needs a tweak...
253	//----------------------------------
254
255	if ( is_ie )
256	{
257		left_px += ( negpad ) ? -2 : 2;
258	}
259
260	//----------------------------------
261	// Finalize menu position
262	//----------------------------------
263
264	mobj.style.left   = left_px + "px";
265	mobj.style.top    = top_px  + "px";
266	mobj.style.zIndex = 100;
267
268	//----------------------------------
269	// Run a custom function?
270	//----------------------------------
271
272	if ( menu_openfuncs[ callbackobj ] )
273	{
274		eval( menu_openfuncs[ callbackobj ] );
275	}
276
277	//----------------------------------
278	// Workaround for IE bug which shows
279	// select boxes and other windows GUI
280	// over divs. SHOW IFRAME
281	//----------------------------------
282
283	if ( is_ie )
284	{
285		try
286		{
287			if ( ! document.getElementById( 'if_' + e.id ) )
288			{
289				var iframeobj = document.createElement('iframe');
290
291				iframeobj.src = 'javascript;';
292				iframeobj.id  = 'if_' + e.id;
293
294				document.getElementsByTagName('body').appendChild( iframeobj );
295			}
296			else
297			{
298				var iframeobj = document.getElementById( 'if_' + e.id );
299			}
300
301			iframeobj.scrolling      = 'no';
302			iframeobj.frameborder    = 'no';
303			iframeobj.className      = 'iframeshim';
304			iframeobj.style.position = 'absolute';
305
306			iframeobj.style.width   = parseInt(mobj.offsetWidth)  + 'px';
307			iframeobj.style.height  = parseInt(mobj.offsetHeight) + 'px';
308			iframeobj.style.top     = mobj.style.top;
309			iframeobj.style.left    = mobj.style.left;
310			iframeobj.style.zIndex  = 99;
311			iframeobj.style.display = "block";
312
313    	}
314    	catch(e)
315    	{
316    		//alert(e); // Oh dear, someones stolen the iframe
317    	}
318	}
319
320	//----------------------------------
321	// Work around for safari which doesnt
322	// allow a hrefs top be clickable in
323	// a pop up div
324	//----------------------------------
325
326	if ( is_safari )
327	{
328		try
329		{
330			mlinks = mobj.getElementsByTagName('a');
331
332			for ( var i = 0 ; i <= mlinks.length ; i++ )
333			{
334				//----------------------------------
335				// Ignore non links and links that end with #
336				// As safari likes to do that with href='#' links
337				//----------------------------------
338
339				if ( mlinks[i].href && ( mlinks[i].href.indexOf( '#', 0 ) != (mlinks[i].href.length - 1) ) )
340				{
341					mlinks[i].onmousedown = _safari_onclick_handler;
342					mlinks[i].id          = 'saf-link-' + mid + i;
343				}
344			}
345		}
346		catch( e )
347		{
348			//alert( e );
349		}
350	}
351
352	return false;
353}
354
355/*-------------------------------------------------------------------------*/
356// Safari: bug fix
357/*-------------------------------------------------------------------------*/
358
359function _safari_onclick_handler()
360{
361	if ( this.id )
362	{
363		window.location = document.getElementById( this.id ).href;
364	}
365}
366
367
368/*-------------------------------------------------------------------------*/
369// ACTION: Close all open menus
370/*-------------------------------------------------------------------------*/
371
372function menu_action_close()
373{
374	if ( menu_cur_open )
375	{
376		for ( i in menu_open_menus )
377		{
378			if ( my_getbyid(_menu_get_base_name(i) + "_menu") ) {
379			    my_getbyid(_menu_get_base_name(i) + "_menu").style.display = "none";
380            }
381			//----------------------------------
382			// Workaround for IE bug which shows
383			// select boxes and other windows GUI
384			// over divs. Hide IFRAME
385			//----------------------------------
386
387			if ( is_ie )
388			{
389				if ( document.getElementById( 'if_' + i ) ) {
390				    try
391				    {
392					    document.getElementById( 'if_' + i ).style.display = "none";
393				    }
394				    catch(e)
395				    {
396					    //alert(e);// Oh dear, someones stolen the iframe
397				    }
398			    }
399			}
400            if ( menu_open_menus[i] ) {
401			    menu_open_menus[i] = false;
402		    }
403		}
404	}
405
406	menu_cur_open = false;
407}
408
409/*-------------------------------------------------------------------------*/
410// ACTION: If menu open and hover over another cid, close cur open new
411/*-------------------------------------------------------------------------*/
412
413function menu_action_hover(e)
414{
415	for ( i in menu_open_menus )
416	{
417		if (menu_open_menus[i] == true && i != e.id)
418		{
419			menu_action_open(e);
420			return;
421		}
422	}
423}
424
425/*-------------------------------------------------------------------------*/
426// Prevent browser bubblin'
427/*-------------------------------------------------------------------------*/
428
429function _cancel_bubble(obj, extra)
430{
431	if ( ! obj || is_ie)
432	{
433		if ( extra )
434		{
435			window.event.returnValue = false;
436		}
437
438		window.event.cancelBubble = true;
439
440		return window.event;
441	}
442	else
443	{
444		if (obj.target.type == 'submit')
445		{
446			obj.target.form.submit();
447		}
448
449		obj.stopPropagation();
450
451		if ( extra )
452		{
453			obj.preventDefault();
454		}
455
456		return obj;
457	}
458}
459
460/*-------------------------------------------------------------------------*/
461// EVENT : Mouse over menu
462/*-------------------------------------------------------------------------*/
463
464function _event_menu_mouseover(e)
465{
466	e = _cancel_bubble(e, true);
467	menu_action_hover(this);
468}
469
470/*-------------------------------------------------------------------------*/
471// EVENT: Menu click
472/*-------------------------------------------------------------------------*/
473
474function _event_menu_click(e)
475{
476	e = _cancel_bubble(e, true);
477	menu_action_open(this);
478}
479
480/*-------------------------------------------------------------------------*/
481// Get menu basename
482/*-------------------------------------------------------------------------*/
483
484function _menu_get_base_name(cid)
485{
486	var endpos = cid.indexOf(".");
487
488	if (endpos != -1)
489	{
490		return cid.substr(0, endpos);
491	}
492	else
493	{
494		return cid;
495	}
496}
497
498/*-------------------------------------------------------------------------*/
499// Get left posititon of object
500/*-------------------------------------------------------------------------*/
501
502function _get_obj_leftpos(obj)
503{
504	var left = obj.offsetLeft;
505
506	while( (obj = obj.offsetParent) != null )
507	{
508		left += obj.offsetLeft;
509	}
510
511	return left;
512}
513
514/*-------------------------------------------------------------------------*/
515// Get top position of object
516/*-------------------------------------------------------------------------*/
517
518function _get_obj_toppos(obj)
519{
520	var top = obj.offsetTop;
521
522	while( (obj = obj.offsetParent) != null )
523	{
524		top += obj.offsetTop;
525	}
526
527	return top;
528}

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.