-/**
- * $Id: mctabs.js 162 2007-01-03 16:16:52Z spocke $
- *
- * Moxiecode DHTML Tabs script.
- *
- * @author Moxiecode
- * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
- */
-
-function MCTabs() {
- this.settings = new Array();
-};
-
-MCTabs.prototype.init = function(settings) {
- this.settings = settings;
-};
-
-MCTabs.prototype.getParam = function(name, default_value) {
- var value = null;
-
- value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
-
- // Fix bool values
- if (value == "true" || value == "false")
- return (value == "true");
-
- return value;
-};
-
-MCTabs.prototype.displayTab = function(tab_id, panel_id) {
- var panelElm = document.getElementById(panel_id);
- var panelContainerElm = panelElm ? panelElm.parentNode : null;
- var tabElm = document.getElementById(tab_id);
- var tabContainerElm = tabElm ? tabElm.parentNode : null;
- var selectionClass = this.getParam('selection_class', 'current');
-
- if (tabElm && tabContainerElm) {
- var nodes = tabContainerElm.childNodes;
-
- // Hide all other tabs
- for (var i=0; i<nodes.length; i++) {
- if (nodes[i].nodeName == "LI")
- nodes[i].className = '';
- }
-
- // Show selected tab
- tabElm.className = 'current';
- }
-
- if (panelElm && panelContainerElm) {
- var nodes = panelContainerElm.childNodes;
-
- // Hide all other panels
- for (var i=0; i<nodes.length; i++) {
- if (nodes[i].nodeName == "DIV")
- nodes[i].className = 'panel';
- }
-
- // Show selected panel
- panelElm.className = 'current';
- }
-};
-
-MCTabs.prototype.getAnchor = function() {
- var pos, url = document.location.href;
-
- if ((pos = url.lastIndexOf('#')) != -1)
- return url.substring(pos + 1);
-
- return "";
-};
-
-// Global instance
-var mcTabs = new MCTabs();
+/**\r
+ * mctabs.js\r
+ *\r
+ * Copyright 2009, Moxiecode Systems AB\r
+ * Released under LGPL License.\r
+ *\r
+ * License: http://tinymce.moxiecode.com/license\r
+ * Contributing: http://tinymce.moxiecode.com/contributing\r
+ */\r
+\r
+function MCTabs() {\r
+ this.settings = [];\r
+ this.onChange = tinyMCEPopup.editor.windowManager.createInstance('tinymce.util.Dispatcher');\r
+};\r
+\r
+MCTabs.prototype.init = function(settings) {\r
+ this.settings = settings;\r
+};\r
+\r
+MCTabs.prototype.getParam = function(name, default_value) {\r
+ var value = null;\r
+\r
+ value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];\r
+\r
+ // Fix bool values\r
+ if (value == "true" || value == "false")\r
+ return (value == "true");\r
+\r
+ return value;\r
+};\r
+\r
+MCTabs.prototype.showTab =function(tab){\r
+ tab.className = 'current';\r
+ tab.setAttribute("aria-selected", true);\r
+ tab.setAttribute("aria-expanded", true);\r
+ tab.tabIndex = 0;\r
+};\r
+\r
+MCTabs.prototype.hideTab =function(tab){\r
+ var t=this;\r
+\r
+ tab.className = '';\r
+ tab.setAttribute("aria-selected", false);\r
+ tab.setAttribute("aria-expanded", false);\r
+ tab.tabIndex = -1;\r
+};\r
+\r
+MCTabs.prototype.showPanel = function(panel) {\r
+ panel.className = 'current'; \r
+ panel.setAttribute("aria-hidden", false);\r
+};\r
+\r
+MCTabs.prototype.hidePanel = function(panel) {\r
+ panel.className = 'panel';\r
+ panel.setAttribute("aria-hidden", true);\r
+}; \r
+\r
+MCTabs.prototype.getPanelForTab = function(tabElm) {\r
+ return tinyMCEPopup.dom.getAttrib(tabElm, "aria-controls");\r
+};\r
+\r
+MCTabs.prototype.displayTab = function(tab_id, panel_id, avoid_focus) {\r
+ var panelElm, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i, t = this;\r
+\r
+ tabElm = document.getElementById(tab_id);\r
+\r
+ if (panel_id === undefined) {\r
+ panel_id = t.getPanelForTab(tabElm);\r
+ }\r
+\r
+ panelElm= document.getElementById(panel_id);\r
+ panelContainerElm = panelElm ? panelElm.parentNode : null;\r
+ tabContainerElm = tabElm ? tabElm.parentNode : null;\r
+ selectionClass = t.getParam('selection_class', 'current');\r
+\r
+ if (tabElm && tabContainerElm) {\r
+ nodes = tabContainerElm.childNodes;\r
+\r
+ // Hide all other tabs\r
+ for (i = 0; i < nodes.length; i++) {\r
+ if (nodes[i].nodeName == "LI") {\r
+ t.hideTab(nodes[i]);\r
+ }\r
+ }\r
+\r
+ // Show selected tab\r
+ t.showTab(tabElm);\r
+ }\r
+\r
+ if (panelElm && panelContainerElm) {\r
+ nodes = panelContainerElm.childNodes;\r
+\r
+ // Hide all other panels\r
+ for (i = 0; i < nodes.length; i++) {\r
+ if (nodes[i].nodeName == "DIV")\r
+ t.hidePanel(nodes[i]);\r
+ }\r
+\r
+ if (!avoid_focus) { \r
+ tabElm.focus();\r
+ }\r
+\r
+ // Show selected panel\r
+ t.showPanel(panelElm);\r
+ }\r
+};\r
+\r
+MCTabs.prototype.getAnchor = function() {\r
+ var pos, url = document.location.href;\r
+\r
+ if ((pos = url.lastIndexOf('#')) != -1)\r
+ return url.substring(pos + 1);\r
+\r
+ return "";\r
+};\r
+\r
+\r
+//Global instance\r
+var mcTabs = new MCTabs();\r
+\r
+tinyMCEPopup.onInit.add(function() {\r
+ var tinymce = tinyMCEPopup.getWin().tinymce, dom = tinyMCEPopup.dom, each = tinymce.each;\r
+\r
+ each(dom.select('div.tabs'), function(tabContainerElm) {\r
+ var keyNav;\r
+\r
+ dom.setAttrib(tabContainerElm, "role", "tablist"); \r
+\r
+ var items = tinyMCEPopup.dom.select('li', tabContainerElm);\r
+ var action = function(id) {\r
+ mcTabs.displayTab(id, mcTabs.getPanelForTab(id));\r
+ mcTabs.onChange.dispatch(id);\r
+ };\r
+\r
+ each(items, function(item) {\r
+ dom.setAttrib(item, 'role', 'tab');\r
+ dom.bind(item, 'click', function(evt) {\r
+ action(item.id);\r
+ });\r
+ });\r
+\r
+ dom.bind(dom.getRoot(), 'keydown', function(evt) {\r
+ if (evt.keyCode === 9 && evt.ctrlKey && !evt.altKey) { // Tab\r
+ keyNav.moveFocus(evt.shiftKey ? -1 : 1);\r
+ tinymce.dom.Event.cancel(evt);\r
+ }\r
+ });\r
+\r
+ each(dom.select('a', tabContainerElm), function(a) {\r
+ dom.setAttrib(a, 'tabindex', '-1');\r
+ });\r
+\r
+ keyNav = tinyMCEPopup.editor.windowManager.createInstance('tinymce.ui.KeyboardNavigation', {\r
+ root: tabContainerElm,\r
+ items: items,\r
+ onAction: action,\r
+ actOnFocus: true,\r
+ enableLeftRight: true,\r
+ enableUpDown: true\r
+ }, tinyMCEPopup.dom);\r
+ });\r
+});
\ No newline at end of file