A QCodo powered CMS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.8 KiB

  1. /**
  2. * $Id: mctabs.js 422 2008-12-12 18:28:35Z erikwinn $
  3. *
  4. * Moxiecode DHTML Tabs script.
  5. *
  6. * @author Moxiecode
  7. * @copyright Copyright 2004-2008, Moxiecode Systems AB, All rights reserved.
  8. */
  9. function MCTabs() {
  10. this.settings = [];
  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, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i;
  25. panelElm= document.getElementById(panel_id);
  26. panelContainerElm = panelElm ? panelElm.parentNode : null;
  27. tabElm = document.getElementById(tab_id);
  28. tabContainerElm = tabElm ? tabElm.parentNode : null;
  29. selectionClass = this.getParam('selection_class', 'current');
  30. if (tabElm && tabContainerElm) {
  31. nodes = tabContainerElm.childNodes;
  32. // Hide all other tabs
  33. for (i = 0; i < nodes.length; i++) {
  34. if (nodes[i].nodeName == "LI")
  35. nodes[i].className = '';
  36. }
  37. // Show selected tab
  38. tabElm.className = 'current';
  39. }
  40. if (panelElm && panelContainerElm) {
  41. nodes = panelContainerElm.childNodes;
  42. // Hide all other panels
  43. for (i = 0; i < nodes.length; i++) {
  44. if (nodes[i].nodeName == "DIV")
  45. nodes[i].className = 'panel';
  46. }
  47. // Show selected panel
  48. panelElm.className = 'current';
  49. }
  50. };
  51. MCTabs.prototype.getAnchor = function() {
  52. var pos, url = document.location.href;
  53. if ((pos = url.lastIndexOf('#')) != -1)
  54. return url.substring(pos + 1);
  55. return "";
  56. };
  57. // Global instance
  58. var mcTabs = new MCTabs();