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

📄 dtree.js

📁 尚洋仓库管理系统,对仓库
💻 JS
📖 第 1 页 / 共 4 页
字号:
  return '</DIV>';
}

function dt_openTableSimple(id, spac, padd, styleText, events, add, r) {
   return '<Table id="'+id+'" '+events+' cellspacing='+spac+' cellpadding='+padd+' '+add+' style="'+styleText+'" border=0>'+ (r?'<tr>':'');
}

function dt_closeTable(r) {
  return (r?'</tr>':'') + '</Table>';
}

function dt_createTd(id, styleText, add, html)
{
  return '<td id="'+id+'" '+add+' style="'+pmStyle+styleText+'">'+html+'</td>';
}

function dt_openImg(id, url, w, h, add) {
  return '<img id="'+id+'" src="'+url+'" width='+w+' height='+h+' '+add+' border=0>';
}



function dt_createDX(menu, itVar)
// Creates a space before item
{
  var s='';
  with (itVar)
  {
      var bl = dt_openImg('', tblankImage, dx, 1, '');
      
      for (var k=level; k>=0; k--)
          if (menu.hasPoints && k!=level)
              s += (ptMask.charAt(level-k-1)=='1') ? dt_createTd('', 'background-repeat:repeat-y', 'background="'+menu.pointsImg+'"', bl) : dt_createTd('', '', '', bl);
          else
              s += dt_createTd('', '', '', dt_openImg('', tblankImage, ((k==level)?2:dx), 1, ''));
  }
  return s;
}


function dt_createExpandBtn(menu, itVar)
// Creates [+]-button (expand-button)
{
  with (itVar)
  {
      var s   = '';
      var st  = '';
      var add = 'onMouseDown="dt_BtnClick(\''+id+'\')"';
      
      if (tdynamicTree)                                                            // items can be expanded/collapsed by user
      {
          if (hasChild) add += ' style="cursor:pointer"';
          st = (ptMask.charAt(level)=='2') ? 'background: url('+menu.pointsCImg+') no-repeat' : 'background: url('+menu.pointsImg+') repeat-y';
      }

      var html = dt_openImg(id+'btn', (hasChild ? (expanded ? menu.btns[2] : menu.btns[0]) : tblankImage), menu.btnW, menu.btnH, add);
      s += dt_createTd('', st, '', html);
  }

  s += (menu.btnAlign=="right") ? dt_createDX(menu, itVar) : '';
  return s;
}


function dt_createIcon(menu, itVar)
// Creates item icon
{
  with (itVar)
  {
      if (!icon[0]) return '';
      var pressed = (dt_menu[mInd].pressedItemID==id);
      //if ((!tdynamicTree || expanded || pressed)) alert(text);
      var s = dt_createTd('', '', '', dt_openImg(id+'icon', ((!tdynamicTree || expanded || pressed) ? icon[2] : icon[0]), iconW, iconH, ''));
  }
  return s;
}


function dt_createSpace(menu, itVar, drawPoints)
// Created space within item
{
  return dt_createTd('',
                       'background-repeat:repeat-x;',
                       ((menu.hasPoints && drawPoints && itVar.hasChild) ? 'background="'+menu.pointsVImg+'"' : ''),
                       dt_openImg('', tblankImage, 5, 1, '')
                      );
}


function dt_getItemText(itVar)
// Returns item text within <span> tag.
// It's necessary to create <span> (or other inline tag) because in other case when font style is assigned to <td> IE shows wait-cursor on mouseover/mouseout
{
  with (dt_menu[itVar.mInd])
      with (itVar)
      {
          with (itStyle)
          {
              var pressed = (pressedItemID==id);
              var fColor  = isDisabled ? fntColorDisabled : (pressed ? pressedFontColor : fntColor[0]);
              var s = '<span id="'+id+'font" style="color:'+fColor+';font:'+fntStyle+';font-decoration:'+fntDecor[0]+'">'+text+'</span>';
          }
      }
  return s;
}


function dt_createItemText(menu, itVar)
{
  with (itVar)
  {
      if (!text) return;
      var s = dt_createTd(id+'textTD',
                                'width:100%;',
                                menu.nowrap+' height='+menu.itemH+' align='+align,
                                dt_getItemText(itVar));
  }
  return s;
}


