User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 425,972 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,682 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1988 | Replies: 0
Reply
Join Date: Jan 2008
Location: Largo Florida
Posts: 269
Reputation: serkansendur is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 23
serkansendur's Avatar
serkansendur serkansendur is offline Offline
Posting Whiz in Training

Javascript tab menu with rounded corners generator

  #1  
Mar 11th, 2008
I have searched for a tab menu script for a long time but none of them was flexible enough,then i created one for me. The algorithm is nice so the script is not too long although being flexible.

your tab menu is in an html table row as follows :
<tr id="foo">
                                <td align="left">
                                    <img alt="" src="images/tab_sol.jpg"></td>
                                <td nowrap="true" align="center" bgcolor="#333333">
                                   foo1  </td>
                                <td align="right">
                                    <img alt="" src="images/tab_sag.jpg"></td>
                                                                <td align="left">
                                    <img alt="" src="images/tabGri_sol.jpg"></td>
                                <td align="center" bgcolor="#646464" >
                                   foo2</td>
                                <td align="right">
                                    <img alt="" src="images/tabGri_sag.jpg"></td>
                            </tr>
in the bottom of your page just add script below to create menu from the markup above :
<script type="text/javascript">
    tableTabControl("foo");
</script>
required script is as follows :
function tableTabControl(anyTdIdFromTabRow)
    {
    var nodes = xGetElementById(anyTdIdFromTabRow).childNodes;
        for(var i = 0; i <  nodes.length; i++)
        {
            if(nodes[i].childNodes[0].nodeName == "#text" || nodes[i].childNodes[0].nodeName== "A")
            {
              
                 
                  addEvent( nodes[i],"click",clickFunction);
                  
                   
                   nodes[i].style.cursor = "hand";
            }
        }
       
        function clickFunction()
        {
        
             for(var i = 0; i <  nodes.length; i++)
            {
                if(nodes[i].childNodes[0].nodeName == "#text" || nodes[i].childNodes[0].nodeName == "A")
                {
                        if( nodes[i] != this)
                        {
                        nodes[i].style.backgroundColor = "#646464";
                        nodes[i].previousSibling.childNodes[0].src="images/tabGri_sol.jpg";
                        nodes[i].nextSibling.childNodes[0].src="images/tabGri_sag.jpg";
                        }
                        else
                        {
                         this.style.backgroundColor = "#333333";
                         this.previousSibling.childNodes[0].src="images/tab_sol.jpg";
                         this.nextSibling.childNodes[0].src="images/tab_sag.jpg";
                       
                        }
                       
                }
            }
         
        }
the following is the crossbrowser generic event registration method :
function addEvent(element, type, handler) {
	if (element.addEventListener) {
		element.addEventListener(type, handler, false);
	} else {
		// assign each event handler a unique ID
		if (!handler.$$guid) handler.$$guid = addEvent.guid++;
		// create a hash table of event types for the element
		if (!element.events) element.events = {};
		// create a hash table of event handlers for each element/event pair
		var handlers = element.events[type];
		if (!handlers) {
			handlers = element.events[type] = {};
			// store the existing event handler (if there is one)
			if (element["on" + type]) {
				handlers[0] = element["on" + type];
			}
		}
		// store the event handler in the hash table
		handlers[handler.$$guid] = handler;
		// assign a global event handler to do all the work
		element["on" + type] = handleEvent;
	}
};
// a counter used to create unique IDs
addEvent.guid = 1;

function removeEvent(element, type, handler) {
	if (element.removeEventListener) 
	{
		element.removeEventListener(type, handler, false);
	} 
	else 
	{
		// delete the event handler from the hash table
		if (element.events && element.events[type]) {
			delete element.events[type][handler.$$guid];
		}
	}
};

function handleEvent(event) {
	var returnValue = true;
	// grab the event object (IE uses a global event object)
	event = event || fixEvent(((this.ownerDocument || this.document || this).parentWindow || window).event);
	// get a reference to the hash table of event handlers
	var handlers = this.events[event.type];
	// execute each event handler
	for (var i in handlers) {
		this.$$handleEvent = handlers[i];
		if (this.$$handleEvent(event) === false) {
			returnValue = false;
		}
	}
	return returnValue;
};

function fixEvent(event) {
	// add W3C standard event methods
	event.preventDefault = fixEvent.preventDefault;
	event.stopPropagation = fixEvent.stopPropagation;
	return event;
};
fixEvent.preventDefault = function() {
	this.returnValue = false;
};
fixEvent.stopPropagation = function() {
	this.cancelBubble = true;
};
Last edited by ~s.o.s~ : Mar 13th, 2008 at 10:20 pm. Reason: Added code tags, learn to use them.
Serkan Şendur
MCAD.NET
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 11:11 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC