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.
 
 
 
 
 

164 rivejä
3.8 KiB

  1. /**
  2. * mctabs.js
  3. *
  4. * Released under LGPL License.
  5. * Copyright (c) 1999-2015 Ephox Corp. All rights reserved
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /*jshint globals: tinyMCEPopup */
  11. function MCTabs() {
  12. this.settings = [];
  13. this.onChange = tinyMCEPopup.editor.windowManager.createInstance('tinymce.util.Dispatcher');
  14. };
  15. MCTabs.prototype.init = function(settings) {
  16. this.settings = settings;
  17. };
  18. MCTabs.prototype.getParam = function(name, default_value) {
  19. var value = null;
  20. value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
  21. // Fix bool values
  22. if (value == "true" || value == "false")
  23. return (value == "true");
  24. return value;
  25. };
  26. MCTabs.prototype.showTab =function(tab){
  27. tab.className = 'current';
  28. tab.setAttribute("aria-selected", true);
  29. tab.setAttribute("aria-expanded", true);
  30. tab.tabIndex = 0;
  31. };
  32. MCTabs.prototype.hideTab =function(tab){
  33. var t=this;
  34. tab.className = '';
  35. tab.setAttribute("aria-selected", false);
  36. tab.setAttribute("aria-expanded", false);
  37. tab.tabIndex = -1;
  38. };
  39. MCTabs.prototype.showPanel = function(panel) {
  40. panel.className = 'current';
  41. panel.setAttribute("aria-hidden", false);
  42. };
  43. MCTabs.prototype.hidePanel = function(panel) {
  44. panel.className = 'panel';
  45. panel.setAttribute("aria-hidden", true);
  46. };
  47. MCTabs.prototype.getPanelForTab = function(tabElm) {
  48. return tinyMCEPopup.dom.getAttrib(tabElm, "aria-controls");
  49. };
  50. MCTabs.prototype.displayTab = function(tab_id, panel_id, avoid_focus) {
  51. var panelElm, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i, t = this;
  52. tabElm = document.getElementById(tab_id);
  53. if (panel_id === undefined) {
  54. panel_id = t.getPanelForTab(tabElm);
  55. }
  56. panelElm= document.getElementById(panel_id);
  57. panelContainerElm = panelElm ? panelElm.parentNode : null;
  58. tabContainerElm = tabElm ? tabElm.parentNode : null;
  59. selectionClass = t.getParam('selection_class', 'current');
  60. if (tabElm && tabContainerElm) {
  61. nodes = tabContainerElm.childNodes;
  62. // Hide all other tabs
  63. for (i = 0; i < nodes.length; i++) {
  64. if (nodes[i].nodeName == "LI") {
  65. t.hideTab(nodes[i]);
  66. }
  67. }
  68. // Show selected tab
  69. t.showTab(tabElm);
  70. }
  71. if (panelElm && panelContainerElm) {
  72. nodes = panelContainerElm.childNodes;
  73. // Hide all other panels
  74. for (i = 0; i < nodes.length; i++) {
  75. if (nodes[i].nodeName == "DIV")
  76. t.hidePanel(nodes[i]);
  77. }
  78. if (!avoid_focus) {
  79. tabElm.focus();
  80. }
  81. // Show selected panel
  82. t.showPanel(panelElm);
  83. }
  84. };
  85. MCTabs.prototype.getAnchor = function() {
  86. var pos, url = document.location.href;
  87. if ((pos = url.lastIndexOf('#')) != -1)
  88. return url.substring(pos + 1);
  89. return "";
  90. };
  91. //Global instance
  92. var mcTabs = new MCTabs();
  93. tinyMCEPopup.onInit.add(function() {
  94. var tinymce = tinyMCEPopup.getWin().tinymce, dom = tinyMCEPopup.dom, each = tinymce.each;
  95. each(dom.select('div.tabs'), function(tabContainerElm) {
  96. //var keyNav;
  97. dom.setAttrib(tabContainerElm, "role", "tablist");
  98. var items = tinyMCEPopup.dom.select('li', tabContainerElm);
  99. var action = function(id) {
  100. mcTabs.displayTab(id, mcTabs.getPanelForTab(id));
  101. mcTabs.onChange.dispatch(id);
  102. };
  103. each(items, function(item) {
  104. dom.setAttrib(item, 'role', 'tab');
  105. dom.bind(item, 'click', function(evt) {
  106. action(item.id);
  107. });
  108. });
  109. dom.bind(dom.getRoot(), 'keydown', function(evt) {
  110. if (evt.keyCode === 9 && evt.ctrlKey && !evt.altKey) { // Tab
  111. //keyNav.moveFocus(evt.shiftKey ? -1 : 1);
  112. tinymce.dom.Event.cancel(evt);
  113. }
  114. });
  115. each(dom.select('a', tabContainerElm), function(a) {
  116. dom.setAttrib(a, 'tabindex', '-1');
  117. });
  118. /*keyNav = tinyMCEPopup.editor.windowManager.createInstance('tinymce.ui.KeyboardNavigation', {
  119. root: tabContainerElm,
  120. items: items,
  121. onAction: action,
  122. actOnFocus: true,
  123. enableLeftRight: true,
  124. enableUpDown: true
  125. }, tinyMCEPopup.dom);*/
  126. });
  127. });