⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toolbars.js

📁 oa系统的源代码
💻 JS
📖 第 1 页 / 共 2 页
字号:
  //Update state and appearance based on type of button
  switch (element.TBTYPE) {
    case "toggle" :
      if (element.TBSTATE == "checked") {
        element.TBSTATE = "unchecked";
        if (tbMouseOutWhileInOnClick) {
          element.className = "tbButton";
        } else {
          element.className = "tbButtonMouseOverUp";
        }
        image.className = "tbIcon";
      } else {
        element.TBSTATE = "checked";
        if (tbMouseOutWhileInOnClick) {
          element.className = "tbButtonDown";
        } else {
          element.className = "tbButtonMouseOverDown";
        }
        image.className = "tbIconDown";
      }
    break;
      
    case "radio" :
      // Turn this element on if its not already on
      if (element.TBSTATE == "checked"){
        image.className = "tbIconDown";
        break;
      }
      element.TBSTATE = "checked";
      if (tbMouseOutWhileInOnClick) {
        element.className = "tbButtonDown";
      } else {
        element.className = "tbButtonMouseOverDown";
      }
      image.className = "tbIconDown";
    
      // Turn off every other radio button in this group by going through everything in the parent container
      radioButtons = element.parentElement.children;
      for (i=0; i<radioButtons.length; i++) {
        if ((radioButtons[i].NAME == element.NAME) && (radioButtons[i] != element)) {
          radioButtons[i].TBSTATE = "unchecked";
          radioButtons[i].className = "tbButton";
          radioButtons[i].children.tags("IMG")[0].className = "tbIcon";
        }
      }
    break;
    
    default : // Regular button
      if (tbMouseOutWhileInOnClick) {
        element.className = "tbButton";
      } else {
        element.className = "tbButtonMouseOverUp";
      }
      image.className = "tbIcon";
  }
  
  event.cancelBubble=true;
  return false;
  
} // TBButtonMouseUp


// Initialize a toolbar button
function TBInitButton(element, mouseOver) {
  var image;
 
  // Make user-settable properties all lowercase and do a validity check
  if (element.TBTYPE) {
    element.TBTYPE = element.TBTYPE.toLowerCase();
    if ((element.TBTYPE != "toggle") && (element.TBTYPE != "radio")) {
      return TB_E_INVALID_TYPE;
    }
  }
  if (element.TBSTATE) {
    element.TBSTATE = element.TBSTATE.toLowerCase();
    if ((element.TBSTATE != "gray") && (element.TBSTATE != "checked") && (element.TBSTATE != "unchecked")) {
      return TB_E_INVALID_STATE;
    }
  }
 
  image = element.children.tags("IMG")[0]; 

  // Set up all our event handlers
  if (mouseOver) {
    element.onmouseover = TBButtonMouseOver;
    element.onmouseout = TBButtonMouseOut;
  }
  
  element.onmousedown = TBButtonMouseDown; 
  element.onmouseup = TBButtonMouseUp; 
  element.ondragstart = TBCancelEvent;
  element.onselectstart = TBCancelEvent;
  element.onselect = TBCancelEvent;
  element.TBUSERONCLICK = element.onclick; // Save away the original onclick event
  element.onclick = TBCancelEvent;
   
  // Set up initial button state
  if (element.TBSTATE == "gray") {
    element.style.filter = TB_DISABLED_OPACITY_FILTER;
    return TB_STS_OK;
  }
  if (element.TBTYPE == "toggle" || element.TBTYPE == "radio") {
    if (element.TBSTATE == "checked") {
      element.className = "tbButtonDown";
      image.className = "tbIconDown";
    } else {
      element.TBSTATE = "unchecked";
    }
  }
  element.TBINITIALIZED = true;
  return TB_STS_OK;
} // TBInitButton


// Populate a toolbar with the elements within it
function TBPopulateToolbar(tb) {
  var i, elements, s;

  // Iterate through all the top-level elements in the toolbar
  elements = tb.children;
  for (i=0; i<elements.length; i++) {
    if (elements[i].tagName == "SCRIPT" || elements[i].tagName == "!") {
      continue;
    }
    switch (elements[i].className) {
      case "tbButton" :			
        if (elements[i].TBINITIALIZED == null) {
          if ((s = TBInitButton(elements[i], tb.TBTYPE != "nomouseover")) != TB_STS_OK) {
            alert("Problem initializing:" + elements[i].id + " Status:" + s);
            return s;
          }
        }
        elements[i].style.posLeft = tb.TBTOOLBARWIDTH;
        tb.TBTOOLBARWIDTH += elements[i].offsetWidth + 1; 
      break;
       
      case "tbMenu" :
        if (typeof(tbMenu) == "undefined") {
          alert("You need to include tbmenus.js if you want to use menus. See tutorial for details. Element: " + elements[i].id + " has class=tbMenu");
        } else {
          if (elements[i].TBINITIALIZED == null) {
            if ((s = TBInitToolbarMenu(elements[i], tb.TBTYPE != "nomouseover")) != TB_STS_OK) {
               alert("Problem initializing:" + elements[i].id + " Status:" + s);
             return s;
            }
          }
          elements[i].style.posLeft = tb.TBTOOLBARWIDTH;
          tb.TBTOOLBARWIDTH += elements[i].offsetWidth + TB_MENU_BUTTON_PADDING; 
        }
      break;
        
      case "tbGeneral" :
        elements[i].style.posLeft = tb.TBTOOLBARWIDTH;
        tb.TBTOOLBARWIDTH += elements[i].offsetWidth + 1; 
      break;
                
      case "tbSeparator" :
        elements[i].style.posLeft = tb.TBTOOLBARWIDTH + 2;
        tb.TBTOOLBARWIDTH += TB_SEPARATOR_PADDING;
      break;
      
      case "tbHandleDiv":
      break;
 
      default :
        alert("Invalid class: " + elements[i].className + " on Element: " + elements[i].id + " <" + elements[i].tagName + ">");
        return TB_E_INVALID_CLASS;
    }
  }
  return TB_STS_OK;
} // TBPopulateToolbar


