A tumblelog CMS built on AJAX, PHP and MySQL.

mctabs.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * $Id: mctabs.js 162 2007-01-03 16:16:52Z spocke $
  3. *
  4. * Moxiecode DHTML Tabs script.
  5. *
  6. * @author Moxiecode
  7. * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
  8. */
  9. function MCTabs() {
  10. this.settings = new Array();
  11. };
  12. MCTabs.prototype.init = function(settings) {
  13. this.settings = settings;
  14. };
  15. MCTabs.prototype.getParam = function(name, default_value) {
  16. var value = null;
  17. value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
  18. // Fix bool values
  19. if (value == "true" || value == "false")
  20. return (value == "true");
  21. return value;
  22. };
  23. MCTabs.prototype.displayTab = function(tab_id, panel_id) {
  24. var panelElm = document.getElementById(panel_id);
  25. var panelContainerElm = panelElm ? panelElm.parentNode : null;
  26. var tabElm = document.getElementById(tab_id);
  27. var tabContainerElm = tabElm ? tabElm.parentNode : null;
  28. var selectionClass = this.getParam('selection_class', 'current');
  29. if (tabElm && tabContainerElm) {
  30. var nodes = tabContainerElm.childNodes;
  31. // Hide all other tabs
  32. for (var i=0; i<nodes.length; i++) {
  33. if (nodes[i].nodeName == "LI")
  34. nodes[i].className = '';
  35. }
  36. // Show selected tab
  37. tabElm.className = 'current';
  38. }
  39. if (panelElm && panelContainerElm) {
  40. var nodes = panelContainerElm.childNodes;
  41. // Hide all other panels
  42. for (var i=0; i<nodes.length; i++) {
  43. if (nodes[i].nodeName == "DIV")
  44. nodes[i].className = 'panel';
  45. }
  46. // Show selected panel
  47. panelElm.className = 'current';
  48. }
  49. };
  50. MCTabs.prototype.getAnchor = function() {
  51. var pos, url = document.location.href;
  52. if ((pos = url.lastIndexOf('#')) != -1)
  53. return url.substring(pos + 1);
  54. return "";
  55. };
  56. // Global instance
  57. var mcTabs = new MCTabs();