function dt_createXPSubmenu(menu, itVar, disp)
// Creates XP title with or without icon.
// Creates DIV for XP submenu.
{
  with (itVar)
  {
      var prm = '\''+id+'\'';
      
      var s = dt_openTableSimple(id, 0, 0, 'width:100%;cursor:pointer', '', 'title="'+tip+'" onMouseOver="dt_XPTitleChange(this,'+prm+',1)" onMouseOut="dt_XPTitleChange(this,'+prm+',0)" onClick="dt_XPTitleClick('+prm+')"', 0) +
              '<TR style="display:'+disp+'">';


      // HTML of cell with item's text
      var textTD = dt_createTd(id+'textTD',
                                 'width:100%;background:'+xpStyle.xpTitleBackColor+' url('+xpStyle.xpTitleBackImage+') repeat-y',
                                 '',
                                 dt_getItemText(itVar));

      var btnImg = expanded ? xpStyle.xpBtn[2] : xpStyle.xpBtn[0];
      
      
      if (icon[0])                   // XP-title has icon
          s += dt_createTd('', '', 'rowspan=2', dt_openImg('', icon[0], menu.xpIconW, menu.xpIconH, '')) +
               dt_createTd('', 'height:'+(menu.xpIconH-menu.xpBtnH)+'px', 'colspan=2', '') +
               '</TR><TR>' + textTD +
               dt_createTd('', '', '', dt_openImg(id+'btn', btnImg, menu.xpBtnW, menu.xpBtnH, ''));
      else
          s += dt_createTd('', 'height:'+menu.xpBtnH+'px', '', dt_openImg('', xpStyle.xpTitleLeft, xpStyle.xpTitleLeftW, menu.xpBtnH, '')) +
               textTD +
               dt_createTd('', '', '', dt_openImg(id+'btn', btnImg, menu.xpBtnW, menu.xpBtnH, ''));

      s += dt_closeTable(1) +
           // Create submenu DIVs
           dt_openDIV(id+'divXP', 'width:100%;position:relative;overflow:visible;height:auto;' + (expanded ? '' : 'display:none;'), '') +
           dt_openDIV(id+'divXP2','width:100%;height:auto;position:relative;top:0px;left:0px;filter:blendTrans(duration=0.2);', '') +
           dt_openTableSimple(id+'tbl', 0, 0, 'border:solid '+menu.xpBrdWidth+'px '+menu.xpBrdColor+';border-top:none;width:100%;background:'+menu.backColor+' ' + (menu.backImage ? 'url('+menu.backImage+') repeat' : ''), '', '', 0);
    }
  return s;
}


function dt_closeXPSubmenu()
// Closes XP submenu
{
  return dt_closeTable(0) + dt_closeDIV() + dt_closeDIV() +
         dt_openDIV('', 'height:10px;font-size:1px;', '')+dt_closeDIV();      // create space between submenus
}


function dt_openItemsTable(menu)
// Opens items table for standard style (not XP)
{
  return dt_openTableSimple(menu.id+'tbl', 0, 0, 'width:100%;background:'+menu.backColor+' ' + (menu.backImage ? 'url('+menu.backImage+') repeat;' : ''), '', '', 0);
}


function dt_createItem(menu, itVar, disp, newRow)
// Creates standard item
{
  with (itVar)
  {
      var prm = '\''+id+'\'';
      var s = (newRow ? '<TR id="'+id+'TR" style="display:'+disp+'"><TD style="'+pmStyle+'">' : '') +

                  dt_openTableSimple(id, 0, 0, 'cursor:'+cursor+';width:100%;background:'+itStyle.backColor[0]+' ' + (itStyle.backImage[0] ? 'url('+itStyle.backImage[0]+') repeat;' : ''),
                  'title="'+tip+'"', 'onMouseOver="dt_changeItem(this,'+prm+',1)" onMouseOut="dt_changeItem(this,'+prm+',0)" onClick="dt_Click('+prm+')" onContextMenu="return dt_RightClick('+prm+')"', 1) +

                      ((menu.btnAlign!='right')  ? dt_createDX(menu, itVar) + dt_createExpandBtn(menu, itVar) + dt_createSpace(menu, itVar, 1): '') +
                      ((menu.iconAlign!='right') ? dt_createIcon(menu, itVar) + dt_createSpace(menu, itVar, 0) : '') +
                      dt_createItemText(menu, itVar) +
                      ((menu.iconAlign=='right') ? dt_createSpace(menu, itVar, 0) + dt_createIcon(menu, itVar) : '') +
                      ((menu.btnAlign=='right')  ? dt_createSpace(menu, itVar, 1) + dt_createExpandBtn(menu, itVar) + dt_createDX(menu, itVar) : '') +

                  dt_closeTable(1) +
              
              (newRow ? '</TD></TR>' : '');
  }
  return s;
}


function dt_createMoveSpacer(menu)
// Creates move spacer
{
  with (menu)
      var s = dt_openDIV(id+'move',
                           'font-size:1px;width:100%;height:'+moveHeight+'px;background:'+moveClr+' url('+moveImage+') repeat;cursor:move',
                           'onMouseDown="dt_startMoving(event,'+ind+')" onMouseUp="dt_stopMoving(event,'+ind+')"'
                          ) +
              dt_closeDIV();
      
  return s;
}



