Delete everything from menuitem array

Having problems with DHTML Menu? There is usually somebody here who knows the answer.
Post Reply
qperkins
Beginner
Beginner
Posts: 3
Joined: Wed Jan 19, 2005 5:56 am

Delete everything from menuitem array

Post by qperkins »

I know that the ability to remove items from a menu dynamically after the menu is loaded is on the feature request list, and that the hide a menu item will not work for me.

I don't suppose anyone knows which array I could nuke (length=0?) to remove all of the items from a menu? I could then add items back in using the insertitem dynamically as I need them. I was trying to modify the insertitems script, but quickly found that I was over my head. Basically, I'd love a similar script that would allow me to call menuname.nuke() and it would remove all items from that particular menu array. I could then use the excellent insertitem to repopulate it. (Never would it remain empty).

Any ideas?
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

Here is a beta of a function that will remove a menu item from an already built menu:

I'm now working on the insertItem funciton - Could have sworn I'd already written this but cannot seemto find a reference to it anywhere. Please let me know where it is if you can find it.

Cheers
Andy

Code: Select all

function mm_deleteItem(_mN, _iN) 
{
	_mnu=getMenuByName(_mN)
	_ii=_m[_mnu][0][_iN-1]
	_tA=_nA()
	for(_r=0;_r<_mi.length;_r++)
	{
		if(_r!=_ii)_tA[_tA.length]=_mi[_r]
	}
	_mi=_tA
	_tA=_nA()
	
	_cnt=0;
	for(_r=0;_r<_m[_mnu][0].length;_r++)
	{	
		if(_m[_mnu][0][_r]!=_ii)
		{
			_tA[_tA.length]=_m[_mnu][0][_cnt]
			_cnt++
		}
	}
	_m[_mnu][0]=_tA	
	
	
	for(_r=_mnu+1;_r<_m.length;_r++)
	{
		for(_p=0;_p<_m[_r][0].length;_p++)
		{
			_m[_r][0][_p]--
		}
	}
		
	for(_r=0;_r<_m.length;_r++)
	{
		_m[_r][23]=0
		_gm=gmobj("menu"+_r)	
		if(_m[_r][7])
		{
			_gm.innerHTML=_drawMenu(_r)
		}
		else
		{
			_gm.innerHTML=""
			_fixMenu(_mnu)
		}
	}
}
Syntax is mm_deleteItem('MENUNAME', ITEMNUMBER)

ie, mm_deleteItem('Main Menu', 3) will delete the third item in the main menu

-- Andy
User avatar
Andy
Milonic
Milonic
Posts: 3308
Joined: Sun May 19, 2002 8:23 pm
Location: Menu Developer
Contact:

Post by Andy »

Just developed a module for editing menu items, it's at

http://milonic.com/mm_menueditapi.js

Hope this helps
Andy
Streetwise
Advanced
Advanced
Posts: 15
Joined: Mon Jan 10, 2005 1:14 pm

Post by Streetwise »

(showing my ignorance here)

How does one use this code to remove items? Do I put it in a new page? If I have to ask, I probably shouldn't be thinking about using it :P

Dave
qperkins
Beginner
Beginner
Posts: 3
Joined: Wed Jan 19, 2005 5:56 am

Thanks so much, but...

Post by qperkins »

I really appreciate you sharing the remove script and I have several areas I can immediately use it!

However, I was wondering if there was an easy way to accomplish my original task of erasing all of the items from a particular menu. Or, alternately I could use the remove script your provided if there was a way to query how many items there were in a particular menu (the length of the appropriate array?)

Thanks for your help!
suraina
Beginner
Beginner
Posts: 1
Joined: Mon Feb 11, 2008 10:10 am

Re: Delete everything from menuitem array

Post by suraina »

Hi Andy

I tried to use mm_deleteItem () and other functions given in the mm_menueditapi.js mentioned above ...
but every time i get a JS error

object expected referencing to mmenudom.js
In my code i have also included milonic_src.js


Sunny
Post Reply