Content in the Javascript library assumes a sound understanding of ECMAScript, CSS, XHTML and DOM.

Tabbed Panels

Code listing for tp.js

  1. /*
  2. * date: 2002-10-11
  3. * info: http://inspire.server101.com/js/tp/
  4. */
  5. var tp = [];
  6. var tpl = [];
  7. function tpSet(i, c) {
  8. if (document.createElement) {
  9. var e = document.getElementById(i);
  10. var l = document.createElement('ul');
  11. var p = document.createElement('div');
  12. e.className = l.className = p.className = c;
  13. var a, j;
  14. for (j = 2; j < arguments.length; j++) {
  15. c = document.getElementById(arguments[j]);
  16. tp[arguments[j]] = c.parentNode.removeChild(c);
  17. a = l.appendChild(document.createElement('li'));
  18. a.className = c.className;
  19. tpl[arguments[j]] = a = a.appendChild(document.createElement('a'));
  20. a.setAttribute('href', 'javascript:tpShow(\''+i+'\', \''+arguments[j]+'\');');
  21. a.appendChild(document.createTextNode(c.getAttribute('title')));
  22. }
  23. p.appendChild(tp[arguments[2]]);
  24. tpl[arguments[2]].className = 'active';
  25. while (e.firstChild) e.removeChild(e.firstChild);
  26. e.appendChild(l);
  27. e.appendChild(p);
  28. }}
  29. function tpShow(e, p) {
  30. e = document.getElementById(e).lastChild;
  31. tpl[e.replaceChild(tp[p], e.firstChild).getAttribute('id')].className = null;
  32. tpl[p].className = 'active';
  33. }

function tpSet(i, c)

Sets elements as tabbed panels.

i
String: id of element to contain tabs and panels (tab control).
c
String: class name to be used.
[arguments]
Optional strings: id of each element to create a tabbed panel from.

function tpShow(e, p)

Show (swap) a tabbed panel.

e
String: id of element to contain tabs and panels (tab control).
p
String: id of tab to show.
[ inspire logo ]
Code in the javascript library is free to use. Enjoy! Feedback welcome.
© Ben Boyle 2003.