home *** CD-ROM | disk | FTP | other *** search
/ PC World 2004 December / PCWorld_2004-12_cd.bin / software / komercni / netgenium / NETGenium.msi / _B4A5F9DE730F039E0CBFC30C1A8A8467 / _8E6F2A9B58094515B88AC95662CA08AB < prev    next >
Text File  |  2004-10-01  |  5KB  |  154 lines

  1. <PUBLIC:COMPONENT>
  2.     <PUBLIC:ATTACH EVENT="onmousedown" ONEVENT="fnDown()" />
  3.     
  4.     <SCRIPT LANGUAGE="JScript">
  5.     
  6.     function fnDown()
  7.     {
  8.         var o = window.document.elementFromPoint(event.clientX, event.clientY);
  9.         // sometimes IE returns BODY object if element is disabled
  10.         if (o.disabled == false && o.tagName != "BODY")
  11.         {
  12.             if (event.srcElement != element)
  13.             {
  14.                 element.fireEvent("onmousedown");
  15.                 return;
  16.             }
  17.             event.srcElement.ondragstart = fnCancel;
  18.             
  19.             // Get ItemID
  20.             jsDD_MovingItem = jsDD_ActiveItem = element.ItemID;
  21.             
  22.             // Create line
  23.             if (window.document.dragLine2 == null)
  24.             {
  25.                 window.document.dragLine2 = window.document.createElement("HR");
  26.                 window.document.dragLine2.style.position = "absolute";
  27.                 window.document.dragLine2.style.color = "#333333";
  28.                 window.document.dragLine2.style.height = 1;
  29.                 window.document.dragLine2.style.display = "none";
  30.                 window.document.body.insertAdjacentElement("afterBegin", window.document.dragLine2);
  31.             }
  32.             
  33.             // Create window
  34.             if (window.document.dragWindow == null)
  35.             {
  36.                 window.document.dragWindow = window.document.createElement("SPAN");
  37.                 window.document.dragWindow.className = "DragWindow";
  38.                 window.document.body.insertAdjacentElement("afterBegin", window.document.dragWindow);
  39.             }
  40.             window.document.dragWindow.style.height = element.offsetHeight;
  41.             window.document.dragWindow.style.width = element.offsetWidth + 10;
  42.             window.document.dragWindow.move = false;
  43.             element.cY = event.clientY;
  44.             element.cX = event.clientX;
  45.             element.oY = event.offsetY;
  46.             if (element.tagName == "TR") element.oY -= element.cells(0).offsetTop;
  47.             element.oX = event.offsetX + 5;
  48.  
  49.             // Attach events
  50.             if (element.ItemID > 0)
  51.             {
  52.                 window.document.attachEvent("onmousemove", fnMove);
  53.                 window.document.attachEvent("onscroll", fnMove);
  54.             }
  55.             window.document.attachEvent("onmouseup", fnUp);
  56.             window.document.attachEvent("onselectstart", fnCancel);
  57.         }
  58.     }
  59.     
  60.     function fnMove()
  61.     {
  62.         if (!window.document.dragWindow.move && Math.abs(element.cY - event.clientY) < 10 && Math.abs(element.cX - event.clientX) < 10) return;
  63.         window.document.dragWindow.move = true;
  64.         
  65.         // Move window
  66.         window.document.dragWindow.style.top = event.clientY - element.oY + window.document.body.scrollTop;
  67.         window.document.dragWindow.style.left = event.clientX - element.oX + window.document.body.scrollLeft;
  68.         
  69.         // Scroll page if needed
  70.         if (event.clientY > window.document.body.clientHeight - 40 && window.document.body.scrollTop + event.clientY < window.document.body.scrollHeight - 60)
  71.         {
  72.             window.scrollBy(0, 20);
  73.         }
  74.         else if (event.clientY < 40)
  75.         {
  76.             window.scrollBy(0, -20);
  77.         }
  78.         
  79.         // Get table or cell with ItemID attribute
  80.         window.document.dragWindow.style.display = "none";
  81.         var o = window.document.elementFromPoint(event.clientX, event.clientY);
  82.         window.document.dragWindow.style.display = "block";
  83.         
  84.         try
  85.         {
  86.             while (o.ItemID == null) o = o.parentElement;
  87.             jsDD_ActiveItem = o.ItemID;
  88.             
  89.             if (jsDD_MovingItem != jsDD_ActiveItem)
  90.             {
  91.                 var margin = 0;
  92.                 window.document.dragLine2.style.width = o.offsetWidth;
  93.                 if (element.tagName == "TR")
  94.                 {
  95.                     margin = -1;
  96.                     o = o.cells(0);
  97.                 }
  98.                 window.document.dragLine2.style.top = jsMarginTop() + jsOffsetTop(o) + margin;
  99.                 window.document.dragLine2.style.left = jsMarginLeft() + jsOffsetLeft(o);
  100.                 window.document.dragLine2.style.display = "";
  101.             }
  102.             else window.document.dragLine2.style.display = "none";
  103.         }
  104.         catch (e)
  105.         {
  106.             if (element.tagName == "TR") // Set reference to the last item in the table
  107.             {
  108.                 o = element.parentElement.parentElement;
  109.                 if (event.clientY > jsMarginTop() + jsOffsetTop(o, true))
  110.                 {
  111.                     jsDD_ActiveItem = o.rows(o.rows.length - 1).ItemID + 1;
  112.                     window.document.dragLine2.style.width = o.offsetWidth;
  113.                     window.document.dragLine2.style.top = jsMarginTop() + jsOffsetTop(o, true);
  114.                     window.document.dragLine2.style.left = jsMarginLeft() + jsOffsetLeft(o);
  115.                     window.document.dragLine2.style.display = "";
  116.                 }
  117.                 else jsDD_ActiveItem = 0;
  118.             }
  119.             else jsDD_ActiveItem = 0; // Item is a table, unknown element...
  120.         }
  121.     }
  122.     
  123.     function fnUp()
  124.     {
  125.         // Hide line and window
  126.         window.document.dragLine2.style.display = window.document.dragWindow.style.display = "none";
  127.         
  128.         // Detach events
  129.         if (element.ItemID > 0)
  130.         {
  131.             window.document.detachEvent("onmousemove" , fnMove);
  132.             window.document.detachEvent("onscroll" , fnMove);
  133.         }
  134.         window.document.detachEvent("onmouseup" , fnUp);
  135.         window.document.detachEvent("onselectstart", fnCancel);
  136.         
  137.         // Execute
  138.         if (jsDD_MovingItem == jsDD_ActiveItem)
  139.         {
  140.             if (!window.document.dragWindow.move) jsDD_Click(element); // OnClick
  141.         }
  142.         else if (jsDD_ActiveItem != 0)
  143.         {
  144.             jsExecuteDrag(element.Command);
  145.         }
  146.     }
  147.  
  148.     function fnCancel()
  149.     {
  150.         return false;
  151.     }
  152.  
  153.     </SCRIPT>
  154. </PUBLIC:COMPONENT>