Mercurial > public > sg101
comparison static/js/tiny_mce/utils/mctabs.js @ 442:6c182ceb7147
Fixing #217; upgrade TinyMCE to 3.4.2 and enable the paste plugin.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 26 May 2011 00:43:49 +0000 |
parents | 88b2b9cb8c1f |
children |
comparison
equal
deleted
inserted
replaced
441:33d0c55e57a9 | 442:6c182ceb7147 |
---|---|
8 * Contributing: http://tinymce.moxiecode.com/contributing | 8 * Contributing: http://tinymce.moxiecode.com/contributing |
9 */ | 9 */ |
10 | 10 |
11 function MCTabs() { | 11 function MCTabs() { |
12 this.settings = []; | 12 this.settings = []; |
13 this.onChange = tinyMCEPopup.editor.windowManager.createInstance('tinymce.util.Dispatcher'); | |
13 }; | 14 }; |
14 | 15 |
15 MCTabs.prototype.init = function(settings) { | 16 MCTabs.prototype.init = function(settings) { |
16 this.settings = settings; | 17 this.settings = settings; |
17 }; | 18 }; |
26 return (value == "true"); | 27 return (value == "true"); |
27 | 28 |
28 return value; | 29 return value; |
29 }; | 30 }; |
30 | 31 |
31 MCTabs.prototype.displayTab = function(tab_id, panel_id) { | 32 MCTabs.prototype.showTab =function(tab){ |
32 var panelElm, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i; | 33 tab.className = 'current'; |
34 tab.setAttribute("aria-selected", true); | |
35 tab.setAttribute("aria-expanded", true); | |
36 tab.tabIndex = 0; | |
37 }; | |
38 | |
39 MCTabs.prototype.hideTab =function(tab){ | |
40 var t=this; | |
41 | |
42 tab.className = ''; | |
43 tab.setAttribute("aria-selected", false); | |
44 tab.setAttribute("aria-expanded", false); | |
45 tab.tabIndex = -1; | |
46 }; | |
47 | |
48 MCTabs.prototype.showPanel = function(panel) { | |
49 panel.className = 'current'; | |
50 panel.setAttribute("aria-hidden", false); | |
51 }; | |
52 | |
53 MCTabs.prototype.hidePanel = function(panel) { | |
54 panel.className = 'panel'; | |
55 panel.setAttribute("aria-hidden", true); | |
56 }; | |
57 | |
58 MCTabs.prototype.getPanelForTab = function(tabElm) { | |
59 return tinyMCEPopup.dom.getAttrib(tabElm, "aria-controls"); | |
60 }; | |
61 | |
62 MCTabs.prototype.displayTab = function(tab_id, panel_id, avoid_focus) { | |
63 var panelElm, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i, t = this; | |
64 | |
65 tabElm = document.getElementById(tab_id); | |
66 | |
67 if (panel_id === undefined) { | |
68 panel_id = t.getPanelForTab(tabElm); | |
69 } | |
33 | 70 |
34 panelElm= document.getElementById(panel_id); | 71 panelElm= document.getElementById(panel_id); |
35 panelContainerElm = panelElm ? panelElm.parentNode : null; | 72 panelContainerElm = panelElm ? panelElm.parentNode : null; |
36 tabElm = document.getElementById(tab_id); | |
37 tabContainerElm = tabElm ? tabElm.parentNode : null; | 73 tabContainerElm = tabElm ? tabElm.parentNode : null; |
38 selectionClass = this.getParam('selection_class', 'current'); | 74 selectionClass = t.getParam('selection_class', 'current'); |
39 | 75 |
40 if (tabElm && tabContainerElm) { | 76 if (tabElm && tabContainerElm) { |
41 nodes = tabContainerElm.childNodes; | 77 nodes = tabContainerElm.childNodes; |
42 | 78 |
43 // Hide all other tabs | 79 // Hide all other tabs |
44 for (i = 0; i < nodes.length; i++) { | 80 for (i = 0; i < nodes.length; i++) { |
45 if (nodes[i].nodeName == "LI") | 81 if (nodes[i].nodeName == "LI") { |
46 nodes[i].className = ''; | 82 t.hideTab(nodes[i]); |
83 } | |
47 } | 84 } |
48 | 85 |
49 // Show selected tab | 86 // Show selected tab |
50 tabElm.className = 'current'; | 87 t.showTab(tabElm); |
51 } | 88 } |
52 | 89 |
53 if (panelElm && panelContainerElm) { | 90 if (panelElm && panelContainerElm) { |
54 nodes = panelContainerElm.childNodes; | 91 nodes = panelContainerElm.childNodes; |
55 | 92 |
56 // Hide all other panels | 93 // Hide all other panels |
57 for (i = 0; i < nodes.length; i++) { | 94 for (i = 0; i < nodes.length; i++) { |
58 if (nodes[i].nodeName == "DIV") | 95 if (nodes[i].nodeName == "DIV") |
59 nodes[i].className = 'panel'; | 96 t.hidePanel(nodes[i]); |
97 } | |
98 | |
99 if (!avoid_focus) { | |
100 tabElm.focus(); | |
60 } | 101 } |
61 | 102 |
62 // Show selected panel | 103 // Show selected panel |
63 panelElm.className = 'current'; | 104 t.showPanel(panelElm); |
64 } | 105 } |
65 }; | 106 }; |
66 | 107 |
67 MCTabs.prototype.getAnchor = function() { | 108 MCTabs.prototype.getAnchor = function() { |
68 var pos, url = document.location.href; | 109 var pos, url = document.location.href; |
71 return url.substring(pos + 1); | 112 return url.substring(pos + 1); |
72 | 113 |
73 return ""; | 114 return ""; |
74 }; | 115 }; |
75 | 116 |
76 // Global instance | 117 |
118 //Global instance | |
77 var mcTabs = new MCTabs(); | 119 var mcTabs = new MCTabs(); |
120 | |
121 tinyMCEPopup.onInit.add(function() { | |
122 var tinymce = tinyMCEPopup.getWin().tinymce, dom = tinyMCEPopup.dom, each = tinymce.each; | |
123 | |
124 each(dom.select('div.tabs'), function(tabContainerElm) { | |
125 var keyNav; | |
126 | |
127 dom.setAttrib(tabContainerElm, "role", "tablist"); | |
128 | |
129 var items = tinyMCEPopup.dom.select('li', tabContainerElm); | |
130 var action = function(id) { | |
131 mcTabs.displayTab(id, mcTabs.getPanelForTab(id)); | |
132 mcTabs.onChange.dispatch(id); | |
133 }; | |
134 | |
135 each(items, function(item) { | |
136 dom.setAttrib(item, 'role', 'tab'); | |
137 dom.bind(item, 'click', function(evt) { | |
138 action(item.id); | |
139 }); | |
140 }); | |
141 | |
142 dom.bind(dom.getRoot(), 'keydown', function(evt) { | |
143 if (evt.keyCode === 9 && evt.ctrlKey && !evt.altKey) { // Tab | |
144 keyNav.moveFocus(evt.shiftKey ? -1 : 1); | |
145 tinymce.dom.Event.cancel(evt); | |
146 } | |
147 }); | |
148 | |
149 each(dom.select('a', tabContainerElm), function(a) { | |
150 dom.setAttrib(a, 'tabindex', '-1'); | |
151 }); | |
152 | |
153 keyNav = tinyMCEPopup.editor.windowManager.createInstance('tinymce.ui.KeyboardNavigation', { | |
154 root: tabContainerElm, | |
155 items: items, | |
156 onAction: action, | |
157 actOnFocus: true, | |
158 enableLeftRight: true, | |
159 enableUpDown: true | |
160 }, tinyMCEPopup.dom); | |
161 }); | |
162 }); |