function dtree_init()
// Initializes the menu
{
    dt_checkGlobalParams();

    // Install the module for external functions
    if (tfloatable || tmoveable) dt_addScript('dtree_add');
    if (tdynamic)   dt_addScript('dtree_dyn');

    with (tcurMenu)
    {
        dt_createMenuParams(ind);
        if (!ind) dt_setOnLoad();
    
        // Saving state parameters
        if (mVar.saveState) dt_loadState(ind);

        dt_parseItemsData();
        if (mVar.hasPoints) dt_detectPointsDraw(mVar, mVar.maxLevel);  // Detect where draw points
        var menu = mVar;
    }

    var s = '';
    var itVar=menu.i[0], prm, disp;

    with (menu)
    {
        // Create main DIV
        s += dt_openDIV(id+'div', 'background:'+backColor+' ' + (backImage ? 'url('+backImage+') repeat' : '') + ';border:'+brdStyle+' '+brdWidth+'px '+brdColor+';' +
                          'width:'+width+';position:'+(absPos ? 'absolute' : 'static')+';height:'+ (height ? height : 'auto') + ';left:'+left+'px;top:'+top+'px;z-index:1000;'+(height ? 'overflow:auto' : ''),
                          '');


        if (moving)     s += dt_createMoveSpacer(menu);
        if (!isXPStyle) s += dt_openItemsTable(menu);


        // Run items
        do
        {
            with (itVar)
                if (isXPStyle)
                {
                    disp = (!isHidden && (isVisible || level<=1)) ? '' : 'none';        // if it isn't a 1-level item => hidden=true
                    if (!level) s += dt_createXPSubmenu(menu, itVar, disp);
                    else        s += dt_createItem(menu, itVar, disp, 1);
                }
                else
                    s += dt_createItem(menu, itVar, ((isVisible && !isHidden) ? '' : 'none'), 1);

            // Close XP submenu
            if (isXPStyle && (!dt_getNextItem(itVar) || dt_getNextItem(itVar).level==0)) s += dt_closeXPSubmenu();

        }
        while ((itVar=dt_getNextItem(itVar)))

        if (!isXPStyle) s += dt_closeTable(0);

        // Close main DIV
        s += dt_closeDIV();
    }


    dtdo.write(s);

    //===regregregregregregregregreg===
         if (isIEPC && isVER<7) dtNag=dt_setNag();
    //===regregregregregregregregreg===
    
    tcurMenu.ind++;
    tcurMenu.curPressedIt = -1;
}


function dt_getItemVarByID(id)
{
  var itVar;
  for (var j=0; j<dt_menu.ln(); j++)
  {
      itVar = dt_menu[j].i[0];
      do
      {
          if (itVar.id==id) return itVar;
      }
      while ((itVar=dt_getNextItem(itVar)))
  }
  return null;
}


//##############################################################################
// XP-style events
//##############################################################################

function dt_Min(v)
{
  return (v<1)?1:v;
}


function dt_AnimExpand(divID, mInd, itInd, inc)
// Animated expand/collapse of XP submenu (called in setInterval)
{
  var menu   = dt_menu[mInd]
  var itVar  = menu.i[itInd];
  var smDIV  = dt_getObjectByID(divID)
  var smDIV2 = dt_getObjectByID(divID+'2')
  var oh     = smDIV2.offsetHeight;
  with (smDIV)
      var h = style.height ? parseInt(style.height) : offsetHeight;


  if (inc==-1)                                   // collapse submenu
  {
      var cond = (h>1);
      h -= dt_Min(( isMAC ? h : h/menu.xpIterations ));
  }
  else                                           // expand submenu
  {
      var cond = (h<oh);
      if (cond) h += dt_Min(( isMAC ? h : (oh-h)/menu.xpIterations ));
      if (h>oh)
      {
          h    = oh;
          cond = 0;
      }
  }


  if (cond)
  {
      smDIV.style.height = h+'px';
      smDIV2.style.top   = h-oh+'px';
  }
  else
  {
      window.clearInterval(itVar.timer);
      itVar.timer=null;
      if (inc==-1) smDIV.style.display = 'none';
      else
          if (isNS && isVER<7) smDIV.style.display = '';
          else
              with (smDIV.style)
              {
                  overflow = 'visible';
                  height='auto';
              }
              
      menu.isBusy--;
  }
}


function dt_Filter(menu, obj, vis, dur)
// Enabled fade filter for XP submenu
{
  with (obj.filters[0])
  {
      duration = dur;
      apply();
      obj.style.visibility = vis;
      play();
  }
}


function dt_getDuration(menu, h)
{
  if (!h) return 0.3;
  var n=1;
  while (h>1)
  {
      h=h/menu.xpIterations;
      n++;
  }
  return 0.15*n;
}


function dt_XPTitleClick(itID, selfCall)
// Start expand/collapse XP submenu
{
  var itVar = dt_getItemVarByID(itID);
  var menu  = dt_menu[itVar.mInd];

  if (!tdynamicTree || itVar.isHidden || itVar.isDeleted) return;

  var an = !(isNS && isVER<7);
  with (itVar)
  {
      if (timer) return;                                                 // if submenu is in expanding/collapsing process
      menu.isBusy++;
      var btnObj = dt_getObjectByID(id+'btn');
      var smDIV  = dt_getObjectByID(id+'divXP');
      var smDIVs = smDIV.style;
      var smDIV2 = dt_getObjectByID(id+'divXP2');
      var f      = (isIE && isVER>=5.5 && menu.xpFilter);

⌨️ 快捷键说明

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