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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript not working

    Hi,
    currently we are using IE 7 in that for showing submenu we are using the following code but it is not working in google chrome and firefox..basically it is a seperate .js file where functions are stored


    Code :

    Code:
     if( typeof ( gCSSList ) == 'undefined' || gCSSList == null ) var gCSSList= new Array();gCSSList[1]= Array('MENU_BLOCK_1','MENU_ITEM_1','MENU_ITEM_HL_1','MENU_ITEM_SL_1','MENU_ITEM_COL_LEFT_1','MENU_ITEM_COL_LEFT_HL_1','MENU_ITEM_COL_LEFT_SL_1','MENU_ITEM_COL_RIGHT_1','MENU_ITEM_COL_RIGHT_HL_1','MENU_ITEM_COL_RIGHT_SL_1','MENU_ITEM_HEADING_1','SUBMENU_BLOCK_1');
    
    
            
            var gMainmenuFrm    =   'left';
            var gSubmenuFrm     =   'right';
    
             
            if( typeof ( gTimer ) == 'undefined' || gTimer == null )   var gTimer = new Array();
    
            
            if( typeof ( HLItemList ) == 'undefined' || HLItemList == null )   var HLItemList = new Array();
    
            
            if( typeof ( MenuList ) == 'undefined' || MenuList == null ) var MenuList = new Array();
    
            function vMenu_AddtoHLList ( pCtrlId, pItemId )
            {
                
                if( typeof ( HLItemList[pCtrlId] ) == 'undefined' || HLItemList[pCtrlId] == null ) HLItemList[pCtrlId] = pItemId+ ',';
    
                
                else    HLItemList[pCtrlId] = HLItemList[pCtrlId] + pItemId+ ',';
            }
    
           
            function vMenu_AddtoMenuList ( pCtrlId, pMenuID )
            {
                
                if( typeof ( MenuList[pCtrlId] ) == 'undefined' || MenuList[pCtrlId] == null ) MenuList[pCtrlId] = pMenuID + ',';
    
             
                else    MenuList[pCtrlId] = MenuList[pCtrlId] + pMenuID + ',';
            }
    
            
            function vMenu_HideSubmenu ( pCtrlId, pMenuLevel )
            {
                try
                {
                    var MenuStr         =       new String();
                    objFrm = window.parent.frames(gSubmenuFrm);
    
                  
                    if( typeof ( MenuList[pCtrlId] ) == 'undefined' || MenuList[pCtrlId] == null )    return;
    
                    MenuStr             =       MenuList[pCtrlId];
                    MenuArr             =       MenuStr.split(',');
    
                    
                   
                    for( i=0; i < ( MenuArr.length - 1 ); i++ )
                    {
                         MenuIds        =       MenuArr[i].split('_');
    
                        
                        if( MenuIds[2] > pMenuLevel )
                        {
                            object      =       objFrm.document.getElementById(MenuArr[i]);
                            object.style.visibility     =       "hidden";
                            objFrm.document.getElementById('IF_'+object.id).style.visibility="hidden";
                           
                            MenuStr     =       MenuStr.replace(MenuArr[i]+',','');
                        }
                    }
    
                    
                    MenuList[pCtrlId]   =       MenuStr;
                }
                catch(e)
                {
                    
                }
            }
    
            
            
            function vMenu_UnHilightItems ( pCtrlId, pLevel )
            {
                objFrm              =       window.parent.frames(gSubmenuFrm);
                var ItemStr         =       new String();
                ItemStr             =       HLItemList[pCtrlId];
    
                
                if( typeof ( HLItemList[pCtrlId] ) == 'undefined' || HLItemList[pCtrlId]  ==  null ) return;
    
                
                ItemArr             =       ItemStr.split(',');
    
                
                for( i=0; i < ( ItemArr.length - 1 ); i++ )
                {
                     ItemIds        =       ItemArr[i].split('_');
    
                   
                    if(ItemIds[2] >= pLevel )
                    {
                       
                        if( ItemIds[2] == 1 )
                        {
                            objmfr              =       window.parent.frames(gMainmenuFrm);
                            object              =       objmfr.document.getElementById(ItemArr[i]);
                            
                            object.className    =       gCSSList[pCtrlId][1];
                            objmfr.document.getElementById(object.id+'_1').className    =   gCSSList[pCtrlId][4];
                            objmfr.document.getElementById(object.id+'_2').className    =   gCSSList[pCtrlId][7];
                        }
    
                        // case : Item will be on submenu frame, use submenu frame reference to unhighlight item
                        else
                        {
                            object              =       objFrm.document.getElementById(ItemArr[i]);
                           
                            object.className    =       gCSSList[pCtrlId][1];
                            objFrm.document.getElementById(object.id+'_1').className    =   gCSSList[pCtrlId][4];
                            objFrm.document.getElementById(object.id+'_2').className    =   gCSSList[pCtrlId][7];
                        }
    
                       
                        ItemStr = ItemStr.replace(ItemArr[i]+',','');
                    }
                }
    
                
                HLItemList[pCtrlId]             =       ItemStr;
            }
    
            
            function vMenu_HighlightItems ( pCtrlId, pEventItemId, EventFrm )
            {
                
                objFrm                          =       window.parent.frames(EventFrm);
                
                objFrm.document.getElementById(pEventItemId).className          =       gCSSList[pCtrlId][2];
               
                objFrm.document.getElementById(pEventItemId+'_1').className     =       gCSSList[pCtrlId][5];
                objFrm.document.getElementById(pEventItemId+'_2').className     =       gCSSList[pCtrlId][8];
            }
    
         
            function vMenu_MenuItem_OnClick ( pTargetPage, pTargetType, pEventItem, pTargetFeatures, pReplace )
            {
                var EventItemId         =       pEventItem.id;
                var IDs                 =       EventItemId.split('_');
                var CtrlId              =       new Number(IDs[1]);
    
               
                vMenu_HideSubmenu( CtrlId, 0 );
                vMenu_UnHilightItems( CtrlId, 0 );
    
                window.open( pTargetPage, pTargetType, pTargetFeatures, pReplace );
            }
    
            item
            function vMenu_MenuItem_OnMouseOut ( pEventItem )
            {
                var EventItemId         =       pEventItem.id;
                var IDs                 =       EventItemId.split('_');
                var CtrlId              =       new Number(IDs[1]);
                var Level               =       new Number(IDs[2]);
    
               
                vMenu_setMenuTimer ( CtrlId );
            }
    
           
            function vMenu_MenuItem_OnMouseOver ( pEventItem )
            {
                var EventItemId         =       pEventItem.id;
                var EventFrm            =       window.name;
                // split item id, to get detail about item
                var IDs                 =       EventItemId.split('_');
                var CtrlId              =       new Number(IDs[1]);
                var Level               =       new Number(IDs[2]);
                var ItemType            =       new Number(IDs[3]);
                var ItemIndex           =       new Number(IDs[4]);
    
               
                vMenu_clearMenuTimer ( CtrlId );
    
               
                if( ( ItemType == 1 ) || ( ItemType == 4 ) )  return;
    
                
                vMenu_HideSubmenu ( CtrlId, Level );
    
               
                vMenu_UnHilightItems( CtrlId, Level );
    
                
                if( ItemType == 3 )
                {
                   
                    MenuId = 'MNU_' + CtrlId + '_' + (Level+1) + '_' + ItemIndex;
    
                    
                    vMenu_ShowSubmenu ( EventItemId, MenuId );
    
                    
                    vMenu_AddtoMenuList ( CtrlId, MenuId );
                }
    
               
                vMenu_HighlightItems ( CtrlId, EventItemId, EventFrm );
    
                
                vMenu_AddtoHLList ( CtrlId, EventItemId );
            }
    
           
            function vMenu_ShowSubmenu ( pEventItemId, pMenuID )
            {
                try
                {
                    
                    var IDs             =       pEventItemId.split('_');
                   
                    var Level           =       new Number(IDs[2]);
                    var SFrm;
    
                    
                    if ( Level == 1 )
                    {
                        SFrm            =       window.name;
                        objectfrm       =       window.parent.self;
                    }
    
                   
                    else
                    {
                        SFrm            =       gSubmenuFrm;
                        objectfrm       =       window.parent.frames(SFrm);
                    }
    
                    
                    objtgtfrm           =       window.parent.frames(gSubmenuFrm);
    
                                       
    
                    
                    windowHeight        =       vMenu_GetWindowHeight ( SFrm );
    
                   
                    windowYOffset       =       vMenu_GetWindowYOffset ( SFrm );
    
                   
                    TopVal              =       vMenu_GetObjectTop ( pEventItemId, SFrm );
    
                    
                    object              =       objtgtfrm.document.getElementById ( pMenuID );
    
                    
                    tMenuHeight         =       object.offsetHeight;
    
                    
                    
                    if ( Level == 1 )
                    {
                        
                        windowSubHeight     =       vMenu_GetWindowHeight ( gSubmenuFrm );
    
                        
                        TopVal              =       TopVal - windowYOffset;
    
                        
                        windowSubYOffset    =       vMenu_GetWindowYOffset ( gSubmenuFrm );
    
                       
                        TopVal              =       TopVal + windowSubYOffset;
    
                      
                      
                        if ( ( TopVal + tMenuHeight ) > ( windowSubHeight + windowSubYOffset ) )
                        {
                            TopVal      =       windowSubHeight + windowSubYOffset - tMenuHeight;
    
                           
                            if(TopVal < 0)  TopVal = 0;
                        }
                    }
    
                   
                    else
                    {
                        
                        if ( ( TopVal + tMenuHeight ) > ( windowHeight + windowYOffset ) )
                        {
                            TopVal      =       windowHeight + windowYOffset - tMenuHeight;
    
                            
                            if(TopVal < 0)  TopVal = 0;
                        }
                    }
    
                                  
               
                windowXOffset       =           vMenu_GetWindowXOffset ( gSubmenuFrm );
    
               
                if ( Level == 1 )
                {
                    LeftVal         =           windowXOffset;
                }
    
                /
                else
                {
                   
                    windowWidth     =           vMenu_GetWindowWidth ( gSubmenuFrm );
    
                    
                    LeftVal         =           vMenu_GetObjectLeft ( pEventItemId, gSubmenuFrm );
    
                    
                    object          =           objectfrm.document.getElementById ( pEventItemId );
                    ParentWidth     =           object.offsetWidth;
    
                    
                    object          =           objtgtfrm.document.getElementById ( pMenuID );
                   
                    tMenuWidth      =           object.offsetWidth;
                    
                    LeftVal         =           ParentWidth + LeftVal;
    
                   
                    if (LeftVal + tMenuWidth > windowWidth + windowXOffset)
                    {
                        LeftVal     =       LeftVal-ParentWidth-tMenuWidth;
    
                        // case : calculated left is out of window area, set left to zero
                        if(LeftVal<0)   LeftVal = 0;
                    }
                }
    
                // set left and top of menu object(table)
                object.style.left       =       LeftVal;
                object.style.top        =       TopVal;
                // set visibility of menu object to true
                object.style.visibility     =   "visible";
    
                // set iframe position and dimension in such a way that it is displayed
                // at the same location and of the same dimention
                object_if               =       objtgtfrm.document.getElementById('IF_'+object.id);
                object_if.style.width   =       object.offsetWidth;
                object_if.style.height  =       object.offsetHeight;
                object_if.style.top     =       object.style.top;
                object_if.style.left    =       object.style.left;
                // set visibility of iframe related to menu
                object_if.style.visibility  =   "visible";
    
                }
                catch (e)
                {
                    // debug
                    // alert ('exception:'+e);
                }
            }
    
            // function determines width of specified frame window
            //  ???? Unsure which condition gives value under which scenario.
            function vMenu_GetWindowWidth ( pFrm )
            {
                var value               =       0;
                objectfrm               =       window.parent.frames(pFrm);
    
                if ( objectfrm.document.documentElement && objectfrm.document.documentElement.clientWidth )
                {
                    value               =       objectfrm.document.documentElement.clientWidth;
                }
    
                else if ( objectfrm.document.body )
                {
                    value               =       objectfrm.document.body.clientWidth;
                }
    
                if ( isNaN ( value ) )
                {
                    value               =       top.innerWidth;
                }
    
                return (value);
            }
    
            // function determines height of the specified frame window
            //  ???? Unsure which condition gives value under which scenario
            function vMenu_GetWindowHeight ( pFrm )
            {
                var value               =       0;
                objectfrm               =       window.parent.frames(pFrm);
    
                if ( objectfrm.document.documentElement && objectfrm.document.documentElement.clientHeight )
                {
                    value               =       objectfrm.document.documentElement.clientHeight;
                }
    
                else if ( objectfrm.document.body )
                {
                    value               =       objectfrm.document.body.clientHeight;
                }
    
                if ( isNaN ( value ) )
                {
                    value               =       top.innerHeight;
                }
    
                return (value);
            }
    
            // function that determines verticle offset of specified frame window (based on verticle scroll position)
            //  ???? Unsure which condition gives value under which scenario
            function vMenu_GetWindowXOffset ( pFrm )
            {
                var value               =       0;
                objectfrm               =       window.parent.frames(pFrm);
    
                if ( objectfrm.document.documentElement && objectfrm.document.documentElement.scrollLeft )
                {
                    value               =       objectfrm.document.documentElement.scrollLeft;
                }
    
                else if ( objectfrm.document.body )
                {
                    value               =       objectfrm.document.body.scrollLeft;
                }
    
                return (value);
            }
    
            // function that determines horizontal offset of specified frame window (based on verticle scroll position)
            //  ???? Unsure which condition gives value under which scenario
            function vMenu_GetWindowYOffset ( pFrm )
            {
                var value               =       0;
    
                objectfrm = window.parent.frames(pFrm);
    
                if ( objectfrm.document.documentElement && objectfrm.document.documentElement.scrollTop )
                {
                    value               =       objectfrm.document.documentElement.scrollTop;
                }
    
                else if ( objectfrm.document.body )
                {
                    value               =       objectfrm.document.body.scrollTop;
                }
    
                return (value);
            }
    
            // calculate Left position of given object from left of the document
            function vMenu_GetObjectLeft ( pObjectName, pFrm )
            {
                var value               =       0;
                objectfrm               =       window.parent.frames(pFrm);
                object = objectfrm.document.all(pObjectName);
    
                // Loopthru parents to calculate left value
                // until parent is Body or does not have parent container
                while ( object.tagName != "BODY" && object.offsetParent )
                {
                    // retrives reference to the container object of given object
                    object              =       object.offsetParent;
                    value               +=      object.offsetLeft;
                }
    
                return (value);
            }
    
            // calculates Top position of given object from tope of the document
            function vMenu_GetObjectTop ( pObjectName, pFrm )
            {
                var value               =       0;
                objectfrm               =       window.parent.frames(pFrm);
                object                  =       objectfrm.document.all(pObjectName);
                value                   =       object.offsetTop;
    
                // Loopthru parents to calculate top value
                // until parent is Body or does not have parent container
                while ( object.tagName != "BODY" && object.offsetParent )
                {
                    // retrives reference to the container object of given object
                    object              =       object.offsetParent;
                    value               +=      object.offsetTop;
                }
    
                return (value);
            }
    
            // this function sets timer, and Function to be executed after timer time out
            // settimeout function returns reference, whcih can be used to clear timer
            // this function is called on mouse out of Menu item, so that Menu is closed automatically after some time
            function vMenu_setMenuTimer ( pCtrlId )
            {
                gTimer[pCtrlId]         =       setTimeout('vMenu_HideSubmenu('+pCtrlId+',0);vMenu_UnHilightItems('+pCtrlId+',0);', 1000);
            }
    
            // this function clears timer using timer reference available, called onmouse over of menu item
            function vMenu_clearMenuTimer ( pCtrlId )
            {
                clearTimeout(gTimer[pCtrlId]);
            }
    Last edited by VIPStephan; 03-13-2012 at 11:53 AM. Reason: wrapped code BB tags around code

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Please wrap your code parts in [ code ] and [ /code ] tags (without the spaces) to ensure proper styling and indentation of your code. You can also achieve that by using the octathorpe # symbol (not the #i symbol) on top of the text area.


  •  

    Posting Permissions

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