annotate WebContent/jscripts/tiny_mce/utils/mctabs.js @ 20:6629e8422760

half baked version for new JWT auth :-(
author casties
date Fri, 23 Mar 2012 21:41:53 +0100
parents 0be9d53a6967
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
2 * mctabs.js
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
3 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
4 * Copyright 2009, Moxiecode Systems AB
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
5 * Released under LGPL License.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
6 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
7 * License: http://tinymce.moxiecode.com/license
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
8 * Contributing: http://tinymce.moxiecode.com/contributing
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
9 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
10
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
11 function MCTabs() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
12 this.settings = [];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
13 this.onChange = tinyMCEPopup.editor.windowManager.createInstance('tinymce.util.Dispatcher');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
14 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
15
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
16 MCTabs.prototype.init = function(settings) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
17 this.settings = settings;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
18 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
19
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
20 MCTabs.prototype.getParam = function(name, default_value) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
21 var value = null;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
22
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
23 value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
24
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
25 // Fix bool values
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
26 if (value == "true" || value == "false")
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
27 return (value == "true");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
28
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
29 return value;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
30 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
31
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
32 MCTabs.prototype.showTab =function(tab){
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
33 tab.className = 'current';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
34 tab.setAttribute("aria-selected", true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
35 tab.setAttribute("aria-expanded", true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
36 tab.tabIndex = 0;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
37 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
38
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
39 MCTabs.prototype.hideTab =function(tab){
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
40 var t=this;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
41
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
42 tab.className = '';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
43 tab.setAttribute("aria-selected", false);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
44 tab.setAttribute("aria-expanded", false);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
45 tab.tabIndex = -1;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
46 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
47
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
48 MCTabs.prototype.showPanel = function(panel) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
49 panel.className = 'current';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
50 panel.setAttribute("aria-hidden", false);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
51 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
52
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
53 MCTabs.prototype.hidePanel = function(panel) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
54 panel.className = 'panel';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
55 panel.setAttribute("aria-hidden", true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
56 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
57
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
58 MCTabs.prototype.getPanelForTab = function(tabElm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
59 return tinyMCEPopup.dom.getAttrib(tabElm, "aria-controls");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
60 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
61
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
62 MCTabs.prototype.displayTab = function(tab_id, panel_id, avoid_focus) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
63 var panelElm, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i, t = this;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
64
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
65 tabElm = document.getElementById(tab_id);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
66
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
67 if (panel_id === undefined) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
68 panel_id = t.getPanelForTab(tabElm);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
69 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
70
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
71 panelElm= document.getElementById(panel_id);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
72 panelContainerElm = panelElm ? panelElm.parentNode : null;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
73 tabContainerElm = tabElm ? tabElm.parentNode : null;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
74 selectionClass = t.getParam('selection_class', 'current');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
75
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
76 if (tabElm && tabContainerElm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
77 nodes = tabContainerElm.childNodes;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
78
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
79 // Hide all other tabs
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
80 for (i = 0; i < nodes.length; i++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
81 if (nodes[i].nodeName == "LI") {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
82 t.hideTab(nodes[i]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
83 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
84 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
85
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
86 // Show selected tab
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
87 t.showTab(tabElm);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
88 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
89
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
90 if (panelElm && panelContainerElm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
91 nodes = panelContainerElm.childNodes;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
92
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
93 // Hide all other panels
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
94 for (i = 0; i < nodes.length; i++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
95 if (nodes[i].nodeName == "DIV")
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
96 t.hidePanel(nodes[i]);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
97 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
98
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
99 if (!avoid_focus) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
100 tabElm.focus();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
101 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
102
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
103 // Show selected panel
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
104 t.showPanel(panelElm);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
105 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
106 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
107
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
108 MCTabs.prototype.getAnchor = function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
109 var pos, url = document.location.href;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
110
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
111 if ((pos = url.lastIndexOf('#')) != -1)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
112 return url.substring(pos + 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
113
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
114 return "";
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
115 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
116
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
117
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
118 //Global instance
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
119 var mcTabs = new MCTabs();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
120
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
121 tinyMCEPopup.onInit.add(function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
122 var tinymce = tinyMCEPopup.getWin().tinymce, dom = tinyMCEPopup.dom, each = tinymce.each;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
123
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
124 each(dom.select('div.tabs'), function(tabContainerElm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
125 var keyNav;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
126
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
127 dom.setAttrib(tabContainerElm, "role", "tablist");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
128
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
129 var items = tinyMCEPopup.dom.select('li', tabContainerElm);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
130 var action = function(id) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
131 mcTabs.displayTab(id, mcTabs.getPanelForTab(id));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
132 mcTabs.onChange.dispatch(id);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
133 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
134
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
135 each(items, function(item) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
136 dom.setAttrib(item, 'role', 'tab');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
137 dom.bind(item, 'click', function(evt) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
138 action(item.id);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
139 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
140 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
141
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
142 dom.bind(dom.getRoot(), 'keydown', function(evt) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
143 if (evt.keyCode === 9 && evt.ctrlKey && !evt.altKey) { // Tab
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
144 keyNav.moveFocus(evt.shiftKey ? -1 : 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
145 tinymce.dom.Event.cancel(evt);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
146 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
147 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
148
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
149 each(dom.select('a', tabContainerElm), function(a) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
150 dom.setAttrib(a, 'tabindex', '-1');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
151 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
152
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
153 keyNav = tinyMCEPopup.editor.windowManager.createInstance('tinymce.ui.KeyboardNavigation', {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
154 root: tabContainerElm,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
155 items: items,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
156 onAction: action,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
157 actOnFocus: true,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
158 enableLeftRight: true,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
159 enableUpDown: true
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
160 }, tinyMCEPopup.dom);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
161 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
162 });