// Initialize a toolbar. 
function TBInitToolbar(tb) {
  var s1, tr; 

  // Set up toolbar attributes
  if (tb.TBSTATE) {
    tb.TBSTATE = tb.TBSTATE.toLowerCase();
    if ((tb.TBSTATE != "dockedtop") && (tb.TBSTATE != "dockedbottom") && (tb.TBSTATE != "hidden")) {
      return TB_E_INVALID_STATE;    
    }
  } else {
    tb.TBSTATE = "dockedtop";
  }
  
  if (tb.TBSTATE == "hidden") {
    tb.style.visibility = "hidden";
  }
  
  if (tb.TBTYPE) {
    tb.TBTYPE = tb.TBTYPE.toLowerCase();
    if (tb.TBTYPE != "nomouseover") {
      return TB_E_INVALID_TYPE;    
    }
  }
  
  // Set initial size of toolbar to that of the handle
  tb.TBTOOLBARWIDTH = TB_HANDLE_WIDTH;
    
  // Populate the toolbar with its contents
  if ((s = TBPopulateToolbar(tb)) != TB_STS_OK) {
    return s;
  }
  
  // Set the toolbar width and put in the handle
  tb.style.posWidth = tb.TBTOOLBARWIDTH + TB_TOOLBAR_PADDING;
  tb.insertAdjacentHTML("AfterBegin", TB_HANDLE);
  
  return TB_STS_OK;
} // TBInitToolbar


// Lay out the docked toolbars
function TBLayoutToolbars() {
  var x,y,i;
  
  x = 0; y = 0;
  
  // If no toolbars we're outta here
  if (tbToolbars.length == 0) {
    return;
  }
  
  // Lay out any dockedTop toolbars
  for (i=0; i<tbToolbars.length; i++) {
    if (tbToolbars[i].TBSTATE == "dockedtop") {
      if ((x > 0) && (x + parseInt(tbToolbars[i].TBTOOLBARWIDTH) > document.body.offsetWidth)) {
        x=0; y += tbToolbars[i].offsetHeight;
      }
      tbToolbars[i].style.left = x;
      x += parseInt(tbToolbars[i].TBTOOLBARWIDTH) + TB_TOOLBAR_PADDING;
      tbToolbars[i].style.posTop = y;
    }
  } 

  // Adjust the top of the bodyElement if there were dockedTop toolbars
  if ((x != 0) || (y !=0)) {
    tbContentElementTop = y + tbToolbars[0].offsetHeight + TB_CLIENT_AREA_GAP;
  }
    
  // Lay out any dockedBottom toolbars
  x = 0; y = document.body.clientHeight - tbToolbars[0].offsetHeight;
  for (i=tbToolbars.length - 1; i>=0; i--) {
    if (tbToolbars[i].TBSTATE == "dockedbottom") {
      if ((x > 0) && (x + parseInt(tbToolbars[i].TBTOOLBARWIDTH) > document.body.offsetWidth)) {
        x=0; y -= tbToolbars[i].offsetHeight;
      }
      tbToolbars[i].style.left = x;
      x += parseInt(tbToolbars[i].TBTOOLBARWIDTH) + TB_TOOLBAR_PADDING;
      tbToolbars[i].style.posTop = y;
    }
  }
  
  // Adjust the bottom of the bodyElement if there were dockedBottom toolbars
  if ((x != 0) || (y != (document.body.offsetHeight - tbToolbars[0].offsetHeight))) {
    tbContentElementBottom = document.body.offsetHeight - y + TB_CLIENT_AREA_GAP;
  }
  
  tbLastHeight = 0;
  tbLastWidth = 0;
  
} // TBLayoutToolbars


