I am looking at code that toggles displaying and hiding a table column.
I am assuming this creates an array:
var States = { };
Why no need for the new operator?
Does this line set the States col element .isOpen property to true?
States[col] = {isOpen : true};
I am figuring out how to modify this function so I can save the state of this column with a cookie. i.e. - when page is rendered, column is set to none by default. However, if the last operation was show column and the page is re-rendered I would like the column to still be open, not go back to default.
The code:
/**************************************************************************
*
* Function: toggleVis
*
* Description: Following Function hides and expands the main column.
*
*
***************************************************************************/
// Set the default "show" mode to that specified by W3C DOM
// compliant browsers
var showMode = 'table-cell';
// However, IE5 at least does not render table cells correctly
// using the style 'table-cell', but does when the style 'block'
// is used, so handle this
if (document.all) showMode='block';
// This is the function that actually does the manipulation
var States = { };
function toggleVis(col){
if (!States[col] || States[col].IsOpen == null)
{
States[col] = {isOpen : true}; // This assumes the cell is already shown
//States[col] = {isOpen : false}; // This assumes the cell is already hidden
}
//mode = States[col].IsOpen ? showMode : 'none';
mode = States[col].IsOpen ? 'none' : showMode; //starts from closed, next click need open
cells = document.getElementsByName(col);
for(j = 0; j < cells.length; j++) cells[j].style.display = mode;
States[col].IsOpen = !States[col].IsOpen;
}