By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,398 Members | 1,362 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,398 IT Pros & Developers. It's quick & easy.

script problems in FireFox

P: 2
this script work fine in IE but not in FireFox
where is the problem?

here is the script


Expand|Select|Wrap|Line Numbers
  1. /*------------------------------------------------------------------
  2.  File:            menu.js
  3.  Use:            Collection of clients functions
  4.                 that used for interface of the menu bar.
  5. -------------------------------------------------------------------*/
  6. var g_MaincontextMenu;
  7. var currentMenu; //The last sub menu that open.
  8.  
  9. /*-----------------------------------------------------------------
  10.     Calculate the top position of the object.
  11.     Parameters: 
  12.     Name                Description
  13.     -------------------------------------------------------------------
  14.     obj                    The object
  15. ------------------------------------------------------------------*/
  16. function offsetTop(obj)
  17. {
  18.     var top = 0;
  19.  
  20.     for (; obj; obj=obj.offsetParent)
  21.     {
  22.         top = top + obj.offsetTop;
  23.     }
  24.     return(top);
  25. }
  26.  
  27. /*-----------------------------------------------------------------
  28.     Calculate the left position of the object.
  29.     Parameters: 
  30.     Name                Description
  31.     -------------------------------------------------------------------
  32.     obj                    The object
  33. ------------------------------------------------------------------*/
  34. function offsetLeft(obj)
  35. {
  36.     var left = 0;
  37.  
  38.     for (; obj; obj=obj.offsetParent)
  39.     {
  40.         if (obj.tagName == "BODY") break;
  41.         left = left + obj.offsetLeft;
  42.     }
  43.     return(left);
  44. }
  45.  
  46. /*-----------------------------------------------------------------
  47.     Loaded the child of the first menu.
  48.     Parameters: 
  49.     Name                Description
  50.     -------------------------------------------------------------------
  51.     obj                    The object
  52.     p_Dir                Direction of the web: RTL or LTR
  53. ------------------------------------------------------------------*/
  54. function loadContextMenu(obj, p_Dir)
  55. {
  56.     var contextMenu;
  57.     var parentMenu;
  58.     parentMenu = returnContainer(obj);
  59.     contextMenu = document.all[obj.id + "Sub"];
  60.  
  61.     //document.form2.strSearch.value = document.form2.strSearch.value + "," + contextMenu.id;
  62.  
  63.     if (currentMenu)
  64.     {
  65.         menuOut(currentMenu);
  66.  
  67.     }
  68.  
  69.  
  70.     if (contextMenu != null)
  71.     {
  72.  
  73.  
  74.         if(contextMenu.style.display == "block")
  75.             return;
  76.  
  77.  
  78.         contextMenu.style.display = "block";
  79.         var l_contextMenu_Top = offsetTop(parentMenu) + parentMenu.offsetHeight - 2;
  80.         contextMenu.style.top = l_contextMenu_Top;
  81.         contextMenu.style.width = parentMenu.offsetWidth;
  82.         contextMenu.firstChild.style.width = "100%";
  83.         contextMenu.parentMenu = parentMenu;
  84.         parentMenu.subMenu = contextMenu;
  85.         currentMenu = parentMenu;
  86.  
  87.  
  88.         if (p_Dir == 'RTL'){
  89.             if(contextMenu.clientWidth > parentMenu.clientWidth){
  90.                 var contextMenuPosition = offsetLeft(parentMenu) - (contextMenu.clientWidth - parentMenu.clientWidth);
  91.             }else{
  92.                 var contextMenuPosition = offsetLeft(parentMenu);
  93.             }
  94.             if(contextMenuPosition < 0){
  95.                 contextMenu.style.left = 0;
  96.             }else{
  97.                 contextMenu.style.left = contextMenuPosition;
  98.             }
  99.  
  100.         }else{
  101.             contextMenu.style.left = offsetLeft(parentMenu);
  102.             var l_WindowWidth = document.body.clientWidth;
  103.             var l_DivWidth = contextMenu.clientWidth;
  104.             var contextMenuLeft = offsetLeft(parentMenu)
  105.             //alert("l_WindowWidth = " + l_WindowWidth)//
  106.             //alert("l_WindowWidth = " + l_WindowWidth + " : l_DivWidth + contextMenuLeft = " + eval(l_DivWidth + contextMenuLeft));
  107.             //alert(contextMenuLeft);
  108.             if(l_WindowWidth  < l_DivWidth + contextMenuLeft){
  109.                 //alert("l_WindowWidth = " + l_WindowWidth + " : l_DivWidth + contextMenuLeft = " + eval(l_DivWidth + contextMenuLeft));
  110.                 contextMenu.style.left = l_WindowWidth - l_DivWidth;
  111.             }
  112.         }
  113.  
  114.         contextMenu.style.height = 0;
  115.  
  116.         var l_DivHeight = contextMenu.clientHeight + 2;
  117.  
  118.         //-----Set The div top postion ------------------
  119.         var l_WindowHeight = document.body.clientHeight;
  120.         var l_ScrollTop = document.body.scrollTop;
  121.         //alert(l_WindowHeight);
  122.         //alert(document.body.scrollTop);
  123.  
  124.         if(l_WindowHeight < (l_contextMenu_Top + l_DivHeight) - l_ScrollTop)
  125.             contextMenu.style.top  = l_contextMenu_Top - ((l_contextMenu_Top + l_DivHeight - l_ScrollTop) - l_WindowHeight);
  126.         //-------------------------------------------------
  127.  
  128.         contextMenu.style.overflowY = 'hidden';
  129.         contextMenu.style.height = 0;
  130.  
  131.         //contextMenu.style.display = "none";
  132.         var g_MaincontextMenu = "";
  133.         SetMainDiv(contextMenu);
  134.         BuildDiv(0, l_DivHeight);
  135.  
  136.  
  137.     }
  138. }
  139.  
  140. var y="";
  141. function SetMainDiv(p_MaincontextMenu){
  142.     g_MaincontextMenu = p_MaincontextMenu;
  143.     clearTimeout(y);
  144. }
  145.  
  146.  
  147. function BuildDiv(p_Height, p_HighHeight){
  148.  
  149.     //alert(1);
  150.     //document.form2.strSearch.value = document.form2.strSearch.value + "," + p_Height + "," + p_HighHeight;
  151.  
  152.     //document.form2.strSearch.value = document.form2.strSearch.value + "," + g_MaincontextMenu.id;
  153.  
  154.     var l_contextMenu = g_MaincontextMenu;
  155.     //g_MaincontextMenu = "";
  156.     //alert(l_contextMenu);
  157.     //alert ("p_Height = " + p_Height);
  158.     //alert ("p_HighHeight = " + p_HighHeight);
  159.  
  160.  
  161.     //alert(l_contextMenu.id);
  162.     if (p_Height < p_HighHeight){
  163.         l_contextMenu.style.height = p_Height + 10;
  164.         //alert(p_contextMenu.clientHeight);
  165.         //alert(1);
  166.         y = setTimeout('BuildDiv(' +  parseInt(p_Height + 10) + ',' + p_HighHeight + ');', 30);    
  167.         //alert(2);
  168.         //alert(p_contextMenu.style.height);
  169.     }else{
  170.         clearTimeout(y);
  171.  
  172.         //alert('Clear');
  173.     }
  174. }
  175.  
  176. /*-----------------------------------------------------------------
  177.     Loaded the child of the submenus.
  178.     Parameters: 
  179.     Name                Description
  180.     -------------------------------------------------------------------
  181.     obj                    The  object
  182. ------------------------------------------------------------------*/
  183. function loadContextMenuSub(obj) {
  184.     var contextMenu;
  185.     var parentMenu;
  186.     //alert('loadContextMenuSub');
  187.     parentMenu = returnContainer(obj);
  188.     contextMenu = document.all[obj.id + "Sub"];
  189.     contextMenu.style.display = "block";
  190.  
  191.     var l_contextMenu_Top =  obj.offsetTop + parentMenu.offsetTop;
  192.     contextMenu.style.top = l_contextMenu_Top;
  193.  
  194.     var l_DivHeight = contextMenu.clientHeight;
  195.     if (parentMenu.offsetLeft - contextMenu.offsetWidth + 1 < 0)
  196.         contextMenu.style.left = parentMenu.offsetLeft + parentMenu.offsetWidth - 7;
  197.     else
  198.         contextMenu.style.left = parentMenu.offsetLeft - contextMenu.offsetWidth + 7;
  199.     contextMenu.parentMenu = parentMenu;
  200.     parentMenu.subMenu = contextMenu;
  201.  
  202.  
  203.     //-----Set The div top postion ------------------
  204.     var l_WindowHeight = document.body.clientHeight;
  205.     var l_ScrollTop = document.body.scrollTop;
  206.     //alert(l_WindowHeight);
  207.     //alert(document.body.scrollTop);
  208.  
  209.     if(l_WindowHeight < (l_contextMenu_Top + l_DivHeight) - l_ScrollTop)
  210.         contextMenu.style.top  = l_contextMenu_Top - ((l_contextMenu_Top + l_DivHeight - l_ScrollTop) - l_WindowHeight);
  211.     //-------------------------------------------------
  212.  
  213.  
  214. }
  215.  
  216. /*-----------------------------------------------------------------
  217.     function that change the interface of the menu item on mouseover event.
  218.     Parameters: 
  219.     Name                Description
  220.     -------------------------------------------------------------------
  221.     obj                    The object
  222. ------------------------------------------------------------------*/
  223. function menuOver(obj)
  224. {
  225.     var parentMenu;
  226.     var subMenu;
  227.     var i;
  228.  
  229.     parentMenu = returnContainer(obj);
  230.  
  231.     for (i=0; i < obj.childNodes.length; i++)
  232.     {
  233.         obj.childNodes(i).className = obj.SubMenuTextClassOver;
  234.     }
  235.  
  236.     if (parentMenu.subMenu != null && parentMenu != parentMenu.subMenu)
  237.     {
  238.         subMenu = parentMenu.subMenu;
  239.  
  240.         while (subMenu != null)
  241.         {
  242.             subMenu.style.display = "none";
  243.             subMenu = subMenu.subMenu;
  244.         }
  245.     }
  246. }
  247.  
  248. /*-----------------------------------------------------------------
  249.     function that change the interface of the menu item on mouseout event.
  250.     Parameters: 
  251.     Name                Description
  252.     -------------------------------------------------------------------
  253.     row                    The object
  254. ------------------------------------------------------------------*/
  255. function menuOut(row)
  256. {
  257.  
  258.  
  259.     var parentMenu;
  260.     var subMenu;
  261.     var i;
  262.  
  263.     parentMenu = returnContainer(row);
  264.     if (parentMenu != row)
  265.     {
  266.         for (i=0; i < row.childNodes.length; i++)
  267.         {
  268.             //alert(row.childNodes(i).className);
  269.             row.childNodes(i).className = row.SubMenuTextClass;
  270.  
  271.         }
  272.     }
  273.  
  274.     var toElement = returnContainer(event.toElement);
  275.     var toHide = true;
  276.     if (toElement == null)
  277.     {
  278.         if (parentMenu.subMenu) parentMenu = parentMenu.subMenu;
  279.         while (parentMenu.parentMenu != null)
  280.         {
  281.             parentMenu.style.display = "none";
  282.             parentMenu = parentMenu.parentMenu;
  283.         }
  284.     }
  285.     else
  286.     {
  287.         while (toElement)
  288.         {
  289.             if (toElement == parentMenu)
  290.             {
  291.                 toHide = false;
  292.                 window.event.cancelBubble = true;
  293.                 break;
  294.             }
  295.             toElement = toElement.parentMenu;
  296.         }
  297.         if (toHide)
  298.         {
  299.             subMenu = parentMenu.subMenu;
  300.             while (subMenu != null)
  301.             {
  302.                 subMenu.style.display = "none";
  303.                 subMenu = subMenu.subMenu;
  304.             }
  305.         }
  306.     }
  307. }
  308.  
  309. function contextHighlightRow(obj)
  310. {
  311.     var parentMenu;
  312.     var subMenu;
  313.     var i;
  314.  
  315.     parentMenu = returnContainer(obj);
  316.  
  317.     if (obj.selected == "false")
  318.     {
  319.         for (i=0; i < obj.childNodes.length; i++)
  320.         {
  321.             obj.childNodes(i).style.borderTop = "1px solid white";
  322.             obj.childNodes(i).style.borderBottom = "1px solid white";
  323.             if (obj.childNodes(i).cellIndex == 0 || obj.childNodes.length == 1)
  324.             {
  325.                 obj.childNodes(i).style.borderLeft = "1px solid white";
  326.             }
  327.             if (obj.childNodes(i).cellIndex != 0 || obj.childNodes.length == 1)
  328.             {
  329.                 if (obj.childNodes(i).cellIndex == obj.cells.length-1)
  330.                 {
  331.                     obj.childNodes(i).style.borderRight = "1px solid white";
  332.                 }
  333.             }
  334.         }
  335.  
  336.         if (parentMenu.subMenu != null && parentMenu != parentMenu.subMenu)
  337.         {
  338.             subMenu = parentMenu.subMenu;
  339.  
  340.             while(subMenu != null)
  341.             {
  342.                 subMenu.style.display = "none";
  343.                 subMenu = subMenu.subMenu;
  344.             }
  345.         }
  346.         obj.selected = "true";
  347.     }
  348.     else
  349.     {
  350.         for (i=0; i < obj.childNodes.length; i++)
  351.         {
  352.             if (i == 0)
  353.             {
  354.                 //obj.childNodes(i).style.borderTop = "1px solid " + obj.background;
  355.                 obj.childNodes(i).style.borderTop = "1px solid white";
  356.                 //obj.childNodes(i).style.borderBottom = "1px solid " + obj.background;
  357.                 obj.childNodes(i).style.borderBottom = "1px solid white";
  358.             }
  359.             else
  360.             {
  361.                 //obj.childNodes(i).style.borderTop = "1px solid " + obj.titlebar;
  362.                 //obj.childNodes(i).style.borderBottom = "1px solid " + obj.titlebar;
  363.                 obj.childNodes(i).style.borderTop = "1px solid white";
  364.                 obj.childNodes(i).style.borderBottom = "1px solid white";
  365.             }
  366.  
  367.             if (obj.childNodes(i).cellIndex == 0 || obj.childNodes.length == 1)
  368.             {
  369.                 //obj.childNodes(i).style.borderLeft = "1px solid " + obj.titlebar;
  370.                 obj.childNodes(i).style.borderLeft = "1px solid white";
  371.             }
  372.             if (obj.childNodes(i).cellIndex != 0 || obj.childNodes.length == 1)
  373.             {
  374.                 if (obj.childNodes(i).cellIndex == obj.cells.length-1)
  375.                 {
  376.                     //obj.childNodes(i).style.borderRight = "1px solid " + obj.background;
  377.                     obj.childNodes(i).style.borderRight = "1px solid white";
  378.                 }
  379.             }
  380.         }
  381.         obj.selected = "false";
  382.     }
  383. }
  384.  
  385. /*-----------------------------------------------------------------
  386.     function that return the parent of the item.
  387.     Parameters: 
  388.     Name                Description
  389.     -------------------------------------------------------------------
  390.     container            The Item
  391. ------------------------------------------------------------------*/
  392. function returnContainer(container)
  393. {
  394.     if (container)
  395.     {
  396.         while (!container.menuElement)
  397.         {
  398.             if (container.parentElement)
  399.             {
  400.                 container = container.parentElement;
  401.             }
  402.             else
  403.             {
  404.                 container = null;
  405.                 break;
  406.             }
  407.         }
  408.     }
  409.     return(container);
  410. }
  411.  
  412.  
  413. /*-----------------------------------------------------------------
  414.     Open new window 
  415.     Parameters: 
  416.     Name                Description
  417.     -------------------------------------------------------------------
  418.     p_Id                    Category Id
  419. */
  420.     function loadCategoryFile(p_Id){
  421.         window.open ("OpenFileById.asp?Id=" + p_Id,"");
  422.     }
  423.  
  424.  
  425.  
  426. /*-----------------------------------------------------------------
  427.     Redirect function
  428.     Parameters: 
  429.     Name                Description
  430.     -------------------------------------------------------------------
  431.     lngCategoryID        The CategoryID
  432. ------------------------------------------------------------------*/
  433. function loadCategory(lngCategoryID)
  434. {
  435.     window.location = "main.asp?lngCategoryID=" + lngCategoryID;
  436. }
  437.  
  438.  
  439. /*-----------------------------------------------------------------
  440.  
  441.             Open Window
  442.  
  443.             Parameters: 
  444.  
  445.     Name                                                Description
  446.  
  447.     -------------------------------------------------------------------
  448.  
  449.     p_Url                         Url to Open
  450.     p_Width        The                   Width of the window
  451.     p_Height                   The Height of the window
  452.     p_Resizable              yes or no
  453.     p_Scrollbars  yes or no
  454.     p_Status                   yes or no
  455.     p_Addressbar            yes or no
  456.     p_Toolbar                  yes or no
  457. ------------------------------------------------------------------*/
  458.  
  459. function OpenNewWindow(p_Url, p_Width, p_Height, p_Resizable, p_Scrollbars, p_Status, p_Addressbar, p_Toolbar)
  460. {
  461.             window.open(p_Url,"" ,"height=" + p_Height + ",width=" + p_Width + ",top=100,left=100,resizable=" + p_Resizable + ",scrollbars=" + p_Scrollbars + ",status=" + p_Status + ",location=" + p_Addressbar + ",toolbar=" + p_Toolbar);
  462. }
  463. /*-----------------------------------------------------------------
  464.     function that handling the onclick event
  465.     Parameters: 
  466.     Name                Description
  467.     -------------------------------------------------------------------
  468.     item                The object that on click occured in
  469.     lngCategoryID        The CategoryID
  470. ------------------------------------------------------------------*/
  471. function clickMenu(item, lngCategoryID)
  472. {
  473.     lngCategoryID = parseInt(lngCategoryID.substr(1));
  474.     switch (item.TypeRef)
  475.     {
  476.     case "1":
  477.         break;
  478.     case "2":
  479.         switch (item.TargetRef)
  480.         {
  481.             case "1":
  482.                 window.open(item.Link);
  483.                 break;
  484.             case "2":
  485.                 window.location = item.Link;
  486.                 break;
  487.             case "3":
  488.                 parent.location = item.Link;
  489.                 break;
  490.         }
  491.         break;
  492.     case "3":
  493.         window.location = "main.asp?lngCategoryID=" + lngCategoryID;
  494.         break;
  495.     case "6":
  496.         // item of the menu is a folder
  497.         window.location = "PublicLibrary.asp?lngCategoryID=" + lngCategoryID;
  498.         break;
  499.  
  500.     case "8":
  501.         window.location = "DisplayNodeList.asp?lngCategoryID=" + lngCategoryID;
  502.         break;
  503.     }
  504. }
  505. //-------------------------------------------------------------------------
  506.  
  507.  
  508. /*-----------------------------------------------------------------
  509.     Loaded the child of the submenus.
  510.     Parameters: 
  511.     Name                Description
  512.     -------------------------------------------------------------------
  513.     obj                    The  object
  514. ------------------------------------------------------------------*/
  515. function loadContextMenuSubRight(obj) {
  516.     //alert();
  517.     var contextMenu;
  518.     var parentMenu;
  519.     parentMenu = returnContainer(obj);
  520.     contextMenu = document.all[obj.id + "Sub"];
  521.     contextMenu.style.display = "block";
  522.  
  523.     var l_contextMenu_Top =  obj.offsetTop + parentMenu.offsetTop;
  524.     contextMenu.style.top = l_contextMenu_Top;
  525.  
  526.     var contextMenuLeft = parentMenu.offsetLeft + parentMenu.offsetWidth - 7;
  527.     var l_WindowWidth = document.body.clientWidth;
  528.     var l_DivWidth = contextMenu.clientWidth;
  529.     //alert("l_WindowWidth = " + l_WindowWidth + " : l_DivWidth + contextMenuLeft = " + eval(l_DivWidth + contextMenuLeft));
  530.     //alert(contextMenuLeft);
  531.     if(l_WindowWidth  < l_DivWidth + contextMenuLeft){
  532.         //alert("l_WindowWidth = " + l_WindowWidth + " : l_DivWidth + contextMenuLeft = " + eval(l_DivWidth + contextMenuLeft));
  533.         contextMenu.style.left = l_WindowWidth - parentMenu.offsetWidth - l_DivWidth;
  534.     }else{
  535.         contextMenu.style.left = contextMenuLeft;
  536.     }
  537.  
  538.     var l_DivHeight = contextMenu.clientHeight;
  539.     //-----Set The div top postion ------------------
  540.     var l_WindowHeight = document.body.clientHeight;
  541.     var l_ScrollTop = document.body.scrollTop;
  542.     //alert(l_WindowHeight);
  543.     //alert(document.body.scrollTop);
  544.  
  545.     if(l_WindowHeight < (l_contextMenu_Top + l_DivHeight) - l_ScrollTop)
  546.         contextMenu.style.top  = l_contextMenu_Top - ((l_contextMenu_Top + l_DivHeight - l_ScrollTop) - l_WindowHeight);
  547.     //-------------------------------------------------
  548.  
  549.  
  550.     contextMenu.parentMenu = parentMenu;
  551.     parentMenu.subMenu = contextMenu;
  552. }
  553.  
  554.  
Feb 19 '09 #1
Share this Question
Share on Google+
1 Reply


Dormilich
Expert Mod 5K+
P: 8,639
Microsoft proprietary syntax does not necessarily work in standard compliant browsers. actually, there are quite a lot of methods and properties that differ between IE and the rest of the world.

have a look at Firefox' Error Console, that should tell you what's going wrong.
Feb 19 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.