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.
 
 
 
 
 
 

78 lines
1.8 KiB

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