Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Old TOC script wont work in modern browser

    Hi, I would be grateful if somebody could point me in the right direction on how to modernise this TOC script so it will function in the latest browsers.
    It seems to work OK in IE upto version 8 but I cant get it to work in firefox or chrome. The script is clearly very old and written for IE5.5 and netscape but I have to use this everyday for my work and would like to modify it to make it less hassle to use.

    I have copied in the complete script below. The error on firefox is dveloper toolbar is

    Non-standard document.all property was used. Use W3C standard document.getElementById() instead. @ file:///D:/Data/js/Toc.js:231
    But I dont know how to change this code to get it to work correctly and will I encounter further issues further down the line.

    Any Guidance or pointers to a tutorial would be much appreciated.

    Code:
    / * Toc.js
    
    var eCurrentUL, eCurrentLI, eUL, tempIndex, syncIndex = null;
    var eTagName, eSrc, eImgIndex, eSynchedNode = null;
    var tempImgIndex = '0';
    
    function getNextULNS(eSrc)
    {
        var all = document.getElementsByTagName("*");
        for(var i = tempIndex; i < all.length; i++)
        {
            if( "UL" == all[ i ].tagName )
            {
    	    eImgIndex = all[tempIndex - 2];
                return all[ i ];
            }	
            else if( "LI" == all[ i ].tagName )
            {
                break;
            }
        }
        return false;
    }
    
    function getNextULIE(eSrc)
    {
        eImgIndex = document.all[eSrc.sourceIndex + 1];
        for(var i = eSrc.sourceIndex + 1; i < document.all.length; i++)
        {
            if( "UL" == document.all[ i ].tagName )
            {
                return document.all[ i ];
            }
            else if( "LI" == document.all[ i ].tagName )
            {
                break;
            }
        }
        return false;
    }
    
    function TOCClick(e)
    {
        self.status= "Select a Functional Group";
        if (e==null)
        {
    	eSrc = window.event.srcElement;
    	eTagName = eSrc.tagName;
        }
        else
        {	
        	window.event = e;
    	window.event.srcElement = e.target;
    	window.event.srcElement.parentElement = e.target.parentNode;
    	eTagName = window.event.srcElement.parentElement.tagName;
    	if ("A" == eTagName)
    		tempIndex = window.event.srcElement.parentElement.id;	
    	else
    		tempIndex = e.target.id;
    	eSrc = window.event.srcElement;
        }
        
        if("IMG" == eSrc.tagName ||("A" == eTagName)) 
        {
    	    if("noHand" != eSrc.className)
    	    {
            	eLI = eSrc.parentElement;
    		if (e == null)
    			eUL = getNextULIE(eLI);
    		else
    	 		eUL = getNextULNS(eLI);
    	        if(eUL && "kidShown" == eLI.className)
            	{
    	             eLI.className = "kid";
    	             eUL.className = "clsHidden";
    		     eSrc.src = "../../../../common/img/collapse.gif";
    	     	     eImgIndex.src = "../../../../common/img/fldc.gif";	
    	    	}
    	        else if(eUL)
            	{
    		    eLI.className = "kidShown";
            	    eUL.className = "clsShown";
    		    eSrc.src = "../../../../common/img/expand.gif";
    	    	    eImgIndex.src = "../../../../common/img/fldo.gif";
            	}
    	        else if("kid" == eLI.className)
            	{
                        eLI.className = "kidShown";
    	            eUL.className = "clsShown";
            	    window.eCurrentUL = eUL;
            	}
    	    }
        }
        markSync(eSrc.parentElement, e);	
    
        if (navigator.appName == "Microsoft Internet Explorer")
    	sessionTabNameIE();
        else if(navigator.appName == "Netscape")
    	sessionTabNameNS();
    
         var SessionTabName = parent.TabManager.document.tabManager.SessionTabName.value;
    
         if (SessionTabName == "ServiceInfo")
    	  parent.TabManager.document.tabManager.ServiceInfoIndex.value = tempImgIndex; 
         else if (SessionTabName == "TSB")
    	parent.TabManager.document.tabManager.TSBIndex.value = tempImgIndex; 
         else if (SessionTabName == "Wiring")
    	parent.TabManager.document.tabManager.WiringIndex.value = tempImgIndex; 
         else if (SessionTabName == "Parts")
    	parent.TabManager.document.tabManager.PartsIndex.value = tempImgIndex; 
         else if (SessionTabName == "Diagnostics")
    	 parent.TabManager.document.tabManager.DiagnosticsIndex.value = tempImgIndex;
    }
    
    
    function sessionTabNameIE()
    {
        if ('IMG' == eSrc.tagName) 
        {
    	tempImgIndex = eSrc.sourceIndex + 1; 
        }
        else 
    	tempImgIndex = eSrc.sourceIndex; 
    }
    
    function sessionTabNameNS()
    {
         if ( ('object' == typeof(eSrc)) && ('LI' != eSrc.tagName) )
         {
           if ('IMG' == eSrc.tagName)
           {
                tempImgIndex = 1;
           } 
           else
           	    tempImgIndex = eSrc.parentNode.id;
       
           tempImgIndex = tempImgIndex - 1;
         } 
    }
    
    
    function markSync(eSrc, e) 
    {
    	if("object" == typeof(eSynchedNode) && eSynchedNode )
        	{
    		eSynchedNode.getElementsByTagName("A")[0].style.fontWeight = "normal";
    		eSynchedNode.getElementsByTagName("A")[0].style.backgroundColor = "";
    		eSynchedNode.getElementsByTagName("A")[0].style.color = "#003366";
            	eSynchedNode = null;
        	}
    	if(syncIndex != null)
        	{
    		document.getElementById(syncIndex).style.fontWeight = "normal";
    		document.getElementById(syncIndex).style.backgroundColor = "";
    		document.getElementById(syncIndex).style.color = "#003366";
    		syncIndex = null;
        	}
    
        	if("LI" == eSrc.tagName.toUpperCase()) 
        	{
    		eSrc.getElementsByTagName("A")[0].style.fontWeight = "bold";
    		//eSrc.getElementsByTagName("A")[0].style.backgroundColor = "#FFFF99";
    		eSrc.getElementsByTagName("A")[0].style.backgroundColor = "#336699";
    		eSrc.getElementsByTagName("A")[0].style.color = "#FFFFFF";
    		eSynchedNode = eSrc;
    	}
        	else if( "A" == eSrc.tagName.toUpperCase() )
        	{
    		document.getElementById(tempIndex).style.fontWeight = "bold";
    		//document.getElementById(tempIndex).style.backgroundColor = "#FFFF99";
    		document.getElementById(tempIndex).style.backgroundColor = "#336699";
    		document.getElementById(tempIndex).style.color = "#FFFFFF";
    		syncIndex = tempIndex;
        	}
    	if ((e == null) && ("A" == eTagName.toUpperCase()))
        	{
    		eSrc.getElementsByTagName("A")[0].style.fontWeight = "bold";
    		eSrc.getElementsByTagName("A")[0].style.backgroundColor = "#336699";
    		eSrc.getElementsByTagName("A")[0].style.color = "#FFFFFF";
    		eSynchedNode = eSrc;
    	}
    }
    
    function tsbSession()
    {
      var tsbSessionFlag = 'TRUE';
      var tsbSessionObject = document.all[tabSessionIndex];
    
      if ((tabSessionIndex != null ) && (tabSessionIndex != "0"))
      { 
        if ( ('LI' != tsbSessionObject.tagName) && ('TD' != tsbSessionObject.tagName) ) 
        {
    	var tsbSessionParentObject = tsbSessionObject.parentElement;
     	tsbSessionObject.style.fontWeight = 'bold'; 
    	tsbSessionObject.style.backgroundColor = '#336699'; 
    	tsbSessionObject.style.color = '#FFFFFF'; 
    
    	if (tsbSessionObject.href != null ) 
    		window.open(tsbSessionObject.href, 'TEXTGRAPHIC'); 
    
    	eSynchedNode= tsbSessionObject.parentElement; 
    
    	while(tsbSessionFlag == 'TRUE') 
    	{ 
    		tsbSessionObject = document.all[tabSessionIndex]; 
    		tsbSessionParentObject = tsbSessionObject.parentElement; 
    		
    		if (tsbSessionParentObject.tagName == 'UL') 
    		{ 
    			tsbSessionParentObject.className = 'clsShown'; 
    			tsbSessionObject = document.all[tabSessionIndex - 3]; 
    			tsbSessionObject.src = '../../../../common/img/expand.gif'; 
    		}
    		
    		tabSessionIndex = tsbSessionParentObject.sourceIndex; 
    
    		if (tabSessionIndex < 12 ) 
    			tsbSessionFlag = 'FALSE'; 
    	} 
        }
      }
    }
    
    function tabSession()
    {
      var tabSessionFlag = 'TRUE';
      var tabSessionObject = document.all[tabSessionIndex];
    
      if ((tabSessionIndex != null ) && (tabSessionIndex != "0"))
      { 
        if ('LI' != tabSessionObject.tagName)
        { 
    	var tabSessionParentObject = tabSessionObject.parentElement; 
    	tabSessionObject.style.fontWeight = 'bold'; 
    	tabSessionObject.style.backgroundColor = '#336699'; 
    	tabSessionObject.style.color = '#FFFFFF'; 
    
    	if (tabSessionObject.href != null ) 
    		window.open(tabSessionObject.href, 'TEXTGRAPHIC'); 
    
    	eSynchedNode= tabSessionObject.parentElement; 
    	tabSessionIndex = tabSessionParentObject.sourceIndex; 
    	tabSessionObject = document.all[tabSessionIndex]; 
    	tabSessionParentObject = tabSessionObject.parentElement; 
    	tabSessionIndex = tabSessionParentObject.sourceIndex; 
    	tabSessionParentObject.className = 'clsShown'; 
    
    	while(tabSessionFlag == 'TRUE') 
    	{ 
    		tabSessionObject = document.all[tabSessionIndex];
    		tabSessionParentObject = tabSessionObject.parentElement;
    		tabSessionIndex = tabSessionParentObject.sourceIndex; 
    		tabSessionObject = document.all[tabSessionIndex+1]; 
    		tabSessionObject.src = '../../../../common/img/expand.gif'; 
    		tabSessionObject = document.all[tabSessionIndex]; 
    		tabSessionParentObject = tabSessionObject.parentElement; 
    		tabSessionIndex = tabSessionParentObject.sourceIndex; 
    		tabSessionParentObject.className = 'clsShown'; 
    
    		if (tabSessionIndex < 9 ) 
    			tabSessionFlag = 'FALSE'; 
    	}
         }
      } 
    }
    
    var tabSessionIndex;
    
    function manageSession()
    {
         var tabSessionName = parent.TabManager.document.tabManager.SessionTabName.value;
    	
         if (tabSessionName == "ServiceInfo")
         {
    	  tabSessionIndex = parent.TabManager.document.tabManager.ServiceInfoIndex.value; 
    	  tabSession();
         }
         else if (tabSessionName == "TSB")
         {	
    	tabSessionIndex = parent.TabManager.document.tabManager.TSBIndex.value; 
    	tsbSession();
         }
         else if (tabSessionName == "Wiring")
         {
    	tabSessionIndex = parent.TabManager.document.tabManager.WiringIndex.value; 
    	tabSession();
         }
         else if (tabSessionName == "Parts")
         {
    	tabSessionIndex = parent.TabManager.document.tabManager.PartsIndex.value; 
            tabSession();
         }
         else if (tabSessionName == "Diagnostics")
         {
    	 tabSessionIndex = parent.TabManager.document.tabManager.DiagnosticsIndex.value;
    	 tabSession();
         }
    }
    
    
    function windowLoad()
    {
    	manageSession();
    	var ulRoot = document.getElementById( "ulRoot" );
    	if (ulRoot != null)
               ulRoot.onclick=TOCClick;
    }
    
    window.onload = windowLoad;

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 634 Times in 624 Posts
    document.all is a proprietary Microsoft command that only works in IE4 through IE8. As that script uses document.all in almost every statement in the code it will need to be completely rewritten to work with modern browsers.

    The standard commands that document.all was set up to emulate are document.getElementById() and document.getElementsByTagName()

    There is also no need to distinguish between different browsers any more as all browsers since IE5 all recognise these standard calls.



    So the getNextULIE function can be deleted because the getNextULNS function will work for all current browsers.

    Also the tabSession function will need to be rewritten to get rid of the document.all calls.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    mrnorx (03-11-2013)

  • #3
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I am also facing the same problem with Old TOC script.

    Could you please let me know whether your problem got fixed or not


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •