473,396 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help with Dynamic Column Resizing in Firefox

I'm trying to get this iframe to dynamically resize by dragging a vertical bar, but it's not working in Mozilla (It originally worked in IE but I've been trying to port it over). Any help will be appreciated.

Here's the resize.js
Expand|Select|Wrap|Line Numbers
  1. var sResizableElement = "TH"; //Elements to be resized
  2. var iResizeThreshold = 8;
  3. var iEdgeThreshold = 8;
  4. var iSizeThreshold = 20;
  5. var sVBarID = "VBar";
  6.  
  7. var oResizeTarget = null; //position and distance moved
  8. var iStartX = null;
  9. var iEndX = null;
  10. var iSizeX = null;
  11. var oAdjacentCell = null;
  12.  
  13. function TableResize_CreateVBar() //Creates VBar on load
  14. {
  15.     var objItem = document.getElementById(sVBarID);
  16.     //alert(objItem);
  17.  
  18.     if(!objItem)
  19.     {
  20.         objItem = document.createElement("SPAN");
  21.  
  22.  
  23.         objItem.id = sVBarID;
  24.         objItem.style.position = "absolute";
  25.         objItem.style.top = "0px";
  26.         objItem.style.left = "0px";
  27.         objItem.style.height = "0px";
  28.         objItem.style.width = "2px";
  29.         objItem.style.background = "silver";
  30.         objItem.style.borderleft = "1px solid black";
  31.         objItem.style.display = "none";
  32.  
  33.         document.body.appendChild(objItem);
  34.         //alert(objItem);
  35.     }
  36. }
  37.  
  38.  
  39.     window.addEventListener("load", TableResize_CreateVBar,0);
  40.  
  41.  
  42. function TableResize_GetOwnerHeader(objReference) //gets the TH
  43. {
  44.     var oElement = objReference;
  45.     while(oElement != null && oElement.tagName != null && oElement.tagName != "BODY")
  46.     {
  47.         if(oElement.tagName.toUpperCase() == sResizeableElement)
  48.         {
  49.             return oElement; //print alert?
  50.         }
  51.  
  52.         oElement = oElement.parentNode;
  53.         //alert(oElement);
  54.     }
  55.  
  56.     return null;
  57. }
  58.  
  59. function TableResize_GetFirstColumnCell(objTable, iCellIndex)
  60. {
  61.     var oHeaderCell = objTable.rows[0].cells[iCellIndex];
  62.     //alert(oHeaderCell);
  63.     return oHeaderCell; //alert?
  64.  
  65. }
  66.  
  67. function TableResize_CleanUp()
  68. {
  69.     var oVBar = document.getElementById(sVBarID);
  70.  
  71.  
  72.     if(oVBar)
  73.     {
  74.         oVBar.style.display = "none";
  75.     }
  76.  
  77.     iEndX = null;
  78.     iSizeX = null;
  79.     iStartX = null;
  80.     oResizeTarget = null;
  81.     oAdjacentCell = null;
  82.  
  83.     //alert(oVBar);
  84.     return true;
  85. }
  86.  
  87. function TableResize_OnMouseMove(objTable, event)
  88. {
  89.     var objTH = null;
  90.  
  91.     objTH = objTable.createTHead(objTable, event); //creates a new thead or returns the current thead
  92.     //alert(objTH);
  93.  
  94.     if(!objTH)
  95.         return;
  96.  
  97.     var oVBar = document.getElementById(sVBarID);
  98.     //alert(oVBar);
  99.  
  100.     if (!oVBar)
  101.         return;
  102.  
  103.     var oAdjacentCell = objTH.nextSibling;
  104.  
  105.  
  106.     if((event.layerX >= (objTH.offsetWidth - iEdgeThreshold)) && (oAdjacentCell != null))
  107.     {
  108.         objTH.style.cursor = "e-resize"; //find correct property
  109.     }
  110.     else
  111.     {
  112.         if(objTH.style.cursor)
  113.         {
  114.             objTH.style.cursor = objTH.style.cursor;
  115.         }
  116.         else
  117.         {
  118.             objTH.style.cursor = "e-resize";
  119.         }
  120.     }
  121.  
  122.     if(oVBar.style.display == "inline")
  123.     {
  124.         oVBar.style.left = window.event.clientX + document.body.scrollLeft;
  125.         document.selection.empty(); //window.event?
  126.     }
  127. return true
  128. }
  129.  
  130. function TableResize_OnMouseDown(objTable, event)
  131. {
  132.     var oTargetCell = event.target;
  133.     //alert(oTargetCell);
  134.  
  135.     if(!oTargetCell)
  136.         return;
  137.  
  138.     if(oTargetCell.parentNode.tagName.toUpperCase() == sResizableElement)
  139.     {
  140.         oTargetCell = oTargetCell.parentNode;
  141.  
  142.     }
  143.     //alert(objTable);
  144.     var oHeaderCell = TableResize_GetFirstColumnCell(objTable, oTargetCell.cellIndex);
  145.     //alert(oHeaderCell);
  146.  
  147.     if((oHeaderCell.tagName.toUpperCase() == sResizableElement) && (oTargetCell.style.cursor == "e-resize"))
  148.     {
  149.         iStartX = event.screenX;
  150.         oResizeTarget = oHeaderCell;
  151.         objTable.setAttribute("Resizing","true");
  152.         //Set Capture?
  153.  
  154.         oVBar.style.left = event.clientX + document.body.scrollLeft;
  155.         oVBar.style.top = objTable.parentNode.offsetTop + objTable.offsetTop;
  156.         oVBar.style.height = objTable.parentNode.offsetHeight;
  157.         oVBar.style.display = "inline";
  158.     }
  159.     //alert(objTable.offsetTop);
  160.     return true;
  161. }
  162.  
  163. function TableResize_OnMouseUp(objTable, event)
  164. {
  165.     var oAdjacentCell = null;
  166.     var iAdjCellOldWidth = 0;
  167.     var iResizeOldWidth = 0;
  168.  
  169.     if(iStartX != null && oResizeTarget != null)
  170.     {
  171.         iEndX = event.screenX;
  172.         iSizeX = iEndX - iStartX;
  173.  
  174.         objTable.setAttribute("Resizing", "false");
  175.  
  176.         if((oResizeTarget.offsetWidth + iSizeX) >= iSizeThreshold)
  177.         {
  178.             if(Math.abs(iSizeX) >= iResizeThreshold)
  179.             {
  180.                 if(oResizeTarget.nextSibling != null)
  181.                 {
  182.                     oAdjacentCell = oResizeTarget.nextSibling;
  183.                     iAdjCellOldWidth = (oAdjacentCell.offsetWidth);
  184.                 }
  185.                 else
  186.                 {
  187.                     oAdjacentCell = null;
  188.                 }
  189.  
  190.                 iResizeOldWidth = (oResizeTarget.offsetWidth);
  191.                 oResizeTarget.style.width = iResizeOldWidth + iSizeX;
  192.  
  193.                 if((oAdjacentCell != null) && (oAdjacentCell.tagName.toUpperCase() == sResizableElement))
  194.                 {
  195.                     oAdjacentCell.style.width = (((iAdjacentCellOldWidth - iSizeX) >= iSizeThreshold) ? (iAdjCellOldWidth - iSizeX):(oAdjacentCell.style.width = iSizeThreshold))
  196.                 }
  197.             }
  198.         }
  199.         else
  200.         {
  201.             oResizeTarget.style.width = iSizeThreshold;
  202.         }
  203.     }
  204.  
  205.     TableResize_CleanUp();
  206.     return true;
  207.  
  208. }
Here's the HTML:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3.  
  4. <head>
  5. <title>Table Test</title>
  6. <link rel="stylesheet" type="text/css" href="tabletest.css" />
  7. <script type="text/javascript" src="libs/tableresize.js"></script>
  8.  
  9.  
  10. </head>
  11.  
  12. <body>
  13.  
  14.  
  15. <div class="tablecontainer">
  16. <table border="0" cellspacing="0" cellpadding="0" class="mytable"
  17. onmousemove="TableResize_OnMouseMove(this,event);"
  18. onmouseup="TableResize_OnMouseUp(this,event);"
  19. onmousedown="TableResize_OnMouseDown(this,event);">
  20.  
  21. <tr>
  22. <th><iframe id="left_frame" name="left_frame" src=""  frameborder=0 ></iframe></th>
  23. <th><iframe id="right_frame" name="right_frame" src="" frameborder=0 ></iframe></th>
  24. </tr>
  25.  
  26. </table>
  27. </div>
  28.  
  29. </body>
  30. </html>
  31.  
  32.  
May 8 '07 #1
13 4368
pbmods
5,821 Expert 4TB
Heya, bgraphics2031. Welcome to TSDN!

I'm trying to get this iframe to dynamically resize by dragging a vertical bar, but it's not working in Mozilla (It originally worked in IE but I've been trying to port it over). Any help will be appreciated.
What's not working about it?

I've had problems building a drag & drop library that centered around attaching the mousemove event to the window (works) rather than the dragged element (not work so well). Without knowing more about why it's not working, that's about the best I can offer.
May 8 '07 #2
Hi! Thanks for your response. Sorry for not being more specific. In Mozilla (Firefox) I cannot resize the column. It created the vertical bar (VBar) but it doesn't seem to recognize the event that I want to drag the bar? I'm new to JS and looked it up extensively but come to a dead end. Thanks!
May 9 '07 #3
pbmods
5,821 Expert 4TB
It doesn't seem to recognize the event that I want to drag the bar? I'm new to JS and looked it up extensively but come to a dead end.
Here's what I would do:
- Create a textarea somewhere on your page and give it some kind of ID. For the purposes of this example, we'll call it 'debug'.
- In each of your event handlers, call
Expand|Select|Wrap|Line Numbers
  1. document.getElementById('debug').value += 'MOUSEMOVE\n';
  2.  
Or whatnot, depending on which function that line is in.

Then run your script, and you should be able to get an idea of where it stops working based on the text in your textarea.
May 10 '07 #4
Okay, is this what you mean?

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3.  
  4. <head>
  5. <title>Table Test</title>
  6. <link rel="stylesheet" type="text/css" href="tabletest.css" />
  7. <script type="text/javascript" src="libs/libdetect.js"></script>
  8. <script type="text/javascript" src="libs/resize_iframe.js"></script>
  9. <script type="text/javascript" src="libs/tableresize.js"></script>
  10.  
  11.  
  12. </head>
  13.  
  14. <body>
  15.  
  16.  
  17. <div class="tablecontainer">
  18. <table border="0" cellspacing="0" cellpadding="0" class="mytable"
  19. onmousemove="TableResize_OnMouseMove(this, event);document.getElementById('debug').value += 'MOUSEMOVE\n';"
  20. onmouseup="TableResize_OnMouseUp(this, event);document.getElementById('debug').value += 'MOUSEMOVE\n';"
  21. onmousedown="TableResize_OnMouseDown(this, event);document.getElementById('debug').value += 'MOUSEMOVE\n';">
  22.  
  23. <tr>
  24. <th><iframe id="left_frame" name="left_frame" src=""  frameborder=0 onload="resize_iframe()"></iframe></th>
  25. <th><iframe id="right_frame" name="right_frame" src="" frameborder=0 onload="resize_iframe()"></iframe></th>
  26. </tr>
  27.  
  28. </table>
  29. <TEXTAREA NAME="debug" ROWS="10" COLS="40">
  30. Displayed Text
  31. </TEXTAREA>
  32. </div>
  33.  
  34.  
  35.  
  36. </body>
  37. </html>
I just want to make sure I understand correctly what you're saying =)
May 10 '07 #5
pbmods
5,821 Expert 4TB
I just want to make sure I understand correctly what you're saying =)
That looks about right.

When I was debugging my drag-and-drop script, I got:

MOUSEDOWN
MOUSEMOVE
MOUSEUP

I.e., only caught mousemove once, even though it should be firing a few hundred times a second.

If you got a whole buncha MOUSEMOVEs, though, then the problem would probably be either getting the correct coordinates of the mouse event (very much a pain in IE, so should be no problem in FireFox) or setting the position/size of the target elements.
May 10 '07 #6
Yeah, I'm getting a buncha MOUSEMOVEs in the textarea everytime I click on the resizing bar.

I guess this is where I have to drill down and figure out what's not working correctly.

Expand|Select|Wrap|Line Numbers
  1. function TableResize_OnMouseMove(objTable, event)
  2. {
  3.     var objTH = null;
  4.  
  5.     objTH = objTable.createTHead(objTable, event); //creates a new thead or returns the current thead
  6.     //alert(objTH);
  7.  
  8.     if(!objTH)
  9.         return;
  10.  
  11.     var oVBar = document.getElementById(sVBarID);
  12.     //alert(oVBar);
  13.  
  14.     if (!oVBar)
  15.         return;
  16.  
  17.     var oAdjacentCell = objTH.nextSibling;
  18.     //alert(oAdjacentCell);
  19.  
  20.  
  21.     if((event.layerX >= (objTH.offsetWidth - iEdgeThreshold)) && (oAdjacentCell != null))
  22.     {
  23.         document.body.style.cursor = "e-resize"; //find correct property
  24.     }
  25.     else
  26.     {
  27.         if(document.body.style.cursor)
  28.         {
  29.             document.body.style.cursor = document.body.style.cursor;
  30.         }
  31.         else
  32.         {
  33.             document.body.style.cursor = "e-resize";
  34.         }
  35.     }
  36.  
  37.     if(oVBar.style.display == "inline")
  38.     {
  39.          oVBar.style.left = event.clientX + document.body.scrollLeft;
  40.         document.selection.empty(); //window.event?
  41.     }
  42.  
  43. return true
  44. }
May 10 '07 #7
pbmods
5,821 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. if(document.body.style.cursor)
  2.         {
  3.             document.body.style.cursor = document.body.style.cursor;
  4.         }
  5.  
Alright. I give. What's this code do?

Expand|Select|Wrap|Line Numbers
  1.         document.selection.empty(); //window.event?
  2.  
In Firefox / other browsers, use document.body.focus().

Expand|Select|Wrap|Line Numbers
  1. oVBar.style.left = event.clientX + document.body.scrollLeft;
  2.  
Check out this guy:

Expand|Select|Wrap|Line Numbers
  1. mousePosition: function() {
  2.         var x, y;
  3.         if(this.pageX) {
  4.                 x = this.pageX;
  5.                 y = this.pageY;
  6.         } else {
  7.  
  8.             /****************
  9.             //
  10.             //    IE uses clientX, which represents the cursor's position relative to the top-left corner of the browser view... but doesn't take into account how far down the page the User may have scrolled.  Since all other aspects of moving stuff around uses the position from the top left corner of the document OBJECT, this is quite possibly the most useless implementation of mouse event I've ever come across.
  11.             //
  12.             //    But really, I'm not bitter.
  13.             */
  14.             x = this.clientX + document.body.scrollLeft - document.body.clientLeft;
  15.             y = this.clientY + document.body.scrollTop - document.body.clientTop;
  16.         }
  17. .
  18. .
  19. .
  20.  
[EDIT: This function extends an Event object (incidentally, similarly to the way prototype.js does it). You can't modify the Event prototype in some browsers, however, so we have to do it on a per-event basis. But that's why there's a bunch of {this}s and no event argument, if you were curious.]

There's more to this particular function; it then checks for an align property and optionally returns a value relative to a given corner or center of the target element.

But this is the basic code that I use that seems to work in every browser so far.

And yes, I have a LOT of comments like that in my code :)
May 10 '07 #8
If I haven't said, "Thank you pbmods" yet, where are my manners =X You're the only one who's taken an interest in helping me figure this out.

I'm still working out the code trying to make it work in Mozilla, and this is what i have so far with your suggestions:

Expand|Select|Wrap|Line Numbers
  1. var sResizableElement = "TH"; //Elements to be resized
  2. var iResizeThreshold = 8;
  3. var iEdgeThreshold = 8;
  4. var iSizeThreshold = 20;
  5. var sVBarID = "VBar";
  6.  
  7. var oResizeTarget = null; //position and distance moved
  8. var iStartX = null;
  9. var iEndX = null;
  10. var iSizeX = null;
  11. var oAdjacentCell = null;
  12.  
  13. function TableResize_CreateVBar() //Creates VBar on load
  14. {
  15.     var objItem = document.getElementById(sVBarID);
  16.     //alert(objItem);
  17.  
  18.     if(!objItem)
  19.     {
  20.         objItem = document.createElement("SPAN");
  21.  
  22.  
  23.         objItem.id = sVBarID;
  24.         objItem.style.position = "absolute";
  25.         objItem.style.top = "0px";
  26.         objItem.style.left = "0px";
  27.         objItem.style.height = "0px";
  28.         objItem.style.width = "2px";
  29.         objItem.style.background = "silver";
  30.         objItem.style.borderleft = "1px solid black";
  31.         objItem.style.display = "none";
  32.  
  33.         document.body.appendChild(objItem);
  34.         //alert(objItem);
  35.     }
  36. }
  37.  
  38.  
  39.     window.addEventListener("load", TableResize_CreateVBar, 0);
  40.  
  41.  
  42. function TableResize_GetOwnerHeader(objReference) //gets the TH
  43. {
  44.     var oElement = objReference;
  45.     while(oElement != null && oElement.tagName != null && oElement.tagName != "BODY")
  46.     {
  47.         if(oElement.tagName.toUpperCase() == sResizableElement)
  48.         {
  49.             return oElement; //print alert?
  50.         }
  51.  
  52.         oElement = oElement.parentNode;
  53.  
  54.     }
  55.     //alert(oElement);
  56.     return null;
  57. }
  58.  
  59. function TableResize_GetFirstColumnCell(objTable, iCellIndex)
  60. {
  61.     var oHeaderCell = objTable.rows[0].cells[iCellIndex];
  62.     //alert(objTable.rows[0].cells[iCellIndex]);
  63.     return oHeaderCell; //alert?
  64.  
  65. }
  66.  
  67. function TableResize_CleanUp()
  68. {
  69.     var oVBar = document.getElementById(sVBarID);
  70.  
  71.  
  72.     if(oVBar)
  73.     {
  74.         oVBar.style.display = "none";
  75.     }
  76.  
  77.     iEndX = null;
  78.     iSizeX = null;
  79.     iStartX = null;
  80.     oResizeTarget = null;
  81.     oAdjacentCell = null;
  82.  
  83.     //alert(oVBar.style.display);
  84.     return true;
  85. }
  86.  
  87. function TableResize_OnMouseMove(objTable, event)
  88. {
  89.     var objTH = null;
  90.  
  91.     objTH = objTable.createTHead(objTable, event); //creates a new thead or returns the current thead
  92.     //alert(objTH);
  93.  
  94.     if(!objTH)
  95.         return;
  96.  
  97.     var oVBar = document.getElementById(sVBarID);
  98.     //alert(oVBar);
  99.  
  100.     if (!oVBar)
  101.         return;
  102.  
  103.     var oAdjacentCell = objTH.nextSibling;
  104.     //alert(objTH.clientWidth);
  105.  
  106.  
  107.     if((event.layerX >= (objTH.offsetWidth - iEdgeThreshold)) && (oAdjacentCell != null))
  108.     {
  109.         document.body.style.cursor = "e-resize"; //find correct property
  110.     }
  111.     else
  112.     {
  113.  
  114.         document.body.style.cursor = "pointer";
  115.     }
  116.  
  117.     if(oVBar.style.display == "inline")
  118.     {
  119.          oVBar.style.left = event.clientX + document.body.scrollLeft;
  120.         document.body.focus();
  121.     }
  122. //alert(event.clientX + document.body.scrollLeft);
  123. return true
  124. }
  125.  
  126. function TableResize_OnMouseDown(objTable, event)
  127. {
  128.     var oTargetCell = event.currentTarget;
  129.     //alert(oTargetCell);
  130.  
  131.     if(!oTargetCell)
  132.         return;
  133.  
  134.     if(oTargetCell.parentNode.tagName.toUpperCase() == sResizableElement)
  135.     {
  136.         oTargetCell = oTargetCell.parentNode;
  137.  
  138.     }
  139.     //alert(oTargetCell);
  140.     var oHeaderCell = TableResize_GetFirstColumnCell(objTable, oTargetCell.cellIndex);
  141.     //alert(oHeaderCell);
  142.  
  143.     if((oHeaderCell.tagName.toUpperCase() == sResizableElement) && (oTargetCell.style.cursor == "e-resize"))
  144.     {
  145.         iStartX = event.screenX;
  146.         oResizeTarget = oHeaderCell;
  147.         objTable.setAttribute("Resizing","true");
  148.         //Set Capture?
  149.  
  150.         document.getElementById(sVBarID).style.left = document.body.scrollLeft - document.body.clientLeft;
  151.         document.getElementById(sVBarID).style.top = objTable.parentNode.offsetTop + objTable.offsetTop;
  152.         document.getElementById(sVBarID).style.height = objTable.parentNode.offsetHeight;
  153.         document.getElementById(sVBarID).style.display = "inline";
  154.     }
  155.     //alert(document.getElementById(sVBarID).style.display);
  156.     return true;
  157. }
  158.  
  159. function TableResize_OnMouseUp(objTable, event)
  160. {
  161.     var oAdjacentCell = null;
  162.     var iAdjCellOldWidth = 0;
  163.     var iResizeOldWidth = 0;
  164.  
  165.     if(iStartX != null && oResizeTarget != null)
  166.     {
  167.         iEndX = event.screenX;
  168.         iSizeX = iEndX - iStartX;
  169.  
  170.         objTable.setAttribute("Resizing", "false");
  171.  
  172.         if((oResizeTarget.offsetWidth + iSizeX) >= iSizeThreshold)
  173.         {
  174.             if(Math.abs(iSizeX) >= iResizeThreshold)
  175.             {
  176.                 if(oResizeTarget.nextSibling != null)
  177.                 {
  178.                     oAdjacentCell = oResizeTarget.nextSibling;
  179.                     iAdjCellOldWidth = (oAdjacentCell.offsetWidth);
  180.                 }
  181.                 else
  182.                 {
  183.                     oAdjacentCell = null;
  184.                 }
  185.  
  186.                 iResizeOldWidth = (oResizeTarget.offsetWidth);
  187.                 oResizeTarget.style.width = iResizeOldWidth + iSizeX;
  188.  
  189.                 if((oAdjacentCell != null) && (oAdjacentCell.tagName.toUpperCase() == sResizableElement))
  190.                 {
  191.                     oAdjacentCell.style.width = (((iAdjacentCellOldWidth - iSizeX) >= iSizeThreshold) ? (iAdjCellOldWidth - iSizeX):(oAdjacentCell.style.width = iSizeThreshold))
  192.                 }
  193.             }
  194.         }
  195.         else
  196.         {
  197.             oResizeTarget.style.width = iSizeThreshold;
  198.         }
  199.     }
  200.  
  201.     TableResize_CleanUp();
  202.     return true;
  203.  
  204. }
I have more to change, but just wanted to show you that I'm listening to you.
May 10 '07 #9
pbmods here what i've modified since the last post. Can you please take a look at it and tell me if you see anything wrong? It still doesn't work I don't know how it make it work ='(

Expand|Select|Wrap|Line Numbers
  1. var sResizableElement = "TH"; //Elements to be resized
  2. var iResizeThreshold = 8;
  3. var iEdgeThreshold = 8;
  4. var iSizeThreshold = 20;
  5. var sVBarID = "VBar";
  6.  
  7. var oResizeTarget = null; //position and distance moved
  8. var iStartX = null;
  9. var iEndX = null;
  10. var iSizeX = null;
  11. var oAdjacentCell = null;
  12.  
  13. function TableResize_CreateVBar() //Creates VBar on load
  14. {
  15.     var objItem = document.getElementById(sVBarID);
  16.     //alert(objItem);
  17.  
  18.     if(!objItem)
  19.     {
  20.         objItem = document.createElement("SPAN");
  21.  
  22.  
  23.         objItem.id = sVBarID;
  24.         objItem.style.position = "absolute";
  25.         objItem.style.top = "0px";
  26.         objItem.style.left = "0px";
  27.         objItem.style.height = "0px";
  28.         objItem.style.width = "2px";
  29.         objItem.style.background = "silver";
  30.         objItem.style.borderleft = "1px solid black";
  31.         objItem.style.display = "none";
  32.  
  33.         document.body.appendChild(objItem);
  34.         //alert(objItem);
  35.     }
  36. }
  37.  
  38.  
  39.     window.addEventListener("load", TableResize_CreateVBar, 0);
  40.  
  41.  
  42. function TableResize_GetOwnerHeader(objReference) //gets the TH
  43. {
  44.     var oElement = objReference;
  45.     while(oElement != null && oElement.tagName != null && oElement.tagName != "BODY")
  46.     {
  47.         if(oElement.tagName.toUpperCase() == sResizableElement)
  48.         {
  49.             return oElement; //print alert?
  50.         }
  51.  
  52.         oElement = oElement.parentNode;
  53.         //alert(oElement);
  54.  
  55.     }
  56.     //alert(oElement);
  57.     return null;
  58. }
  59.  
  60. function TableResize_GetFirstColumnCell(objTable, cellIndex)
  61. {
  62.     var oHeaderCell = document.body.getElementsByTagName('table')[0].getElementsByTagName('tr')[0].getElementsByTagName('*')[0];
  63.     //var oHeaderCell = objTable.rows[0].cells[0];
  64.     //alert(objTable.cells[cellIndex]);
  65.     //var cellIndex = objTable.rows[0].cells[0];
  66.     //alert(cellIndex);
  67.     return oHeaderCell; //alert?
  68.  
  69. }
  70.  
  71. function TableResize_CleanUp()
  72. {
  73.     var oVBar = document.getElementById(sVBarID);
  74.  
  75.  
  76.     if(oVBar)
  77.     {
  78.         oVBar.style.display = "none";
  79.     }
  80.  
  81.     iEndX = null;
  82.     iSizeX = null;
  83.     iStartX = null;
  84.     oResizeTarget = null;
  85.     oAdjacentCell = null;
  86.  
  87.     //alert(oVBar.style.display);
  88.     return true;
  89. }
  90.  
  91. function TableResize_OnMouseMove(objTable, event)
  92. {
  93.     var objTH = null;
  94.  
  95.     //objTH = TableResize_GetOwnerHeader(objTable, event);
  96.     objTH = objTable.createTHead(objTable, event); //creates a new thead or returns the current thead
  97.     //alert(objTH);
  98.  
  99.     if(!objTH)
  100.         return;
  101.  
  102.     var oVBar = document.getElementById(sVBarID);
  103.     //alert(oVBar);
  104.  
  105.     if (!oVBar)
  106.         return;
  107.  
  108.     var oAdjacentCell = objTH.nextSibling;
  109.     //alert(objTH.clientWidth);
  110.  
  111.  
  112.     if((event.layerX >= (objTH.offsetWidth - iEdgeThreshold)) && (oAdjacentCell != null))
  113.     {
  114.         document.body.style.cursor = "e-resize"; //find correct property
  115.     }
  116.     else
  117.     {
  118.  
  119.         document.body.style.cursor = "pointer";
  120.     }
  121.  
  122.     if(oVBar.style.display == "inline")
  123.     {
  124.          oVBar.style.left = event.clientX + document.body.scrollLeft - document.body.clientLeft;
  125.         document.body.focus();
  126.     }
  127. //alert(event.clientX + document.body.scrollLeft);
  128. return true
  129. }
  130.  
  131. function TableResize_OnMouseDown(objTable, event)
  132. {
  133.     var oTargetCell = event.currentTarget;
  134.     //alert(oTargetCell);
  135.  
  136.     if(!oTargetCell)
  137.         return;
  138.  
  139.     if(oTargetCell.parentNode.tagName.toUpperCase() == sResizableElement)
  140.     {
  141.         oTargetCell = oTargetCell.parentNode;
  142.  
  143.     }
  144.     //alert(oTargetCell);
  145.     var oHeaderCell = TableResize_GetFirstColumnCell(objTable, oTargetCell.cellIndex);
  146.     alert(oTargetCell.cellIndex);
  147.  
  148.     if((oHeaderCell.tagName.toUpperCase() == sResizableElement) && (oTargetCell.style.cursor == "e-resize"))
  149.     {
  150.         iStartX = event.screenX;
  151.         oResizeTarget = oHeaderCell;
  152.         objTable.setAttribute("Resizing","true");
  153.         //Set Capture?
  154.  
  155.         oVBar.style.left = document.body.scrollLeft - document.body.clientLeft;
  156.         oVBar.style.top = objTable.parentNode.offsetTop + objTable.offsetTop;
  157.         oVBar.style.height = objTable.parentNode.offsetHeight;
  158.         oVBar.style.display = "inline";
  159.     }
  160.     //alert(document.body.scrollLeft - document.body.clientLeft);
  161.     return true;
  162. }
  163.  
  164. function TableResize_OnMouseUp(objTable, event)
  165. {
  166.     var oAdjacentCell = null;
  167.     var iAdjCellOldWidth = 0;
  168.     var iResizeOldWidth = 0;
  169.  
  170.     if(iStartX != null && oResizeTarget != null)
  171.     {
  172.         iEndX = event.screenX;
  173.         iSizeX = iEndX - iStartX;
  174.  
  175.         objTable.setAttribute("Resizing", "false");
  176.  
  177.         if((oResizeTarget.offsetWidth + iSizeX) >= iSizeThreshold)
  178.         {
  179.             if(Math.abs(iSizeX) >= iResizeThreshold)
  180.             {
  181.                 if(oResizeTarget.nextSibling != null)
  182.                 {
  183.                     oAdjacentCell = oResizeTarget.nextSibling;
  184.                     iAdjCellOldWidth = (oAdjacentCell.offsetWidth);
  185.                 }
  186.                 else
  187.                 {
  188.                     oAdjacentCell = null;
  189.                 }
  190.  
  191.                 iResizeOldWidth = (oResizeTarget.offsetWidth);
  192.                 oResizeTarget.style.width = iResizeOldWidth + iSizeX;
  193.  
  194.                 if((oAdjacentCell != null) && (oAdjacentCell.tagName.toUpperCase() == sResizableElement))
  195.                 {
  196.                     oAdjacentCell.style.width = (((iAdjacentCellOldWidth - iSizeX) >= iSizeThreshold) ? (iAdjCellOldWidth - iSizeX):(oAdjacentCell.style.width = iSizeThreshold))
  197.                 }
  198.             }
  199.         }
  200.         else
  201.         {
  202.             oResizeTarget.style.width = iSizeThreshold;
  203.         }
  204.     }
  205.  
  206.     TableResize_CleanUp();
  207.     return true;
  208.  
  209. }
May 13 '07 #10
pbmods
5,821 Expert 4TB
Since your debug textarea was showing events properly, the problem must be something about your onmousemove handler.

Expand|Select|Wrap|Line Numbers
  1. function TableResize_OnMouseMove(objTable, event)
  2. {
  3.     var objTH = null;
  4.  
  5.     //objTH = TableResize_GetOwnerHeader(objTable, event);
  6.     objTH = objTable.createTHead(objTable, event); //creates a new thead or returns the current thead
  7.     //alert(objTH);
  8.  
  9.     if(!objTH)
  10.         return;
  11.  
  12.     var oVBar = document.getElementById(sVBarID);
  13.     //alert(oVBar);
  14.  
  15.     if (!oVBar)
  16.         return;
  17.  
  18.     var oAdjacentCell = objTH.nextSibling;
  19.     //alert(objTH.clientWidth);
  20.  
  21.  
  22.     if((event.layerX >= (objTH.offsetWidth - iEdgeThreshold)) && (oAdjacentCell != null))
  23.     {
  24.         document.body.style.cursor = "e-resize"; //find correct property
  25.     }
  26.     else
  27.     {
  28.  
  29.         document.body.style.cursor = "pointer";
  30.     }
  31.  
  32.     if(oVBar.style.display == "inline")
  33.     {
  34.          oVBar.style.left = event.clientX + document.body.scrollLeft - document.body.clientLeft;
  35.         document.body.focus();
  36.     }
  37. //alert(event.clientX + document.body.scrollLeft);
  38. return true
  39. }
Since you're not getting an error, your function must either be returning prematurely, or else it's not changing anything visible.

What I would do to debug this is to continue using that textbox, but output more specific information:

Expand|Select|Wrap|Line Numbers
  1.     
  2.     if(!objTH)
  3.         return;
  4.  
  5.     document.getElementById('debug').value += '\tPASSED objTH\n';
  6.  
  7.     var oVBar = document.getElementById(sVBarID);
  8.     //alert(oVBar);
  9.     
  10.     .
  11.     .
  12.     .
  13.     
  14.     if (!oVBar)
  15.         return;
  16.  
  17.     document.getElementById('debug').value += '\tPASSED oVBar\n';
  18.  
  19.     var oAdjacentCell = objTH.nextSibling;
  20.     //alert(objTH.clientWidth);
  21.     
  22.     .
  23.     .
  24.     .
  25.     {
  26.  
  27.         document.body.style.cursor = "pointer";
  28.     }
  29.  
  30.     var origDisp = oVBar.style.display;
  31.     var origLeft = oVBar.style.left;
  32.  
  33.     if(oVBar.style.display == "inline")
  34.     {
  35.         oVBar.style.left = event.clientX + document.body.scrollLeft - document.body.clientLeft;
  36.         document.body.focus();
  37.     }
  38.  
  39.     document.getElementById('debug').value += '\toVBar is ' + origDisp + '\nLeft was ' + origLeft + ', now ' + oVBar.style.left + '\n';
  40.  
  41. //alert(event.clientX + document.body.scrollLeft);
  42. return true;
  43. }
  44.  
Now all that's to do is to check what shows up in the debug textarea and figure out where your script isn't doing what it's supposed to.
May 13 '07 #11
Since your debug textarea was showing events properly, the problem must be something about your onmousemove handler.



Since you're not getting an error, your function must either be returning prematurely, or else it's not changing anything visible.

What I would do to debug this is to continue using that textbox, but output more specific information:

Now all that's to do is to check what shows up in the debug textarea and figure out where your script isn't doing what it's supposed to.
Thanks a lot pbmods! I think I have it working now, just some minor tweaks are needed. You were a great help to a js newbie like me.
May 14 '07 #12
Thanks a lot pbmods! I think I have it working now, just some minor tweaks are needed. You were a great help to a js newbie like me.
bgraphics2031, can you please share the code that works in FF as well?
I checked your site and http://blogs.crankygoblin.com/blogs/geoff.appleby/archive/2005/02/09/50712.aspx and it may help me if it works in FF too.
Jun 13 '07 #13
dli07
7
bgraphics2031, can you please share the code that works in FF as well?
I checked your site and http://blogs.crankygoblin.com/blogs/geoff.appleby/archive/2005/02/09/50712.aspx and it may help me if it works in FF too.
Yeah, bgraphics2031, it would be great if you could share the final working code. I'm working on a similar project, and this would be very helpful.
Jun 18 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Gord | last post by:
Hello, Anybody know how to detect when a user drags between columns in a MSHFlexGrid when resizing column width? (Short of setting up a timer event that continuously monitors column width.)...
0
by: douglas.gennetten | last post by:
Here's a great example of what I would like to do (Firefox-only): http://www.mozilla.org/docs/dom/samples/resize/index.html But, I'd really like to get a cross-browser solution going, as well...
3
by: bismarkjoe | last post by:
Hello, I am trying to set the widths on the columns of a DataGrid component, and I'm not sure if I'm doing it correctly. My code is below: //load some inital data table = db.GetDataTable(...
0
by: Mark Parter | last post by:
I'm adding a dynamic column to a gridview control at runtime but I'm encountering a problem whereby I can only add 1 item to the column header. The column header should show the date in the...
1
by: Nagaraj | last post by:
Hello All, My Problem: Dynamic column – Example, if there is an Employee details, I should able to add or remove columns very easily. Selected Model: Meta-data model – storing all the values...
8
by: hyejin | last post by:
I have a problem with dynamic iframe and document.close() on Firefox. Below two files create a dynamic iframe by JavaScript. These two samples do not have any problems on IE. But, on Firefox, the...
9
by: dli07 | last post by:
Hello, I'm trying to convert a piece of code that creates a dynamic vertical resizing bar in a table from internet explorer to firefox. It's based on a post from...
0
by: KA NMC | last post by:
I have a dataGrid that is populated by SQL table. The Datagrid has two dynamic columns - that I created to for calculations. I want to sort the grid on frmload by one of the dynamic columns is that...
0
by: DannielHS | last post by:
I think Windows7 is good, but the resizing feature seems to be a little bit limited, including dynamic volume, anyone here could tell other alternative ways!
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.