includes/clientside/static/fadefilter.js
author Dan
Mon, 06 Jul 2009 11:27:02 -0400
changeset 1037 61354f877e06
parent 907 44851d7e9bda
child 1053 bdbb49cf6f1b
permissions -rw-r--r--
History: Fixed missing $q in fetchrow()

/**
 * Darkens the browser screen. This will make the entire page un-clickable except for any floating divs created after this is called. Restore with enlighten().
 * @param bool Controls whether the fade should be disabled or not. aclDisableTransitionFX will override this if set to true, and fades are never fired on IE.
 * @param int When specified, represents the numeric opacity value to set the fade layer to. 1-100.
 */

var darkener_index = [];

function darken(nofade, opacVal, layerid)
{
  layerid = ( layerid ) ? layerid : 'specialLayer_darkener';
  if(IE)
    nofade = true;
  if ( !opacVal )
    opacVal = 70;
  darkener_index[layerid] = ( typeof(darkener_index[layerid]) == 'number' ) ? darkener_index[layerid] + 1 : 1;
  if(document.getElementById(layerid) && !document.getElementById(layerid).destroying)
  {
    document.getElementById(layerid).style.zIndex = getHighestZ() + 1;
    if(nofade)
    {
      changeOpac(opacVal, layerid);
      document.getElementById(layerid).style.display = 'block';
      document.getElementById(layerid).myOpacVal = opacVal;
    }
    else
    {
      if ( document.getElementById(layerid).style.display != 'none' )
      {
        var currentOpac = document.getElementById(layerid).myOpacVal;
        opacity(layerid, currentOpac, opacVal, 1000);
        document.getElementById(layerid).myOpacVal = opacVal;
      }
      else
      {
        document.getElementById(layerid).style.display = 'block';
        document.getElementById(layerid).myOpacVal = opacVal;
        opacity(layerid, 0, opacVal, 1000);
      }
    }
  }
  else if(document.getElementById(layerid) && document.getElementById(layerid).destroying)
  {
    // fade in progress - abort
    console.warn('Aborting fade');
    abortFades();
    changeOpac(opacVal, layerid);
    document.getElementById(layerid).destroying = false;
    return document.getElementById(layerid);
  }
  else
  {
    w = getWidth();
    h = getHeight();
    var thediv = document.createElement('div');
    if(IE)
      thediv.style.position = 'absolute';
    else
      thediv.style.position = 'fixed';
    if ( IE )
    {
      var top = getScrollOffset();
      thediv.style.top = String(top) + 'px';
    }
    else
    {
      thediv.style.top = '0px';
    }
    thediv.style.left = '0px';
    thediv.style.opacity = '0';
    thediv.style.filter = 'alpha(opacity=0)';
    thediv.style.backgroundColor = '#000000';
    thediv.style.width =  '100%';
    thediv.style.height = '100%';
    thediv.style.zIndex = getHighestZ() + 1;
    thediv.id = layerid;
    thediv.myOpacVal = opacVal;
    if(nofade)
    {
      thediv.style.opacity = ( parseFloat(opacVal) / 100 );
      thediv.style.filter = 'alpha(opacity=' + opacVal + ')';
      body = document.getElementsByTagName('body');
      body = body[0];
      body.appendChild(thediv);
    } else {
      body = document.getElementsByTagName('body');
      body = body[0];
      body.appendChild(thediv);
      opacity(layerid, 0, opacVal, 1000);
    }
  }
  return document.getElementById(layerid);
}

/**
 * Un-darkens the screen and re-enables clicking of on-screen controls.
 * @param bool If true, disables the fade effect. Fades are always disabled if aclDisableTransitionFX is true and on IE.
 */

function enlighten(nofade, layerid)
{
  layerid = ( layerid ) ? layerid : 'specialLayer_darkener';
  
  if(IE)
    nofade = true;
  darkener_index[layerid] -= 1;
  if ( darkener_index[layerid] > 0 )
    return false;
  if(document.getElementById(layerid))
  {
    if(nofade)
    {
      document.getElementById(layerid).style.display = 'none';
    }
    else
    {
      document.getElementById(layerid).destroying = true;
      var from = document.getElementById(layerid).myOpacVal;
      opacity(layerid, from, 0, 1000);
      setTimeout("var l = document.getElementById('" + layerid + "'); var b = document.getElementsByTagName('body')[0]; b.removeChild(l);", 1000);
    }
  }
  return document.getElementById(layerid);
}