Line # Revision Author
1 3 ahitrov@rambler.ru /**
2 * mctabs.js
3 *
4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
6 *
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
9 */
10
11 function MCTabs() {
12 this.settings = [];
13 };
14
15 MCTabs.prototype.init = function(settings) {
16 this.settings = settings;
17 };
18
19 MCTabs.prototype.getParam = function(name, default_value) {
20 var value = null;
21
22 value = (typeof(this.settings[name]) == "undefined") ? default_value : this.settings[name];
23
24 // Fix bool values
25 if (value == "true" || value == "false")
26 return (value == "true");
27
28 return value;
29 };
30
31 MCTabs.prototype.displayTab = function(tab_id, panel_id) {
32 var panelElm, panelContainerElm, tabElm, tabContainerElm, selectionClass, nodes, i;
33
34 panelElm= document.getElementById(panel_id);
35 panelContainerElm = panelElm ? panelElm.parentNode : null;
36 tabElm = document.getElementById(tab_id);
37 tabContainerElm = tabElm ? tabElm.parentNode : null;
38 selectionClass = this.getParam('selection_class', 'current');
39
40 if (tabElm && tabContainerElm) {
41 nodes = tabContainerElm.childNodes;
42
43 // Hide all other tabs
44 for (i = 0; i < nodes.length; i++) {
45 if (nodes[i].nodeName == "LI")
46 nodes[i].className = '';
47 }
48
49 // Show selected tab
50 tabElm.className = 'current';
51 }
52
53 if (panelElm && panelContainerElm) {
54 nodes = panelContainerElm.childNodes;
55
56 // Hide all other panels
57 for (i = 0; i < nodes.length; i++) {
58 if (nodes[i].nodeName == "DIV")
59 nodes[i].className = 'panel';
60 }
61
62 // Show selected panel
63 panelElm.className = 'current';
64 }
65 };
66
67 MCTabs.prototype.getAnchor = function() {
68 var pos, url = document.location.href;
69
70 if ((pos = url.lastIndexOf('#')) != -1)
71 return url.substring(pos + 1);
72
73 return "";
74 };
75
76 // Global instance
77 var mcTabs = new MCTabs();