Flip/flop tables

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Flip/flop tables

Post by redhair »

Hi all....it's been a long time..
Eventualy I had to come back for something...

I'm trying to make my cute tables to fold up/down like on this page: http://nhdp.nl/

I managed to gracefully steal the code, and include it into my page,...

But their are just 2 problems remaining.

See http://redhair.nl.nu/news

As you might notice, the menu's are folding great, but here is the catch: The minus image does not get changed to a plus image (..while it is there), and also the cookies dont seem to work (...which will remember the last folding state of a particular menu.).

Here is the javascript:

Code: Select all

function GetCookie(name) {
  var arg=name+"=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i  = 0;
  while (i < clen) &#123;
    var j = i + alen;
    if (document.cookie.substring(i,j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break;
  &#125;
  return null;
&#125;
function getCookieVal (offset) &#123;
   var endstr = document.cookie.indexOf (";", offset);
     if (endstr == 1)
       endstr = document.cookie.length;
     return unescape(document.cookie.substring(offset, endstr));
&#125;
function SetCookie (name, value, expires) &#123;
  var exp = new Date();
  var expiro = (exp.getTime() + (24 * 60 * 60 * 1000 * expires));
  exp.setTime(expiro);
  var expstr = "; expires=" + exp.toGMTString();
  document.cookie = name + "=" + escape(value) + expstr + "; path=/;";
  //  "domain=webmonkey.com;";
&#125;
function DeleteCookie(name)&#123;
  if (GetCookie(name)) &#123;
    document.cookie = name + "=:; expires = Thu, 01-Jan-70 00:00:01 GMT; path=/;";
  &#125;
&#125;
var imagepath = "../img/paneel/";
////////////////////////////////////
blockarray = new Array();
var blockarrayint = -1;
function doblocks(imgpath) &#123;
  if (imgpath != null) imagepath = imgpath;
  for (var q = 0; q < blockarray.length; q++) &#123;
    xyzswitch(blockarray&#1111;q]);
  &#125;
&#125;
function xswitch(listID) &#123;
  if(listID.style.display=="none") &#123;
    listID.style.display="";
  &#125; else &#123;
    listID.style.display="none";
  &#125;
&#125;
function icoswitch(bid) &#123;
  icoID = document.getElementById('pic'+bid);
  if(icoID.src.indexOf("close") != -1) &#123;
    icoID.src = imagepath+"open.png";
    SetCookie('block'+bid,'yes',365);
  &#125; else &#123;
    icoID.src = imagepath+"close.png";
    DeleteCookie('block'+bid);
  &#125;
&#125;
function xyzswitch(bid) &#123;
    xswitch(document.getElementById('pe'+bid));
    xswitch(document.getElementById('ph'+bid));
    icoswitch(bid);
&#125;
function addblock(bid) &#123;
    var blockopen=GetCookie('block'+bid);
    if (blockopen != null) &#123;
        blockarrayint += 1;
        blockarray&#1111;blockarrayint] = bid;
    &#125;
&#125;
////////////////////////////////////
var hiddenblocks = new Array();
var blocks = GetCookie('hiddenblocks');
if (blocks != null) &#123;
  var hidden = blocks.split(":");
  for (var loop = 0; loop < hidden.length; loop++) &#123;
    var hiddenblock = hidden&#1111;loop];
    hiddenblocks&#1111;hiddenblock] = hiddenblock;
  &#125;
&#125;
function blockswitch(bid) &#123;
  var bpe  = document.getElementById('pe'+bid);
  var bph  = document.getElementById('ph'+bid);
  var bico = document.getElementById('pic'+bid);
  if (bpe.style.display=="none") &#123;
    if (bph) &#123; bph.style.display="none"; &#125;
    bpe.style.display="";
    hiddenblocks&#1111;bid] = null;
    bico.src = imagepath+"close.png";
  &#125; else &#123;
    if (bph) &#123; bph.style.display=""; &#125;
    bpe.style.display="none";
    hiddenblocks&#1111;bid] = bid;
    bico.src = imagepath+"open.png";
  &#125;
  var cookie = null;
  for (var q = 0; q < hiddenblocks.length; q++) &#123;
    if (hiddenblocks&#1111;q] != null) &#123;
      if (cookie != null) &#123;
        cookie = (cookie+":"+hiddenblocks&#1111;q]);
      &#125; else &#123;
        cookie = hiddenblocks&#1111;q];
      &#125;
    &#125;
  &#125;
  if (cookie != null) &#123;
    SetCookie('hiddenblocks', cookie, 365);
  &#125; else &#123;
    DeleteCookie('hiddenblocks');
  &#125;
&#125;
Maybe one of you can see the problem....
I am getting rather dizzy..
And I only had 2 beers....
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

I just managed to get the images to change :)

Just the cookie problem left...
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

problem solved
Last edited by redhair on Sat Oct 09, 2004 2:52 pm, edited 1 time in total.
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

Oh btw,..

Here is the solution :)

http://js-x.com/forum/viewtopic.php?t=441

(i just had a great conversation with myself in this topic lol)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

where i come from we use the edit button :P
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

oo yyehh :)
Thanks!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

At least you got it sorted :)

Mac
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

twigletmac wrote:At least you got it sorted :)
Its working sweet :D
Post Reply