// Adjust the position and size of the body element and the bottom and right docked toolbars.
function TBLayoutBodyElement() {
  
  tbContentElementObject.style.posTop = tbContentElementTop;
  tbContentElementObject.style.left = 0; 
  tbContentElementObject.style.posHeight =280;
  tbContentElementObject.style.width = document.body.offsetWidth;
  
  // Update y position of any dockedBottom toolbars
  if (tbLastHeight != 0) {
    for (i=tbToolbars.length - 1; i>=0; i--) {
      if (tbToolbars[i].TBSTATE == "dockedbottom" && tbToolbars[i].style.visibility != "hidden") {
        tbToolbars[i].style.posTop += document.body.offsetHeight - tbLastHeight;
      }
    }
  }
  
  tbLastHeight = document.body.offsetHeight;
  tbLastWidth = document.body.offsetWidth;
  
} // TBLayoutBodyElement


// Initialize everything when the document is ready
function document.onreadystatechange() {
  var i, s;
  
  if (TBInitialized) {
    return;
  }
  
  TBInitialized = true;
  
  document.body.scroll = "no";
  
  // Add a <span> that we will use this to measure the contents of menus
  if (typeof(tbMenu) != "undefined") {
    document.body.insertAdjacentHTML("BeforeEnd", "<span ID=TBMenuMeasureSpan></span>");
  }
  
  // Find all the toolbars and initialize them. 
  for (i=0; i<document.body.all.length; i++) {
    if (document.body.all[i].className == "tbToolbar") {
      if ((s = TBInitToolbar(document.body.all[i])) != TB_STS_OK) {
        alert("Toolbar: " + document.body.all[i].id + " failed to initialize. Status: " + s);
      }
      tbToolbars[tbToolbars.length] = document.body.all[i];
    }
  }
  
  // Get rid of the menu measuring span
  if (typeof(tbMenu) != "undefined") {
    document.all["TBMenuMeasureSpan"].outerHTML = "";
  }
  
  // Lay out the page
  TBLayoutToolbars();
  TBLayoutBodyElement();
  
  // Handle all resize events
  window.onresize = TBLayoutBodyElement;
    
  // Grab global mouse events.
  document.onmousedown = TBGlobalMouseDown;
  document.onmousemove = TBGlobalMouseMove;
  document.onmouseup = TBGlobalMouseUp;
  document.ondragstart = TBGlobalStartEvents;
  document.onselectstart = TBGlobalStartEvents;
}


//
// Immediately executed code
//
{
  tbContentElementObject = document.body.all["tbContentElement"];
   
  if (typeof(tbContentElementObject) == "undefined") {
    alert("Error: There must be one element on the page with an ID of tbContentElement");
  }

  if (tbContentElementObject.className != "tbContentElement") {
    alert('Error: tbContentElement must have its class set to "tbContentElement"');
  }
  
  // Add an onmouseover handler to the tbContentElement. We need this for when the DHTML Edting
  // control is the content element. IE doesn't give the toolbars onmouseout events in that case. 
  document.write('<SCRIPT LANGUAGE="JavaScript" FOR="tbContentElement" EVENT="onmouseover"> TBContentElementMouseOver(); </scrip' +'t>');  
  
}

// Rebuild toolbar; call after inserting or deleting items on toolbar.
function TBRebuildToolbar(toolbar, rebuildMenus)
{
  var toolbarFound = false;

  // Add a <span> that we will use this to measure the contents of menus
  if (typeof(tbMenu) != "undefined") {
    document.body.insertAdjacentHTML("BeforeEnd", "<span ID=TBMenuMeasureSpan></span>");
  }

  // Look through existing toolbars and see if we get a match
  for (i=0; i<tbToolbars.length; i++) {
    if (tbToolbars[i].id == toolbar.id) {
      toolbarFound = true;
      break;
    }
  }

  // is this is a new toolbar?
  if (false == toolbarFound) { 	
      // new toolbar, initialize it and add it to toolbar array
    if ((s = TBInitToolbar(toolbar)) != TB_STS_OK) {
      alert("Toolbar: " + toolbar.id + " failed to initialize. Status: " + s);
    }

    // add the new toolbar to the internal toolbar array
    tbToolbars[tbToolbars.length] = toolbar;

  }
  else {

    // Set initial size of toolbar to that of the handle
    toolbar.TBTOOLBARWIDTH = TB_HANDLE_WIDTH;

    for (i=0; i<document.body.all.length; i++) {
      if (document.body.all[i].className == "tbMenu") {
        TBRebuildMenu(document.body.all[i], rebuildMenus);
      }
    }

    // Populate the toolbar with its contents
    if ((s = TBPopulateToolbar(toolbar)) != TB_STS_OK) {
      alert("Toolbar: " + document.body.all[i].id + " failed to populate. Status: " + s);
    }

    // Set the toolbar width and put in the handle
    toolbar.style.posWidth = toolbar.TBTOOLBARWIDTH + TB_TOOLBAR_PADDING;

    if (false == toolbarFound) // new toolbar, add handle
      tb.insertAdjacentHTML("AfterBegin", TB_HANDLE);
  }
 
  // Get rid of the menu measuring span
  if (typeof(tbMenu) != "undefined") {
    document.all["TBMenuMeasureSpan"].outerHTML = "";
  }
   
  // Lay out the page
  TBLayoutToolbars();
  TBLayoutBodyElement();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -