annotate static/js/tiny_mce/utils/mctabs.js @ 1164:68811c583bfb

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