4 * Released under LGPL License.
5 * Copyright (c) 1999-2015 Ephox Corp. All rights reserved
7 * License: http://www.tinymce.com/license
8 * Contributing: http://www.tinymce.com/contributing
11 /*jshint globals: tinyMCEPopup */
15 this.onChange = tinyMCEPopup.editor.windowManager.createInstance('tinymce.util.Dispatcher');
18 MCTabs.prototype.init = function(settings) {
19 this.settings = settings;
22 MCTabs.prototype.getParam = function(name, default_value) {
25 value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
28 if (value == "true" || value == "false")
29 return (value == "true");
34 MCTabs.prototype.showTab =function(tab){
35 tab.className = 'current';
36 tab.setAttribute("aria-selected", true);
37 tab.setAttribute("aria-expanded", true);
41 MCTabs.prototype.hideTab =function(tab){
45 tab.setAttribute("aria-selected", false);
46 tab.setAttribute("aria-expanded", false);
50 MCTabs.prototype.showPanel = function(panel) {
51 panel.className = 'current';
52 panel.setAttribute("aria-hidden", false);
55 MCTabs.prototype.hidePanel = function(panel) {
56 panel.className = 'panel';
57 panel.setAttribute("aria-hidden", true);
60 MCTabs.prototype.getPanelForTab = function(tabElm) {
61 return tinyMCEPopup.dom.getAttrib(tabElm, "aria-controls");
64 MCTabs.prototype.displayTab = function(tab_id, panel_id, avoid_focus) {
65 var panelElm, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i, t = this;
67 tabElm = document.getElementById(tab_id);
69 if (panel_id === undefined) {
70 panel_id = t.getPanelForTab(tabElm);
73 panelElm= document.getElementById(panel_id);
74 panelContainerElm = panelElm ? panelElm.parentNode : null;
75 tabContainerElm = tabElm ? tabElm.parentNode : null;
76 selectionClass = t.getParam('selection_class', 'current');
78 if (tabElm && tabContainerElm) {
79 nodes = tabContainerElm.childNodes;
81 // Hide all other tabs
82 for (i = 0; i < nodes.length; i++) {
83 if (nodes[i].nodeName == "LI") {
92 if (panelElm && panelContainerElm) {
93 nodes = panelContainerElm.childNodes;
95 // Hide all other panels
96 for (i = 0; i < nodes.length; i++) {
97 if (nodes[i].nodeName == "DIV")
98 t.hidePanel(nodes[i]);
105 // Show selected panel
106 t.showPanel(panelElm);
110 MCTabs.prototype.getAnchor = function() {
111 var pos, url = document.location.href;
113 if ((pos = url.lastIndexOf('#')) != -1)
114 return url.substring(pos + 1);
121 var mcTabs = new MCTabs();
123 tinyMCEPopup.onInit.add(function() {
124 var tinymce = tinyMCEPopup.getWin().tinymce, dom = tinyMCEPopup.dom, each = tinymce.each;
126 each(dom.select('div.tabs'), function(tabContainerElm) {
129 dom.setAttrib(tabContainerElm, "role", "tablist");
131 var items = tinyMCEPopup.dom.select('li', tabContainerElm);
132 var action = function(id) {
133 mcTabs.displayTab(id, mcTabs.getPanelForTab(id));
134 mcTabs.onChange.dispatch(id);
137 each(items, function(item) {
138 dom.setAttrib(item, 'role', 'tab');
139 dom.bind(item, 'click', function(evt) {
144 dom.bind(dom.getRoot(), 'keydown', function(evt) {
145 if (evt.keyCode === 9 && evt.ctrlKey && !evt.altKey) { // Tab
146 //keyNav.moveFocus(evt.shiftKey ? -1 : 1);
147 tinymce.dom.Event.cancel(evt);
151 each(dom.select('a', tabContainerElm), function(a) {
152 dom.setAttrib(a, 'tabindex', '-1');
155 /*keyNav = tinyMCEPopup.editor.windowManager.createInstance('tinymce.ui.KeyboardNavigation', {
156 root: tabContainerElm,
160 enableLeftRight: true,
162 }, tinyMCEPopup.dom);*/