includes/clientside/static/dropdown.js
changeset 40 723bb7acf914
parent 22 d0314575e2f0
child 57 b354deeaa4c4
equal deleted inserted replaced
39:c83ff194977a 40:723bb7acf914
    30 // Opacity that menus should fade to. 1 to 100 or -1 to disable fades. This only works if the slide effect is also enabled.
    30 // Opacity that menus should fade to. 1 to 100 or -1 to disable fades. This only works if the slide effect is also enabled.
    31 // Default is 100
    31 // Default is 100
    32 var jBox_opacity = 100;
    32 var jBox_opacity = 100;
    33 
    33 
    34 // Adds the jBox CSS to the HTML header. Called on window onload.
    34 // Adds the jBox CSS to the HTML header. Called on window onload.
    35 function jBoxInit()
    35 var jBoxInit = function()
    36 {
    36 {
    37   setTimeout('jBoxBatchSetup();', 200);
    37   setTimeout('jBoxBatchSetup();', 200);
    38 }
    38 }
    39 
    39 
    40 // Initializes each menu.
    40 // Initializes each menu.
    55 // Initializes a div with a jBox menu in it.
    55 // Initializes a div with a jBox menu in it.
    56 function jBoxSetup(obj)
    56 function jBoxSetup(obj)
    57 {
    57 {
    58   $(obj).addClass('menu');
    58   $(obj).addClass('menu');
    59   removeTextNodes(obj);
    59   removeTextNodes(obj);
    60   for ( var i in obj.childNodes )
    60   
       
    61   for ( var i = 0; i < obj.childNodes.length; i++ )
    61   {
    62   {
    62     /* normally this would be done in about 2 lines of code, but javascript is so picky..... */
    63     /* normally this would be done in about 2 lines of code, but javascript is so picky..... */
    63     if ( obj.childNodes[i] )
    64     if ( obj.childNodes[i] )
    64     {
    65     {
    65       if ( obj.childNodes[i].tagName )
    66       if ( obj.childNodes[i].tagName )
    66       {
    67       {
    67         if ( obj.childNodes[i].tagName.toLowerCase() == 'a' )
    68         if ( obj.childNodes[i].tagName == 'A' )
    68         {
    69         {
    69           if ( obj.childNodes[i].nextSibling.tagName )
    70           // if ( is_Safari ) alert('It\'s an A: '+obj);
       
    71           if ( obj.childNodes[i].nextSibling )
    70           {
    72           {
    71             if ( obj.childNodes[i].nextSibling.tagName.toLowerCase() == 'ul' || ( obj.childNodes[i].nextSibling.tagName.toLowerCase() == 'div' && obj.childNodes[i].nextSibling.className == 'submenu' ) )
    73             // alert("Next sibling: " + obj.childNodes[i].nextSibling);
       
    74             if ( obj.childNodes[i].nextSibling.tagName )
    72             {
    75             {
    73               // Calculate height
    76               if ( obj.childNodes[i].nextSibling.tagName == 'UL' || ( obj.childNodes[i].nextSibling.tagName.toLowerCase() == 'div' && obj.childNodes[i].nextSibling.className == 'submenu' ) )
    74               var ul = obj.childNodes[i].nextSibling;
    77               {
    75               domObjChangeOpac(0, ul);
    78                 // Calculate height
    76               ul.style.display = 'block';
    79                 var ul = obj.childNodes[i].nextSibling;
    77               var dim = fetch_dimensions(ul);
    80                 domObjChangeOpac(0, ul);
    78               if ( !ul.id )
    81                 ul.style.display = 'block';
    79                 ul.id = 'jBoxmenuobj_' + Math.floor(Math.random() * 10000000);
    82                 var dim = fetch_dimensions(ul);
    80               jBoxMenuHeights[ul.id] = parseInt(dim['h']) - 2; // subtract 2px for border width
    83                 if ( !ul.id )
    81               ul.style.display = 'none';
    84                   ul.id = 'jBoxmenuobj_' + Math.floor(Math.random() * 10000000);
    82               domObjChangeOpac(100, ul);
    85                 jBoxMenuHeights[ul.id] = parseInt(dim['h']) - 2; // subtract 2px for border width
    83               
    86                 ul.style.display = 'none';
    84               // Setup events
    87                 domObjChangeOpac(100, ul);
    85               obj.childNodes[i].onmouseover = function()  { jBoxOverHandler(this); };
    88                 
    86               obj.childNodes[i].onmouseout = function(e)  { jBoxOutHandler(this, e); };
    89                 // Setup events
    87               obj.childNodes[i].nextSibling.onmouseout = function(e)  { jBoxOutHandler(this, e); };
    90                 obj.childNodes[i].onmouseover = function()  { jBoxOverHandler(this); };
       
    91                 obj.childNodes[i].onmouseout = function(e)  { jBoxOutHandler(this, e); };
       
    92                 obj.childNodes[i].nextSibling.onmouseout = function(e)  { jBoxOutHandler(this, e); };
       
    93               }
    88             }
    94             }
    89           }
    95           }
    90         }
    96         }
    91       }
    97       }
    92     }
    98     }
    94 }
   100 }
    95 
   101 
    96 // Called when user hovers mouse over a submenu
   102 // Called when user hovers mouse over a submenu
    97 function jBoxOverHandler(obj)
   103 function jBoxOverHandler(obj)
    98 {
   104 {
    99   if ( is_Safari )
   105   // if ( is_Safari )
   100     alert('Safari and over');
   106   //   alert('Safari and over');
   101   // Random ID used to track the object to perform on
   107   // Random ID used to track the object to perform on
   102   var seed = Math.floor(Math.random() * 1000000);
   108   var seed = Math.floor(Math.random() * 1000000);
   103   jBoxObjCache[seed] = obj;
   109   jBoxObjCache[seed] = obj;
   104   
   110   
   105   // Sleep for a (little more than a tenth of a) second to see if the user really wants the menu to expand
   111   // Sleep for a (little more than a tenth of a) second to see if the user really wants the menu to expand
   418 
   424 
   419 function removeTextNodes(obj)
   425 function removeTextNodes(obj)
   420 {
   426 {
   421   if(obj)
   427   if(obj)
   422   {
   428   {
   423     if(typeof(obj.tagName) != 'string')
   429     if(typeof(obj.tagName) != 'string' || ( String(obj) == '[object Text]' && is_Safari ) )
   424     {
   430     {
   425       if ( obj.nodeType == 3 && obj.data.match(/^([\s]*)$/ig) ) 
   431       if ( ( obj.nodeType == 3 && obj.data.match(/^([\s]*)$/ig) ) ) //  || ( typeof(obj.innerHTML) == undefined && is_Safari ) ) 
   426       {
   432       {
   427         obj.parentNode.removeChild(obj);
   433         obj.parentNode.removeChild(obj);
   428         return;
   434         return;
   429       }
   435       }
   430     }
   436     }
   431     if(obj.firstChild)
   437     if(obj.firstChild)
   432     {
   438     {
   433       for(var i in obj.childNodes)
   439       for(var i = 0; i < obj.childNodes.length; i++)
   434       {
   440       {
   435         removeTextNodes(obj.childNodes[i]);
   441         removeTextNodes(obj.childNodes[i]);
   436       }
   442       }
   437     }
   443     }
   438   }
   444   }
   441 var getElementsByClassName = function(parent, type, cls) {
   447 var getElementsByClassName = function(parent, type, cls) {
   442   if(!type)
   448   if(!type)
   443     type = '*';
   449     type = '*';
   444   ret = new Array();
   450   ret = new Array();
   445   el = parent.getElementsByTagName(type);
   451   el = parent.getElementsByTagName(type);
   446   for ( var i in el )
   452   for ( var i = 0; i < el.length; i++ )
   447   {
   453   {
   448     if ( typeof(el[i]) != 'object')
   454     if ( typeof(el[i]) != 'object')
   449       continue; // toJSONString() compatibility
   455       continue; // toJSONString() compatibility
   450     if(el[i].className)
   456     if(el[i].className)
   451     {
   457     {